summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-30 11:55:28 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-30 11:55:28 +0000
commit25d4e1e3fe393ee845c868a9e5c163de52748379 (patch)
tree62021f2521334e1e05e5a44a0e8d63ef849dc7e7 /src/resources
parent5b6ca06022be1f78b5c39387f71a7bf6580a66bd (diff)
downloadmana-25d4e1e3fe393ee845c868a9e5c163de52748379.tar.gz
mana-25d4e1e3fe393ee845c868a9e5c163de52748379.tar.bz2
mana-25d4e1e3fe393ee845c868a9e5c163de52748379.tar.xz
mana-25d4e1e3fe393ee845c868a9e5c163de52748379.zip
Fixed check for updates directory. Moved search/write path setup from resourcemanager to main initialization.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/resourcemanager.cpp85
-rw-r--r--src/resources/resourcemanager.h34
2 files changed, 80 insertions, 39 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index d58bf791..82029adf 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -44,17 +44,6 @@ 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
- searchAndAddArchives("/", ".zip", 1);
- // Updates, these override other files
- searchAndAddArchives("/updates", ".zip", 0);
}
ResourceManager::~ResourceManager()
@@ -80,6 +69,55 @@ ResourceManager::~ResourceManager()
"to %d resources", danglingReferences, danglingResources);
}
+bool ResourceManager::setWriteDir(const std::string &path)
+{
+ return (bool)PHYSFS_setWriteDir(path.c_str());
+}
+
+void ResourceManager::addToSearchPath(const std::string &path, bool append)
+{
+ PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0);
+}
+
+void ResourceManager::searchAndAddArchives(
+ const std::string &path, const std::string &ext, bool append)
+{
+ const char *dirSep = PHYSFS_getDirSeparator();
+ char **list = PHYSFS_enumerateFiles(path.c_str());
+
+ for (char **i = list; *i != NULL; i++) {
+ size_t len = strlen(*i);
+
+ if (len > ext.length() && !ext.compare((*i)+(len - ext.length()))) {
+ std::string file, realPath, archive;
+
+ file = path + "/" + (*i);
+ realPath = std::string(PHYSFS_getRealDir(file.c_str()));
+ archive = realPath + path + dirSep + (*i);
+
+ logger->log("Adding to PhysicsFS: %s", archive.c_str());
+ addToSearchPath(archive, append);
+ }
+ }
+
+ PHYSFS_freeList(list);
+}
+
+bool ResourceManager::mkdir(const std::string &path)
+{
+ return (bool)PHYSFS_mkdir(path.c_str());
+}
+
+bool ResourceManager::exists(const std::string &path)
+{
+ return PHYSFS_exists(path.c_str());
+}
+
+bool ResourceManager::isDirectory(const std::string &path)
+{
+ return PHYSFS_isDirectory(path.c_str());
+}
+
Resource*
ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath)
{
@@ -192,31 +230,6 @@ ResourceManager::deleteInstance()
}
}
-void
-ResourceManager::searchAndAddArchives(
- const std::string &path, const std::string &ext, int append)
-{
- const char *dirSep = PHYSFS_getDirSeparator();
- char **list = PHYSFS_enumerateFiles(path.c_str());
-
- for (char **i = list; *i != NULL; i++) {
- size_t len = strlen(*i);
-
- if (len > ext.length() && !ext.compare((*i)+(len - ext.length()))) {
- std::string file, realPath, archive;
-
- file = path + "/" + (*i);
- realPath = std::string(PHYSFS_getRealDir(file.c_str()));
- archive = realPath + path + dirSep + (*i);
-
- logger->log("Adding to PhysicsFS: %s", archive.c_str());
- PHYSFS_addToSearchPath(archive.c_str(), append);
- }
- }
-
- PHYSFS_freeList(list);
-}
-
void*
ResourceManager::loadFile(const std::string &fileName, int &fileSize)
{
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index ac3320b6..9db8ccce 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -62,10 +62,38 @@ class ResourceManager
~ResourceManager();
/**
- * Searches for zip files and adds them to the PhysicsFS search path.
+ * Sets the write directory
+ *
+ * @param path The path of the directory to be added.
+ * @return <code>true</code> on success, <code>false</code> otherwise.
+ */
+ bool setWriteDir(const std::string &path);
+
+ /**
+ * Adds a directory or archive to the search path.
+ */
+ void addToSearchPath(const std::string &path, bool append);
+
+ /**
+ * Searches for zip files and adds them to the search path.
+ */
+ void searchAndAddArchives(
+ const std::string &path, const std::string &ext, bool append);
+
+ /**
+ * Creates a directory in the write path
+ */
+ bool mkdir(const std::string &path);
+
+ /**
+ * Checks whether the given file or directory exists in the search path
+ */
+ bool exists(const std::string &path);
+
+ /**
+ * Checks whether the given path is a directory.
*/
- void ResourceManager::searchAndAddArchives(
- const std::string &path, const std::string &ext, int append);
+ bool isDirectory(const std::string &path);
/**
* Creates a resource and adds it to the resource map. The idPath is