diff --git a/README.md b/README.md index dbc92e8a..25d600c3 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,11 @@ _scrcpy_ window. There is no visual feedback, a log is printed to the console. +The target directory can be changed on start: + +```bash +scrcpy --push-target /sdcard/foo/bar/ +``` ### Read-only diff --git a/app/src/device.h b/app/src/device.h index f3449e5e..828443d7 100644 --- a/app/src/device.h +++ b/app/src/device.h @@ -7,7 +7,6 @@ #include "net.h" #define DEVICE_NAME_FIELD_LENGTH 64 -#define DEVICE_SDCARD_PATH "/sdcard/" // name must be at least DEVICE_NAME_FIELD_LENGTH bytes bool diff --git a/app/src/file_handler.c b/app/src/file_handler.c index ec53faae..e02ca2a9 100644 --- a/app/src/file_handler.c +++ b/app/src/file_handler.c @@ -5,17 +5,19 @@ #include "config.h" #include "command.h" -#include "device.h" #include "lock_util.h" #include "log.h" +#define DEFAULT_PUSH_TARGET "/sdcard/" + static void file_handler_request_destroy(struct file_handler_request *req) { SDL_free(req->file); } bool -file_handler_init(struct file_handler *file_handler, const char *serial) { +file_handler_init(struct file_handler *file_handler, const char *serial, + const char *push_target) { cbuf_init(&file_handler->queue); @@ -46,6 +48,8 @@ file_handler_init(struct file_handler *file_handler, const char *serial) { file_handler->stopped = false; file_handler->current_process = PROCESS_NONE; + file_handler->push_target = push_target ? push_target : DEFAULT_PUSH_TARGET; + return true; } @@ -67,8 +71,8 @@ install_apk(const char *serial, const char *file) { } static process_t -push_file(const char *serial, const char *file) { - return adb_push(serial, file, DEVICE_SDCARD_PATH); +push_file(const char *serial, const char *file, const char *push_target) { + return adb_push(serial, file, push_target); } bool @@ -124,7 +128,8 @@ run_file_handler(void *data) { process = install_apk(file_handler->serial, req.file); } else { LOGI("Pushing %s...", req.file); - process = push_file(file_handler->serial, req.file); + process = push_file(file_handler->serial, req.file, + file_handler->push_target); } file_handler->current_process = process; mutex_unlock(file_handler->mutex); @@ -137,9 +142,11 @@ run_file_handler(void *data) { } } else { if (process_check_success(process, "adb push")) { - LOGI("%s successfully pushed to /sdcard/", req.file); + LOGI("%s successfully pushed to %s", req.file, + file_handler->push_target); } else { - LOGE("Failed to push %s to /sdcard/", req.file); + LOGE("Failed to push %s to %s", req.file, + file_handler->push_target); } } diff --git a/app/src/file_handler.h b/app/src/file_handler.h index 22245105..3418c532 100644 --- a/app/src/file_handler.h +++ b/app/src/file_handler.h @@ -22,6 +22,7 @@ struct file_handler_request_queue CBUF(struct file_handler_request, 16); struct file_handler { char *serial; + const char *push_target; SDL_Thread *thread; SDL_mutex *mutex; SDL_cond *event_cond; @@ -32,7 +33,8 @@ struct file_handler { }; bool -file_handler_init(struct file_handler *file_handler, const char *serial); +file_handler_init(struct file_handler *file_handler, const char *serial, + const char *push_target); void file_handler_destroy(struct file_handler *file_handler); diff --git a/app/src/main.c b/app/src/main.c index e322cf7a..7a1cb9db 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -18,6 +18,7 @@ struct args { const char *crop; const char *record_filename; const char *window_title; + const char *push_target; enum recorder_format record_format; bool fullscreen; bool no_control; @@ -76,6 +77,11 @@ static void usage(const char *arg0) { " Set the TCP port the client listens on.\n" " Default is %d.\n" "\n" + " --push-target path\n" + " Set the target directory for pushing files to the device by\n" + " drag & drop. It is passed as-is to \"adb push\".\n" + " Default is \"/sdcard/\".\n" + "\n" " -r, --record file.mp4\n" " Record screen to file.\n" " The format is determined by the -F/--record-format option if\n" @@ -300,6 +306,7 @@ guess_record_format(const char *filename) { #define OPT_RENDER_EXPIRED_FRAMES 1000 #define OPT_WINDOW_TITLE 1001 +#define OPT_PUSH_TARGET 1002 static bool parse_args(struct args *args, int argc, char *argv[]) { @@ -313,6 +320,8 @@ parse_args(struct args *args, int argc, char *argv[]) { {"no-control", no_argument, NULL, 'n'}, {"no-display", no_argument, NULL, 'N'}, {"port", required_argument, NULL, 'p'}, + {"push-target", required_argument, NULL, + OPT_PUSH_TARGET}, {"record", required_argument, NULL, 'r'}, {"record-format", required_argument, NULL, 'f'}, {"render-expired-frames", no_argument, NULL, @@ -388,6 +397,9 @@ parse_args(struct args *args, int argc, char *argv[]) { case OPT_WINDOW_TITLE: args->window_title = optarg; break; + case OPT_PUSH_TARGET: + args->push_target = optarg; + break; default: // getopt prints the error message on stderr return false; @@ -445,6 +457,7 @@ main(int argc, char *argv[]) { .crop = NULL, .record_filename = NULL, .window_title = NULL, + .push_target = NULL, .record_format = 0, .help = false, .version = false, @@ -490,6 +503,7 @@ main(int argc, char *argv[]) { .port = args.port, .record_filename = args.record_filename, .window_title = args.window_title, + .push_target = args.push_target, .record_format = args.record_format, .max_size = args.max_size, .bit_rate = args.bit_rate, diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index d9088155..01dc52e4 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -334,7 +334,8 @@ scrcpy(const struct scrcpy_options *options) { video_buffer_initialized = true; if (options->control) { - if (!file_handler_init(&file_handler, server.serial)) { + if (!file_handler_init(&file_handler, server.serial, + options->push_target)) { goto end; } file_handler_initialized = true; diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index fd86bad1..faeb246f 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -10,6 +10,7 @@ struct scrcpy_options { const char *crop; const char *record_filename; const char *window_title; + const char *push_target; enum recorder_format record_format; uint16_t port; uint16_t max_size;