diff --git a/configuration.c b/configuration.c index bec0b42878..da10440ad8 100644 --- a/configuration.c +++ b/configuration.c @@ -3797,19 +3797,19 @@ bool config_save_file(const char *path) RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE)); else - path_file_remove(LAKKA_SSH_PATH); + filestream_delete(LAKKA_SSH_PATH); if (settings->bools.samba_enable) filestream_close(filestream_open(LAKKA_SAMBA_PATH, RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE)); else - path_file_remove(LAKKA_SAMBA_PATH); + filestream_delete(LAKKA_SAMBA_PATH); if (settings->bools.bluetooth_enable) filestream_close(filestream_open(LAKKA_BLUETOOTH_PATH, RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE)); else - path_file_remove(LAKKA_BLUETOOTH_PATH); + filestream_delete(LAKKA_BLUETOOTH_PATH); #endif for (i = 0; i < MAX_USERS; i++) diff --git a/griffin/griffin.c b/griffin/griffin.c index 1f88192ae3..dab466aaa0 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -1046,7 +1046,17 @@ MENU #include "../menu/menu_setting.c" #include "../menu/menu_cbs.c" #include "../menu/menu_content.c" + +#ifdef __cplusplus +extern "C" { +#endif + #include "../menu/menu_networking.c" + +#ifdef __cplusplus +} +#endif + #include "../menu/widgets/menu_entry.c" #include "../menu/widgets/menu_filebrowser.c" #include "../menu/widgets/menu_dialog.c" diff --git a/input/input_remapping.c b/input/input_remapping.c index 1493368454..5830565e09 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "input_driver.h" @@ -241,7 +242,7 @@ bool input_remapping_remove_file(const char *path) fill_pathname_noext(remap_file, buf, ".rmp", path_size); - ret = path_file_remove(remap_file) == 0 ? true : false;; + ret = filestream_delete(remap_file) == 0 ? true : false; free(buf); free(remap_file); return ret; diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 52b6b45a7b..3ae3471a59 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -926,107 +926,3 @@ void fill_short_pathname_representation_noext(char* out_rep, fill_short_pathname_representation(out_rep, in_path, size); path_remove_extension(out_rep); } - -bool path_file_remove(const char *path) -{ - char *path_local = NULL; - wchar_t *path_wide = NULL; - - if (!path || !*path) - return false; - - (void)path_local; - (void)path_wide; - -#if defined(_WIN32) && !defined(_XBOX) -#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 - path_local = utf8_to_local_string_alloc(path); - - if (path_local) - { - int ret = remove(path_local); - free(path_local); - - if (ret == 0) - return true; - } -#else - path_wide = utf8_to_utf16_string_alloc(path); - - if (path_wide) - { - int ret = _wremove(path_wide); - free(path_wide); - - if (ret == 0) - return true; - } -#endif -#else - if (remove(path) == 0) - return true; -#endif - return false; -} - -bool path_file_rename(const char *old_path, const char *new_path) -{ - char *old_path_local = NULL; - char *new_path_local = NULL; - wchar_t *old_path_wide = NULL; - wchar_t *new_path_wide = NULL; - - if (!old_path || !*old_path || !new_path || !*new_path) - return false; - - (void)old_path_local; - (void)new_path_local; - (void)old_path_wide; - (void)new_path_wide; - -#if defined(_WIN32) && !defined(_XBOX) -#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 - old_path_local = utf8_to_local_string_alloc(old_path); - new_path_local = utf8_to_local_string_alloc(new_path); - - if (old_path_local) - { - if (new_path_local) - { - int ret = rename(old_path_local, new_path_local); - free(old_path_local); - free(new_path_local); - return ret; - } - - free(old_path_local); - } - - if (new_path_local) - free(new_path_local); -#else - old_path_wide = utf8_to_utf16_string_alloc(old_path); - new_path_wide = utf8_to_utf16_string_alloc(new_path); - - if (old_path_wide) - { - if (new_path_wide) - { - int ret = _wrename(old_path_wide, new_path_wide); - free(old_path_wide); - free(new_path_wide); - return ret; - } - - free(old_path_wide); - } - - if (new_path_wide) - free(new_path_wide); -#endif -#else - if (rename(old_path, new_path) == 0) - return true; -#endif - return false; -} diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index d4cd442c5b..52e292b069 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -466,10 +466,6 @@ bool path_is_valid(const char *path); int32_t path_get_size(const char *path); -bool path_file_remove(const char *path); - -bool path_file_rename(const char *old_path, const char *new_path); - RETRO_END_DECLS #endif diff --git a/libretro-common/include/libretro_vfs.h b/libretro-common/include/libretro_vfs.h index e2573c5b72..1b2c6bcadc 100644 --- a/libretro-common/include/libretro_vfs.h +++ b/libretro-common/include/libretro_vfs.h @@ -87,6 +87,10 @@ typedef int (RETRO_CALLCONV *retro_vfs_file_flush_t)(struct retro_vfs_file_handl * Introduced in VFS API v1 */ typedef int (RETRO_CALLCONV *retro_vfs_file_delete_t)(const char *path); +/* Rename the specified file. Returns 0 on success, -1 on failure + * Introduced in VFS API v1 */ +typedef int (RETRO_CALLCONV *retro_vfs_file_rename_t)(const char *old_path, const char *new_path); + struct retro_vfs_interface { retro_vfs_file_get_path_t file_get_path; @@ -99,6 +103,7 @@ struct retro_vfs_interface retro_vfs_file_write_t file_write; retro_vfs_file_flush_t file_flush; retro_vfs_file_delete_t file_delete; + retro_vfs_file_rename_t file_rename; }; struct retro_vfs_interface_info diff --git a/libretro-common/include/streams/file_stream.h b/libretro-common/include/streams/file_stream.h index 73c446b277..0539f6214b 100644 --- a/libretro-common/include/streams/file_stream.h +++ b/libretro-common/include/streams/file_stream.h @@ -92,6 +92,8 @@ int filestream_flush(RFILE *stream); int filestream_delete(const char *path); +int filestream_rename(const char *old_path, const char *new_path); + const char *filestream_get_path(RFILE *stream); static INLINE char *filestream_getline(RFILE *stream) diff --git a/libretro-common/include/vfs/vfs_implementation.h b/libretro-common/include/vfs/vfs_implementation.h index c8961e2926..8abcda7ad5 100644 --- a/libretro-common/include/vfs/vfs_implementation.h +++ b/libretro-common/include/vfs/vfs_implementation.h @@ -58,6 +58,8 @@ int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream); int retro_vfs_file_delete_impl(const char *path); +int retro_vfs_file_rename_impl(const char *old_path, const char *new_path); + const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream); #endif diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index f2aa9c526f..4354189f33 100644 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -46,6 +46,7 @@ static retro_vfs_file_read_t filestream_read_cb = NULL; static retro_vfs_file_write_t filestream_write_cb = NULL; static retro_vfs_file_flush_t filestream_flush_cb = NULL; static retro_vfs_file_delete_t filestream_delete_cb = NULL; +static retro_vfs_file_rename_t filestream_rename_cb = NULL; struct RFILE { @@ -69,6 +70,7 @@ void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info) filestream_write_cb = NULL; filestream_flush_cb = NULL; filestream_delete_cb = NULL; + filestream_rename_cb = NULL; vfs_iface = vfs_info->iface; @@ -86,6 +88,7 @@ void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info) filestream_write_cb = vfs_iface->file_write; filestream_flush_cb = vfs_iface->file_flush; filestream_delete_cb = vfs_iface->file_delete; + filestream_rename_cb = vfs_iface->file_rename; } /* Callback wrappers */ @@ -255,6 +258,14 @@ int filestream_delete(const char *path) return retro_vfs_file_delete_impl(path); } +int filestream_rename(const char *old_path, const char *new_path) +{ + if (filestream_rename_cb != NULL) + return filestream_rename_cb(old_path, new_path); + + return retro_vfs_file_rename_impl(old_path, new_path); +} + const char *filestream_get_path(RFILE *stream) { if (filestream_get_path_cb != NULL) diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 218eb946ee..2b967a0e42 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -433,7 +433,105 @@ int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream) int retro_vfs_file_delete_impl(const char *path) { - return remove(path) == 0; + char *path_local = NULL; + wchar_t *path_wide = NULL; + + if (!path || !*path) + return false; + + (void)path_local; + (void)path_wide; + +#if defined(_WIN32) && !defined(_XBOX) +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 + path_local = utf8_to_local_string_alloc(path); + + if (path_local) + { + int ret = remove(path_local); + free(path_local); + + if (ret == 0) + return true; + } +#else + path_wide = utf8_to_utf16_string_alloc(path); + + if (path_wide) + { + int ret = _wremove(path_wide); + free(path_wide); + + if (ret == 0) + return true; + } +#endif +#else + if (remove(path) == 0) + return true; +#endif + return false; +} + +int retro_vfs_file_rename_impl(const char *old_path, const char *new_path) +{ + char *old_path_local = NULL; + char *new_path_local = NULL; + wchar_t *old_path_wide = NULL; + wchar_t *new_path_wide = NULL; + + if (!old_path || !*old_path || !new_path || !*new_path) + return -1; + + (void)old_path_local; + (void)new_path_local; + (void)old_path_wide; + (void)new_path_wide; + +#if defined(_WIN32) && !defined(_XBOX) +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 + old_path_local = utf8_to_local_string_alloc(old_path); + new_path_local = utf8_to_local_string_alloc(new_path); + + if (old_path_local) + { + if (new_path_local) + { + int ret = rename(old_path_local, new_path_local); + free(old_path_local); + free(new_path_local); + return ret; + } + + free(old_path_local); + } + + if (new_path_local) + free(new_path_local); +#else + old_path_wide = utf8_to_utf16_string_alloc(old_path); + new_path_wide = utf8_to_utf16_string_alloc(new_path); + + if (old_path_wide) + { + if (new_path_wide) + { + int ret = _wrename(old_path_wide, new_path_wide); + free(old_path_wide); + free(new_path_wide); + return ret; + } + + free(old_path_wide); + } + + if (new_path_wide) + free(new_path_wide); +#endif +#else + return rename(old_path, new_path); +#endif + return -1; } const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index bca45f8de2..5f47aeea29 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2458,7 +2458,7 @@ static void cb_decompressed(void *task_data, void *user_data, const char *err) if (dec) { if (path_file_exists(dec->source_file)) - path_file_remove(dec->source_file); + filestream_delete(dec->source_file); free(dec->source_file); free(dec); @@ -3865,7 +3865,7 @@ static int action_ok_core_delete(const char *path, generic_action_ok_command(CMD_EVENT_UNLOAD_CORE); menu_entries_flush_stack(0, 0); - if (path_file_remove(core_path) != 0) { } + if (filestream_delete(core_path) != 0) { } free(core_path); diff --git a/menu/menu_setting.c b/menu/menu_setting.c index f9ddce0cc1..c5ad60c223 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -1885,7 +1885,7 @@ static void systemd_service_toggle(const char *path, char *unit, bool enable) RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE)); else - path_file_remove(path); + filestream_delete(path); if (pid == 0) execvp(args[0], args); diff --git a/tasks/task_content.c b/tasks/task_content.c index ff69f366de..09f984bc61 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1718,7 +1718,7 @@ void content_deinit(void) RARCH_LOG("%s: %s.\n", msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path); - if (!path_file_remove(path)) + if (!filestream_delete(path)) RARCH_ERR("%s: %s.\n", msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE), path); diff --git a/tasks/task_save.c b/tasks/task_save.c index 770fe19882..b821e2122e 100644 --- a/tasks/task_save.c +++ b/tasks/task_save.c @@ -1273,9 +1273,9 @@ bool content_rename_state(const char *origin, const char *dest) { int ret = 0; if (path_file_exists(dest)) - path_file_remove(dest); + filestream_delete(dest); - ret = path_file_rename(origin, dest); + ret = filestream_rename(origin, dest); if (!ret) return true;