move melon_fopen() to Platform.cpp

melon_fopen_local() will need fixoring
This commit is contained in:
Arisotura 2019-03-27 04:23:03 +01:00
parent 5d127f9e55
commit 6d7e80b677
8 changed files with 44 additions and 33 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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