X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faddon_manager.cpp;h=dcbbdf126cf56e2ae30f057b792352bb7374604a;hb=a983f6648d43492632c41e2b7519b70458b53cf4;hp=3181bb77ca49893365590e7804acfe039f3f8185;hpb=1a6dbe26f00e7f9eabb65a1844ab7d2aa5648126;p=supertux.git diff --git a/src/addon_manager.cpp b/src/addon_manager.cpp index 3181bb77c..dcbbdf126 100644 --- a/src/addon_manager.cpp +++ b/src/addon_manager.cpp @@ -36,7 +36,7 @@ #ifdef HAVE_LIBCURL namespace { - size_t my_curl_string_append(void *ptr, size_t size, size_t nmemb, void *string_ptr) + size_t my_curl_string_append(void *ptr, size_t size, size_t nmemb, void *string_ptr) { std::string& s = *static_cast(string_ptr); std::string buf(static_cast(ptr), size * nmemb); @@ -44,8 +44,8 @@ namespace { log_debug << "read " << size * nmemb << " bytes of data..." << std::endl; 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); @@ -56,7 +56,7 @@ namespace { } #endif -AddonManager& +AddonManager& AddonManager::get_instance() { static AddonManager instance; @@ -76,8 +76,8 @@ AddonManager::~AddonManager() curl_global_cleanup(); #endif } - -std::vector + +std::vector AddonManager::get_addons() const { std::vector addons; @@ -99,11 +99,11 @@ AddonManager::get_addons() const // make sure it looks like an archive static const std::string archiveExt = ".zip"; if (fileName.compare(fileName.length()-archiveExt.length(), archiveExt.length(), archiveExt) != 0) continue; - + // make sure it exists struct stat stats; if (stat(fileName.c_str(), &stats) != 0) continue; - + // make sure it's an actual file if (!S_ISREG(stats.st_mode)) continue; @@ -112,13 +112,13 @@ AddonManager::get_addons() const std::string::size_type n = fileName.rfind(dirSep) + 1; if (n == std::string::npos) n = 0; std::string title = fileName.substr(n, fileName.length() - n - archiveExt.length()); - + Addon addon; addon.title = title; addon.fname = fileName; addon.isInstalled = true; - addons.push_back(addon); + addons.push_back(addon); } #ifdef HAVE_LIBCURL @@ -165,12 +165,12 @@ AddonManager::get_addons() const static const std::string archiveExt = ".zip"; if (url.compare(url.length()-archiveExt.length(), archiveExt.length(), archiveExt) != 0) continue; - // extract nice title + // extract nice title std::string::size_type n = url.rfind('/') + 1; if (n == std::string::npos) n = 0; std::string title = url.substr(n, url.length() - n - archiveExt.length()); - // construct file name + // construct file name std::string fname = url.substr(n); // make sure it does not contain weird characters @@ -182,17 +182,17 @@ AddonManager::get_addons() const addon.url = url; addon.isInstalled = false; - addons.push_back(addon); + addons.push_back(addon); } #endif - + return addons; } void -AddonManager::install(const Addon& - #ifdef HAVE_LIBCURL +AddonManager::install(const Addon& + #ifdef HAVE_LIBCURL addon #endif ) @@ -219,7 +219,7 @@ AddonManager::install(const Addon& PHYSFS_close(f); free(url); - + static const std::string writeDir = PHYSFS_getWriteDir(); static const std::string dirSep = PHYSFS_getDirSeparator(); std::string fullFilename = writeDir + dirSep + addon.fname; @@ -229,10 +229,9 @@ AddonManager::install(const Addon& } -void +void AddonManager::remove(const Addon& addon) { PHYSFS_removeFromSearchPath(addon.fname.c_str()); unlink(addon.fname.c_str()); } -