Skip to content
Permalink
Browse files

quick fix for unicode filenames on windows

  • Loading branch information
denisfa authored and rkitover committed Jun 23, 2019
1 parent dfa4fec commit ccc91fa04b8b6f2206f4b6b18594d217b2344f8a
Showing with 36 additions and 79 deletions.
  1. +6 −4 src/Util.cpp
  2. +25 −52 src/wx/panel.cpp
  3. +4 −22 src/wx/sys.cpp
  4. +1 −1 src/wx/wxvbam.h
@@ -569,7 +569,8 @@ IMAGE_TYPE utilFindType(const char *file, char (&buffer)[2048])
return IMAGE_UNKNOWN;
}
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?
// {
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);
file = buffer;
// }
free(file_conv);
//free(file_conv);
#else
// 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;
}
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;
fex_t *fe = scan_arc(file_conv, accept, buffer);
if (!fe)
return NULL;
free(file_conv);
//free(file_conv);
#else
fex_t *fe = scan_arc(file, accept, buffer);
if (!fe)
@@ -80,13 +80,13 @@ void GameArea::LoadGame(const wxString& name)

// auto-conversion of wxCharBuffer to const char * seems broken
// 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();
IMAGE_TYPE t = badfile ? IMAGE_UNKNOWN : utilFindType(fn);

if (t == IMAGE_UNKNOWN) {
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);
dlg.ShowModal();
return;
@@ -143,7 +143,7 @@ void GameArea::LoadGame(const wxString& name)
if (t == IMAGE_GB) {
if (!gbLoadRom(fn)) {
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);
dlg.ShowModal();
return;
@@ -153,10 +153,7 @@ void GameArea::LoadGame(const wxString& name)

if (loadpatch) {
int size = rom_size;
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer pfnb(pfn.GetFullPath().mb_fn_str());
applyPatch(pfnb.data(), &gbRom, &size);
applyPatch(pfn.GetFullPath().mb_str(), &gbRom, &size);

if (size != (int)rom_size)
gbUpdateSizes();
@@ -177,25 +174,14 @@ void GameArea::LoadGame(const wxString& name)
// this **MUST** be called **AFTER** setting sample rate because the core calls soundInit()
soundSetThrottle(throttle);
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) {
use_bios = useBiosFileGBC;
fnb = gopts.gbc_bios.mb_fn_str();
} else {
use_bios = useBiosFileGB;
fnb = gopts.gb_bios.mb_fn_str();
}

fn = fnb.data();
bool use_bios = gbCgbMode ? useBiosFileGBC : useBiosFileGB;
const char* fn = (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).mb_str();

gbCPUInit(fn, use_bios);

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
// user to do it
}
@@ -218,7 +204,7 @@ void GameArea::LoadGame(const wxString& name)
{
if (!(rom_size = CPULoadRom(fn))) {
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);
dlg.ShowModal();
return;
@@ -230,10 +216,7 @@ void GameArea::LoadGame(const wxString& name)
// don't use real rom size or it might try to resize rom[]
// instead, use known size of rom[]
int size = 0x2000000;
// auto-conversion of wxCharBuffer to const char * seems broken
// so save underlying wxCharBuffer (or create one of none is used)
wxCharBuffer pfnb(pfn.GetFullPath().mb_fn_str());
applyPatch(pfnb.data(), &rom, &size);
applyPatch(pfn.GetFullPath().mb_str(), &rom, &size);
// 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);

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
// user to do it
}
@@ -354,11 +337,10 @@ void GameArea::LoadGame(const wxString& name)
#endif
bname.append(wxT(".sav"));
wxFileName bat(batdir, bname);
fnb = bat.GetFullPath().mb_fn_str();

if (emusys->emuReadBattery(fnb.data())) {
if (emusys->emuReadBattery(bat.GetFullPath().mb_str())) {
wxString msg;
msg.Printf(_("Loaded battery %s"), bat.GetFullPath().c_str());
msg.Printf(_("Loaded battery %s"), bat.GetFullPath().mb_str());
systemScreenMessage(msg);

if (cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) {
@@ -577,7 +559,7 @@ bool GameArea::LoadState()
bool GameArea::LoadState(int slot)
{
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));
}

@@ -611,7 +593,7 @@ bool GameArea::LoadState(const wxFileName& fname)

wxString msg;
msg.Printf(ret ? _("Loaded state %s") : _("Error loading state %s"),
fname.GetFullPath().c_str());
fname.GetFullPath().mb_str());
systemScreenMessage(msg);
return ret;
}
@@ -624,7 +606,7 @@ bool GameArea::SaveState()
bool GameArea::SaveState(int slot)
{
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));
}

@@ -635,7 +617,7 @@ bool GameArea::SaveState(const wxFileName& fname)
wxGetApp().frame->update_state_ts(true);
wxString msg;
msg.Printf(ret ? _("Saved state %s") : _("Error saving state %s"),
fname.GetFullPath().c_str());
fname.GetFullPath().mb_str());
systemScreenMessage(msg);
return ret;
}
@@ -657,15 +639,12 @@ void GameArea::SaveBattery()
wxFileName bat(batdir, bname);
bat.Mkdir(0777, wxPATH_MKDIR_FULL);
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
// of course some games just write battery way too often for such
// a thing to be useful
if (!emusys->emuWriteBattery(fnb.data()))
wxLogError(_("Error writing battery %s"), fn.c_str());
if (!emusys->emuWriteBattery(fn.mb_str()))
wxLogError(_("Error writing battery %s"), fn.mb_str());

systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
}
@@ -1853,15 +1832,15 @@ void DrawingPanelBase::DrawArea(uint8_t** data)

if (panel->osdstat.size())
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 (systemGetClock() - panel->osdtime < OSD_TIME) {
wxString message = panel->osdtext;
int linelen = std::ceil(width * scale - 20) / 8;
int nlines = (message.size() + linelen - 1) / linelen;
int cury = height - 14 - nlines * 10;
char* buf = strdup(message.utf8_str());
char* buf = strdup(message.mb_str());
char* ptr = buf;

while (nlines > 1) {
@@ -2357,15 +2336,12 @@ static const wxString media_err(MediaRet ret)

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;

if ((ret = vid_rec.Record(fnb.data(), basic_width, basic_height,
if ((ret = vid_rec.Record(fname.mb_str(), basic_width, basic_height,
systemColorDepth))
!= 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));
else {
MainFrame* mf = wxGetApp().frame;
@@ -2390,13 +2366,10 @@ void GameArea::StopVidRecording()

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;

if ((ret = snd_rec.Record(fnb.data())) != MRET_OK)
wxLogError(_("Unable to begin recording to %s (%s)"), fname.c_str(),
if ((ret = snd_rec.Record(fname.mb_str())) != MRET_OK)
wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(),
media_err(ret));
else {
MainFrame* mf = wxGetApp().frame;
@@ -43,9 +43,6 @@ void systemMessage(int id, const char* fmt, ...)
static char* buf = NULL;
static int buflen = 80;
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) {
buf = (char*)malloc(buflen);
@@ -56,7 +53,7 @@ void systemMessage(int id, const char* fmt, ...)

while (1) {
va_start(args, fmt);
int needsz = vsnprintf(buf, buflen, _fmt.data(), args);
int needsz = vsnprintf(buf, buflen, fmt, args);
va_end(args);

if (needsz < buflen)
@@ -1296,13 +1293,11 @@ bool debugWaitSocket()

void log(const char* defaultMsg, ...)
{
static FILE* out = NULL;
va_list valist;
char buf[2048];
va_start(valist, defaultMsg);
vsnprintf(buf, 2048, defaultMsg, valist);
wxString msg = wxString::Format(defaultMsg, valist);
va_end(valist);
wxGetApp().log.append(wxString(buf, wxConvLibc));
wxGetApp().log.append(msg);

if (wxGetApp().IsMainLoopRunning()) {
LogDialog* d = wxGetApp().frame->logdlg;
@@ -1311,19 +1306,6 @@ void log(const char* defaultMsg, ...)
d->Update();
}

systemScreenMessage(buf);
}

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;
systemScreenMessage(msg);
}

va_start(valist, defaultMsg);
vfprintf(out, defaultMsg, valist);
va_end(valist);
}
@@ -44,7 +44,7 @@
#undef wxLogDebug
#define wxLogDebug(...) \
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); \
} while(0)
#endif

0 comments on commit ccc91fa

Please sign in to comment.
You can’t perform that action at this time.