diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-07-27 23:22:45 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-07-27 23:22:45 +0000 |
commit | 227aeae87bcca1ecb0183530a4cca1b038863635 (patch) | |
tree | 1f2dd29f93e904ccef0fdd9fe2c7d9778b867934 /src/resources | |
parent | d15d76976b6e57a9f421ab034c6f841051b962f3 (diff) | |
download | mana-227aeae87bcca1ecb0183530a4cca1b038863635.tar.gz mana-227aeae87bcca1ecb0183530a4cca1b038863635.tar.bz2 mana-227aeae87bcca1ecb0183530a4cca1b038863635.tar.xz mana-227aeae87bcca1ecb0183530a4cca1b038863635.zip |
Added support for updates to the resource manager.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/resourcemanager.cpp | 84 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 13 |
2 files changed, 31 insertions, 66 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 6ed933e4..c757e35b 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -25,6 +25,7 @@ #include "../main.h" #include "resourcemanager.h" #include "../log.h" +#include "../configuration.h" #include <iostream> #include <sstream> #include <physfs.h> @@ -43,8 +44,17 @@ ResourceManager *ResourceManager::instance = NULL; ResourceManager::ResourceManager() { + // Add the main data directory to our PhysicsFS search path + PHYSFS_addToSearchPath("data", 1); + PHYSFS_addToSearchPath(TMW_DATADIR "data", 1); + + // Add the user's homedir to PhysicsFS search path + PHYSFS_addToSearchPath(config.getValue("homeDir", "").c_str(), 0); + // Add zip files to PhysicsFS - searchAndAddZipFiles(); + searchAndAddArchives("/", ".zip", 1); + // Updates, these override other files + searchAndAddArchives("/updates", ".zip", 0); } ResourceManager::~ResourceManager() @@ -183,72 +193,28 @@ ResourceManager::deleteInstance() } void -ResourceManager::searchAndAddZipFiles() +ResourceManager::searchAndAddArchives( + const std::string &path, const std::string &ext, int append) { - // Add the main data directory to our PhysicsFS search path - PHYSFS_addToSearchPath("data", 1); - PHYSFS_addToSearchPath(TMW_DATADIR "data", 1); - -#ifdef _WIN32 - // Define the path in which to search - std::string searchString = std::string("data/*.zip"); - - // Create our find file data structure - struct _finddata_t findFileInfo; - - // Find the first zipped file - long handle = - static_cast<long>(::_findfirst(searchString.c_str(), &findFileInfo)); - long file = handle; + const char *dirSep = PHYSFS_getDirSeparator(); + char **list = PHYSFS_enumerateFiles(path.c_str()); - // Loop until all files we're searching for are found - while (file >= 0) { - // Define the file path string - std::string filePath = std::string("data/") + - std::string(findFileInfo.name); + for (char **i = list; *i != NULL; i++) { + size_t len = strlen(*i); - logger->log("Adding to PhysicsFS: %s", findFileInfo.name); + if (len > ext.length() && !ext.compare((*i)+(len - ext.length()))) { + std::string file, realPath, archive; - // Add the zip file to our PhysicsFS search path - PHYSFS_addToSearchPath(filePath.c_str(), 1); + file = path + dirSep + (*i); + realPath = std::string(PHYSFS_getRealDir(file.c_str())); + archive = realPath + path + dirSep + (*i); - // Find the next file - file = ::_findnext(handle, &findFileInfo); - } - - // Shutdown findfile stuff - ::_findclose(handle); -#else - // Retrieve the current path - char programPath[256]; - getcwd(programPath, 256); - strncat(programPath, "/data", 256 - strlen(programPath) - 1); - - // Create our directory structure - DIR *dir = opendir(programPath); - - // Return if the directory is invalid - if (dir == NULL) { - return; - } - - struct dirent *direntry; - while ((direntry = readdir(dir)) != NULL) { - char *ext = strstr(direntry->d_name, ".zip"); - if (ext != NULL && strcmp(ext, ".zip") == 0) { - // Define the file path string - std::string filePath = std::string(programPath) + - std::string("/") + std::string(direntry->d_name); - - logger->log("Adding to PhysicsFS: %s", filePath.c_str()); - - // Add the zip file to our PhysicsFS search path - PHYSFS_addToSearchPath(filePath.c_str(), 1); + logger->log("Adding to PhysicsFS: %s", archive.c_str()); + PHYSFS_addToSearchPath(archive.c_str(), append); } } - closedir(dir); -#endif + PHYSFS_freeList(list); } void* diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 93c2dd85..ac3320b6 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -62,6 +62,12 @@ class ResourceManager ~ResourceManager(); /** + * Searches for zip files and adds them to the PhysicsFS search path. + */ + void ResourceManager::searchAndAddArchives( + const std::string &path, const std::string &ext, int append); + + /** * Creates a resource and adds it to the resource map. The idPath is * converted into the appropriate path for the current operating system * and the resource is loaded. @@ -134,13 +140,6 @@ class ResourceManager deleteInstance(); private: - /** - * Searches for zip files and adds them to the PhysicsFS search path. - */ - void - searchAndAddZipFiles(); - - static ResourceManager *instance; std::map<std::string, Resource*> resources; }; |