aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2006-04-11 22:29:51 +0000
committerMax Horn2006-04-11 22:29:51 +0000
commit0c75d7d1c01b36ba0f13f9cf1d53307841a5f26e (patch)
treeebb31fa273de10f90d28b4cd737a36287a3733aa
parent9610a4daefb6717dacefc4fc428faf6a23529c9e (diff)
downloadscummvm-rg350-0c75d7d1c01b36ba0f13f9cf1d53307841a5f26e.tar.gz
scummvm-rg350-0c75d7d1c01b36ba0f13f9cf1d53307841a5f26e.tar.bz2
scummvm-rg350-0c75d7d1c01b36ba0f13f9cf1d53307841a5f26e.zip
Removed the PalmOS specific hack in file.cpp in favor for code that should work everywhere (and hopefully will help the GP32 port, too).
svn-id: r21811
-rwxr-xr-xbackends/PalmOS/Src/native/zodiacARM.cpp7
-rw-r--r--common/file.cpp75
2 files changed, 34 insertions, 48 deletions
diff --git a/backends/PalmOS/Src/native/zodiacARM.cpp b/backends/PalmOS/Src/native/zodiacARM.cpp
index 20e8f52b80..9b0db9122d 100755
--- a/backends/PalmOS/Src/native/zodiacARM.cpp
+++ b/backends/PalmOS/Src/native/zodiacARM.cpp
@@ -60,15 +60,8 @@ static void palm_main(int argc, char **argvP) {
assert(g_system);
- // Invoke the actual ScummVM main entry point:
- extern void initGlobalHashes();
- initGlobalHashes();
-
scummvm_main(argc, argvP);
- extern void freeGlobalHashes();
- freeGlobalHashes();
-
g_system->quit(); // TODO: Consider removing / replacing this!
}
diff --git a/common/file.cpp b/common/file.cpp
index 30ed40935e..a0b6f9763d 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -37,20 +37,8 @@ typedef HashMap<String, int> StringIntMap;
// The following two objects could be turned into static members of class
// File. However, then we would be forced to #include hashmap in file.h
// which seems to be a high price just for a simple beautification...
-#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG))
-static StringIntMap _defaultDirectories;
-static FilesMap _filesMap;
-
-#else
-// This is a very bad hack to make these global objects work with PalmOS ARM version.
-// In fact global objects are correctly allocated but constructors/destructors are not called
-// and so, the object is not correctly initialized. See also the 2 functions at end of file.
-// This is related to how ARM apps are handled in PalmOS, there is no problem with 68k version.
-static StringIntMap *__defaultDirectories;
-static FilesMap *__filesMap;
-#define _defaultDirectories (*__defaultDirectories)
-#define _filesMap (*__filesMap)
-#endif
+static StringIntMap *_defaultDirectories;
+static FilesMap *_filesMap;
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode) {
FILE *file;
@@ -133,9 +121,12 @@ void File::addDefaultDirectoryRecursive(const String &directory, int level) {
if (level <= 0)
return;
+ if (!_defaultDirectories)
+ _defaultDirectories = new StringIntMap;
+
// Do not add directories multiple times, unless this time they are added
// with a bigger depth.
- if (_defaultDirectories.contains(directory) && _defaultDirectories[directory] >= level)
+ if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level)
return;
FilesystemNode dir(directory.c_str());
@@ -144,7 +135,10 @@ void File::addDefaultDirectoryRecursive(const String &directory, int level) {
if (!dir.isDirectory())
return;
- _defaultDirectories[directory] = level;
+ (*_defaultDirectories)[directory] = level;
+
+ if (!_filesMap)
+ _filesMap = new FilesMap;
const FSList fslist(dir.listDir(FilesystemNode::kListAllNoRoot));
@@ -154,15 +148,18 @@ void File::addDefaultDirectoryRecursive(const String &directory, int level) {
} else {
String lfn = file->displayName();
lfn.toLowercase();
- if (!_filesMap.contains(lfn))
- _filesMap[lfn] = file->path();
+ if (!_filesMap->contains(lfn))
+ (*_filesMap)[lfn] = file->path();
}
}
}
void File::resetDefaultDirectories() {
- _defaultDirectories.clear();
- _filesMap.clear();
+ delete _defaultDirectories;
+ delete _filesMap;
+
+ _defaultDirectories = 0;
+ _filesMap = 0;
}
File::File()
@@ -214,21 +211,28 @@ bool File::open(const char *filename, AccessMode mode, const char *directory) {
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
if (mode == kFileWriteMode || directory) {
_handle = fopenNoCase(filename, directory ? directory : "", modeStr);
- } else if (_filesMap.contains(fname)) {
- debug(3, "Opening hashed: %s", _filesMap[fname].c_str());
- _handle = fopen(_filesMap[fname].c_str(), modeStr);
- } else if (_filesMap.contains(fname + ".")) {
+ } else if (_filesMap && _filesMap->contains(fname)) {
+ fname = (*_filesMap)[fname];
+ debug(3, "Opening hashed: %s", fname.c_str());
+ _handle = fopen(fname.c_str(), modeStr);
+ } else if (_filesMap && _filesMap->contains(fname + ".")) {
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
- debug(3, "Opening hashed: %s", _filesMap[fname].c_str());
- _handle = fopen(_filesMap[fname].c_str(), modeStr);
+
+ // FIXME: Shouldn't we add a '+ "."' after fname here?
+ fname = (*_filesMap)[fname];
+ debug(3, "Opening hashed: %s", fname.c_str());
+ _handle = fopen(fname.c_str(), modeStr);
} else {
- StringIntMap::const_iterator x;
- // Try all default directories
- for (x = _defaultDirectories.begin(); _handle == NULL && x != _defaultDirectories.end(); ++x) {
- _handle = fopenNoCase(filename, x->_key.c_str(), modeStr);
+ if (_defaultDirectories) {
+ // Try all default directories
+ StringIntMap::const_iterator x(_defaultDirectories->begin());
+ for (; _handle == NULL && x != _defaultDirectories->end(); ++x) {
+ _handle = fopenNoCase(filename, x->_key.c_str(), modeStr);
+ }
}
+
// Last resort: try the current directory
if (_handle == NULL)
_handle = fopenNoCase(filename, "", modeStr);
@@ -370,14 +374,3 @@ uint32 File::write(const void *ptr, uint32 len) {
}
} // End of namespace Common
-
-#if defined(PALMOS_ARM) || defined(PALMOS_DEBUG)
-void initGlobalHashes() {
- Common::__defaultDirectories = new Common::StringIntMap;
- Common::__filesMap = new Common::FilesMap;
-}
-void freeGlobalHashes() {
- delete Common::__defaultDirectories;
- delete Common::__filesMap;
-}
-#endif