aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2018-10-27 13:50:29 +0200
committerStapleButter <thetotalworm@gmail.com>2018-10-27 13:50:29 +0200
commitf4890137c040947825f07c66272985793f9284b2 (patch)
tree662c59dfd29b497c3d5d427e7854a663cfa4c6d6 /src
parentd4d4965b2fffc69958685a25a9d9fc0c78b54567 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index 035c304..780ddde 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