diff --git a/core/usblink.c b/core/usblink.c index 49199029..f4b89577 100644 --- a/core/usblink.c +++ b/core/usblink.c @@ -278,7 +278,8 @@ void put_file_next(struct packet *in) { teardown: throttle_timer_on(); put_file_state = 0; - fclose(put_file); + if (put_file) + fclose(put_file); put_file = NULL; } @@ -527,7 +528,7 @@ void usblink_received_packet(const uint8_t *data, uint32_t size) { bool usblink_put_file(const char *local, const char *remote, usblink_progress_cb callback, void *user_data) { mode = File_Send; - char *dot = strrchr(local, '.'); + char *dot = local ? strrchr(local, '.') : NULL; // TODO (thanks for the reminder, Excale :P) : Filter depending on which model is being emulated if (dot && (!strcmp(dot, ".tno") || !strcmp(dot, ".tnc") || !strcmp(dot, ".tco") || !strcmp(dot, ".tcc") @@ -542,17 +543,23 @@ bool usblink_put_file(const char *local, const char *remote, usblink_progress_cb current_user_data = user_data; current_file_callback = callback; - FILE *f = fopen_utf8(local, "rb"); - if (!f) { - gui_perror(local); - return 0; - } if (put_file) fclose(put_file); - put_file = f; - fseek(f, 0, SEEK_END); - put_file_size_orig = put_file_size = ftell(f); - fseek(f, 0, SEEK_SET); + + if (local && local[0] != '\0') { + put_file = fopen_utf8(local, "rb"); + if (!put_file) { + gui_perror(local); + return 0; + } + fseek(put_file, 0, SEEK_END); + put_file_size_orig = put_file_size = ftell(put_file); + fseek(put_file, 0, SEEK_SET); + } else { + put_file = NULL; + put_file_size_orig = put_file_size = 0; + } + put_file_state = SENDING_03; /* Send the first packet */ diff --git a/core/usblink.h b/core/usblink.h index a50b0376..6b998fdd 100644 --- a/core/usblink.h +++ b/core/usblink.h @@ -27,6 +27,7 @@ typedef void (*usblink_progress_cb)(int progress, void *user_data); void usblink_delete(const char *path, bool is_dir, usblink_progress_cb callback, void *user_data); void usblink_dirlist(const char *path, usblink_dirlist_cb callback, void *user_data); bool usblink_get_file(const char *path, const char *dest, usblink_progress_cb callback, void *user_data); +/* local = NULL or empty creates an empty file */ bool usblink_put_file(const char *local, const char *remote, usblink_progress_cb callback, void *user_data); void usblink_new_dir(const char *path, usblink_progress_cb callback, void *user_data); void usblink_move(const char *old_path, const char *new_path, usblink_progress_cb callback, void *user_data);