From 045aaa8dad89efc690657d192b3919001c230691 Mon Sep 17 00:00:00 2001 From: William JCM Date: Thu, 24 Jun 2021 21:44:29 +0200 Subject: [PATCH] MassBuilderManager: use the Known Folders WinAPI. According to the MS docs, it's supposedly better, so even though CSIDLs are probably not gonna go away because of Microsoft's strong stance on backwards compatibility, might as well use the "better" stuff. --- src/MassBuilderManager/MassBuilderManager.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MassBuilderManager/MassBuilderManager.cpp b/src/MassBuilderManager/MassBuilderManager.cpp index 2cbc9ee..2ac969a 100644 --- a/src/MassBuilderManager/MassBuilderManager.cpp +++ b/src/MassBuilderManager/MassBuilderManager.cpp @@ -68,13 +68,15 @@ auto MassBuilderManager::gameState() -> GameState { } auto MassBuilderManager::findSaveDirectory() -> bool { - wchar_t h[MAX_PATH]; - if(!SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, h))) { - _lastError = "SHGetFolderPathW() failed in MassBuilderManager::findSaveDirectory()"; + wchar_t* localappdata_path; + Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree}; + if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK) + { + _lastError = "SHGetKnownFolderPath() failed in MassBuilderManager::findSaveDirectory()"; return false; } - _saveDirectory = Utility::Directory::join(Utility::Directory::fromNativeSeparators(Utility::Unicode::narrow(h)), "MASS_Builder"); + _saveDirectory = Utility::Directory::join(Utility::Directory::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"); if(!Utility::Directory::exists(_saveDirectory)) { _lastError = _saveDirectory + " wasn't found.";