From fbe4f0dd48c290701532e39502551cd07d881dcb Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 30 Jul 2008 15:38:42 +0000 Subject: Simplified advanced detector file sys scanning code svn-id: r33455 --- common/system.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 8d528258f4..2dd0192aec 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -121,3 +121,132 @@ void OSystem::clearScreen() { memset(screen->pixels, 0, screen->h * screen->pitch); unlockScreen(); } + + +/* +FIXME: The config file loading code below needs to be cleaned up. + Port specific variants should be pushed into the respective ports. + + Ideally, the default OSystem::openConfigFileForReading/Writing methods + should be removed completely. +*/ + +#include "common/file.h" + +#ifdef __PLAYSTATION2__ +#include "backends/platform/ps2/systemps2.h" +#endif + +#ifdef IPHONE +#include "backends/platform/iphone/osys_iphone.h" +#endif + + +#if defined(UNIX) +#ifdef MACOSX +#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" +#else +#define DEFAULT_CONFIG_FILE ".scummvmrc" +#endif +#else +#define DEFAULT_CONFIG_FILE "scummvm.ini" +#endif + +static Common::String getDefaultConfigFileName() { + char configFile[MAXPATHLEN]; + +#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) + 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", configFile, sizeof(configFile))) + error("Unable to access application data directory"); + } else { + if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) + error("Unable to access user profile directory"); + + strcat(configFile, "\\Application Data"); + CreateDirectory(configFile, NULL); + } + + strcat(configFile, "\\ScummVM"); + CreateDirectory(configFile, NULL); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + + if (fopen(configFile, "r") == NULL) { + // Check windows directory + char oldConfigFile[MAXPATHLEN]; + GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); + if (fopen(oldConfigFile, "r")) { + printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n"); + printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n"); + printf("file from the old default location:\n"); + printf("%s\n", oldConfigFile); + printf("to the new default location:\n"); + printf("%s\n\n", configFile); + strcpy(configFile, oldConfigFile); + } + } + } else { + // Check windows directory + GetWindowsDirectory(configFile, MAXPATHLEN); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + } + +#elif defined(PALMOS_MODE) + strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); +#elif defined(IPHONE) + strcpy(configFile, OSystem_IPHONE::getConfigPath()); +#elif defined(__PLAYSTATION2__) + ((OSystem_PS2*)g_system)->makeConfigPath(configFile); +#elif defined(__PSP__) + strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); +#elif defined (__SYMBIAN32__) + strcpy(configFile, Symbian::GetExecutablePath()); + strcat(configFile, DEFAULT_CONFIG_FILE); +#elif defined(UNIX) && !defined(GP2X) && !defined(IPHONE) + // On UNIX type systems, by default we store the config file inside + // to the HOME directory of the user. + // + // GP2X is Linux based but Home dir can be read only so do not use + // it and put the config in the executable dir. + // + // On the iPhone, the home dir of the user when you launch the app + // from the Springboard, is /. Which we don't want. + const char *home = getenv("HOME"); + if (home != NULL && strlen(home) < MAXPATHLEN) + snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); + else + strcpy(configFile, DEFAULT_CONFIG_FILE); + +#else + strcpy(configFile, DEFAULT_CONFIG_FILE); +#endif + + + return configFile; +} + +Common::SeekableReadStream *OSystem::openConfigFileForReading() { + Common::File *confFile = new Common::File(); + assert(confFile); + confFile->open(getDefaultConfigFileName()); + return confFile; +} + +Common::WriteStream *OSystem::openConfigFileForWriting() { +#ifdef __DC__ + return 0; +#else + Common::DumpFile *confFile = new Common::DumpFile(); + assert(confFile); + confFile->open(getDefaultConfigFileName()); + return confFile; +#endif +} -- cgit v1.2.3 From 4632a33087524a2ccb872ddb567b5a01b11aee26 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 30 Jul 2008 15:44:34 +0000 Subject: Revert my accidental commit of the OSystem changes (oops) svn-id: r33456 --- common/system.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 2dd0192aec..200b1a3fc7 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -250,3 +250,131 @@ Common::WriteStream *OSystem::openConfigFileForWriting() { return confFile; #endif } + + +/* +FIXME: The config file loading code below needs to be cleaned up. + Port specific variants should be pushed into the respective ports. + + Ideally, the default OSystem::openConfigFileForReading/Writing methods + should be removed completely. +*/ + +#include "common/file.h" + +#ifdef __PLAYSTATION2__ +#include "backends/platform/ps2/systemps2.h" +#endif + +#ifdef IPHONE +#include "backends/platform/iphone/osys_iphone.h" +#endif + + +#if defined(UNIX) +#ifdef MACOSX +#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" +#else +#define DEFAULT_CONFIG_FILE ".scummvmrc" +#endif +#else +#define DEFAULT_CONFIG_FILE "scummvm.ini" +#endif + +static Common::String getDefaultConfigFileName() { + char configFile[MAXPATHLEN]; +#if defined(UNIX) && !defined(GP2X) && !defined(IPHONE) + // On UNIX type systems, by default we store the config file inside + // to the HOME directory of the user. + // + // GP2X is Linux based but Home dir can be read only so do not use + // it and put the config in the executable dir. + // + // On the iPhone, the home dir of the user when you launch the app + // from the Springboard, is /. Which we don't want. + const char *home = getenv("HOME"); + if (home != NULL && strlen(home) < MAXPATHLEN) + snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); + else + strcpy(configFile, DEFAULT_CONFIG_FILE); +#else + #if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) + 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", configFile, sizeof(configFile))) + error("Unable to access application data directory"); + } else { + if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) + error("Unable to access user profile directory"); + + strcat(configFile, "\\Application Data"); + CreateDirectory(configFile, NULL); + } + + strcat(configFile, "\\ScummVM"); + CreateDirectory(configFile, NULL); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + + if (fopen(configFile, "r") == NULL) { + // Check windows directory + char oldConfigFile[MAXPATHLEN]; + GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); + if (fopen(oldConfigFile, "r")) { + printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n"); + printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n"); + printf("file from the old default location:\n"); + printf("%s\n", oldConfigFile); + printf("to the new default location:\n"); + printf("%s\n\n", configFile); + strcpy(configFile, oldConfigFile); + } + } + } else { + // Check windows directory + GetWindowsDirectory(configFile, MAXPATHLEN); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + } + + #elif defined(PALMOS_MODE) + strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); + #elif defined(IPHONE) + strcpy(configFile, OSystem_IPHONE::getConfigPath()); + #elif defined(__PLAYSTATION2__) + ((OSystem_PS2*)g_system)->makeConfigPath(configFile); + #elif defined(__PSP__) + strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); + #elif defined (__SYMBIAN32__) + strcpy(configFile, Symbian::GetExecutablePath()); + strcat(configFile, DEFAULT_CONFIG_FILE); + #else + strcpy(configFile, DEFAULT_CONFIG_FILE); + #endif +#endif + + return configFile; +} + +Common::SeekableReadStream *OSystem::openConfigFileForReading() { + Common::File *confFile = new Common::File(); + assert(confFile); + confFile->open(getDefaultConfigFileName()); + return confFile; +} + +Common::WriteStream *OSystem::openConfigFileForWriting() { +#ifdef __DC__ + return 0; +#else + Common::DumpFile *confFile = new Common::DumpFile(); + assert(confFile); + confFile->open(getDefaultConfigFileName()); + return confFile; +#endif +} -- cgit v1.2.3 From 55e4eb8d15e1cb9966963bdd5bf326db587e98fb Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Wed, 30 Jul 2008 16:06:46 +0000 Subject: Fixed Win32 build, after Fingolfin's commits (probably because of the revert in revision 33456). svn-id: r33458 --- common/system.cpp | 110 +++++------------------------------------------------- 1 file changed, 10 insertions(+), 100 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 200b1a3fc7..f959ec7ab0 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -128,7 +128,7 @@ FIXME: The config file loading code below needs to be cleaned up. Port specific variants should be pushed into the respective ports. Ideally, the default OSystem::openConfigFileForReading/Writing methods - should be removed completely. + should be removed completely. */ #include "common/file.h" @@ -141,6 +141,12 @@ FIXME: The config file loading code below needs to be cleaned up. #include "backends/platform/iphone/osys_iphone.h" #endif +#if defined(WIN32) +#include +// winnt.h defines ARRAYSIZE, but we want our own one... +#undef ARRAYSIZE +#endif + #if defined(UNIX) #ifdef MACOSX @@ -152,104 +158,8 @@ FIXME: The config file loading code below needs to be cleaned up. #define DEFAULT_CONFIG_FILE "scummvm.ini" #endif -static Common::String getDefaultConfigFileName() { - char configFile[MAXPATHLEN]; - -#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) - 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", configFile, sizeof(configFile))) - error("Unable to access application data directory"); - } else { - if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) - error("Unable to access user profile directory"); - - strcat(configFile, "\\Application Data"); - CreateDirectory(configFile, NULL); - } - - strcat(configFile, "\\ScummVM"); - CreateDirectory(configFile, NULL); - strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - - if (fopen(configFile, "r") == NULL) { - // Check windows directory - char oldConfigFile[MAXPATHLEN]; - GetWindowsDirectory(oldConfigFile, MAXPATHLEN); - strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); - if (fopen(oldConfigFile, "r")) { - printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n"); - printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n"); - printf("file from the old default location:\n"); - printf("%s\n", oldConfigFile); - printf("to the new default location:\n"); - printf("%s\n\n", configFile); - strcpy(configFile, oldConfigFile); - } - } - } else { - // Check windows directory - GetWindowsDirectory(configFile, MAXPATHLEN); - strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - } - -#elif defined(PALMOS_MODE) - strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); -#elif defined(IPHONE) - strcpy(configFile, OSystem_IPHONE::getConfigPath()); -#elif defined(__PLAYSTATION2__) - ((OSystem_PS2*)g_system)->makeConfigPath(configFile); -#elif defined(__PSP__) - strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); -#elif defined (__SYMBIAN32__) - strcpy(configFile, Symbian::GetExecutablePath()); - strcat(configFile, DEFAULT_CONFIG_FILE); -#elif defined(UNIX) && !defined(GP2X) && !defined(IPHONE) - // On UNIX type systems, by default we store the config file inside - // to the HOME directory of the user. - // - // GP2X is Linux based but Home dir can be read only so do not use - // it and put the config in the executable dir. - // - // On the iPhone, the home dir of the user when you launch the app - // from the Springboard, is /. Which we don't want. - const char *home = getenv("HOME"); - if (home != NULL && strlen(home) < MAXPATHLEN) - snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); - else - strcpy(configFile, DEFAULT_CONFIG_FILE); - -#else - strcpy(configFile, DEFAULT_CONFIG_FILE); -#endif - - return configFile; -} - -Common::SeekableReadStream *OSystem::openConfigFileForReading() { - Common::File *confFile = new Common::File(); - assert(confFile); - confFile->open(getDefaultConfigFileName()); - return confFile; -} -Common::WriteStream *OSystem::openConfigFileForWriting() { -#ifdef __DC__ - return 0; -#else - Common::DumpFile *confFile = new Common::DumpFile(); - assert(confFile); - confFile->open(getDefaultConfigFileName()); - return confFile; -#endif -} /* @@ -257,7 +167,7 @@ FIXME: The config file loading code below needs to be cleaned up. Port specific variants should be pushed into the respective ports. Ideally, the default OSystem::openConfigFileForReading/Writing methods - should be removed completely. + should be removed completely. */ #include "common/file.h" @@ -286,7 +196,7 @@ static Common::String getDefaultConfigFileName() { #if defined(UNIX) && !defined(GP2X) && !defined(IPHONE) // On UNIX type systems, by default we store the config file inside // to the HOME directory of the user. - // + // // GP2X is Linux based but Home dir can be read only so do not use // it and put the config in the executable dir. // @@ -345,7 +255,7 @@ static Common::String getDefaultConfigFileName() { #elif defined(PALMOS_MODE) strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); #elif defined(IPHONE) - strcpy(configFile, OSystem_IPHONE::getConfigPath()); + strcpy(configFile, OSystem_IPHONE::getConfigPath()); #elif defined(__PLAYSTATION2__) ((OSystem_PS2*)g_system)->makeConfigPath(configFile); #elif defined(__PSP__) -- cgit v1.2.3 From 278a5fbb57f5707cbb2d0b3688c37d4bce946fc6 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 30 Jul 2008 16:26:38 +0000 Subject: This time properly reverted my accidental commits of the osystem&configman patch (I didn't mean to commit it in the first place, still waiting for any replies to my corresponding scummvm-devel mail). Sorry for messing up so badly svn-id: r33459 --- common/system.cpp | 167 ------------------------------------------------------ 1 file changed, 167 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index f959ec7ab0..8d528258f4 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -121,170 +121,3 @@ void OSystem::clearScreen() { memset(screen->pixels, 0, screen->h * screen->pitch); unlockScreen(); } - - -/* -FIXME: The config file loading code below needs to be cleaned up. - Port specific variants should be pushed into the respective ports. - - Ideally, the default OSystem::openConfigFileForReading/Writing methods - should be removed completely. -*/ - -#include "common/file.h" - -#ifdef __PLAYSTATION2__ -#include "backends/platform/ps2/systemps2.h" -#endif - -#ifdef IPHONE -#include "backends/platform/iphone/osys_iphone.h" -#endif - -#if defined(WIN32) -#include -// winnt.h defines ARRAYSIZE, but we want our own one... -#undef ARRAYSIZE -#endif - - -#if defined(UNIX) -#ifdef MACOSX -#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" -#else -#define DEFAULT_CONFIG_FILE ".scummvmrc" -#endif -#else -#define DEFAULT_CONFIG_FILE "scummvm.ini" -#endif - - - - - -/* -FIXME: The config file loading code below needs to be cleaned up. - Port specific variants should be pushed into the respective ports. - - Ideally, the default OSystem::openConfigFileForReading/Writing methods - should be removed completely. -*/ - -#include "common/file.h" - -#ifdef __PLAYSTATION2__ -#include "backends/platform/ps2/systemps2.h" -#endif - -#ifdef IPHONE -#include "backends/platform/iphone/osys_iphone.h" -#endif - - -#if defined(UNIX) -#ifdef MACOSX -#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" -#else -#define DEFAULT_CONFIG_FILE ".scummvmrc" -#endif -#else -#define DEFAULT_CONFIG_FILE "scummvm.ini" -#endif - -static Common::String getDefaultConfigFileName() { - char configFile[MAXPATHLEN]; -#if defined(UNIX) && !defined(GP2X) && !defined(IPHONE) - // On UNIX type systems, by default we store the config file inside - // to the HOME directory of the user. - // - // GP2X is Linux based but Home dir can be read only so do not use - // it and put the config in the executable dir. - // - // On the iPhone, the home dir of the user when you launch the app - // from the Springboard, is /. Which we don't want. - const char *home = getenv("HOME"); - if (home != NULL && strlen(home) < MAXPATHLEN) - snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); - else - strcpy(configFile, DEFAULT_CONFIG_FILE); -#else - #if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) - 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", configFile, sizeof(configFile))) - error("Unable to access application data directory"); - } else { - if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) - error("Unable to access user profile directory"); - - strcat(configFile, "\\Application Data"); - CreateDirectory(configFile, NULL); - } - - strcat(configFile, "\\ScummVM"); - CreateDirectory(configFile, NULL); - strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - - if (fopen(configFile, "r") == NULL) { - // Check windows directory - char oldConfigFile[MAXPATHLEN]; - GetWindowsDirectory(oldConfigFile, MAXPATHLEN); - strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); - if (fopen(oldConfigFile, "r")) { - printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n"); - printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n"); - printf("file from the old default location:\n"); - printf("%s\n", oldConfigFile); - printf("to the new default location:\n"); - printf("%s\n\n", configFile); - strcpy(configFile, oldConfigFile); - } - } - } else { - // Check windows directory - GetWindowsDirectory(configFile, MAXPATHLEN); - strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - } - - #elif defined(PALMOS_MODE) - strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); - #elif defined(IPHONE) - strcpy(configFile, OSystem_IPHONE::getConfigPath()); - #elif defined(__PLAYSTATION2__) - ((OSystem_PS2*)g_system)->makeConfigPath(configFile); - #elif defined(__PSP__) - strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); - #elif defined (__SYMBIAN32__) - strcpy(configFile, Symbian::GetExecutablePath()); - strcat(configFile, DEFAULT_CONFIG_FILE); - #else - strcpy(configFile, DEFAULT_CONFIG_FILE); - #endif -#endif - - return configFile; -} - -Common::SeekableReadStream *OSystem::openConfigFileForReading() { - Common::File *confFile = new Common::File(); - assert(confFile); - confFile->open(getDefaultConfigFileName()); - return confFile; -} - -Common::WriteStream *OSystem::openConfigFileForWriting() { -#ifdef __DC__ - return 0; -#else - Common::DumpFile *confFile = new Common::DumpFile(); - assert(confFile); - confFile->open(getDefaultConfigFileName()); - return confFile; -#endif -} -- cgit v1.2.3 From 6377b8bdd570d3c23dbdc9239b844492f7e09b9d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 3 Aug 2008 16:54:18 +0000 Subject: New OSystem API for loading/storing default config file svn-id: r33584 --- common/system.cpp | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 8d528258f4..1362177011 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -121,3 +121,135 @@ void OSystem::clearScreen() { memset(screen->pixels, 0, screen->h * screen->pitch); unlockScreen(); } + + +/* +FIXME: The config file loading code below needs to be cleaned up. + Port specific variants should be pushed into the respective ports. + + Ideally, the default OSystem::openConfigFileForReading/Writing methods + should be removed completely. +*/ + +#include "common/file.h" + +#ifdef __PLAYSTATION2__ +#include "backends/platform/ps2/systemps2.h" +#endif + +#ifdef IPHONE +#include "backends/platform/iphone/osys_iphone.h" +#endif + +#if defined(WIN32) +#include +// winnt.h defines ARRAYSIZE, but we want our own one... +#undef ARRAYSIZE +#endif + + +#if defined(UNIX) +#ifdef MACOSX +#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" +#else +#define DEFAULT_CONFIG_FILE ".scummvmrc" +#endif +#else +#define DEFAULT_CONFIG_FILE "scummvm.ini" +#endif + +static Common::String getDefaultConfigFileName() { + char configFile[MAXPATHLEN]; +#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) + 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", configFile, sizeof(configFile))) + error("Unable to access application data directory"); + } else { + if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) + error("Unable to access user profile directory"); + + strcat(configFile, "\\Application Data"); + CreateDirectory(configFile, NULL); + } + + strcat(configFile, "\\ScummVM"); + CreateDirectory(configFile, NULL); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + + if (fopen(configFile, "r") == NULL) { + // Check windows directory + char oldConfigFile[MAXPATHLEN]; + GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); + if (fopen(oldConfigFile, "r")) { + printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n"); + printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n"); + printf("file from the old default location:\n"); + printf("%s\n", oldConfigFile); + printf("to the new default location:\n"); + printf("%s\n\n", configFile); + strcpy(configFile, oldConfigFile); + } + } + } else { + // Check windows directory + GetWindowsDirectory(configFile, MAXPATHLEN); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + } + +#elif defined(PALMOS_MODE) + strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); +#elif defined(IPHONE) + strcpy(configFile, OSystem_IPHONE::getConfigPath()); +#elif defined(__PLAYSTATION2__) + ((OSystem_PS2*)g_system)->makeConfigPath(configFile); +#elif defined(__PSP__) + strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); +#elif defined (__SYMBIAN32__) + strcpy(configFile, Symbian::GetExecutablePath()); + strcat(configFile, DEFAULT_CONFIG_FILE); +#elif defined(UNIX) && !defined(GP2X) && !defined(IPHONE) + // On UNIX type systems, by default we store the config file inside + // to the HOME directory of the user. + // + // GP2X is Linux based but Home dir can be read only so do not use + // it and put the config in the executable dir. + // + // On the iPhone, the home dir of the user when you launch the app + // from the Springboard, is /. Which we don't want. + const char *home = getenv("HOME"); + if (home != NULL && strlen(home) < MAXPATHLEN) + snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); + else + strcpy(configFile, DEFAULT_CONFIG_FILE); +#else + strcpy(configFile, DEFAULT_CONFIG_FILE); +#endif + + return configFile; +} + +Common::SeekableReadStream *OSystem::openConfigFileForReading() { + Common::File *confFile = new Common::File(); + assert(confFile); + confFile->open(getDefaultConfigFileName()); + return confFile; +} + +Common::WriteStream *OSystem::openConfigFileForWriting() { +#ifdef __DC__ + return 0; +#else + Common::DumpFile *confFile = new Common::DumpFile(); + assert(confFile); + confFile->open(getDefaultConfigFileName()); + return confFile; +#endif +} -- cgit v1.2.3 From b54a1227d9bb53135e434ba9e00ce6cba592f6b1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 3 Aug 2008 17:05:01 +0000 Subject: OSYSTEM: Pushed some SDL/Symbian specific code to the respective backends; made openConfigFileForReading/openConfigFileForWriting return 0 if they failed to open a file svn-id: r33585 --- common/system.cpp | 77 +++++++------------------------------------------------ 1 file changed, 9 insertions(+), 68 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 1362177011..1b18339623 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -149,62 +149,14 @@ FIXME: The config file loading code below needs to be cleaned up. #if defined(UNIX) -#ifdef MACOSX -#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" -#else #define DEFAULT_CONFIG_FILE ".scummvmrc" -#endif #else #define DEFAULT_CONFIG_FILE "scummvm.ini" #endif static Common::String getDefaultConfigFileName() { char configFile[MAXPATHLEN]; -#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) - 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", configFile, sizeof(configFile))) - error("Unable to access application data directory"); - } else { - if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) - error("Unable to access user profile directory"); - - strcat(configFile, "\\Application Data"); - CreateDirectory(configFile, NULL); - } - - strcat(configFile, "\\ScummVM"); - CreateDirectory(configFile, NULL); - strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - - if (fopen(configFile, "r") == NULL) { - // Check windows directory - char oldConfigFile[MAXPATHLEN]; - GetWindowsDirectory(oldConfigFile, MAXPATHLEN); - strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); - if (fopen(oldConfigFile, "r")) { - printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n"); - printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n"); - printf("file from the old default location:\n"); - printf("%s\n", oldConfigFile); - printf("to the new default location:\n"); - printf("%s\n\n", configFile); - strcpy(configFile, oldConfigFile); - } - } - } else { - // Check windows directory - GetWindowsDirectory(configFile, MAXPATHLEN); - strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - } - -#elif defined(PALMOS_MODE) +#if defined(PALMOS_MODE) strcpy(configFile,"/PALM/Programs/ScummVM/" DEFAULT_CONFIG_FILE); #elif defined(IPHONE) strcpy(configFile, OSystem_IPHONE::getConfigPath()); @@ -212,23 +164,6 @@ static Common::String getDefaultConfigFileName() { ((OSystem_PS2*)g_system)->makeConfigPath(configFile); #elif defined(__PSP__) strcpy(configFile, "ms0:/" DEFAULT_CONFIG_FILE); -#elif defined (__SYMBIAN32__) - strcpy(configFile, Symbian::GetExecutablePath()); - strcat(configFile, DEFAULT_CONFIG_FILE); -#elif defined(UNIX) && !defined(GP2X) && !defined(IPHONE) - // On UNIX type systems, by default we store the config file inside - // to the HOME directory of the user. - // - // GP2X is Linux based but Home dir can be read only so do not use - // it and put the config in the executable dir. - // - // On the iPhone, the home dir of the user when you launch the app - // from the Springboard, is /. Which we don't want. - const char *home = getenv("HOME"); - if (home != NULL && strlen(home) < MAXPATHLEN) - snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); - else - strcpy(configFile, DEFAULT_CONFIG_FILE); #else strcpy(configFile, DEFAULT_CONFIG_FILE); #endif @@ -239,7 +174,10 @@ static Common::String getDefaultConfigFileName() { Common::SeekableReadStream *OSystem::openConfigFileForReading() { Common::File *confFile = new Common::File(); assert(confFile); - confFile->open(getDefaultConfigFileName()); + if (!confFile->open(getDefaultConfigFileName())) { + delete confFile; + confFile = 0; + } return confFile; } @@ -249,7 +187,10 @@ Common::WriteStream *OSystem::openConfigFileForWriting() { #else Common::DumpFile *confFile = new Common::DumpFile(); assert(confFile); - confFile->open(getDefaultConfigFileName()); + if (!confFile->open(getDefaultConfigFileName())) { + delete confFile; + confFile = 0; + } return confFile; #endif } -- cgit v1.2.3 From 2efe13026d3d19583429f7e0de50b062db838980 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 4 Aug 2008 15:01:41 +0000 Subject: Fixing compilation under MSVC svn-id: r33610 --- common/system.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 1b18339623..ac45656202 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -29,6 +29,10 @@ #include "common/config-manager.h" #include "common/system.h" #include "common/timer.h" +#if defined(WIN32) && defined(ARRAYSIZE) +// winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h +#undef ARRAYSIZE +#endif #include "common/util.h" #include "graphics/colormasks.h" -- cgit v1.2.3 From 4900a3e96ec7bb8ce2414776f55f96d8c84ebb32 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 4 Aug 2008 17:46:22 +0000 Subject: Remove some code which was rendered obsolete by md5's commit r33610 svn-id: r33617 --- common/system.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index ac45656202..e3f81a69b6 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -145,12 +145,6 @@ FIXME: The config file loading code below needs to be cleaned up. #include "backends/platform/iphone/osys_iphone.h" #endif -#if defined(WIN32) -#include -// winnt.h defines ARRAYSIZE, but we want our own one... -#undef ARRAYSIZE -#endif - #if defined(UNIX) #define DEFAULT_CONFIG_FILE ".scummvmrc" -- cgit v1.2.3 From f7cc93f71ab5b7526a69bae5df80abeafeef5d31 Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Tue, 5 Aug 2008 00:27:25 +0000 Subject: Removed unneeded #includes. svn-id: r33627 --- common/system.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index e3f81a69b6..3e07e4ac4c 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -28,16 +28,9 @@ #include "common/config-manager.h" #include "common/system.h" -#include "common/timer.h" -#if defined(WIN32) && defined(ARRAYSIZE) -// winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h -#undef ARRAYSIZE -#endif -#include "common/util.h" #include "graphics/colormasks.h" #include "gui/message.h" -#include "sound/mixer.h" OSystem *g_system = 0; -- cgit v1.2.3 From dca7116cb54026cfa3ee25148cf3b961f7febdd2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 9 Aug 2008 23:07:32 +0000 Subject: Use FSNode API in default OSystem::openConfigFileForReading & OSystem::openConfigFileForWriting method implementations svn-id: r33730 --- common/system.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 3e07e4ac4c..d0548cdd2d 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -163,25 +163,15 @@ static Common::String getDefaultConfigFileName() { } Common::SeekableReadStream *OSystem::openConfigFileForReading() { - Common::File *confFile = new Common::File(); - assert(confFile); - if (!confFile->open(getDefaultConfigFileName())) { - delete confFile; - confFile = 0; - } - return confFile; + FilesystemNode file(getDefaultConfigFileName()); + return file.openForReading(); } Common::WriteStream *OSystem::openConfigFileForWriting() { #ifdef __DC__ return 0; #else - Common::DumpFile *confFile = new Common::DumpFile(); - assert(confFile); - if (!confFile->open(getDefaultConfigFileName())) { - delete confFile; - confFile = 0; - } - return confFile; + FilesystemNode file(getDefaultConfigFileName()); + return file.openForWriting(); #endif } -- cgit v1.2.3 From 3ea8f70792b62c70bfcae97b970e3830d85c5d72 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 2 Sep 2008 13:11:54 +0000 Subject: Handle OSystem::lockScreen fail in default OSystem::clearScreen implementation. svn-id: r34276 --- common/system.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index d0548cdd2d..863f395671 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -115,7 +115,8 @@ Common::EventManager *OSystem::getEventManager() { void OSystem::clearScreen() { Graphics::Surface *screen = lockScreen(); - memset(screen->pixels, 0, screen->h * screen->pitch); + if (screen && screen->pixels) + memset(screen->pixels, 0, screen->h * screen->pitch); unlockScreen(); } -- cgit v1.2.3 From 531bcf847ceef2b9eca82e0b3ef8473612889632 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 3 Sep 2008 11:22:51 +0000 Subject: Moved FilesystemNode / FSList to namespace Common; also got rid of some 'typedef Common::String String;' name aliases svn-id: r34302 --- common/system.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 863f395671..6ed9d46e12 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -164,7 +164,7 @@ static Common::String getDefaultConfigFileName() { } Common::SeekableReadStream *OSystem::openConfigFileForReading() { - FilesystemNode file(getDefaultConfigFileName()); + Common::FilesystemNode file(getDefaultConfigFileName()); return file.openForReading(); } @@ -172,7 +172,7 @@ Common::WriteStream *OSystem::openConfigFileForWriting() { #ifdef __DC__ return 0; #else - FilesystemNode file(getDefaultConfigFileName()); + Common::FilesystemNode file(getDefaultConfigFileName()); return file.openForWriting(); #endif } -- cgit v1.2.3 From 12106a159912055d77668f8436c1a1e87d6c0f4e Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Fri, 5 Sep 2008 11:41:39 +0000 Subject: Removed useless dependencies from common/file.h in common code. When complete removal was not possibile, dependency has been pushed to the cpp files from the headers. svn-id: r34343 --- common/system.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'common/system.cpp') diff --git a/common/system.cpp b/common/system.cpp index 6ed9d46e12..d9bc027e91 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -126,10 +126,9 @@ FIXME: The config file loading code below needs to be cleaned up. Port specific variants should be pushed into the respective ports. Ideally, the default OSystem::openConfigFileForReading/Writing methods - should be removed completely. + should be removed completely. */ -#include "common/file.h" #ifdef __PLAYSTATION2__ #include "backends/platform/ps2/systemps2.h" -- cgit v1.2.3