aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/package
diff options
context:
space:
mode:
authorEugene Sandulenko2010-09-25 19:48:26 +0000
committerEugene Sandulenko2010-10-13 00:02:51 +0000
commit8582c1ad5770b6385381f524a4610934d115cd88 (patch)
tree3a0c29c16f23c5c8992f5d29b36dbbda53a6fa3c /engines/sword25/package
parent736ae4c07aa33589a5f9651643d7af07b5d0a877 (diff)
downloadscummvm-rg350-8582c1ad5770b6385381f524a4610934d115cd88.tar.gz
scummvm-rg350-8582c1ad5770b6385381f524a4610934d115cd88.tar.bz2
scummvm-rg350-8582c1ad5770b6385381f524a4610934d115cd88.zip
SWORD25: Enforse code naming conventions in PackageManager and Sword25Engine
svn-id: r53380
Diffstat (limited to 'engines/sword25/package')
-rw-r--r--engines/sword25/package/packagemanager.cpp36
-rw-r--r--engines/sword25/package/packagemanager.h34
-rw-r--r--engines/sword25/package/packagemanager_script.cpp151
3 files changed, 94 insertions, 127 deletions
diff --git a/engines/sword25/package/packagemanager.cpp b/engines/sword25/package/packagemanager.cpp
index 801f695f15..18b2453d6d 100644
--- a/engines/sword25/package/packagemanager.cpp
+++ b/engines/sword25/package/packagemanager.cpp
@@ -61,7 +61,7 @@ static Common::String normalizePath(const Common::String &path, const Common::St
PackageManager::PackageManager(Kernel *pKernel) : Service(pKernel),
_currentDirectory(PATH_SEPARATOR),
_rootFolder(ConfMan.get("path")) {
- if (!_RegisterScriptBindings())
+ if (!registerScriptBindings())
BS_LOG_ERRORLN("Script bindings could not be registered.");
else
BS_LOGLN("Script bindings registered.");
@@ -82,7 +82,7 @@ Service *PackageManager_CreateObject(Kernel *kernelPtr) {
/**
* Scans through the archive list for a specified file
*/
-Common::ArchiveMemberPtr PackageManager::GetArchiveMember(const Common::String &fileName) {
+Common::ArchiveMemberPtr PackageManager::getArchiveMember(const Common::String &fileName) {
// Loop through checking each archive
Common::List<ArchiveEntry *>::iterator i;
for (i = _archiveList.begin(); i != _archiveList.end(); ++i) {
@@ -105,8 +105,8 @@ Common::ArchiveMemberPtr PackageManager::GetArchiveMember(const Common::String &
return Common::ArchiveMemberPtr();
}
-bool PackageManager::LoadPackage(const Common::String &fileName, const Common::String &mountPosition) {
- debug(0, "LoadPackage(%s, %s)", fileName.c_str(), mountPosition.c_str());
+bool PackageManager::loadPackage(const Common::String &fileName, const Common::String &mountPosition) {
+ debug(3, "loadPackage(%s, %s)", fileName.c_str(), mountPosition.c_str());
Common::Archive *zipFile = Common::makeZipArchive(fileName);
if (zipFile == NULL) {
@@ -116,7 +116,7 @@ bool PackageManager::LoadPackage(const Common::String &fileName, const Common::S
BS_LOGLN("Package '%s' mounted as '%s'.", fileName.c_str(), mountPosition.c_str());
Common::ArchiveMemberList files;
zipFile->listMembers(files);
- debug(0, "Capacity %d", files.size());
+ debug(3, "Capacity %d", files.size());
for (Common::ArchiveMemberList::iterator it = files.begin(); it != files.end(); ++it)
debug(3, "%s", (*it)->getName().c_str());
@@ -127,7 +127,7 @@ bool PackageManager::LoadPackage(const Common::String &fileName, const Common::S
}
}
-bool PackageManager::LoadDirectoryAsPackage(const Common::String &directoryName, const Common::String &mountPosition) {
+bool PackageManager::loadDirectoryAsPackage(const Common::String &directoryName, const Common::String &mountPosition) {
Common::FSNode directory(directoryName);
Common::Archive *folderArchive = new Common::FSDirectory(directory, 6);
if (!directory.exists() || (folderArchive == NULL)) {
@@ -146,7 +146,7 @@ bool PackageManager::LoadDirectoryAsPackage(const Common::String &directoryName,
}
}
-byte *PackageManager::GetFile(const Common::String &fileName, uint *fileSizePtr) {
+byte *PackageManager::getFile(const Common::String &fileName, uint *fileSizePtr) {
const Common::String B25S_EXTENSION(".b25s");
Common::SeekableReadStream *in;
@@ -170,7 +170,7 @@ byte *PackageManager::GetFile(const Common::String &fileName, uint *fileSizePtr)
return buffer;
}
- Common::ArchiveMemberPtr fileNode = GetArchiveMember(normalizePath(fileName, _currentDirectory));
+ Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory));
if (!fileNode)
return 0;
if (!(in = fileNode->createReadStream()))
@@ -196,9 +196,9 @@ byte *PackageManager::GetFile(const Common::String &fileName, uint *fileSizePtr)
return buffer;
}
-Common::SeekableReadStream *PackageManager::GetStream(const Common::String &fileName) {
+Common::SeekableReadStream *PackageManager::getStream(const Common::String &fileName) {
Common::SeekableReadStream *in;
- Common::ArchiveMemberPtr fileNode = GetArchiveMember(normalizePath(fileName, _currentDirectory));
+ Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory));
if (!fileNode)
return 0;
if (!(in = fileNode->createReadStream()))
@@ -207,23 +207,23 @@ Common::SeekableReadStream *PackageManager::GetStream(const Common::String &file
return in;
}
-Common::String PackageManager::GetCurrentDirectory() {
+Common::String PackageManager::getCurrentDirectory() {
return _currentDirectory;
}
-bool PackageManager::ChangeDirectory(const Common::String &directory) {
+bool PackageManager::changeDirectory(const Common::String &directory) {
// Get the path elements for the file
_currentDirectory = normalizePath(directory, _currentDirectory);
return true;
}
-Common::String PackageManager::GetAbsolutePath(const Common::String &fileName) {
+Common::String PackageManager::getAbsolutePath(const Common::String &fileName) {
return normalizePath(fileName, _currentDirectory);
}
-uint PackageManager::GetFileSize(const Common::String &fileName) {
+uint PackageManager::getFileSize(const Common::String &fileName) {
Common::SeekableReadStream *in;
- Common::ArchiveMemberPtr fileNode = GetArchiveMember(normalizePath(fileName, _currentDirectory));
+ Common::ArchiveMemberPtr fileNode = getArchiveMember(normalizePath(fileName, _currentDirectory));
if (!fileNode)
return 0;
if (!(in = fileNode->createReadStream()))
@@ -234,15 +234,15 @@ uint PackageManager::GetFileSize(const Common::String &fileName) {
return fileSize;
}
-uint PackageManager::GetFileType(const Common::String &fileName) {
+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));
+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 1441c92606..96f136dd83 100644
--- a/engines/sword25/package/packagemanager.h
+++ b/engines/sword25/package/packagemanager.h
@@ -91,7 +91,7 @@ private:
Common::FSNode _rootFolder;
Common::List<ArchiveEntry *> _archiveList;
- Common::ArchiveMemberPtr GetArchiveMember(const Common::String &fileName);
+ Common::ArchiveMemberPtr getArchiveMember(const Common::String &fileName);
public:
PackageManager(Kernel *pKernel);
@@ -108,14 +108,14 @@ public:
* @param MountPosition The directory name under which the package should be mounted
* @return Returns true if the mount was successful, otherwise false.
*/
- bool LoadPackage(const Common::String &FileName, const Common::String &MountPosition);
+ bool loadPackage(const Common::String &fileName, const Common::String &mountPosition);
/**
* Mounts the contents of a directory in the specified directory in the directory tree.
* @param The name of the directory to mount
* @param MountPosition The directory name under which the package should be mounted
* @return Returns true if the mount was successful, otherwise false.
*/
- bool LoadDirectoryAsPackage(const Common::String &DirectoryName, const Common::String &MountPosition);
+ bool loadDirectoryAsPackage(const Common::String &directoryName, const Common::String &mountPosition);
/**
* Downloads a file from the directory tree
* @param FileName The filename of the file to load
@@ -123,14 +123,14 @@ public:
* @return Specifies a pointer to the loaded data of the file
* @remark The client must not forget to release the data of the file using BE_DELETE_A.
*/
- byte *GetFile(const Common::String &FileName, uint *pFileSize = NULL);
+ byte *getFile(const Common::String &fileName, uint *pFileSize = NULL);
/**
* Returns a stream from file file from the directory tree
* @param FileName The filename of the file to load
* @return Pointer to the stream object
*/
- Common::SeekableReadStream *GetStream(const Common::String &fileName);
+ Common::SeekableReadStream *getStream(const Common::String &fileName);
/**
* Downloads an XML file and prefixes it with an XML Version key, since the XML files don't contain it,
* and it is required for ScummVM to correctly parse the XML.
@@ -139,17 +139,19 @@ public:
* @return Specifies a pointer to the loaded data of the file
* @remark The client must not forget to release the data of the file using BE_DELETE_A.
*/
- char *GetXmlFile(const Common::String &FileName, uint *pFileSize = NULL) {
+ char *getXmlFile(const Common::String &fileName, uint *pFileSize = NULL) {
const char *versionStr = "<?xml version=\"1.0\"?>";
uint fileSize;
- char *data = (char *)GetFile(FileName, &fileSize);
+ char *data = (char *)getFile(fileName, &fileSize);
char *result = (char *)malloc(fileSize + strlen(versionStr) + 1);
strcpy(result, versionStr);
Common::copy(data, data + fileSize, result + strlen(versionStr));
result[fileSize + strlen(versionStr)] = '\0';
delete[] data;
- if (pFileSize) *pFileSize = fileSize + strlen(versionStr);
+ if (pFileSize)
+ *pFileSize = fileSize + strlen(versionStr);
+
return result;
}
@@ -159,14 +161,14 @@ public:
* If the path could not be determined, an empty string is returned.
* @remark For cutting path elements '\' is used rather than '/' elements.
*/
- Common::String GetCurrentDirectory();
+ Common::String getCurrentDirectory();
/**
* Changes the current directory.
* @param Directory The path to the new directory. The path can be relative.
* @return Returns true if the operation was successful, otherwise false.
* @remark For cutting path elements '\' is used rather than '/' elements.
*/
- bool ChangeDirectory(const Common::String &Directory);
+ bool changeDirectory(const Common::String &directory);
/**
* Returns the absolute path to a file in the directory tree.
* @param FileName The filename of the file whose absolute path is to be determined.
@@ -174,7 +176,7 @@ public:
* @return Returns an absolute path to the given file.
* @remark For cutting path elements '\' is used rather than '/' elements.
*/
- Common::String GetAbsolutePath(const Common::String &FileName);
+ Common::String getAbsolutePath(const Common::String &fileName);
/**
* Creates a BS_PackageManager::FileSearch object to search for files
* @param Filter Specifies the search string. Wildcards of '*' and '?' are allowed
@@ -185,7 +187,7 @@ public:
* @return Specifies a pointer to a BS_PackageManager::FileSearch object, or NULL if no file was found.
* @remark Do not forget to delete the object after use.
*/
- int doSearch(Common::ArchiveMemberList &list, const Common::String &Filter, const Common::String &Path, uint TypeFilter = FT_DIRECTORY | FT_FILE);
+ int doSearch(Common::ArchiveMemberList &list, const Common::String &filter, const Common::String &path, uint typeFilter = FT_DIRECTORY | FT_FILE);
/**
* Returns a file's size
@@ -193,7 +195,7 @@ public:
* @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);
+ uint getFileSize(const Common::String &fileName);
/**
* Returns the type of a file.
@@ -202,17 +204,17 @@ public:
* or BS_PackageManager::FT_FILE).
* If the file was not found, then 0 is returned.
*/
- uint GetFileType(const Common::String &FileName);
+ uint getFileType(const Common::String &fileName);
/**
* Determines whether a file exists
* @param FileName The filename
* @return Returns true if the file exists, otherwise false.
*/
- bool FileExists(const Common::String &FileName);
+ bool fileExists(const Common::String &FileName);
private:
- bool _RegisterScriptBindings();
+ bool registerScriptBindings();
};
} // End of namespace Sword25
diff --git a/engines/sword25/package/packagemanager_script.cpp b/engines/sword25/package/packagemanager_script.cpp
index b3e987ea62..409eb1ab7a 100644
--- a/engines/sword25/package/packagemanager_script.cpp
+++ b/engines/sword25/package/packagemanager_script.cpp
@@ -32,10 +32,6 @@
*
*/
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
#include "sword25/kernel/common.h"
#include "sword25/kernel/kernel.h"
#include "sword25/script/script.h"
@@ -47,9 +43,7 @@ namespace Sword25 {
using namespace Lua;
-// -----------------------------------------------------------------------------
-
-static PackageManager *GetPM() {
+static PackageManager *getPM() {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
PackageManager *pPM = static_cast<PackageManager *>(pKernel->GetService("package"));
@@ -57,104 +51,86 @@ static PackageManager *GetPM() {
return pPM;
}
-// -----------------------------------------------------------------------------
-
-static int LoadPackage(lua_State *L) {
- PackageManager *pPM = GetPM();
+static int loadPackage(lua_State *L) {
+ PackageManager *pPM = getPM();
- lua_pushbooleancpp(L, pPM->LoadPackage(luaL_checkstring(L, 1), luaL_checkstring(L, 2)));
+ lua_pushbooleancpp(L, pPM->loadPackage(luaL_checkstring(L, 1), luaL_checkstring(L, 2)));
return 1;
}
-// -----------------------------------------------------------------------------
+static int loadDirectoryAsPackage(lua_State *L) {
+ PackageManager *pPM = getPM();
-static int LoadDirectoryAsPackage(lua_State *L) {
- PackageManager *pPM = GetPM();
-
- lua_pushbooleancpp(L, pPM->LoadDirectoryAsPackage(luaL_checkstring(L, 1), luaL_checkstring(L, 2)));
+ lua_pushbooleancpp(L, pPM->loadDirectoryAsPackage(luaL_checkstring(L, 1), luaL_checkstring(L, 2)));
return 1;
}
-// -----------------------------------------------------------------------------
-
-static int GetCurrentDirectory(lua_State *L) {
- PackageManager *pPM = GetPM();
+static int getCurrentDirectory(lua_State *L) {
+ PackageManager *pPM = getPM();
- lua_pushstring(L, pPM->GetCurrentDirectory().c_str());
+ lua_pushstring(L, pPM->getCurrentDirectory().c_str());
return 1;
}
-// -----------------------------------------------------------------------------
+static int changeDirectory(lua_State *L) {
+ PackageManager *pPM = getPM();
-static int ChangeDirectory(lua_State *L) {
- PackageManager *pPM = GetPM();
-
- lua_pushbooleancpp(L, pPM->ChangeDirectory(luaL_checkstring(L, 1)));
+ lua_pushbooleancpp(L, pPM->changeDirectory(luaL_checkstring(L, 1)));
return 1;
}
-// -----------------------------------------------------------------------------
-
-static int GetAbsolutePath(lua_State *L) {
- PackageManager *pPM = GetPM();
+static int getAbsolutePath(lua_State *L) {
+ PackageManager *pPM = getPM();
- lua_pushstring(L, pPM->GetAbsolutePath(luaL_checkstring(L, 1)).c_str());
+ lua_pushstring(L, pPM->getAbsolutePath(luaL_checkstring(L, 1)).c_str());
return 1;
}
-// -----------------------------------------------------------------------------
+static int getFileSize(lua_State *L) {
+ PackageManager *pPM = getPM();
-static int GetFileSize(lua_State *L) {
- PackageManager *pPM = GetPM();
-
- lua_pushnumber(L, pPM->GetFileSize(luaL_checkstring(L, 1)));
+ lua_pushnumber(L, pPM->getFileSize(luaL_checkstring(L, 1)));
return 1;
}
-// -----------------------------------------------------------------------------
-
-static int GetFileType(lua_State *L) {
- PackageManager *pPM = GetPM();
+static int getFileType(lua_State *L) {
+ PackageManager *pPM = getPM();
- lua_pushnumber(L, pPM->GetFileType(luaL_checkstring(L, 1)));
+ lua_pushnumber(L, pPM->getFileType(luaL_checkstring(L, 1)));
return 1;
}
-// -----------------------------------------------------------------------------
-
-static void SplitSearchPath(const Common::String &Path, Common::String &Directory, Common::String &Filter) {
+static void splitSearchPath(const Common::String &path, Common::String &directory, Common::String &filter) {
// Scan backwards for a trailing slash
- const char *sPath = Path.c_str();
+ const char *sPath = path.c_str();
const char *lastSlash = sPath + strlen(sPath) - 1;
while ((lastSlash >= sPath) && (*lastSlash != '/')) --lastSlash;
if (lastSlash >= sPath) {
- Directory = "";
- Filter = Path;
+ directory = "";
+ filter = path;
} else {
- Directory = Common::String(sPath, lastSlash - sPath);
- Filter = Common::String(lastSlash + 1);
+ directory = Common::String(sPath, lastSlash - sPath);
+ filter = Common::String(lastSlash + 1);
}
}
-// -----------------------------------------------------------------------------
-
-static void DoSearch(lua_State *L, const Common::String &path, uint type) {
- PackageManager *pPM = GetPM();
+static void doSearch(lua_State *L, const Common::String &path, uint type) {
+ PackageManager *pPM = getPM();
// Der Packagemanager-Service muss den Suchstring und den Pfad getrennt übergeben bekommen.
// Um die Benutzbarkeit zu verbessern sollen Skriptprogrammierer dieses als ein Pfad übergeben können.
// Daher muss der übergebene Pfad am letzten Slash aufgesplittet werden.
Common::String directory;
Common::String filter;
- SplitSearchPath(path, directory, filter);
+ splitSearchPath(path, directory, filter);
// Ergebnistable auf dem Lua-Stack erstellen
lua_newtable(L);
@@ -176,65 +152,53 @@ static void DoSearch(lua_State *L, const Common::String &path, uint type) {
}
}
-// -----------------------------------------------------------------------------
-
-static int FindFiles(lua_State *L) {
- DoSearch(L, luaL_checkstring(L, 1), PackageManager::FT_FILE);
+static int findFiles(lua_State *L) {
+ doSearch(L, luaL_checkstring(L, 1), PackageManager::FT_FILE);
return 1;
}
-// -----------------------------------------------------------------------------
-
-static int FindDirectories(lua_State *L) {
- DoSearch(L, luaL_checkstring(L, 1), PackageManager::FT_DIRECTORY);
+static int findDirectories(lua_State *L) {
+ doSearch(L, luaL_checkstring(L, 1), PackageManager::FT_DIRECTORY);
return 1;
}
-// -----------------------------------------------------------------------------
+static int getFileAsString(lua_State *L) {
+ PackageManager *pPM = getPM();
-static int GetFileAsString(lua_State *L) {
- PackageManager *pPM = GetPM();
-
- uint FileSize;
- char *FileData = (char *)pPM->GetFile(luaL_checkstring(L, 1), &FileSize);
- if (FileData) {
- lua_pushlstring(L, FileData, FileSize);
- delete[] FileData;
+ uint fileSize;
+ char *fileData = (char *)pPM->getFile(luaL_checkstring(L, 1), &fileSize);
+ if (fileData) {
+ lua_pushlstring(L, fileData, fileSize);
+ delete[] fileData;
return 1;
} else
return 0;
}
-// -----------------------------------------------------------------------------
-
-static int FileExists(lua_State *L) {
- lua_pushbooleancpp(L, GetPM()->FileExists(luaL_checkstring(L, 1)));
+static int fileExists(lua_State *L) {
+ lua_pushbooleancpp(L, getPM()->fileExists(luaL_checkstring(L, 1)));
return 1;
}
-// -----------------------------------------------------------------------------
-
static const char *PACKAGE_LIBRARY_NAME = "Package";
static const luaL_reg PACKAGE_FUNCTIONS[] = {
- {"LoadPackage", LoadPackage},
- {"LoadDirectoryAsPackage", LoadDirectoryAsPackage},
- {"GetCurrentDirectory", GetCurrentDirectory},
- {"ChangeDirectory", ChangeDirectory},
- {"GetAbsolutePath", GetAbsolutePath},
- {"GetFileSize", GetFileSize},
- {"GetFileType", GetFileType},
- {"FindFiles", FindFiles},
- {"FindDirectories", FindDirectories},
- {"GetFileAsString", GetFileAsString},
- {"FileExists", FileExists},
+ {"LoadPackage", loadPackage},
+ {"LoadDirectoryAsPackage", loadDirectoryAsPackage},
+ {"GetCurrentDirectory", getCurrentDirectory},
+ {"ChangeDirectory", changeDirectory},
+ {"GetAbsolutePath", getAbsolutePath},
+ {"GetFileSize", getFileSize},
+ {"GetFileType", getFileType},
+ {"FindFiles", findFiles},
+ {"FindDirectories", findDirectories},
+ {"GetFileAsString", getFileAsString},
+ {"FileExists", fileExists},
{0, 0}
};
-// -----------------------------------------------------------------------------
-
-bool PackageManager::_RegisterScriptBindings() {
+bool PackageManager::registerScriptBindings() {
Kernel *pKernel = Kernel::GetInstance();
BS_ASSERT(pKernel);
ScriptEngine *pScript = static_cast<ScriptEngine *>(pKernel->GetService("script"));
@@ -242,7 +206,8 @@ bool PackageManager::_RegisterScriptBindings() {
lua_State *L = static_cast<lua_State *>(pScript->GetScriptObject());
BS_ASSERT(L);
- if (!LuaBindhelper::AddFunctionsToLib(L, PACKAGE_LIBRARY_NAME, PACKAGE_FUNCTIONS)) return false;
+ if (!LuaBindhelper::AddFunctionsToLib(L, PACKAGE_LIBRARY_NAME, PACKAGE_FUNCTIONS))
+ return false;
return true;
}