mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Replace the file handling code from secondary_core.c with the file streams
Hide secondary instance menu item if dynamic libraries are not supported Remove unlink_utf8 stuff Fix a compiler warning
This commit is contained in:
parent
c5ec1885f2
commit
77f2b7d326
@ -56,9 +56,6 @@ COMPATIBILITY
|
|||||||
|
|
||||||
#include "../libretro-common/compat/compat_fnmatch.c"
|
#include "../libretro-common/compat/compat_fnmatch.c"
|
||||||
#include "../libretro-common/compat/fopen_utf8.c"
|
#include "../libretro-common/compat/fopen_utf8.c"
|
||||||
#if defined(HAVE_DYNAMIC) && HAVE_DYNAMIC
|
|
||||||
#include "../libretro-common/compat/unlink_utf8.c"
|
|
||||||
#endif
|
|
||||||
#include "../libretro-common/memmap/memalign.c"
|
#include "../libretro-common/memmap/memalign.c"
|
||||||
|
|
||||||
/*============================================================
|
/*============================================================
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
#include <compat/unlink_utf8.h>
|
|
||||||
#include <encodings/utf.h>
|
|
||||||
#include <boolean.h>
|
|
||||||
|
|
||||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
|
|
||||||
#ifndef LEGACY_WIN32
|
|
||||||
#define LEGACY_WIN32
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#define NOMINMAX
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
bool unlink_utf8(const char * filename)
|
|
||||||
{
|
|
||||||
#if defined(LEGACY_WIN32)
|
|
||||||
bool result = DeleteFileA(filename);
|
|
||||||
#else
|
|
||||||
wchar_t * filename_w = utf8_to_utf16_string_alloc(filename);
|
|
||||||
bool result = DeleteFileW(filename_w);
|
|
||||||
free(filename_w);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef __UNLINK_UTF8_H
|
|
||||||
#define __UNLINK_UTF8_H
|
|
||||||
|
|
||||||
#include <boolean.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool unlink_utf8(const char * filename);
|
|
||||||
|
|
||||||
#if __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#define unlink_utf8 unlink
|
|
||||||
#endif
|
|
||||||
#endif
|
|
@ -4966,9 +4966,11 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
|
|||||||
menu_displaylist_parse_settings_enum(menu, info,
|
menu_displaylist_parse_settings_enum(menu, info,
|
||||||
MENU_ENUM_LABEL_RUN_AHEAD_FRAMES,
|
MENU_ENUM_LABEL_RUN_AHEAD_FRAMES,
|
||||||
PARSE_ONLY_UINT, false);
|
PARSE_ONLY_UINT, false);
|
||||||
|
#if defined(HAVE_DYNAMIC) && HAVE_DYNAMIC
|
||||||
menu_displaylist_parse_settings_enum(menu, info,
|
menu_displaylist_parse_settings_enum(menu, info,
|
||||||
MENU_ENUM_LABEL_RUN_AHEAD_SECONDARY_INSTANCE,
|
MENU_ENUM_LABEL_RUN_AHEAD_SECONDARY_INSTANCE,
|
||||||
PARSE_ONLY_BOOL, false);
|
PARSE_ONLY_BOOL, false);
|
||||||
|
#endif
|
||||||
if (settings->bools.menu_show_advanced_settings)
|
if (settings->bools.menu_show_advanced_settings)
|
||||||
menu_displaylist_parse_settings_enum(menu, info,
|
menu_displaylist_parse_settings_enum(menu, info,
|
||||||
MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE,
|
MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE,
|
||||||
|
@ -92,7 +92,7 @@ static void runahead_save_state_list_rotate(void)
|
|||||||
firstElement = runahead_save_state_list->data[0];
|
firstElement = runahead_save_state_list->data[0];
|
||||||
for (i = 1; i < runahead_save_state_list->size; i++)
|
for (i = 1; i < runahead_save_state_list->size; i++)
|
||||||
{
|
{
|
||||||
runahead_save_state_list->data[i - 1] = runahead_save_state_list->data[i - 1];
|
runahead_save_state_list->data[i - 1] = runahead_save_state_list->data[i];
|
||||||
}
|
}
|
||||||
runahead_save_state_list->data[runahead_save_state_list->size - 1] = firstElement;
|
runahead_save_state_list->data[runahead_save_state_list->size - 1] = firstElement;
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,9 @@
|
|||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <encodings/utf.h>
|
#include <encodings/utf.h>
|
||||||
#include <compat/fopen_utf8.h>
|
|
||||||
#include <compat/unlink_utf8.h>
|
|
||||||
#include <dynamic/dylib.h>
|
#include <dynamic/dylib.h>
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
|
#include <streams/file_stream.h>
|
||||||
|
|
||||||
#include "mem_util.h"
|
#include "mem_util.h"
|
||||||
|
|
||||||
@ -41,12 +40,8 @@ static char* get_temp_directory_alloc(void);
|
|||||||
|
|
||||||
static char* copy_core_to_temp_file(void);
|
static char* copy_core_to_temp_file(void);
|
||||||
|
|
||||||
static void* read_file_data_alloc(const char *fileName, int *size);
|
|
||||||
|
|
||||||
static bool write_file_data(const char *fileName, const void *data, int dataSize);
|
|
||||||
|
|
||||||
static bool write_file_with_random_name(char **tempDllPath,
|
static bool write_file_with_random_name(char **tempDllPath,
|
||||||
const char *retroarchTempPath, const void* data, int dataSize);
|
const char *retroarchTempPath, const void* data, ssize_t dataSize);
|
||||||
|
|
||||||
static void* InputListElementConstructor(void);
|
static void* InputListElementConstructor(void);
|
||||||
|
|
||||||
@ -66,8 +61,6 @@ void remember_controller_port_device(long port, long device);
|
|||||||
|
|
||||||
void clear_controller_port_map(void);
|
void clear_controller_port_map(void);
|
||||||
|
|
||||||
static void free_file(FILE **file_p);
|
|
||||||
|
|
||||||
char* get_temp_directory_alloc(void)
|
char* get_temp_directory_alloc(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -102,7 +95,7 @@ char* copy_core_to_temp_file(void)
|
|||||||
char *retroarchTempPath = NULL;
|
char *retroarchTempPath = NULL;
|
||||||
char *tempDllPath = NULL;
|
char *tempDllPath = NULL;
|
||||||
void *dllFileData = NULL;
|
void *dllFileData = NULL;
|
||||||
int dllFileSize = 0;
|
ssize_t dllFileSize = 0;
|
||||||
const char *corePath = path_get(RARCH_PATH_CORE);
|
const char *corePath = path_get(RARCH_PATH_CORE);
|
||||||
const char *coreBaseName = path_basename(corePath);
|
const char *coreBaseName = path_basename(corePath);
|
||||||
|
|
||||||
@ -123,14 +116,12 @@ char* copy_core_to_temp_file(void)
|
|||||||
if (!okay)
|
if (!okay)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
dllFileData = read_file_data_alloc(corePath, &dllFileSize);
|
if (!file_stream_read_file(corePath, &dllFileData, &dllFileSize))
|
||||||
|
|
||||||
if (!dllFileData)
|
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
strcat_alloc(&tempDllPath, retroarchTempPath);
|
strcat_alloc(&tempDllPath, retroarchTempPath);
|
||||||
strcat_alloc(&tempDllPath, coreBaseName);
|
strcat_alloc(&tempDllPath, coreBaseName);
|
||||||
okay = write_file_data(tempDllPath, dllFileData, dllFileSize);
|
okay = file_stream_write_file(tempDllPath, dllFileData, dllFileSize);
|
||||||
|
|
||||||
if (!okay)
|
if (!okay)
|
||||||
{
|
{
|
||||||
@ -153,80 +144,8 @@ failed:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* read_file_data_alloc(const char *fileName, int *size)
|
|
||||||
{
|
|
||||||
void *data = NULL;
|
|
||||||
int fileSize = 0;
|
|
||||||
size_t bytesRead = 0;
|
|
||||||
#ifdef _WIN32
|
|
||||||
int64_t fileSizeLong = 0;
|
|
||||||
#else
|
|
||||||
off64_t fileSizeLong = 0;
|
|
||||||
#endif
|
|
||||||
FILE *f = (FILE*)fopen_utf8(fileName, "rb");
|
|
||||||
|
|
||||||
if (!f)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
#ifdef _WIN32
|
|
||||||
fileSizeLong = _ftelli64(f);
|
|
||||||
#else
|
|
||||||
fileSizeLong = ftello64(f);
|
|
||||||
#endif
|
|
||||||
fseek(f, 0, SEEK_SET);
|
|
||||||
|
|
||||||
/* 256MB file size limit for DLL files */
|
|
||||||
if (fileSizeLong < 0 || fileSizeLong > 256 * 1024 * 1024)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
fileSize = (int)fileSizeLong;
|
|
||||||
data = malloc(fileSize);
|
|
||||||
|
|
||||||
if (!data)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
bytesRead = fread(data, 1, fileSize, f);
|
|
||||||
|
|
||||||
if ((int)bytesRead != (int)fileSize)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
success:
|
|
||||||
free_file(&f);
|
|
||||||
if (size)
|
|
||||||
*size = fileSize;
|
|
||||||
return data;
|
|
||||||
failed:
|
|
||||||
free_ptr(&data);
|
|
||||||
free_file(&f);
|
|
||||||
if (size)
|
|
||||||
*size = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool write_file_data(const char *fileName, const void *data, int dataSize)
|
|
||||||
{
|
|
||||||
bool okay = false;
|
|
||||||
size_t bytesWritten = 0;
|
|
||||||
FILE *f = (FILE*)fopen_utf8(fileName, "wb");
|
|
||||||
|
|
||||||
if (!f)
|
|
||||||
goto failed;
|
|
||||||
bytesWritten = fwrite(data, 1, dataSize, f);
|
|
||||||
|
|
||||||
if (bytesWritten != dataSize)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
success:
|
|
||||||
free_file(&f);
|
|
||||||
return true;
|
|
||||||
failed:
|
|
||||||
free_file(&f);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool write_file_with_random_name(char **tempDllPath,
|
bool write_file_with_random_name(char **tempDllPath,
|
||||||
const char *retroarchTempPath, const void* data, int dataSize)
|
const char *retroarchTempPath, const void* data, ssize_t dataSize)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char numberBuf[32];
|
char numberBuf[32];
|
||||||
@ -258,7 +177,7 @@ bool write_file_with_random_name(char **tempDllPath,
|
|||||||
strcat_alloc(tempDllPath, prefix);
|
strcat_alloc(tempDllPath, prefix);
|
||||||
strcat_alloc(tempDllPath, numberBuf);
|
strcat_alloc(tempDllPath, numberBuf);
|
||||||
strcat_alloc(tempDllPath, ext);
|
strcat_alloc(tempDllPath, ext);
|
||||||
okay = write_file_data(*tempDllPath, data, dataSize);
|
okay = write_file_stream(*tempDllPath, data, dataSize);
|
||||||
if (okay)
|
if (okay)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -408,7 +327,7 @@ void secondary_core_destroy(void)
|
|||||||
|
|
||||||
dylib_close(secondary_module);
|
dylib_close(secondary_module);
|
||||||
secondary_module = NULL;
|
secondary_module = NULL;
|
||||||
unlink_utf8(secondary_library_path);
|
filestream_delete(secondary_library_path);
|
||||||
free_str(&secondary_library_path);
|
free_str(&secondary_library_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user