Add option to change the push target
A drag & drop always pushed the file to /sdcard/. Add an option to customize the target directory. Fixes <https://github.com/Genymobile/scrcpy/issues/659>
This commit is contained in:
parent
ca970e8aa6
commit
a90ccbdf3b
7 changed files with 39 additions and 10 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue