aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-03-27 04:23:03 +0100
committerArisotura <thetotalworm@gmail.com>2019-03-27 04:23:03 +0100
commit6d7e80b67768d1c14792f5da5ff59b739e2109e6 (patch)
tree34eaabaf36eb9f37861aa7c1a9f962508b283c37
parent5d127f9e555faf227a7736f74ae579df6adee41a (diff)
move melon_fopen() to Platform.cpp
melon_fopen_local() will need fixoring
-rw-r--r--src/Config.cpp3
-rw-r--r--src/NDSCart.cpp9
-rw-r--r--src/Platform.h2
-rw-r--r--src/Savestate.cpp6
-rw-r--r--src/libui_sdl/Platform.cpp29
-rw-r--r--src/libui_sdl/main.cpp2
-rw-r--r--src/melon_fopen.cpp25
-rw-r--r--src/melon_fopen.h1
8 files changed, 44 insertions, 33 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index d9dfc92..760ad3b 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -20,6 +20,7 @@
#include <string.h>
#include <stdlib.h>
#include "Config.h"
+#include "Platform.h"
#include "melon_fopen.h"
@@ -128,7 +129,7 @@ void Save()
strncpy(&path[dirlen+1], kConfigFile, filelen);
path[dirlen+1+filelen] = '\0';
- f = melon_fopen(path, "w");
+ f = Platform::OpenFile(path, "w");
delete[] path;
if (!f) return;
}
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index 34e64df..7856bc9 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -24,6 +24,7 @@
#include "CRC32.h"
#include "melon_fopen.h"
+#include "Platform.h"
namespace NDSCart_SRAM
@@ -117,7 +118,7 @@ void LoadSave(const char* path, u32 type)
strncpy(SRAMPath, path, 1023);
SRAMPath[1023] = '\0';
- FILE* f = melon_fopen(path, "rb");
+ FILE* f = Platform::OpenFile(path, "rb");
if (f)
{
fseek(f, 0, SEEK_END);
@@ -177,7 +178,7 @@ void RelocateSave(const char* path, bool write)
strncpy(SRAMPath, path, 1023);
SRAMPath[1023] = '\0';
- FILE* f = melon_fopen(path, "wb");
+ FILE* f = Platform::OpenFile(path, "wb");
if (!f)
{
printf("NDSCart_SRAM::RelocateSave: failed to create new file. fuck\n");
@@ -444,7 +445,7 @@ void Write(u8 val, u32 hold)
if (islast && (CurCmd == 0x02 || CurCmd == 0x0A) && (SRAMLength > 0))
{
- FILE* f = melon_fopen(SRAMPath, "wb");
+ FILE* f = Platform::OpenFile(SRAMPath, "wb");
if (f)
{
fwrite(SRAM, SRAMLength, 1, f);
@@ -872,7 +873,7 @@ bool LoadROM(const char* path, const char* sram, bool direct)
// TODO: streaming mode? for really big ROMs or systems with limited RAM
// for now we're lazy
- FILE* f = melon_fopen(path, "rb");
+ FILE* f = Platform::OpenFile(path, "rb");
if (!f)
{
return false;
diff --git a/src/Platform.h b/src/Platform.h
index 2cff3f0..6adc2a2 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -26,6 +26,8 @@ namespace Platform
void StopEmu();
+FILE* OpenFile(const char* path, const char* mode);
+
void* Thread_Create(void (*func)());
void Thread_Free(void* thread);
void Thread_Wait(void* thread);
diff --git a/src/Savestate.cpp b/src/Savestate.cpp
index ee86847..b58d7ac 100644
--- a/src/Savestate.cpp
+++ b/src/Savestate.cpp
@@ -18,7 +18,7 @@
#include <stdio.h>
#include "Savestate.h"
-#include "melon_fopen.h"
+#include "Platform.h"
/*
Savestate format
@@ -56,7 +56,7 @@ Savestate::Savestate(char* filename, bool save)
if (save)
{
Saving = true;
- file = melon_fopen(filename, "wb");
+ file = Platform::OpenFile(filename, "wb");
if (!file)
{
printf("savestate: file %s doesn't exist\n", filename);
@@ -75,7 +75,7 @@ Savestate::Savestate(char* filename, bool save)
else
{
Saving = false;
- file = melon_fopen(filename, "rb");
+ file = Platform::OpenFile(filename, "rb");
if (!file)
{
printf("savestate: file %s doesn't exist\n", filename);
diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp
index f739d63..a3619b5 100644
--- a/src/libui_sdl/Platform.cpp
+++ b/src/libui_sdl/Platform.cpp
@@ -81,6 +81,35 @@ void StopEmu()
}
+FILE* OpenFile(const char* path, const char* mode)
+{
+#ifdef __WIN32__
+
+ int len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
+ if (len < 1) return NULL;
+ WCHAR* fatpath = new WCHAR[len];
+ int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, fatpath, len);
+ if (res != len) { delete[] fatpath; return NULL; } // checkme?
+
+ // this will be more than enough
+ WCHAR fatmode[4];
+ fatmode[0] = mode[0];
+ fatmode[1] = mode[1];
+ fatmode[2] = mode[2];
+ fatmode[3] = 0;
+
+ FILE* ret = _wfopen(fatpath, fatmode);
+ delete[] fatpath;
+ return ret;
+
+#else
+
+ return fopen(path, mode);
+
+#endif
+}
+
+
void* Thread_Create(void (*func)())
{
ThreadData* data = new ThreadData;
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index e4ac78a..4fc6679 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -140,7 +140,7 @@ void GetSavestateName(int slot, char* filename, int len);
bool FileExists(const char* name)
{
- FILE* f = melon_fopen(name, "rb");
+ FILE* f = Platform::OpenFile(name, "rb");
if (!f) return false;
fclose(f);
return true;
diff --git a/src/melon_fopen.cpp b/src/melon_fopen.cpp
index 7f3e3e7..5e0d03f 100644
--- a/src/melon_fopen.cpp
+++ b/src/melon_fopen.cpp
@@ -32,6 +32,7 @@ extern "C" const GUID DECLSPEC_SELECTANY FOLDERID_RoamingAppData = {0x3eb685db,
#include <glib.h>
#endif
+#include "Platform.h"
extern char* EmuDirectory;
@@ -39,26 +40,6 @@ extern char* EmuDirectory;
-FILE* melon_fopen(const char* path, const char* mode)
-{
- int len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
- if (len < 1) return NULL;
- WCHAR* fatass = new WCHAR[len];
- int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, fatass, len);
- if (res != len) { delete[] fatass; return NULL; } // checkme?
-
- // this will be more than enough
- WCHAR fatmode[4];
- fatmode[0] = mode[0];
- fatmode[1] = mode[1];
- fatmode[2] = mode[2];
- fatmode[3] = 0;
-
- FILE* ret = _wfopen(fatass, fatmode);
- delete[] fatass;
- return ret;
-}
-
FILE* melon_fopen_local(const char* fileName, const char* permissions)
{
// Locations are application directory, and AppData/melonDS on windows
@@ -82,7 +63,7 @@ FILE* melon_fopen_local(const char* fileName, const char* permissions)
strncpy(&tmp[dirlen+1], fileName, filelen);
tmp[dirlen+1+filelen] = '\0';
- f = melon_fopen(tmp, permissions);
+ f = Platform::OpenFile(tmp, permissions);
delete[] tmp;
if (f) return f;
}
@@ -132,8 +113,6 @@ FILE* melon_fopen_local(const char* fileName, const char* permissions)
-FILE* melon_fopen(const char* filename, const char* perm) { return fopen(filename, perm); }
-
FILE* melon_fopen_local(const char* fileName, const char* permissions)
{
// Locations are application directory, and XDG_CONFIG_HOME/melonds
diff --git a/src/melon_fopen.h b/src/melon_fopen.h
index 9adde4f..4de11e0 100644
--- a/src/melon_fopen.h
+++ b/src/melon_fopen.h
@@ -20,7 +20,6 @@
#define MELON_FOPEN_H
-FILE* melon_fopen(const char* filename, const char* perm);
FILE* melon_fopen_local(const char* filename, const char* perm);