X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Faddon_manager.cpp;h=b59dde0940d1f185a81d5dcd964f838f2c0602b1;hb=9e7e803e384ed7bf0f5ccf9a4c381dd13b6a01d1;hp=c60a395a18605f071aa8cf8b9ba396503a2ca3d9;hpb=99cf62c2d44b4555e9761f1c8f1b10cf880c33fb;p=supertux.git diff --git a/src/addon_manager.cpp b/src/addon_manager.cpp index c60a395a1..b59dde094 100644 --- a/src/addon_manager.cpp +++ b/src/addon_manager.cpp @@ -21,13 +21,11 @@ #include #include +#include #include -//#include -#include -#include +#include #include #include -#include "SDL.h" #include "addon_manager.hpp" #include "config.h" #include "log.hpp" @@ -53,20 +51,12 @@ namespace { return size * nmemb; } - /*size_t my_curl_physfs_write(void *ptr, size_t size, size_t nmemb, void *f_p) + size_t my_curl_physfs_write(void *ptr, size_t size, size_t nmemb, void *f_p) { PHYSFS_file* f = static_cast(f_p); PHYSFS_sint64 written = PHYSFS_write(f, ptr, size, nmemb); log_debug << "read " << size * nmemb << " bytes of data..." << std::endl; return size * written; - }*/ - - size_t my_curl_sdl_write(void *ptr, size_t size, size_t nmemb, void *f_p) - { - SDL_RWops* f = static_cast(f_p); - int written = SDL_RWwrite(f, ptr, size, nmemb); - log_debug << "wrote " << size * nmemb << " bytes of data..." << std::endl; - return size * written; } } @@ -98,15 +88,16 @@ AddonManager::get_installed_addons() const { std::vector addons; - Unison::VFS::FileSystem &fs = Unison::VFS::FileSystem::get(); - std::vector search_path = fs.get_search_path(); - for(std::vector::iterator iter = search_path.begin();iter != search_path.end();++iter) - { + // iterate over complete search path (i.e. directories and archives) + char **i = PHYSFS_getSearchPath(); + if (!i) throw std::runtime_error("Could not query physfs search path"); + for (; *i != NULL; i++) { + // get filename of potential archive - std::string fileName = *iter; + std::string fileName = *i; // make sure it's in the writeDir - static const std::string writeDir = fs.get_write_dir(); + static const std::string writeDir = PHYSFS_getWriteDir(); if (fileName.compare(0, writeDir.length(), writeDir) != 0) continue; // make sure it looks like an archive @@ -123,7 +114,7 @@ AddonManager::get_installed_addons() const Addon addon; // extract nice title as fallback for when the Add-on has no addoninfo file - static std::string dirSep = fs.get_dir_sep(); + static const char* dirSep = PHYSFS_getDirSeparator(); std::string::size_type n = fileName.rfind(dirSep) + 1; if (n == std::string::npos) n = 0; addon.title = fileName.substr(n, fileName.length() - n - archiveExt.length()); @@ -133,7 +124,7 @@ AddonManager::get_installed_addons() const // read an accompaining .nfo file, if it exists static const std::string infoExt = ".nfo"; std::string infoFileName = fileName.substr(n, fileName.length() - n - archiveExt.length()) + infoExt; - if (fs.exists(infoFileName)) { + if (PHYSFS_exists(infoFileName.c_str())) { addon.parse(infoFileName); if (addon.file != shortFileName) { log_warning << "Add-on \"" << addon.title << "\", contained in file \"" << shortFileName << "\" is accompained by an addoninfo file that specifies \"" << addon.file << "\" as the Add-on's file name. Skipping." << std::endl; @@ -162,7 +153,7 @@ AddonManager::get_available_addons() const char error_buffer[CURL_ERROR_SIZE+1]; - const char* baseUrl = "http://supertux.lethargik.org/addons/index.nfo"; + const char* baseUrl = "http://supertux.berlios.de/addons/index.nfo"; std::string addoninfos = ""; CURL *curl_handle; @@ -175,6 +166,7 @@ AddonManager::get_available_addons() const curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 1); + curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); CURLcode result = curl_easy_perform(curl_handle); curl_easy_cleanup(curl_handle); @@ -230,8 +222,6 @@ AddonManager::install(const Addon& addon) throw std::runtime_error("Add-on has unsafe file name (\""+addon.file+"\")"); } - Unison::VFS::FileSystem &fs = Unison::VFS::FileSystem::get(); - #ifdef HAVE_LIBCURL char error_buffer[CURL_ERROR_SIZE+1]; @@ -239,8 +229,7 @@ AddonManager::install(const Addon& addon) char* url = (char*)malloc(addon.http_url.length() + 1); strncpy(url, addon.http_url.c_str(), addon.http_url.length() + 1); - //PHYSFS_file* f = PHYSFS_openWrite(addon.file.c_str()); - SDL_RWops *f = Unison::VFS::SDL::Utils::open_physfs_in(addon.file); + PHYSFS_file* f = PHYSFS_openWrite(addon.file.c_str()); log_debug << "Downloading \"" << url << "\"" << std::endl; @@ -248,7 +237,7 @@ AddonManager::install(const Addon& addon) curl_handle = curl_easy_init(); curl_easy_setopt(curl_handle, CURLOPT_URL, url); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "SuperTux/" PACKAGE_VERSION " libcURL"); - curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, my_curl_sdl_write); + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, my_curl_physfs_write); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, f); curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, error_buffer); curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1); @@ -257,14 +246,12 @@ AddonManager::install(const Addon& addon) CURLcode result = curl_easy_perform(curl_handle); curl_easy_cleanup(curl_handle); - //PHYSFS_close(f); - SDL_RWclose(f); + PHYSFS_close(f); free(url); if (result != CURLE_OK) { - //PHYSFS_delete(addon.file.c_str()); - fs.rm(addon.file); + PHYSFS_delete(addon.file.c_str()); std::string why = error_buffer[0] ? error_buffer : "unhandled error"; throw std::runtime_error("Downloading Add-on failed: " + why); } @@ -275,14 +262,11 @@ AddonManager::install(const Addon& addon) std::string infoFileName = addon.file.substr(0, addon.file.length()-archiveExt.length()) + infoExt; addon.write(infoFileName); - //static const std::string writeDir = PHYSFS_getWriteDir(); - //static const std::string dirSep = PHYSFS_getDirSeparator(); - static const std::string writeDir = fs.get_write_dir(); - static const std::string dirSep = fs.get_dir_sep(); + static const std::string writeDir = PHYSFS_getWriteDir(); + static const std::string dirSep = PHYSFS_getDirSeparator(); std::string fullFilename = writeDir + dirSep + addon.file; log_debug << "Finished downloading \"" << fullFilename << "\"" << std::endl; - fs.mount(fullFilename, "/", true); - //PHYSFS_addToSearchPath(fullFilename.c_str(), 1); + PHYSFS_addToSearchPath(fullFilename.c_str(), 1); #else (void) addon; #endif @@ -298,18 +282,16 @@ AddonManager::remove(const Addon& addon) } log_debug << "deleting file \"" << addon.file << "\"" << std::endl; - - Unison::VFS::FileSystem &fs = Unison::VFS::FileSystem::get(); - fs.umount(addon.file); - fs.rm(addon.file); + PHYSFS_removeFromSearchPath(addon.file.c_str()); + PHYSFS_delete(addon.file.c_str()); // remove an accompaining .nfo file static const std::string archiveExt = ".zip"; static const std::string infoExt = ".nfo"; std::string infoFileName = addon.file.substr(0, addon.file.length()-archiveExt.length()) + infoExt; - if (fs.exists(infoFileName)) { + if (PHYSFS_exists(infoFileName.c_str())) { log_debug << "deleting file \"" << infoFileName << "\"" << std::endl; - fs.rm(infoFileName); + PHYSFS_delete(infoFileName.c_str()); } }