winport - minimal work to get wacky characters filenames loading via file menu

fixes #192
This commit is contained in:
zeromus 2018-09-22 15:55:02 -04:00
parent 1b10b39603
commit 12c93232b9
3 changed files with 14 additions and 11 deletions

View File

@ -25,6 +25,8 @@
#include <zzip/zzip.h>
#endif
#include "utils/xstring.h"
#ifdef WIN32
#define stat(...) _stat(__VA_ARGS__)
#define S_IFMT _S_IFMT
@ -86,7 +88,7 @@ void* STDROMReaderInit(const char* filename)
return 0;
#endif
FILE* inf = fopen(filename, "rb");
FILE* inf = _wfopen(mbstowcs((std::string)filename).c_str(),L"rb");
if(!inf) return NULL;
STDROMReaderData* ret = new STDROMReaderData();

View File

@ -32,6 +32,7 @@
#include "resource.h"
#include "main.h"
#include "utils/decrypt/header.h"
#include "utils/xstring.h"
static char Str_Tmp[1024];
@ -418,7 +419,7 @@ bool ObtainFile(const char* Name, char *const & LogicalName, char *const & Physi
{
//before sending to FEX, see if we're known to be an NDS file
//(this will stop games beginning with the name ZOO from being mis-recognized as a zoo file)
FILE* inf = fopen(PhysicalName,"rb");
FILE* inf = _wfopen(mbstowcs((std::string)PhysicalName).c_str(),L"rb");
if(!inf) return false;
u8 bytes512[512];
bool got512 = fread(bytes512,1,512,inf)==512;

View File

@ -3055,9 +3055,9 @@ LRESULT OpenFile()
HWND hwnd = MainWindow->getHWnd();
int filterSize = 0, i = 0;
OPENFILENAME ofn;
char filename[MAX_PATH] = "",
fileFilter[512]="";
OPENFILENAMEW ofn;
wchar_t filename[MAX_PATH] = L"",
fileFilter[512]=L"";
NDS_Pause(); //Stop emulation while opening new rom
ZeroMemory(&ofn, sizeof(ofn));
@ -3065,7 +3065,7 @@ LRESULT OpenFile()
ofn.hwndOwner = hwnd;
ofn.lpstrFilter =
"All Usable Files (*.nds, *.ds.gba, *.srl, *.zip, *.7z, *.rar, *.gz)\0*.nds;*.ds.gba;*.srl;*.zip;*.7z;*.rar;*.gz\0"
L"All Usable Files (*.nds, *.ds.gba, *.srl, *.zip, *.7z, *.rar, *.gz)\0*.nds;*.ds.gba;*.srl;*.zip;*.7z;*.rar;*.gz\0"
"NDS ROM file (*.nds,*.srl)\0*.nds;*.srl\0"
"NDS/GBA ROM File (*.ds.gba)\0*.ds.gba\0"
"Zipped NDS ROM file (*.zip)\0*.zip\0"
@ -3079,12 +3079,12 @@ LRESULT OpenFile()
ofn.nFilterIndex = 1;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "nds";
ofn.lpstrDefExt = L"nds";
ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
std::string dir = path.getpath(path.ROMS);
std::wstring dir = mbstowcs(path.getpath(path.ROMS));
ofn.lpstrInitialDir = dir.c_str();
if (GetOpenFileName(&ofn) == NULL)
if (GetOpenFileNameW(&ofn) == NULL)
{
NDS_UnPause();
return 0;
@ -3093,13 +3093,13 @@ LRESULT OpenFile()
{
if(path.savelastromvisit)
{
std::string dir = Path::GetFileDirectoryPath(filename);
std::string dir = Path::GetFileDirectoryPath(wcstombs(filename));
path.setpath(path.ROMS, dir);
WritePrivateProfileString(SECTION, ROMKEY, dir.c_str(), IniName);
}
}
if(!OpenCore(filename))
if(!OpenCore(wcstombs((std::wstring)filename).c_str()))
return 0;
// if(!GetOpenFileName(&ofn))