Removed trailing whitespaces in tilemanager source files (yes I know that code needs...
[supertux.git] / src / addon_manager.cpp
index 3181bb7..1459983 100644 (file)
@@ -23,6 +23,7 @@
 #include <list>
 #include <physfs.h>
 #include <sys/stat.h>
+#include <stdio.h>
 #include "addon_manager.hpp"
 #include "config.h"
 #include "log.hpp"
@@ -36,7 +37,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<std::string*>(string_ptr);
     std::string buf(static_cast<char*>(ptr), size * nmemb);
@@ -44,8 +45,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<PHYSFS_file*>(f_p);
     PHYSFS_sint64 written = PHYSFS_write(f, ptr, size, nmemb);
@@ -56,7 +57,7 @@ namespace {
 }
 #endif
 
-AddonManager& 
+AddonManager&
 AddonManager::get_instance()
 {
   static AddonManager instance;
@@ -76,8 +77,8 @@ AddonManager::~AddonManager()
   curl_global_cleanup();
 #endif
 }
-  
-std::vector<Addon> 
+
+std::vector<Addon>
 AddonManager::get_addons() const
 {
   std::vector<Addon> addons;
@@ -99,11 +100,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 +113,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 +166,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,20 +183,16 @@ 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 
-               addon
-               #endif
-               )
+AddonManager::install(const Addon& addon)
 {
 
 #ifdef HAVE_LIBCURL
@@ -219,20 +216,21 @@ 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;
   log_debug << "Finished downloading \"" << fullFilename << "\"" << std::endl;
   PHYSFS_addToSearchPath(fullFilename.c_str(), 1);
+#else
+  (void) addon;
 #endif
 
 }
 
-void 
+void
 AddonManager::remove(const Addon& addon)
 {
   PHYSFS_removeFromSearchPath(addon.fname.c_str());
-  unlink(addon.fname.c_str());
+  PHYSFS_delete(addon.fname.c_str());
 }
-