From f4890137c040947825f07c66272985793f9284b2 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Sat, 27 Oct 2018 13:50:29 +0200 Subject: [PATCH] fix configfile loading under Windows, for when it checks AppData by making it actually, you know, build the complete file path hopefully that fixes that crash bug, but I couldn't reproduce it after touching the code some. heisenbugs are lots of fun --- src/Config.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Config.cpp b/src/Config.cpp index 035c3049..780ddde4 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -129,7 +129,20 @@ FILE* GetConfigFile(const char* fileName, const char* permissions) SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath); if (!appDataPath) return NULL; - CoTaskMemRealloc(appDataPath, (wcslen(appDataPath)+9+strlen(fileName)+1)*sizeof(WCHAR)); + + const WCHAR* appdir = L"\\melonDS\\"; + + int fnlen = MultiByteToWideChar(CP_UTF8, 0, fileName, -1, NULL, 0); + if (fnlen < 1) return NULL; + WCHAR* wfileName = new WCHAR[fnlen]; + int res = MultiByteToWideChar(CP_UTF8, 0, fileName, -1, wfileName, fnlen); + if (res != fnlen) { delete[] wfileName; return NULL; } // checkme? + + int pos = wcslen(appDataPath); + CoTaskMemRealloc(appDataPath, (pos+wcslen(appdir)+fnlen+1)*sizeof(WCHAR)); + + wcscpy(&appDataPath[pos], appdir); + wcscpy(&appDataPath[pos+9], wfileName); // this will be more than enough WCHAR fatperm[4]; @@ -140,6 +153,7 @@ FILE* GetConfigFile(const char* fileName, const char* permissions) f = _wfopen(appDataPath, fatperm); CoTaskMemFree(appDataPath); + delete[] wfileName; if (f) return f; #else // Now check XDG_CONFIG_HOME