From 388b3f0296f0a55b40017c5a1ad2b722218bd8a9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 16 Aug 2008 22:30:47 +0000 Subject: Properly close files opened when checking for config file on WIN32. svn-id: r33953 --- backends/platform/sdl/sdl.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 5c3b87309d..539b34b78b 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -292,12 +292,13 @@ static Common::String getDefaultConfigFileName() { CreateDirectory(configFile, NULL); strcat(configFile, "\\" DEFAULT_CONFIG_FILE); - if (fopen(configFile, "r") == NULL) { + FILE *tmp = NULL; + if ((tmp = fopen(configFile, "r")) == NULL) { // Check windows directory char oldConfigFile[MAXPATHLEN]; GetWindowsDirectory(oldConfigFile, MAXPATHLEN); strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); - if (fopen(oldConfigFile, "r")) { + if ((tmp = 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"); @@ -305,7 +306,11 @@ static Common::String getDefaultConfigFileName() { printf("to the new default location:\n"); printf("%s\n\n", configFile); strcpy(configFile, oldConfigFile); + + fclose(tmp); } + } else { + fclose(tmp); } } else { // Check windows directory -- cgit v1.2.3 From b727ac880d237cbe10284c2da9db25998ab6eb11 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 22 Aug 2008 11:36:47 +0000 Subject: Turned Windows, AmigaOS and POSIX FSFactories into plain classes; no need for them to be singletons (actually true for all other FS factories) svn-id: r34098 --- backends/platform/sdl/sdl.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 539b34b78b..4ba53ffb5e 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -170,6 +170,21 @@ void OSystem_SDL::initBackend() { _timerID = SDL_AddTimer(10, &timer_handler, _timer); } + if (_fsFactory == 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 backend in OSystem_SDL::getFilesystemFactory + #endif + } + + // Invoke parent implementation of this method OSystem::initBackend(); @@ -196,6 +211,7 @@ OSystem_SDL::OSystem_SDL() _soundMutex(0), _soundCond(0), _soundThread(0), _soundThreadIsRunning(false), _soundThreadShouldQuit(false), #endif + _fsFactory(0), _savefile(0), _mixer(0), _timer(0), @@ -254,17 +270,7 @@ Common::SaveFileManager *OSystem_SDL::getSavefileManager() { } FilesystemFactory *OSystem_SDL::getFilesystemFactory() { - #if defined(__amigaos4__) - return &AmigaOSFilesystemFactory::instance(); - #elif defined(UNIX) - return &POSIXFilesystemFactory::instance(); - #elif defined(WIN32) - return &WindowsFilesystemFactory::instance(); - #elif defined(__SYMBIAN32__) - // Do nothing since its handled by the Symbian SDL inheritance - #else - #error Unknown and unsupported backend in OSystem_SDL::getFilesystemFactory - #endif + return _fsFactory; } static Common::String getDefaultConfigFileName() { -- cgit v1.2.3 From 79751b07aef33512e2ded0867bbca0c50723f314 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 22 Aug 2008 11:45:29 +0000 Subject: SDL backend: Simplified openConfigFileForReading/openConfigFileForWriting impl; also init _fsFactory in constructor, as it is needed to load the config file svn-id: r34100 --- backends/platform/sdl/sdl.cpp | 46 ++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 4ba53ffb5e..44ed5e45ff 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -170,21 +170,6 @@ void OSystem_SDL::initBackend() { _timerID = SDL_AddTimer(10, &timer_handler, _timer); } - if (_fsFactory == 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 backend in OSystem_SDL::getFilesystemFactory - #endif - } - - // Invoke parent implementation of this method OSystem::initBackend(); @@ -229,6 +214,19 @@ OSystem_SDL::OSystem_SDL() memset(&_mouseCurState, 0, sizeof(_mouseCurState)); _inited = false; + + + #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 } OSystem_SDL::~OSystem_SDL() { @@ -345,23 +343,13 @@ static Common::String getDefaultConfigFileName() { } Common::SeekableReadStream *OSystem_SDL::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_SDL::openConfigFileForWriting() { - Common::DumpFile *confFile = new Common::DumpFile(); - assert(confFile); - if (!confFile->open(getDefaultConfigFileName())) { - delete confFile; - confFile = 0; - } - return confFile; + FilesystemNode file(getDefaultConfigFileName()); + return file.openForWriting(); } void OSystem_SDL::setWindowCaption(const char *caption) { -- cgit v1.2.3 From 16e02f051d88c04c4a3eb7fbe319bb6b338d79ae Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 22 Aug 2008 11:49:34 +0000 Subject: Turned SymbianFilesystemFactory from a singleton into a normal class; adapted symbian backend accordingly svn-id: r34101 --- backends/platform/sdl/sdl.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 44ed5e45ff..fa0ea35cb5 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -268,6 +268,7 @@ Common::SaveFileManager *OSystem_SDL::getSavefileManager() { } FilesystemFactory *OSystem_SDL::getFilesystemFactory() { + assert(_fsFactory); return _fsFactory; } -- cgit v1.2.3 From dded0de6c245de3e80dfb4051a9828dd3ad9620e Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Fri, 22 Aug 2008 13:01:23 +0000 Subject: Remove warning about change of config file location under Windows, since it is frequently repeated (due to code restructures). The information is mentioned in the README anyway. svn-id: r34104 --- backends/platform/sdl/sdl.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index fa0ea35cb5..1ed76f4be6 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -304,12 +304,6 @@ static Common::String getDefaultConfigFileName() { GetWindowsDirectory(oldConfigFile, MAXPATHLEN); strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); if ((tmp = 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); fclose(tmp); -- cgit v1.2.3 From 44266bfc28e74befa962795807119f77e8054361 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 27 Aug 2008 18:21:03 +0000 Subject: Slightly cleaned up version of patch #2072006: Enhance OSystem_SDL::setupIcon svn-id: r34192 --- backends/platform/sdl/sdl.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 1ed76f4be6..9abaa3c6fb 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -429,15 +429,21 @@ void OSystem_SDL::quit() { } void OSystem_SDL::setupIcon() { - int w, h, ncols, nbytes, i; - unsigned int rgba[256], icon[32 * 32]; - unsigned char mask[32][4]; + int x, y, w, h, ncols, nbytes, i; + unsigned int rgba[256]; + unsigned int *icon; sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes); - if ((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1)) { - warning("Could not load the icon (%d %d %d %d)", w, h, ncols, nbytes); + if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) { + warning("Could not load the built-in icon (%d %d %d %d)", w, h, ncols, nbytes); return; } + icon = (unsigned int*)malloc(w*h*sizeof(unsigned int)); + if (!icon) { + warning("Could not allocate temp storage for the built-in icon"); + return; + } + for (i = 0; i < ncols; i++) { unsigned char code; char color[32]; @@ -451,26 +457,27 @@ void OSystem_SDL::setupIcon() { sscanf(color + 1, "%06x", &col); col |= 0xFF000000; } else { - warning("Could not load the icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]); + warning("Could not load the built-in icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]); + free(icon); return; } rgba[code] = col; } - memset(mask, 0, sizeof(mask)); - for (h = 0; h < 32; h++) { - const char *line = scummvm_icon[1 + ncols + h]; - for (w = 0; w < 32; w++) { - icon[w + 32 * h] = rgba[(int)line[w]]; - if (rgba[(int)line[w]] & 0xFF000000) { - mask[h][w >> 3] |= 1 << (7 - (w & 0x07)); - } + for (y = 0; y < h; y++) { + const char *line = scummvm_icon[1 + ncols + y]; + for (x = 0; x < w; x++) { + icon[x + w * y] = rgba[(int)line[x]]; } } - SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, 32, 32, 32, 32 * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000); - SDL_WM_SetIcon(sdl_surf, (unsigned char *) mask); + SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, w, h, 32, w * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000); + if (!sdl_surf) { + warning("SDL_CreateRGBSurfaceFrom(icon) failed"); + } + SDL_WM_SetIcon(sdl_surf, NULL); SDL_FreeSurface(sdl_surf); + free(icon); } OSystem::MutexRef OSystem_SDL::createMutex(void) { -- 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 --- backends/platform/sdl/sdl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 9abaa3c6fb..6554483eda 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -338,12 +338,12 @@ static Common::String getDefaultConfigFileName() { } Common::SeekableReadStream *OSystem_SDL::openConfigFileForReading() { - FilesystemNode file(getDefaultConfigFileName()); + Common::FilesystemNode file(getDefaultConfigFileName()); return file.openForReading(); } Common::WriteStream *OSystem_SDL::openConfigFileForWriting() { - FilesystemNode file(getDefaultConfigFileName()); + Common::FilesystemNode file(getDefaultConfigFileName()); return file.openForWriting(); } -- cgit v1.2.3 From 55a05dc0f4c7141de44008148bbcb7add4c1b078 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 3 Sep 2008 15:22:19 +0000 Subject: Some cleanup by peres svn-id: r34308 --- backends/platform/sdl/sdl.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 6554483eda..1332cbc16d 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -34,7 +34,6 @@ #include "backends/platform/sdl/sdl.h" #include "common/config-manager.h" #include "common/events.h" -#include "common/file.h" #include "common/util.h" #include "backends/saves/default/default-saves.h" @@ -516,7 +515,7 @@ void OSystem_SDL::mixerProducerThread() { // Generate samples and put them into the next buffer nextSoundBuffer = _activeSoundBuf ^ 1; _mixer->mixCallback(_soundBuffers[nextSoundBuffer], _soundBufSize); - + // Swap buffers _activeSoundBuf = nextSoundBuffer; } @@ -560,7 +559,7 @@ void OSystem_SDL::deinitThreadedMixer() { SDL_CondBroadcast(_soundCond); SDL_WaitThread(_soundThread, NULL); - // Kill the mutex & cond variables. + // Kill the mutex & cond variables. // Attention: AT this point, the mixer callback must not be running // anymore, else we will crash! SDL_DestroyMutex(_soundMutex); @@ -583,10 +582,10 @@ void OSystem_SDL::mixCallback(void *arg, byte *samples, int len) { // Lock mutex, to ensure our data is not overwritten by the producer thread SDL_LockMutex(this_->_soundMutex); - + // Copy data from the current sound buffer memcpy(samples, this_->_soundBuffers[this_->_activeSoundBuf], len); - + // Unlock mutex and wake up the produced thread SDL_UnlockMutex(this_->_soundMutex); SDL_CondSignal(this_->_soundCond); @@ -646,7 +645,7 @@ void OSystem_SDL::setupMixer() { // even if it didn't. Probably only happens for "weird" rates, though. _samplesPerSec = obtained.freq; debug(1, "Output sample rate: %d Hz", _samplesPerSec); - + // Tell the mixer that we are ready and start the sound processing _mixer->setOutputRate(_samplesPerSec); _mixer->setReady(true); -- cgit v1.2.3 From 38a44f85ae9c897c24d7e6ccbc165021ec191330 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 7 Sep 2008 21:30:55 +0000 Subject: Added new OSystem method addSysArchivesToSearchSet() [better name pending, suggestions welcome] svn-id: r34424 --- backends/platform/sdl/sdl.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 1332cbc16d..3423cd43c5 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -32,6 +32,7 @@ #endif #include "backends/platform/sdl/sdl.h" +#include "common/archive.h" #include "common/config-manager.h" #include "common/events.h" #include "common/util.h" @@ -71,6 +72,9 @@ #define DEFAULT_CONFIG_FILE "scummvm.ini" #endif +#if defined(MACOSX) || defined(IPHONE) +#include "CoreFoundation/CoreFoundation.h" +#endif static Uint32 timer_handler(Uint32 interval, void *param) { @@ -271,6 +275,38 @@ FilesystemFactory *OSystem_SDL::getFilesystemFactory() { return _fsFactory; } +void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s) { + +#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::FilesystemNode dataNode(DATA_PATH); + if (dataNode.exists() && dataNode.isDirectory()) { + Common::ArchivePtr dataArchive(new Common::FSDirectory(dataNode, 4)); + s.add(DATA_PATH, dataArchive); + } +#endif + +#if defined(MACOSX) || defined(IPHONE) + // 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); + Common::ArchivePtr bundleArchive(new Common::FSDirectory(bundlePath)); + s.add("__OSX_BUNDLE__", bundleArchive); + } + CFRelease(fileUrl); + } + +#endif + +} + + static Common::String getDefaultConfigFileName() { char configFile[MAXPATHLEN]; #if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) -- cgit v1.2.3 From 4f9dc057312c858d8d576ea181bdbd064996b1ec Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 7 Sep 2008 21:59:25 +0000 Subject: Add a priority param to OSystem::addSysArchivesToSearchSet (still in search for a better name ;) svn-id: r34432 --- backends/platform/sdl/sdl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'backends/platform/sdl/sdl.cpp') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 3423cd43c5..9a6f294a55 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -275,7 +275,7 @@ FilesystemFactory *OSystem_SDL::getFilesystemFactory() { return _fsFactory; } -void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s) { +void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, uint priority) { #ifdef DATA_PATH // Add the global DATA_PATH to the directory search list @@ -283,7 +283,7 @@ void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s) { Common::FilesystemNode dataNode(DATA_PATH); if (dataNode.exists() && dataNode.isDirectory()) { Common::ArchivePtr dataArchive(new Common::FSDirectory(dataNode, 4)); - s.add(DATA_PATH, dataArchive); + s.add(DATA_PATH, dataArchive, priority); } #endif @@ -297,7 +297,7 @@ void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s) { // Success: Add it to the search path Common::String bundlePath((const char *)buf); Common::ArchivePtr bundleArchive(new Common::FSDirectory(bundlePath)); - s.add("__OSX_BUNDLE__", bundleArchive); + s.add("__OSX_BUNDLE__", bundleArchive, priority); } CFRelease(fileUrl); } -- cgit v1.2.3