diff options
author | Julien | 2011-06-06 01:45:21 +0800 |
---|---|---|
committer | Julien | 2011-06-23 15:11:38 +0800 |
commit | 7fa3a8bbffc625232cd24252cf501e2c2b7b2a55 (patch) | |
tree | 3391926a5ac5e20c7175af55e411e5590fc1d0fa /backends/platform | |
parent | dd21952f9845c2d9947c3ad6459f45063f0588d6 (diff) | |
download | scummvm-rg350-7fa3a8bbffc625232cd24252cf501e2c2b7b2a55.tar.gz scummvm-rg350-7fa3a8bbffc625232cd24252cf501e2c2b7b2a55.tar.bz2 scummvm-rg350-7fa3a8bbffc625232cd24252cf501e2c2b7b2a55.zip |
BACKENDS: Add better error handling to OSystem_Win32::getDefaultConfigFileName()
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/sdl/win32/win32.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 5b02a20abc..814f1955fe 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -155,18 +155,31 @@ Common::String OSystem_Win32::getDefaultConfigFileName() { error("Unable to access user profile directory"); strcat(configFile, "\\Application Data"); - CreateDirectory(configFile, NULL); + + // 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(configFile, NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) + error("Cannot create Application data folder"); + } } strcat(configFile, "\\ScummVM"); - CreateDirectory(configFile, NULL); + if (!CreateDirectory(configFile, NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) + error("Cannot create ScummVM application data folder"); + } + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); FILE *tmp = NULL; if ((tmp = fopen(configFile, "r")) == NULL) { // Check windows directory char oldConfigFile[MAXPATHLEN]; - GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + uint ret = GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + if (ret == 0 || ret > MAXPATHLEN) + error("Cannot retrieve the path of the Windows directory"); + strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); if ((tmp = fopen(oldConfigFile, "r"))) { strcpy(configFile, oldConfigFile); @@ -178,7 +191,10 @@ Common::String OSystem_Win32::getDefaultConfigFileName() { } } else { // Check windows directory - GetWindowsDirectory(configFile, MAXPATHLEN); + uint ret = GetWindowsDirectory(configFile, MAXPATHLEN); + if (ret == 0 || ret > MAXPATHLEN) + error("Cannot retrieve the path of the Windows directory"); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); } |