Support wchar_t in argv for Windows
PR #3547 <https://github.com/Genymobile/scrcpy/pull/3547> Fixes #2932 <https://github.com/Genymobile/scrcpy/issues/2932> Signed-off-by: Yu-Chen Lin <npes87184@gmail.com> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
d71587e39b
commit
48bb6f2ea8
1 changed files with 55 additions and 2 deletions
|
@ -4,6 +4,10 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include "util/str.h"
|
||||||
|
#endif
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
# include <libavdevice/avdevice.h>
|
# include <libavdevice/avdevice.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,8 +22,8 @@
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main_scrcpy(int argc, char *argv[]) {
|
||||||
#ifdef __WINDOWS__
|
#ifdef _WIN32
|
||||||
// disable buffering, we want logs immediately
|
// disable buffering, we want logs immediately
|
||||||
// even line buffering (setvbuf() with mode _IOLBF) is not sufficient
|
// even line buffering (setvbuf() with mode _IOLBF) is not sufficient
|
||||||
setbuf(stdout, NULL);
|
setbuf(stdout, NULL);
|
||||||
|
@ -80,3 +84,52 @@ main(int argc, char *argv[]) {
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[]) {
|
||||||
|
#ifndef _WIN32
|
||||||
|
return main_scrcpy(argc, argv);
|
||||||
|
#else
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
int wargc;
|
||||||
|
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
|
||||||
|
if (!wargv) {
|
||||||
|
LOG_OOM();
|
||||||
|
return SCRCPY_EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char **argv_utf8 = malloc((wargc + 1) * sizeof(*argv_utf8));
|
||||||
|
if (!argv_utf8) {
|
||||||
|
LOG_OOM();
|
||||||
|
LocalFree(wargv);
|
||||||
|
return SCRCPY_EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
argv_utf8[wargc] = NULL;
|
||||||
|
|
||||||
|
for (int i = 0; i < wargc; ++i) {
|
||||||
|
argv_utf8[i] = sc_str_from_wchars(wargv[i]);
|
||||||
|
if (!argv_utf8[i]) {
|
||||||
|
LOG_OOM();
|
||||||
|
for (int j = 0; j < i; ++j) {
|
||||||
|
free(argv_utf8[j]);
|
||||||
|
}
|
||||||
|
LocalFree(wargv);
|
||||||
|
free(argv_utf8);
|
||||||
|
return SCRCPY_EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalFree(wargv);
|
||||||
|
|
||||||
|
int ret = main_scrcpy(wargc, argv_utf8);
|
||||||
|
|
||||||
|
for (int i = 0; i < wargc; ++i) {
|
||||||
|
free(argv_utf8[i]);
|
||||||
|
}
|
||||||
|
free(argv_utf8);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue