quick fix for unicode filenames on windows

This commit is contained in:
Edênis Freindorfer Azevedo 2019-06-23 07:59:13 -03:00 committed by Rafael Kitover
parent dfa4fec3d5
commit ccc91fa04b
4 changed files with 35 additions and 78 deletions

View File

@ -569,7 +569,8 @@ IMAGE_TYPE utilFindType(const char *file, char (&buffer)[2048])
return IMAGE_UNKNOWN; return IMAGE_UNKNOWN;
} }
MultiByteToWideChar(CP_ACP, 0, file, -1, pwText, dwNum); MultiByteToWideChar(CP_ACP, 0, file, -1, pwText, dwNum);
char *file_conv = fex_wide_to_path(pwText); //char *file_conv = fex_wide_to_path(file);
char *file_conv = (char *)file;
// if ( !utilIsImage( file_conv ) ) // TODO: utilIsArchive() instead? // if ( !utilIsImage( file_conv ) ) // TODO: utilIsArchive() instead?
// { // {
fex_t *fe = scan_arc(file_conv, utilIsImage, buffer); fex_t *fe = scan_arc(file_conv, utilIsImage, buffer);
@ -578,7 +579,7 @@ IMAGE_TYPE utilFindType(const char *file, char (&buffer)[2048])
fex_close(fe); fex_close(fe);
file = buffer; file = buffer;
// } // }
free(file_conv); //free(file_conv);
#else #else
// if ( !utilIsImage( file ) ) // TODO: utilIsArchive() instead? // if ( !utilIsImage( file ) ) // TODO: utilIsArchive() instead?
// { // {
@ -612,12 +613,13 @@ uint8_t *utilLoad(const char *file, bool (*accept)(const char *), uint8_t *data,
return NULL; return NULL;
} }
MultiByteToWideChar(CP_ACP, 0, file, -1, pwText, dwNum); MultiByteToWideChar(CP_ACP, 0, file, -1, pwText, dwNum);
char *file_conv = fex_wide_to_path(pwText); //char *file_conv = fex_wide_to_path(file);
char *file_conv = (char *)file;
delete[] pwText; delete[] pwText;
fex_t *fe = scan_arc(file_conv, accept, buffer); fex_t *fe = scan_arc(file_conv, accept, buffer);
if (!fe) if (!fe)
return NULL; return NULL;
free(file_conv); //free(file_conv);
#else #else
fex_t *fe = scan_arc(file, accept, buffer); fex_t *fe = scan_arc(file, accept, buffer);
if (!fe) if (!fe)

View File

