[Scummvm-cvs-logs] SF.net SVN: scummvm:[53838] scummvm/trunk/engines/sword25
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Oct 26 01:19:39 CEST 2010
Revision: 53838
http://scummvm.svn.sourceforge.net/scummvm/?rev=53838&view=rev
Author: fingolfin
Date: 2010-10-25 23:19:39 +0000 (Mon, 25 Oct 2010)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/trunk/engines/sword25/kernel/filesystemutil.cpp
scummvm/trunk/engines/sword25/kernel/filesystemutil.h
scummvm/trunk/engines/sword25/kernel/kernel_script.cpp
scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp
scummvm/trunk/engines/sword25/package/packagemanager.cpp
scummvm/trunk/engines/sword25/package/packagemanager.h
scummvm/trunk/engines/sword25/package/packagemanager_script.cpp
Modified: scummvm/trunk/engines/sword25/kernel/filesystemutil.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/filesystemutil.cpp 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/kernel/filesystemutil.cpp 2010-10-25 23:19:39 UTC (rev 53838)
@@ -43,85 +43,45 @@
#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");
+Common::String FileSystemUtil::getPathSeparator() {
+ // FIXME: This code is a hack which bypasses the savefile API,
+ // and should eventually be removed.
+ return Common::String("/");
+}
- if (path.empty()) {
- error("No save path has been defined");
- return "";
- }
+bool FileSystemUtil::fileExists(const Common::String &filename) {
+ Common::File f;
+ if (f.exists(filename))
+ return true;
- // Return the path
- return path;
- }
+ // 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 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;
-
- // 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();
- }
-
- 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;
- }
-
- 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
Modified: scummvm/trunk/engines/sword25/kernel/filesystemutil.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/filesystemutil.h 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/kernel/filesystemutil.h 2010-10-25 23:19:39 UTC (rev 53838)
@@ -61,8 +61,6 @@
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 @@
* 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;
+ static bool fileExists(const Common::String &filename);
+
/**
- * 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;
- /**
* 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
Modified: scummvm/trunk/engines/sword25/kernel/kernel_script.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel_script.cpp 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/kernel/kernel_script.cpp 2010-10-25 23:19:39 UTC (rev 53838)
@@ -136,22 +136,23 @@
}
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;
}
Modified: scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/kernel/persistenceservice.cpp 2010-10-25 23:19:39 UTC (rev 53838)
@@ -202,7 +202,7 @@
}
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 @@
}
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.
+
// \xDCberpr\xFCfen, ob die Slot-ID zul\xE4ssig 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 @@
// Dateinamen erzeugen.
Common::String filename = generateSavegameFilename(slotID);
- // Sicherstellen, dass das Verzeichnis f\xFCr die Spielstanddateien existiert.
- FileSystemUtil::getInstance().createDirectory(getSavegameDirectory());
-
// Spielstanddatei \xF6ffnen und die Headerdaten schreiben.
Common::SaveFileManager *sfm = g_system->getSavefileManager();
Common::OutSaveFile *file = sfm->openForSaving(filename);
Modified: scummvm/trunk/engines/sword25/package/packagemanager.cpp
===================================================================
--- scummvm/trunk/engines/sword25/package/packagemanager.cpp 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/package/packagemanager.cpp 2010-10-25 23:19:39 UTC (rev 53838)
@@ -150,7 +150,7 @@
// 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 @@
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;
Modified: scummvm/trunk/engines/sword25/package/packagemanager.h
===================================================================
--- scummvm/trunk/engines/sword25/package/packagemanager.h 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/package/packagemanager.h 2010-10-25 23:19:39 UTC (rev 53838)
@@ -190,23 +190,6 @@
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.
Modified: scummvm/trunk/engines/sword25/package/packagemanager_script.cpp
===================================================================
--- scummvm/trunk/engines/sword25/package/packagemanager_script.cpp 2010-10-25 22:41:48 UTC (rev 53837)
+++ scummvm/trunk/engines/sword25/package/packagemanager_script.cpp 2010-10-25 23:19:39 UTC (rev 53838)
@@ -90,18 +90,16 @@
}
static int getFileSize(lua_State *L) {
- PackageManager *pPM = getPM();
+ // This function apparently is not used by the game scripts
+ lua_pushnumber(L, 0);
- lua_pushnumber(L, pPM->getFileSize(luaL_checkstring(L, 1)));
-
return 1;
}
static int getFileType(lua_State *L) {
- PackageManager *pPM = getPM();
+ // This function apparently is not used by the game scripts
+ lua_pushnumber(L, 0);
- lua_pushnumber(L, pPM->getFileType(luaL_checkstring(L, 1)));
-
return 1;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list