Skip to content

Commit

Permalink
attempt to fix some problems caused by users running desmume out of d…
Browse files Browse the repository at this point in the history
…irectories with non-english characters (could manifest as "could not get read/write access to the battery save file")
  • Loading branch information
zeromus committed Jun 5, 2022
1 parent b2ad722 commit 48f5a82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions desmume/src/frontend/windows/winutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "path.h"
#include "winutil.h"
#include "utils/xstring.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
Expand All @@ -26,7 +27,7 @@

char IniName[MAX_PATH];

char* _hack_alternateModulePath;
std::string _hack_alternateModulePathUtf8;


static char vPath[MAX_PATH*2], *szPath;
Expand All @@ -53,14 +54,13 @@ void GetINIPath()

//use an alternate path
useModulePath = false;
static char userpath[MAX_PATH];
SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,NULL,0,userpath);
_snprintf(vPath,MAX_PATH,"%s\\%s",userpath,"DeSmuME");
szPath = vPath;
_hack_alternateModulePath = szPath;
static wchar_t userpath[MAX_PATH];
SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,userpath);
std::wstring blah = (std::wstring)userpath + L"\\DeSmuME";
_hack_alternateModulePathUtf8 = wcstombs(blah);

//not so sure about this.. but lets go for it.
SetCurrentDirectory(userpath);
SetCurrentDirectoryW(blah.c_str());
}
}

Expand Down
20 changes: 12 additions & 8 deletions desmume/src/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,22 @@ void PathInfo::LoadModulePath()
{
#if defined(HOST_WINDOWS)

char *p;
wchar_t *p;
ZeroMemory(pathToModule, sizeof(pathToModule));

GetModuleFileName(NULL, pathToModule, sizeof(pathToModule));
p = pathToModule + lstrlen(pathToModule);
while (p >= pathToModule && *p != DIRECTORY_DELIMITER_CHAR) p--;
if (++p >= pathToModule) *p = 0;
wchar_t wPathToModule[MAX_PATH];
GetModuleFileNameW(NULL, wPathToModule, sizeof(wPathToModule));
p = wPathToModule + wcslen(wPathToModule);
while (p >= wPathToModule && *p != DIRECTORY_DELIMITER_CHAR) p--;
if (++p >= wPathToModule) *p = 0;

extern char* _hack_alternateModulePath;
if (_hack_alternateModulePath)
auto tmp = wcstombs(wPathToModule);
strcpy(pathToModule,tmp.c_str());

extern std::string _hack_alternateModulePathUtf8;
if (!_hack_alternateModulePathUtf8.empty())
{
strcpy(pathToModule, _hack_alternateModulePath);
strcpy(pathToModule, _hack_alternateModulePathUtf8.c_str());
}
#elif defined(DESMUME_COCOA)
std::string pathStr = Path::GetFileDirectoryPath(path);
Expand Down

0 comments on commit 48f5a82

Please sign in to comment.