summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-27 23:22:45 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-27 23:22:45 +0000
commit227aeae87bcca1ecb0183530a4cca1b038863635 (patch)
tree1f2dd29f93e904ccef0fdd9fe2c7d9778b867934 /src/resources/resourcemanager.cpp
parentd15d76976b6e57a9f421ab034c6f841051b962f3 (diff)
downloadMana-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/resourcemanager.cpp')
-rw-r--r--src/resources/resourcemanager.cpp84
1 files changed, 25 insertions, 59 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*