summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/main.cpp25
-rw-r--r--src/resources/resourcemanager.cpp85
-rw-r--r--src/resources/resourcemanager.h34
3 files changed, 97 insertions, 47 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 219df488..b0608c9a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -162,21 +162,33 @@ void init_engine()
}
#endif
- if (!PHYSFS_setWriteDir(homeDir.c_str())) {
+ // Initialize logger
+ logger = new Logger(homeDir + std::string("/tmw.log"));
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ if (!resman->setWriteDir(homeDir)) {
std::cout << homeDir << " couldn't be set as home directory! Exitting." << std::endl;
exit(1);
}
+ // Add the user's homedir to PhysicsFS search path
+ resman->addToSearchPath(homeDir, false);
// Creating and checking the updates folder existence and rights.
- if (!PHYSFS_exists("/updates")) {
- if (!PHYSFS_mkdir("/updates")) {
+ if (!resman->isDirectory("/updates")) {
+ if (!resman->mkdir("/updates")) {
std::cout << homeDir << "/updates can't be made, but it doesn't exist! Exitting." << std::endl;
exit(1);
}
}
- // Initialize logger
- logger = new Logger(homeDir + std::string("/tmw.log"));
+ // Add the main data directory to our PhysicsFS search path
+ resman->addToSearchPath("data", true);
+ resman->addToSearchPath(TMW_DATADIR "data", 1);
+ // Add zip files to PhysicsFS
+ resman->searchAndAddArchives("/", ".zip", true);
+ // Updates, these override other files
+ resman->searchAndAddArchives("/updates", ".zip", false);
// Fill configuration with defaults
config.setValue("host", "animesites.de");
@@ -297,8 +309,6 @@ void init_engine()
// Create the graphics context
graphics = new Graphics(screen);
- ResourceManager *resman = ResourceManager::getInstance();
-
login_wallpaper = resman->getImage(
"graphics/images/login_wallpaper.png");
Image *playerImg = resman->getImage(
@@ -389,7 +399,6 @@ int main(int argc, char *argv[])
init_engine();
-
SDL_Event event;
while (state != EXIT)
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