diff options
author | Max Horn | 2010-10-25 23:19:39 +0000 |
---|---|---|
committer | Max Horn | 2010-10-25 23:19:39 +0000 |
commit | a7832856252828450a63fdd1d10c337cc8fb671e (patch) | |
tree | 265a3aae7e0d4dad340ce73194273e3a9800b299 | |
parent | e0d5db0bb822f4772d90cd404fb23e89524f7b3a (diff) | |
download | scummvm-rg350-a7832856252828450a63fdd1d10c337cc8fb671e.tar.gz scummvm-rg350-a7832856252828450a63fdd1d10c337cc8fb671e.tar.bz2 scummvm-rg350-a7832856252828450a63fdd1d10c337cc8fb671e.zip |
SWORD25: Simplify FS 'wrapper' code a bit, add FIXME comments
The save system of this engine currently partially bypasses the
SaveFileManager API, by (abusing) the fact that the Lua engine allows
creating files in arbitrary places (it exposes fopen, fread, fwrite
etc.). This is used to create a 'config.lua' configuration file. This makes it non-portable.
In addition, the filenames used for the savestates ("0.b25s") do not
comply with our naming conventions for engine savestates.
It should be possible to overcome all this, but it might require hacking
the Lua engine; or we could try to replace some of the BS2.5 script
functions with our own, dynamically.
svn-id: r53838
-rw-r--r-- | engines/sword25/kernel/filesystemutil.cpp | 94 | ||||
-rw-r--r-- | engines/sword25/kernel/filesystemutil.h | 25 | ||||
-rw-r--r-- | engines/sword25/kernel/kernel_script.cpp | 9 | ||||
-rw-r--r-- | engines/sword25/kernel/persistenceservice.cpp | 8 | ||||
-rw-r--r-- | engines/sword25/package/packagemanager.cpp | 22 | ||||
-rw-r--r-- | engines/sword25/package/packagemanager.h | 17 | ||||
-rw-r--r-- | engines/sword25/package/packagemanager_script.cpp | 10 |
7 files changed, 50 insertions, 135 deletions
diff --git a/engines/sword25/kernel/filesystemutil.cpp b/engines/sword25/kernel/filesystemutil.cpp index 4268cf83fa..d05ac922e1 100644 --- a/engines/sword25/kernel/filesystemutil.cpp +++ b/engines/sword25/kernel/filesystemutil.cpp @@ -43,85 +43,45 @@ namespace Sword25 { #define BS_LOG_PREFIX "FILESYSTEMUTIL" -Common::String getAbsolutePath(const Common::String &path) { - Common::FSNode node(path); +Common::String FileSystemUtil::getUserdataDirectory() { + // FIXME: This code is a hack which bypasses the savefile API, + // and should eventually be removed. + Common::String path = ConfMan.get("savepath"); - if (!node.exists()) { - // An error has occurred finding the node - // We can do nothing at this pointer than return an empty string - BS_LOG_ERRORLN("A call to GetAbsolutePath failed."); + if (path.empty()) { + error("No save path has been defined"); return ""; } - // Return the result - return node.getPath(); + // Return the path + return path; } -class BS_FileSystemUtilScummVM : public FileSystemUtil { -public: - virtual Common::String getUserdataDirectory() { - Common::String path = ConfMan.get("savepath"); - - if (path.empty()) { - error("No save path has been defined"); - return ""; - } - - // Return the path - return path; - } - - virtual Common::String getPathSeparator() { - return Common::String("/"); - } - - virtual int32 getFileSize(const Common::String &filename) { - Common::FSNode node(filename); - - // If the file does not exist, return -1 as a result - if (!node.exists()) - return -1; - - // Get the size of the file and return it - Common::File f; - f.open(node); - uint32 size = f.size(); - f.close(); - - return size; - } - - virtual bool fileExists(const Common::String &filename) { - Common::File f; - if (f.exists(filename)) - return true; +Common::String FileSystemUtil::getPathSeparator() { + // FIXME: This code is a hack which bypasses the savefile API, + // and should eventually be removed. + return Common::String("/"); +} - // Check if the file exists in the save folder - Common::FSNode folder(PersistenceService::getSavegameDirectory()); - Common::FSNode fileNode = folder.getChild(FileSystemUtil::getInstance().getPathFilename(filename)); - return fileNode.exists(); - } +bool FileSystemUtil::fileExists(const Common::String &filename) { + Common::File f; + if (f.exists(filename)) + return true; - virtual bool createDirectory(const Common::String &sirectoryName) { - // ScummVM doesn't support creating folders, so this is only a stub - BS_LOG_ERRORLN("CreateDirectory method called"); - return false; - } + // Check if the file exists in the save folder + Common::FSNode folder(PersistenceService::getSavegameDirectory()); + Common::FSNode fileNode = folder.getChild(getPathFilename(filename)); + return fileNode.exists(); +} - virtual Common::String getPathFilename(const Common::String &path) { - for (int i = path.size() - 1; i >= 0; --i) { - if ((path[i] == '/') || (path[i] == '\\')) { - return Common::String(&path.c_str()[i + 1]); - } +Common::String FileSystemUtil::getPathFilename(const Common::String &path) { + for (int i = path.size() - 1; i >= 0; --i) { + if ((path[i] == '/') || (path[i] == '\\')) { + return Common::String(&path.c_str()[i + 1]); } - - return path; } -}; -FileSystemUtil &FileSystemUtil::getInstance() { - static BS_FileSystemUtilScummVM instance; - return instance; + return path; } } // End of namespace Sword25 diff --git a/engines/sword25/kernel/filesystemutil.h b/engines/sword25/kernel/filesystemutil.h index 4c089e1049..38a3fdaa12 100644 --- a/engines/sword25/kernel/filesystemutil.h +++ b/engines/sword25/kernel/filesystemutil.h @@ -61,8 +61,6 @@ namespace Sword25 { class FileSystemUtil { public: - static FileSystemUtil &getInstance(); - virtual ~FileSystemUtil() {} /** * This function returns the name of the directory in which all user data is to be stored. @@ -70,37 +68,32 @@ public: * These are for example Screenshots, game saves, configuration files, log files, ... * @return Returns the name of the directory for user data. */ - virtual Common::String getUserdataDirectory() = 0; + static Common::String getUserdataDirectory(); + /** * @return Returns the path seperator */ - virtual Common::String getPathSeparator() = 0; + static Common::String getPathSeparator(); + /** * @param Filename The path to a file. * @return Returns the size of the specified file. If the size could not be * determined, or the file does not exist, returns -1 */ - virtual int32 getFileSize(const Common::String &filename) = 0; + static int32 getFileSize(const Common::String &filename); + /** * @param Filename The path to a file. * @return Returns true if the file exists. */ - virtual bool fileExists(const Common::String &filename) = 0; - /** - * This function creates a directory - * - * If the parameter is "\b\c\d\e" is passed, and "\b\c" already exists, then folder 'd' - * will be created, and subdirectory 'e' under it. - * @param DirectoryName The name of the directory to be created - * @return Returns true if the folder(s) could be created, otherwise false. - */ - virtual bool createDirectory(const Common::String &directoryName) = 0; + static bool fileExists(const Common::String &filename); + /** * Gets the filename from a path and filename * @param Filename The full path and filename * @return Returns just the filename */ - virtual Common::String getPathFilename(const Common::String &path) = 0; + static Common::String getPathFilename(const Common::String &path); }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp index 275b55fb73..d4b9a56d8e 100644 --- a/engines/sword25/kernel/kernel_script.cpp +++ b/engines/sword25/kernel/kernel_script.cpp @@ -136,22 +136,23 @@ static int executeFile(lua_State *L) { } static int getUserdataDirectory(lua_State *L) { - lua_pushstring(L, FileSystemUtil::getInstance().getUserdataDirectory().c_str()); + lua_pushstring(L, FileSystemUtil::getUserdataDirectory().c_str()); return 1; } static int getPathSeparator(lua_State *L) { - lua_pushstring(L, FileSystemUtil::getInstance().getPathSeparator().c_str()); + lua_pushstring(L, FileSystemUtil::getPathSeparator().c_str()); return 1; } static int fileExists(lua_State *L) { - lua_pushbooleancpp(L, FileSystemUtil::getInstance().fileExists(luaL_checkstring(L, 1))); + lua_pushbooleancpp(L, FileSystemUtil::fileExists(luaL_checkstring(L, 1))); return 1; } static int createDirectory(lua_State *L) { - lua_pushbooleancpp(L, FileSystemUtil::getInstance().createDirectory(luaL_checkstring(L, 1))); + // ScummVM engines cannot create directories, so we do nothing here. + lua_pushbooleancpp(L, false); return 1; } diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp index 0159991e0f..1b41f24a1d 100644 --- a/engines/sword25/kernel/persistenceservice.cpp +++ b/engines/sword25/kernel/persistenceservice.cpp @@ -202,7 +202,7 @@ uint PersistenceService::getSlotCount() { } Common::String PersistenceService::getSavegameDirectory() { - Common::FSNode node(FileSystemUtil::getInstance().getUserdataDirectory()); + Common::FSNode node(FileSystemUtil::getUserdataDirectory()); Common::FSNode childNode = node.getChild(SAVEGAME_DIRECTORY); // Try and return the path using the savegame subfolder. But if doesn't exist, fall back on the data directory @@ -251,6 +251,9 @@ Common::String &PersistenceService::getSavegameFilename(uint slotID) { } bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotFilename) { + // FIXME: This code is a hack which bypasses the savefile API, + // and should eventually be removed. + // Überprüfen, ob die Slot-ID zulässig ist. if (slotID >= SLOT_COUNT) { BS_LOG_ERRORLN("Tried to save to an invalid slot (%d). Only slot ids form 0 to %d are allowed.", slotID, SLOT_COUNT - 1); @@ -260,9 +263,6 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF // Dateinamen erzeugen. Common::String filename = generateSavegameFilename(slotID); - // Sicherstellen, dass das Verzeichnis für die Spielstanddateien existiert. - FileSystemUtil::getInstance().createDirectory(getSavegameDirectory()); - // Spielstanddatei öffnen und die Headerdaten schreiben. Common::SaveFileManager *sfm = g_system->getSavefileManager(); Common::OutSaveFile *file = sfm->openForSaving(filename); diff --git a/engines/sword25/package/packagemanager.cpp b/engines/sword25/package/packagemanager.cpp index ee13cd5920..bd750d0880 100644 --- a/engines/sword25/package/packagemanager.cpp +++ b/engines/sword25/package/packagemanager.cpp @@ -150,7 +150,7 @@ byte *PackageManager::getFile(const Common::String &fileName, uint *fileSizePtr) // Savegame loading logic Common::SaveFileManager *sfm = g_system->getSavefileManager(); Common::InSaveFile *file = sfm->openForLoading( - FileSystemUtil::getInstance().getPathFilename(fileName)); + FileSystemUtil::getPathFilename(fileName)); if (!file) { BS_LOG_ERRORLN("Could not load savegame \"%s\".", fileName.c_str()); return 0; @@ -214,26 +214,6 @@ Common::String PackageManager::getAbsolutePath(const Common::String &fileName) { return normalizePath(fileName, _currentDirectory); } -uint PackageManager::getFileSize(const Common::String &fileName) { - Common::SeekableReadStream *in; - Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory)); - if (!fileNode) - return 0; - if (!(in = fileNode->createReadStream())) - return 0; - - uint fileSize = in->size(); - - return fileSize; -} - -uint PackageManager::getFileType(const Common::String &fileName) { - warning("STUB: BS_PackageManager::GetFileType(%s)", fileName.c_str()); - - //return fileNode.isDirectory() ? BS_PackageManager::FT_DIRECTORY : BS_PackageManager::FT_FILE; - return PackageManager::FT_FILE; -} - bool PackageManager::fileExists(const Common::String &fileName) { Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory)); return fileNode; diff --git a/engines/sword25/package/packagemanager.h b/engines/sword25/package/packagemanager.h index 96f136dd83..03598012a6 100644 --- a/engines/sword25/package/packagemanager.h +++ b/engines/sword25/package/packagemanager.h @@ -190,23 +190,6 @@ public: int doSearch(Common::ArchiveMemberList &list, const Common::String &filter, const Common::String &path, uint typeFilter = FT_DIRECTORY | FT_FILE); /** - * Returns a file's size - * @param FileName The filename - * @return The file size. If an error occurs, then 0xffffffff is returned. - * @remarks For files in packages, then uncompressed size is returned. - **/ - uint getFileSize(const Common::String &fileName); - - /** - * Returns the type of a file. - * @param FileName The filename - * @return Returns the file type, either (BS_PackageManager::FT_DIRECTORY - * or BS_PackageManager::FT_FILE). - * If the file was not found, then 0 is returned. - */ - uint getFileType(const Common::String &fileName); - - /** * Determines whether a file exists * @param FileName The filename * @return Returns true if the file exists, otherwise false. diff --git a/engines/sword25/package/packagemanager_script.cpp b/engines/sword25/package/packagemanager_script.cpp index afab573511..9367ae3071 100644 --- a/engines/sword25/package/packagemanager_script.cpp +++ b/engines/sword25/package/packagemanager_script.cpp @@ -90,17 +90,15 @@ static int getAbsolutePath(lua_State *L) { } static int getFileSize(lua_State *L) { - PackageManager *pPM = getPM(); - - lua_pushnumber(L, pPM->getFileSize(luaL_checkstring(L, 1))); + // This function apparently is not used by the game scripts + lua_pushnumber(L, 0); return 1; } static int getFileType(lua_State *L) { - PackageManager *pPM = getPM(); - - lua_pushnumber(L, pPM->getFileType(luaL_checkstring(L, 1))); + // This function apparently is not used by the game scripts + lua_pushnumber(L, 0); return 1; } |