diff options
author | Cameron Cawley | 2018-12-16 15:04:24 +0000 |
---|---|---|
committer | Filippos Karapetis | 2018-12-16 17:04:24 +0200 |
commit | 1de8f1e5293f4ea72c9926dc6a0bac42fd6f7113 (patch) | |
tree | d5ade46df0d2291482065e30da26893e632bf95f /backends/saves/windows | |
parent | 9725716f26911b15b3f00343bbd9e6ad9bea1e2a (diff) | |
download | scummvm-rg350-1de8f1e5293f4ea72c9926dc6a0bac42fd6f7113.tar.gz scummvm-rg350-1de8f1e5293f4ea72c9926dc6a0bac42fd6f7113.tar.bz2 scummvm-rg350-1de8f1e5293f4ea72c9926dc6a0bac42fd6f7113.zip |
WIN32: Use SHGetFolderPath to get the location of the Application Data folder (#1449)
Diffstat (limited to 'backends/saves/windows')
-rw-r--r-- | backends/saves/windows/windows-saves.cpp | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/backends/saves/windows/windows-saves.cpp b/backends/saves/windows/windows-saves.cpp index b84ab1312d..967f0d8301 100644 --- a/backends/saves/windows/windows-saves.cpp +++ b/backends/saves/windows/windows-saves.cpp @@ -32,37 +32,22 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #undef ARRAYSIZE // winnt.h defines ARRAYSIZE, but we want our own one... +#if defined(__GNUC__) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +// required for SHGFP_TYPE_CURRENT in shlobj.h +#define _WIN32_IE 0x500 +#endif +#include <shlobj.h> #include "common/config-manager.h" #include "common/savefile.h" +#include "backends/platform/sdl/win32/win32_wrapper.h" WindowsSaveFileManager::WindowsSaveFileManager() { char defaultSavepath[MAXPATHLEN]; - OSVERSIONINFO win32OsVersion; - ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO)); - win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&win32OsVersion); - // Check for non-9X version of Windows. - if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) { - // Use the Application Data directory of the user profile. - if (win32OsVersion.dwMajorVersion >= 5) { - if (!GetEnvironmentVariable("APPDATA", defaultSavepath, sizeof(defaultSavepath))) - error("Unable to access application data directory"); - } else { - if (!GetEnvironmentVariable("USERPROFILE", defaultSavepath, sizeof(defaultSavepath))) - error("Unable to access user profile directory"); - - strcat(defaultSavepath, "\\Application Data"); - - // If the directory already exists (as it should in most cases), - // we don't want to fail, but we need to stop on other errors (such as ERROR_PATH_NOT_FOUND) - if (!CreateDirectory(defaultSavepath, NULL)) { - if (GetLastError() != ERROR_ALREADY_EXISTS) - error("Cannot create Application data folder"); - } - } + // Use the Application Data directory of the user profile. + if (SHGetFolderPathFunc(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, defaultSavepath) == S_OK) { strcat(defaultSavepath, "\\ScummVM"); if (!CreateDirectory(defaultSavepath, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) @@ -76,6 +61,8 @@ WindowsSaveFileManager::WindowsSaveFileManager() { } ConfMan.registerDefault("savepath", defaultSavepath); + } else { + warning("Unable to access application data directory"); } } |