mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 06:39:39 +00:00
Pushing via SCP.
This commit is contained in:
parent
5d4016f16c
commit
a424a83d95
3 changed files with 63 additions and 3 deletions
|
@ -102,6 +102,24 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_t
|
||||||
|
scp_execute(const char *const scp_cmd[], size_t len) {
|
||||||
|
const char *cmd[len + 2];
|
||||||
|
unsigned i = 0;
|
||||||
|
process_t process;
|
||||||
|
|
||||||
|
cmd[i++] = "scp";
|
||||||
|
memcpy(&cmd[i], scp_cmd, len * sizeof(const char *));
|
||||||
|
i += len;
|
||||||
|
cmd[i] = NULL;
|
||||||
|
enum process_result r = cmd_execute(cmd, &process);
|
||||||
|
if (r != PROCESS_SUCCESS) {
|
||||||
|
show_adb_err_msg(r, cmd);
|
||||||
|
return PROCESS_NONE;
|
||||||
|
}
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
||||||
const char *const ssh_options[], size_t ssh_options_len) {
|
const char *const ssh_options[], size_t ssh_options_len) {
|
||||||
|
@ -186,6 +204,38 @@ adb_reverse_remove(const char *serial, const char *device_socket_name) {
|
||||||
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_t
|
||||||
|
ssh_push(const char *endpoint, const char *local, const char *remote) {
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
// Windows will parse the string, so the paths must be quoted
|
||||||
|
// (see sys/win/command.c)
|
||||||
|
local = strquote(local);
|
||||||
|
if (!local) {
|
||||||
|
return PROCESS_NONE;
|
||||||
|
}
|
||||||
|
remote = strquote(remote);
|
||||||
|
if (!remote) {
|
||||||
|
SDL_free((void *) local);
|
||||||
|
return PROCESS_NONE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char * destination = (char *) SDL_malloc(strlen(remote) + strlen(endpoint) + 2);
|
||||||
|
strcpy(destination, endpoint);
|
||||||
|
strcat(destination, ":");
|
||||||
|
strcat(destination, remote);
|
||||||
|
const char *const scp_cmd[] = {local, destination};
|
||||||
|
process_t proc = scp_execute(scp_cmd, ARRAY_LEN(scp_cmd));
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
SDL_free((void *) remote);
|
||||||
|
SDL_free((void *) local);
|
||||||
|
#endif
|
||||||
|
SDL_free((void *) destination);
|
||||||
|
|
||||||
|
return proc;
|
||||||
|
}
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
adb_push(const char *serial, const char *local, const char *remote) {
|
adb_push(const char *serial, const char *local, const char *remote) {
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
|
@ -57,6 +57,9 @@ cmd_terminate(process_t pid);
|
||||||
bool
|
bool
|
||||||
cmd_simple_wait(process_t pid, exit_code_t *exit_code);
|
cmd_simple_wait(process_t pid, exit_code_t *exit_code);
|
||||||
|
|
||||||
|
process_t
|
||||||
|
scp_execute(const char *const ssh_cmd[], size_t len);
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
||||||
const char *const ssh_options[], size_t ssh_options_len);
|
const char *const ssh_options[], size_t ssh_options_len);
|
||||||
|
@ -78,6 +81,9 @@ adb_reverse(const char *serial, const char *device_socket_name,
|
||||||
process_t
|
process_t
|
||||||
adb_reverse_remove(const char *serial, const char *device_socket_name);
|
adb_reverse_remove(const char *serial, const char *device_socket_name);
|
||||||
|
|
||||||
|
process_t
|
||||||
|
ssh_push(const char *endpoint, const char *local, const char *remote);
|
||||||
|
|
||||||
process_t
|
process_t
|
||||||
adb_push(const char *serial, const char *local, const char *remote);
|
adb_push(const char *serial, const char *local, const char *remote);
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ get_server_path(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
push_server(const char *serial) {
|
push_server(const char *serial, const struct server_params *params) {
|
||||||
char *server_path = get_server_path();
|
char *server_path = get_server_path();
|
||||||
if (!server_path) {
|
if (!server_path) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -99,7 +99,11 @@ push_server(const char *serial) {
|
||||||
SDL_free(server_path);
|
SDL_free(server_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH);
|
process_t process;
|
||||||
|
if (params->use_ssh)
|
||||||
|
process = ssh_push(params->ssh_endpoint, server_path, DEVICE_SERVER_PATH);
|
||||||
|
else
|
||||||
|
process = adb_push(serial, server_path, DEVICE_SERVER_PATH);
|
||||||
SDL_free(server_path);
|
SDL_free(server_path);
|
||||||
return process_check_success(process, "adb push");
|
return process_check_success(process, "adb push");
|
||||||
}
|
}
|
||||||
|
@ -444,7 +448,7 @@ server_start(struct server *server, const char *serial,
|
||||||
|
|
||||||
server->use_ssh = params->use_ssh;
|
server->use_ssh = params->use_ssh;
|
||||||
|
|
||||||
if (!push_server(serial)) {
|
if (!push_server(serial, params)) {
|
||||||
goto error1;
|
goto error1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue