diff --git a/desmume/src/frontend/windows/winutil.cpp b/desmume/src/frontend/windows/winutil.cpp index dc04691fe..82088024d 100644 --- a/desmume/src/frontend/windows/winutil.cpp +++ b/desmume/src/frontend/windows/winutil.cpp @@ -17,6 +17,7 @@ #include "path.h" #include "winutil.h" +#include "utils/xstring.h" #include #include #include @@ -26,7 +27,7 @@ char IniName[MAX_PATH]; -char* _hack_alternateModulePath; +std::string _hack_alternateModulePathUtf8; static char vPath[MAX_PATH*2], *szPath; @@ -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()); } } diff --git a/desmume/src/path.cpp b/desmume/src/path.cpp index 5e5e05310..8045f9ae7 100644 --- a/desmume/src/path.cpp +++ b/desmume/src/path.cpp @@ -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);