Skip to content

Commit

Permalink
winport - fix bug where desmume would create working directory using …
Browse files Browse the repository at this point in the history
…some wrong locale encoding and produce a Pok魯n directory instead of using the Pokémon that was already there (fixes #791)
  • Loading branch information
zeromus committed May 13, 2024
1 parent 9515af8 commit 4a53a30
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion desmume/src/frontend/windows/winutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void GetINIPath()
}

FCEUD_MakePathDirs(IniName);
wcscpy(IniNameW,mbstowcs(IniName).c_str()); //careful to use locale C-style mbstowcs to get IniName (which is with locale encoding) to unicode
wcscpy(IniNameW,mbstowcs_locale(IniName).c_str());

//write BOM to get unicode
FILE* test = fopen(IniName,"rb");
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void createDirectoryRecursively(std::wstring path)

void FCEUD_MakePathDirs(const char *fname)
{
createDirectoryRecursively(mbstowcs(fname));
createDirectoryRecursively(mbstowcs_locale(fname));
}
#endif
//------------------------------
Expand Down
13 changes: 13 additions & 0 deletions desmume/src/utils/xstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ std::string mass_replace(const std::string &source, const std::string &victim, c
return answer;
}

std::wstring mbstowcs_locale(std::string str)
{
#ifdef HOST_WINDOWS
int plenty = str.size()*4+1;
wchar_t *wgarbage = new wchar_t[plenty];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.data(), -1, wgarbage, plenty);
std::wstring ret = wgarbage;
delete[] wgarbage;
return ret;
#endif
return mbstowcs(str);
}

//convert a std::string to std::wstring
std::wstring mbstowcs(std::string str)
{
Expand Down
2 changes: 2 additions & 0 deletions desmume/src/utils/xstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ std::string mass_replace(const std::string &source, const std::string &victim, c
std::wstring mbstowcs(std::string str);
std::string wcstombs(std::wstring str);

std::wstring mbstowcs_locale(std::string str);


#endif

0 comments on commit 4a53a30

Please sign in to comment.