diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 16 | ||||
-rw-r--r-- | src/main.cpp | 8 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 84 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 13 |
5 files changed, 51 insertions, 77 deletions
@@ -1,3 +1,10 @@ +2005-07-28 Björn Steinbrink <B.Steinbrink@gmx.de> + + * src/main.cpp, src/gui/update.cpp, src/resources/resourcemanager.cpp, + src/resources/resourcemanager.h: Added support for files downloaded + through the update manager to the resource manager. Changed directory name + for updates from "data" to "updates". + 2005-07-27 Bjørn Lindeijer <bjorn@lindeijer.nl> * src/engine.cpp, src/game.cpp, src/graphics.cpp, src/graphics.h, diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index ebe9013f..4295b8cf 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -225,9 +225,9 @@ int UpdaterWindow::downloadThread(void *ptr) } else { - // Download in the proper folder : ./data under win, - // /home/user/.tmw/data for unices - outFilename = uw->mBasePath + "/data/download.temp"; + // Download in the proper folder : ./updates under win, + // /home/user/.tmw/updates for unices + outFilename = uw->mBasePath + "/updates/download.temp"; outfile = fopen(outFilename.c_str(), "wb"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); } @@ -256,7 +256,7 @@ int UpdaterWindow::downloadThread(void *ptr) fclose(outfile); // If the download was successful give the file the proper name // else it will be deleted later - std::string newName(uw->mBasePath + "/data/" + + std::string newName(uw->mBasePath + "/updates/" + uw->mCurrentFile.c_str()); rename(outFilename.c_str(), newName.c_str()); } @@ -374,7 +374,7 @@ void UpdaterWindow::updateData() { mCurrentFile = files[fileIndex]; std::ifstream temp( - (mBasePath + "/data/" + mCurrentFile).c_str()); + (mBasePath + "/updates/" + mCurrentFile).c_str()); if (!temp.is_open()) { temp.close(); download(); @@ -414,7 +414,7 @@ void UpdaterWindow::updateData() free(mMemoryBuffer); in.close(); // Remove downloaded files - remove((mBasePath + "/data/news.txt").c_str()); - remove((mBasePath + "/data/resources.txt").c_str()); - remove((mBasePath + "/data/download.temp").c_str()); + remove((mBasePath + "/updates/news.txt").c_str()); + remove((mBasePath + "/updates/resources.txt").c_str()); + remove((mBasePath + "/updates/download.temp").c_str()); } diff --git a/src/main.cpp b/src/main.cpp index b1ef5661..b2421a07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -161,9 +161,9 @@ void init_engine() exit(1); } - // Creating and checking the ~/.tmw/data folder existence and rights. - std::string dataUpdateDir = homeDir + "/data"; - //sprintf(dataUpdateDir, "%s/data", homeDir); + // Creating and checking the ~/.tmw/updates folder existence and rights. + std::string dataUpdateDir = homeDir + "/updates"; + //sprintf(dataUpdateDir, "%s/updates", homeDir); if ((mkdir(dataUpdateDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) { @@ -444,6 +444,8 @@ int main(int argc, char *argv[]) uw = new UpdaterWindow(); uw->updateData(); delete uw; + ResourceManager::getInstance()-> + searchAndAddArchives("/updates", ".zip", 0); break; default: state = EXIT; 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; }; |