Skip to content

Commit

Permalink
BACKENDS: Add better error handling to OSystem_Win32::getDefaultConfi…
Browse files Browse the repository at this point in the history
…gFileName()
  • Loading branch information
Templier committed Jun 23, 2011
1 parent dd21952 commit 7fa3a8b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions backends/platform/sdl/win32/win32.cpp
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 7fa3a8b

Please sign in to comment.