/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * $URL$ * $Id$ * */ #if defined(WIN32) #include // winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h #undef ARRAYSIZE #endif #include "backends/platform/sdl/file.h" #include "common/archive.h" #ifdef UNIX #include "backends/saves/posix/posix-saves.h" #else #include "backends/saves/default/default-saves.h" #endif /* * Include header files needed for the getFilesystemFactory() method. */ #if defined(__amigaos4__) #include "backends/fs/amigaos4/amigaos4-fs-factory.h" #elif defined(UNIX) #include "backends/fs/posix/posix-fs-factory.h" #elif defined(WIN32) #include "backends/fs/windows/windows-fs-factory.h" #endif #if defined(UNIX) #ifdef MACOSX #define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" #elif defined(SAMSUNGTV) #define DEFAULT_CONFIG_FILE "/dtv/usb/sda1/.scummvmrc" #else #define DEFAULT_CONFIG_FILE ".scummvmrc" #endif #else #define DEFAULT_CONFIG_FILE "scummvm.ini" #endif SdlSubSys_File::SdlSubSys_File() : _inited(false), _fsFactory(0), _savefile(0) { #if defined(__amigaos4__) _fsFactory = new AmigaOSFilesystemFactory(); #elif defined(UNIX) _fsFactory = new POSIXFilesystemFactory(); #elif defined(WIN32) _fsFactory = new WindowsFilesystemFactory(); #elif defined(__SYMBIAN32__) // Do nothing since its handled by the Symbian SDL inheritance #else #error Unknown and unsupported FS backend #endif } SdlSubSys_File::~SdlSubSys_File() { if (_inited) { fileDone(); } } void SdlSubSys_File::fileInit() { if (_inited) { return; } // Create the savefile manager, if none exists yet (we check for this to // allow subclasses to provide their own). if (_savefile == 0) { #ifdef UNIX _savefile = new POSIXSaveFileManager(); #else _savefile = new DefaultSaveFileManager(); #endif } _inited = true; } void SdlSubSys_File::fileDone() { // Event Manager requires save manager for storing // recorded events delete getEventManager(); delete _savefile; _inited = false; } bool SdlSubSys_File::hasFeature(Feature f) { return false; } void SdlSubSys_File::setFeatureState(Feature f, bool enable) { } bool SdlSubSys_File::getFeatureState(Feature f) { return false; } Common::SaveFileManager *SdlSubSys_File::getSavefileManager() { assert(_savefile); return _savefile; } FilesystemFactory *SdlSubSys_File::getFilesystemFactory() { assert(_fsFactory); return _fsFactory; } void SdlSubSys_File::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { #ifdef DATA_PATH // Add the global DATA_PATH to the directory search list // FIXME: We use depth = 4 for now, to match the old code. May want to change that Common::FSNode dataNode(DATA_PATH); if (dataNode.exists() && dataNode.isDirectory()) { s.add(DATA_PATH, new Common::FSDirectory(dataNode, 4), priority); } #endif #ifdef MACOSX // Get URL of the Resource directory of the .app bundle CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if (fileUrl) { // Try to convert the URL to an absolute path UInt8 buf[MAXPATHLEN]; if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) { // Success: Add it to the search path Common::String bundlePath((const char *)buf); s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority); } CFRelease(fileUrl); } #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); FILE *tmp = NULL; if ((tmp = fopen(configFile, "r")) == NULL) { // Check windows directory char oldConfigFile[MAXPATHLEN]; GetWindowsDirectory(oldConfigFile, MAXPATHLEN); strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); if ((tmp = fopen(oldConfigFile, "r"))) { strcpy(configFile, oldConfigFile); fclose(tmp); } } else { fclose(tmp); } } else { // Check windows directory GetWindowsDirectory(configFile, MAXPATHLEN); strcat(configFile, "\\" DEFAULT_CONFIG_FILE); } #elif defined(UNIX) // 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 *SdlSubSys_File::createConfigReadStream() { Common::FSNode file(getDefaultConfigFileName()); return file.createReadStream(); } Common::WriteStream *SdlSubSys_File::createConfigWriteStream() { Common::FSNode file(getDefaultConfigFileName()); return file.createWriteStream(); }