mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-18 23:11:49 +00:00
parent
757e95dd18
commit
9f206af083
2 changed files with 13 additions and 33 deletions
|
@ -81,18 +81,14 @@ show_adb_installation_msg() {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
||||||
size_t n_args, len;
|
char buf[512];
|
||||||
char *buf = NULL;
|
|
||||||
len = xargvlen(argv, &n_args) + (n_args * 3 - 1) + 1;
|
|
||||||
/* buffer large enough to store argv_to_string repr + nul terminator */
|
|
||||||
buf = malloc(len);
|
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case PROCESS_ERROR_GENERIC:
|
case PROCESS_ERROR_GENERIC:
|
||||||
argv_to_string(argv, buf, len);
|
argv_to_string(argv, buf, sizeof(buf));
|
||||||
LOGE("Failed to execute: %s", buf);
|
LOGE("Failed to execute: %s", buf);
|
||||||
break;
|
break;
|
||||||
case PROCESS_ERROR_MISSING_BINARY:
|
case PROCESS_ERROR_MISSING_BINARY:
|
||||||
argv_to_string(argv, buf, len);
|
argv_to_string(argv, buf, sizeof(buf));
|
||||||
LOGE("Command not found: %s", buf);
|
LOGE("Command not found: %s", buf);
|
||||||
LOGE("(make 'adb' accessible from your PATH or define its full"
|
LOGE("(make 'adb' accessible from your PATH or define its full"
|
||||||
"path in the ADB environment variable)");
|
"path in the ADB environment variable)");
|
||||||
|
@ -102,7 +98,6 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
||||||
// do nothing
|
// do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
|
|
|
@ -6,11 +6,6 @@
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/str_util.h"
|
#include "util/str_util.h"
|
||||||
|
|
||||||
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
|
|
||||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
build_cmd(char *cmd, size_t len, const char *const argv[]) {
|
build_cmd(char *cmd, size_t len, const char *const argv[]) {
|
||||||
// Windows command-line parsing is WTF:
|
// Windows command-line parsing is WTF:
|
||||||
|
@ -29,44 +24,34 @@ enum process_result
|
||||||
process_execute(const char *const argv[], HANDLE *handle) {
|
process_execute(const char *const argv[], HANDLE *handle) {
|
||||||
STARTUPINFOW si;
|
STARTUPINFOW si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
wchar_t *wide = NULL;
|
|
||||||
char *cmd = NULL;
|
|
||||||
enum process_result res = PROCESS_SUCCESS;
|
|
||||||
size_t len = xargvlen(argv, NULL) + 1;
|
|
||||||
memset(&si, 0, sizeof(si));
|
memset(&si, 0, sizeof(si));
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
|
|
||||||
cmd = malloc(len);
|
char cmd[256];
|
||||||
if (cmd == NULL || build_cmd(cmd, len, argv) != 0) {
|
if (build_cmd(cmd, sizeof(cmd), argv)) {
|
||||||
*handle = NULL;
|
*handle = NULL;
|
||||||
res = PROCESS_ERROR_GENERIC;
|
return PROCESS_ERROR_GENERIC;
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wide = utf8_to_wide_char(cmd);
|
wchar_t *wide = utf8_to_wide_char(cmd);
|
||||||
if (!wide) {
|
if (!wide) {
|
||||||
LOGC("Could not allocate wide char string");
|
LOGC("Could not allocate wide char string");
|
||||||
res = PROCESS_ERROR_GENERIC;
|
return PROCESS_ERROR_GENERIC;
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, 0, NULL, NULL, &si,
|
if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, 0, NULL, NULL, &si,
|
||||||
&pi)) {
|
&pi)) {
|
||||||
|
free(wide);
|
||||||
*handle = NULL;
|
*handle = NULL;
|
||||||
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
|
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
|
||||||
res = PROCESS_ERROR_MISSING_BINARY;
|
return PROCESS_ERROR_MISSING_BINARY;
|
||||||
} else {
|
|
||||||
res = PROCESS_ERROR_GENERIC;
|
|
||||||
}
|
}
|
||||||
goto end;
|
return PROCESS_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = pi.hProcess;
|
|
||||||
|
|
||||||
end:
|
|
||||||
free(wide);
|
free(wide);
|
||||||
free(cmd);
|
*handle = pi.hProcess;
|
||||||
return res;
|
return PROCESS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue