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.
|
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
|
### Read-only
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
#define DEVICE_NAME_FIELD_LENGTH 64
|
#define DEVICE_NAME_FIELD_LENGTH 64
|
||||||
#define DEVICE_SDCARD_PATH "/sdcard/"
|
|
||||||
|
|
||||||
// name must be at least DEVICE_NAME_FIELD_LENGTH bytes
|
// name must be at least DEVICE_NAME_FIELD_LENGTH bytes
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -5,17 +5,19 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "device.h"
|
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#define DEFAULT_PUSH_TARGET "/sdcard/"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
file_handler_request_destroy(struct file_handler_request *req) {
|
file_handler_request_destroy(struct file_handler_request *req) {
|
||||||
SDL_free(req->file);
|
SDL_free(req->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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);
|
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->stopped = false;
|
||||||
file_handler->current_process = PROCESS_NONE;
|
file_handler->current_process = PROCESS_NONE;
|
||||||
|
|
||||||
|
file_handler->push_target = push_target ? push_target : DEFAULT_PUSH_TARGET;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +71,8 @@ install_apk(const char *serial, const char *file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static process_t
|
static process_t
|
||||||
push_file(const char *serial, const char *file) {
|
push_file(const char *serial, const char *file, const char *push_target) {
|
||||||
return adb_push(serial, file, DEVICE_SDCARD_PATH);
|
return adb_push(serial, file, push_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -124,7 +128,8 @@ run_file_handler(void *data) {
|
||||||
process = install_apk(file_handler->serial, req.file);
|
process = install_apk(file_handler->serial, req.file);
|
||||||
} else {
|
} else {
|
||||||
LOGI("Pushing %s...", req.file);
|
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;
|
file_handler->current_process = process;
|
||||||
mutex_unlock(file_handler->mutex);
|
mutex_unlock(file_handler->mutex);
|
||||||
|
@ -137,9 +142,11 @@ run_file_handler(void *data) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (process_check_success(process, "adb push")) {
|
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 {
|
} 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 {
|
struct file_handler {
|
||||||
char *serial;
|
char *serial;
|
||||||
|
const char *push_target;
|
||||||
SDL_Thread *thread;
|
SDL_Thread *thread;
|
||||||
SDL_mutex *mutex;
|
SDL_mutex *mutex;
|
||||||
SDL_cond *event_cond;
|
SDL_cond *event_cond;
|
||||||
|
@ -32,7 +33,8 @@ struct file_handler {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
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
|
void
|
||||||
file_handler_destroy(struct file_handler *file_handler);
|
file_handler_destroy(struct file_handler *file_handler);
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct args {
|
||||||
const char *crop;
|
const char *crop;
|
||||||
const char *record_filename;
|
const char *record_filename;
|
||||||
const char *window_title;
|
const char *window_title;
|
||||||
|
const char *push_target;
|
||||||
enum recorder_format record_format;
|
enum recorder_format record_format;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool no_control;
|
bool no_control;
|
||||||
|
@ -76,6 +77,11 @@ static void usage(const char *arg0) {
|
||||||
" Set the TCP port the client listens on.\n"
|
" Set the TCP port the client listens on.\n"
|
||||||
" Default is %d.\n"
|
" Default is %d.\n"
|
||||||
"\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"
|
" -r, --record file.mp4\n"
|
||||||
" Record screen to file.\n"
|
" Record screen to file.\n"
|
||||||
" The format is determined by the -F/--record-format option if\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_RENDER_EXPIRED_FRAMES 1000
|
||||||
#define OPT_WINDOW_TITLE 1001
|
#define OPT_WINDOW_TITLE 1001
|
||||||
|
#define OPT_PUSH_TARGET 1002
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_args(struct args *args, int argc, char *argv[]) {
|
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-control", no_argument, NULL, 'n'},
|
||||||
{"no-display", no_argument, NULL, 'N'},
|
{"no-display", no_argument, NULL, 'N'},
|
||||||
{"port", required_argument, NULL, 'p'},
|
{"port", required_argument, NULL, 'p'},
|
||||||
|
{"push-target", required_argument, NULL,
|
||||||
|
OPT_PUSH_TARGET},
|
||||||
{"record", required_argument, NULL, 'r'},
|
{"record", required_argument, NULL, 'r'},
|
||||||
{"record-format", required_argument, NULL, 'f'},
|
{"record-format", required_argument, NULL, 'f'},
|
||||||
{"render-expired-frames", no_argument, NULL,
|
{"render-expired-frames", no_argument, NULL,
|
||||||
|
@ -388,6 +397,9 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
case OPT_WINDOW_TITLE:
|
case OPT_WINDOW_TITLE:
|
||||||
args->window_title = optarg;
|
args->window_title = optarg;
|
||||||
break;
|
break;
|
||||||
|
case OPT_PUSH_TARGET:
|
||||||
|
args->push_target = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// getopt prints the error message on stderr
|
// getopt prints the error message on stderr
|
||||||
return false;
|
return false;
|
||||||
|
@ -445,6 +457,7 @@ main(int argc, char *argv[]) {
|
||||||
.crop = NULL,
|
.crop = NULL,
|
||||||
.record_filename = NULL,
|
.record_filename = NULL,
|
||||||
.window_title = NULL,
|
.window_title = NULL,
|
||||||
|
.push_target = NULL,
|
||||||
.record_format = 0,
|
.record_format = 0,
|
||||||
.help = false,
|
.help = false,
|
||||||
.version = false,
|
.version = false,
|
||||||
|
@ -490,6 +503,7 @@ main(int argc, char *argv[]) {
|
||||||
.port = args.port,
|
.port = args.port,
|
||||||
.record_filename = args.record_filename,
|
.record_filename = args.record_filename,
|
||||||
.window_title = args.window_title,
|
.window_title = args.window_title,
|
||||||
|
.push_target = args.push_target,
|
||||||
.record_format = args.record_format,
|
.record_format = args.record_format,
|
||||||
.max_size = args.max_size,
|
.max_size = args.max_size,
|
||||||
.bit_rate = args.bit_rate,
|
.bit_rate = args.bit_rate,
|
||||||
|
|
|
@ -334,7 +334,8 @@ scrcpy(const struct scrcpy_options *options) {
|
||||||
video_buffer_initialized = true;
|
video_buffer_initialized = true;
|
||||||
|
|
||||||
if (options->control) {
|
if (options->control) {
|
||||||
if (!file_handler_init(&file_handler, server.serial)) {
|
if (!file_handler_init(&file_handler, server.serial,
|
||||||
|
options->push_target)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
file_handler_initialized = true;
|
file_handler_initialized = true;
|
||||||
|
|
|
@ -10,6 +10,7 @@ struct scrcpy_options {
|
||||||
const char *crop;
|
const char *crop;
|
||||||
const char *record_filename;
|
const char *record_filename;
|
||||||
const char *window_title;
|
const char *window_title;
|
||||||
|
const char *push_target;
|
||||||
enum recorder_format record_format;
|
enum recorder_format record_format;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
|
|
Loading…
Reference in a new issue