@ -80,13 +80,13 @@ void GameArea::LoadGame(const wxString& name)
// auto-conversion of wxCharBuffer to const char * seems broken // auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used) // so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer fnb(fnfn.GetFullPath().mb_fn_str()); wxCharBuffer fnb(fnfn.GetFullPath().mb_str(wxConvUTF8));
const char* fn = fnb.data(); const char* fn = fnb.data();
IMAGE_TYPE t = badfile ? IMAGE_UNKNOWN : utilFindType(fn); IMAGE_TYPE t = badfile ? IMAGE_UNKNOWN : utilFindType(fn);
if (t == IMAGE_UNKNOWN) { if (t == IMAGE_UNKNOWN) {
wxString s; wxString s;
s.Printf(_("%s is not a valid ROM file"), name.c_str()); s.Printf(_("%s is not a valid ROM file"), name.mb_str());
wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR); wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR);
dlg.ShowModal(); dlg.ShowModal();
return; return;
@ -143,7 +143,7 @@ void GameArea::LoadGame(const wxString& name)
if (t == IMAGE_GB) { if (t == IMAGE_GB) {
if (!gbLoadRom(fn)) { if (!gbLoadRom(fn)) {
wxString s; wxString s;
s.Printf(_("Unable to load Game Boy ROM %s"), name.c_str()); s.Printf(_("Unable to load Game Boy ROM %s"), name.mb_str());
wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR); wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR);
dlg.ShowModal(); dlg.ShowModal();
return; return;
@ -153,10 +153,7 @@ void GameArea::LoadGame(const wxString& name)
if (loadpatch) { if (loadpatch) {
int size = rom_size; int size = rom_size;
// auto-conversion of wxCharBuffer to const char * seems broken applyPatch(pfn.GetFullPath().mb_str(), &gbRom, &size);
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer pfnb(pfn.GetFullPath().mb_fn_str());
applyPatch(pfnb.data(), &gbRom, &size);
if (size != (int)rom_size) if (size != (int)rom_size)
gbUpdateSizes(); gbUpdateSizes();
@ -177,25 +174,14 @@ void GameArea::LoadGame(const wxString& name)
// this **MUST** be called **AFTER** setting sample rate because the core calls soundInit() // this **MUST** be called **AFTER** setting sample rate because the core calls soundInit()
soundSetThrottle(throttle); soundSetThrottle(throttle);
gbGetHardwareType(); gbGetHardwareType();
bool use_bios = false;
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
const char* fn = NULL;
wxCharBuffer fnb;
if (gbCgbMode) { bool use_bios = gbCgbMode ? useBiosFileGBC : useBiosFileGB;
use_bios = useBiosFileGBC; const char* fn = (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).mb_str();
fnb = gopts.gbc_bios.mb_fn_str();
} else {
use_bios = useBiosFileGB;
fnb = gopts.gb_bios.mb_fn_str();
}
fn = fnb.data();
gbCPUInit(fn, use_bios); gbCPUInit(fn, use_bios);
if (use_bios && !useBios) { if (use_bios && !useBios) {
wxLogError(_("Could not load BIOS %s"), (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).c_str()); wxLogError(_("Could not load BIOS %s"), (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).mb_str());
// could clear use flag & file name now, but better to force // could clear use flag & file name now, but better to force
// user to do it // user to do it
} }
@ -218,7 +204,7 @@ void GameArea::LoadGame(const wxString& name)
{ {
if (!(rom_size = CPULoadRom(fn))) { if (!(rom_size = CPULoadRom(fn))) {
wxString s; wxString s;
s.Printf(_("Unable to load Game Boy Advance ROM %s"), name.c_str()); s.Printf(_("Unable to load Game Boy Advance ROM %s"), name.mb_str());
wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR); wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR);
dlg.ShowModal(); dlg.ShowModal();
return; return;
@ -230,10 +216,7 @@ void GameArea::LoadGame(const wxString& name)
// don't use real rom size or it might try to resize rom[] // don't use real rom size or it might try to resize rom[]
// instead, use known size of rom[] // instead, use known size of rom[]
int size = 0x2000000; int size = 0x2000000;
// auto-conversion of wxCharBuffer to const char * seems broken applyPatch(pfn.GetFullPath().mb_str(), &rom, &size);
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer pfnb(pfn.GetFullPath().mb_fn_str());
applyPatch(pfnb.data(), &rom, &size);
// that means we no longer really know rom_size either <sigh> // that means we no longer really know rom_size either <sigh>
} }
@ -288,7 +271,7 @@ void GameArea::LoadGame(const wxString& name)
CPUInit(gopts.gba_bios.mb_fn_str(), useBiosFileGBA); CPUInit(gopts.gba_bios.mb_fn_str(), useBiosFileGBA);
if (useBiosFileGBA && !useBios) { if (useBiosFileGBA && !useBios) {
wxLogError(_("Could not load BIOS %s"), gopts.gba_bios.c_str()); wxLogError(_("Could not load BIOS %s"), gopts.gba_bios.mb_str());
// could clear use flag & file name now, but better to force // could clear use flag & file name now, but better to force
// user to do it // user to do it
} }
@ -354,11 +337,10 @@ void GameArea::LoadGame(const wxString& name)
#endif #endif
bname.append(wxT(".sav")); bname.append(wxT(".sav"));
wxFileName bat(batdir, bname); wxFileName bat(batdir, bname);
fnb = bat.GetFullPath().mb_fn_str();
if (emusys->emuReadBattery(fnb.data())) { if (emusys->emuReadBattery(bat.GetFullPath().mb_str())) {
wxString msg; wxString msg;
msg.Printf(_("Loaded battery %s"), bat.GetFullPath().c_str()); msg.Printf(_("Loaded battery %s"), bat.GetFullPath().mb_str());
systemScreenMessage(msg); systemScreenMessage(msg);
if (cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) { if (cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) {
@ -577,7 +559,7 @@ bool GameArea::LoadState()
bool GameArea::LoadState(int slot) bool GameArea::LoadState(int slot)
{ {
wxString fname; wxString fname;
fname.Printf(SAVESLOT_FMT, game_name().c_str(), slot); fname.Printf(SAVESLOT_FMT, game_name().mb_str(), slot);
return LoadState(wxFileName(statedir, fname)); return LoadState(wxFileName(statedir, fname));
} }
@ -611,7 +593,7 @@ bool GameArea::LoadState(const wxFileName& fname)
wxString msg; wxString msg;
msg.Printf(ret ? _("Loaded state %s") : _("Error loading state %s"), msg.Printf(ret ? _("Loaded state %s") : _("Error loading state %s"),
fname.GetFullPath().c_str()); fname.GetFullPath().mb_str());
systemScreenMessage(msg); systemScreenMessage(msg);
return ret; return ret;
} }
@ -624,7 +606,7 @@ bool GameArea::SaveState()
bool GameArea::SaveState(int slot) bool GameArea::SaveState(int slot)
{ {
wxString fname; wxString fname;
fname.Printf(SAVESLOT_FMT, game_name().c_str(), slot); fname.Printf(SAVESLOT_FMT, game_name().mb_str(), slot);
return SaveState(wxFileName(statedir, fname)); return SaveState(wxFileName(statedir, fname));
} }
@ -635,7 +617,7 @@ bool GameArea::SaveState(const wxFileName& fname)
wxGetApp().frame->update_state_ts(true); wxGetApp().frame->update_state_ts(true);
wxString msg; wxString msg;
msg.Printf(ret ? _("Saved state %s") : _("Error saving state %s"), msg.Printf(ret ? _("Saved state %s") : _("Error saving state %s"),
fname.GetFullPath().c_str()); fname.GetFullPath().mb_str());
systemScreenMessage(msg); systemScreenMessage(msg);
return ret; return ret;
} }
@ -657,15 +639,12 @@ void GameArea::SaveBattery()
wxFileName bat(batdir, bname); wxFileName bat(batdir, bname);
bat.Mkdir(0777, wxPATH_MKDIR_FULL); bat.Mkdir(0777, wxPATH_MKDIR_FULL);
wxString fn = bat.GetFullPath(); wxString fn = bat.GetFullPath();
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer fnb = fn.mb_fn_str();
// FIXME: add option to support ring of backups // FIXME: add option to support ring of backups
// of course some games just write battery way too often for such // of course some games just write battery way too often for such
// a thing to be useful // a thing to be useful
if (!emusys->emuWriteBattery(fnb.data())) if (!emusys->emuWriteBattery(fn.mb_str()))
wxLogError(_("Error writing battery %s"), fn.c_str()); wxLogError(_("Error writing battery %s"), fn.mb_str());
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
} }
@ -1853,7 +1832,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data)
if (panel->osdstat.size()) if (panel->osdstat.size())
drawText(todraw + outstride * (systemColorDepth != 24), outstride, drawText(todraw + outstride * (systemColorDepth != 24), outstride,
10, 20, panel->osdstat.utf8_str(), showSpeedTransparent); 10, 20, panel->osdstat.mb_str(), showSpeedTransparent);
if (!disableStatusMessages && !panel->osdtext.empty()) { if (!disableStatusMessages && !panel->osdtext.empty()) {
if (systemGetClock() - panel->osdtime < OSD_TIME) { if (systemGetClock() - panel->osdtime < OSD_TIME) {
@ -1861,7 +1840,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data)
int linelen = std::ceil(width * scale - 20) / 8; int linelen = std::ceil(width * scale - 20) / 8;
int nlines = (message.size() + linelen - 1) / linelen; int nlines = (message.size() + linelen - 1) / linelen;
int cury = height - 14 - nlines * 10; int cury = height - 14 - nlines * 10;
char* buf = strdup(message.utf8_str()); char* buf = strdup(message.mb_str());
char* ptr = buf; char* ptr = buf;
while (nlines > 1) { while (nlines > 1) {
@ -2357,15 +2336,12 @@ static const wxString media_err(MediaRet ret)
void GameArea::StartVidRecording(const wxString& fname) void GameArea::StartVidRecording(const wxString& fname)
{ {
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer fnb(fname.mb_fn_str());
MediaRet ret; MediaRet ret;
if ((ret = vid_rec.Record(fnb.data(), basic_width, basic_height, if ((ret = vid_rec.Record(fname.mb_str(), basic_width, basic_height,
systemColorDepth)) systemColorDepth))
!= MRET_OK) != MRET_OK)
wxLogError(_("Unable to begin recording to %s (%s)"), fname.c_str(), wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(),
media_err(ret)); media_err(ret));
else { else {
MainFrame* mf = wxGetApp().frame; MainFrame* mf = wxGetApp().frame;
@ -2390,13 +2366,10 @@ void GameArea::StopVidRecording()
void GameArea::StartSoundRecording(const wxString& fname) void GameArea::StartSoundRecording(const wxString& fname)
{ {
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer fnb(fname.mb_fn_str());
MediaRet ret; MediaRet ret;
if ((ret = snd_rec.Record(fnb.data())) != MRET_OK) if ((ret = snd_rec.Record(fname.mb_str())) != MRET_OK)
wxLogError(_("Unable to begin recording to %s (%s)"), fname.c_str(), wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(),
media_err(ret)); media_err(ret));
else { else {
MainFrame* mf = wxGetApp().frame; MainFrame* mf = wxGetApp().frame;

View File

@ -43,9 +43,6 @@ void systemMessage(int id, const char* fmt, ...)
static char* buf = NULL; static char* buf = NULL;
static int buflen = 80; static int buflen = 80;
va_list args; va_list args;
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer _fmt(wxString(wxGetTranslation(wxString(fmt, wxConvLibc))).utf8_str());
if (!buf) { if (!buf) {
buf = (char*)malloc(buflen); buf = (char*)malloc(buflen);
@ -56,7 +53,7 @@ void systemMessage(int id, const char* fmt, ...)
while (1) { while (1) {
va_start(args, fmt); va_start(args, fmt);
int needsz = vsnprintf(buf, buflen, _fmt.data(), args); int needsz = vsnprintf(buf, buflen, fmt, args);
va_end(args); va_end(args);
if (needsz < buflen) if (needsz < buflen)
@ -1296,13 +1293,11 @@ bool debugWaitSocket()
void log(const char* defaultMsg, ...) void log(const char* defaultMsg, ...)
{ {
static FILE* out = NULL;
va_list valist; va_list valist;
char buf[2048];
va_start(valist, defaultMsg); va_start(valist, defaultMsg);
vsnprintf(buf, 2048, defaultMsg, valist); wxString msg = wxString::Format(defaultMsg, valist);
va_end(valist); va_end(valist);
wxGetApp().log.append(wxString(buf, wxConvLibc)); wxGetApp().log.append(msg);
if (wxGetApp().IsMainLoopRunning()) { if (wxGetApp().IsMainLoopRunning()) {
LogDialog* d = wxGetApp().frame->logdlg; LogDialog* d = wxGetApp().frame->logdlg;
@ -1311,19 +1306,6 @@ void log(const char* defaultMsg, ...)
d->Update(); d->Update();
} }
systemScreenMessage(buf); systemScreenMessage(msg);
} }
if (out == NULL) {
// FIXME: this should be an option
wxFileName trace_log(wxGetApp().GetConfigurationPath(), wxT("trace.log"));
out = fopen(trace_log.GetFullPath().utf8_str(), "w");
if (!out)
return;
}
va_start(valist, defaultMsg);
vfprintf(out, defaultMsg, valist);
va_end(valist);
} }

View File

@ -44,7 +44,7 @@
#undef wxLogDebug #undef wxLogDebug
#define wxLogDebug(...) \ #define wxLogDebug(...) \
do { \ do { \
fputs(wxString::Format(wxDateTime::UNow().Format(wxT("%X")) + wxT(": Debug: ") + __VA_ARGS__).mb_str(), VBAM_DEBUG_STREAM); \ fputs(wxString::Format(wxDateTime::UNow().Format(wxT("%X")) + wxT(": Debug: ") + __VA_ARGS__).utf8_str(), VBAM_DEBUG_STREAM); \
fputc('\n', VBAM_DEBUG_STREAM); \ fputc('\n', VBAM_DEBUG_STREAM); \
} while(0) } while(0)
#endif #endif