move path_file_rename and path_file_remove into VFS

This commit is contained in:
Brad Parker 2017-12-14 13:29:36 -05:00
parent 842ac40c6e
commit 8c0adf3594
14 changed files with 140 additions and 119 deletions

View File

@ -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++)

View File

@ -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"

View File

@ -17,6 +17,7 @@
#include <compat/strl.h>
#include <file/config_file.h>
#include <file/file_path.h>
#include <streams/file_stream.h>
#include <string/stdstring.h>
#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;

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;