#include <version.h>
#include <algorithm>
+#include <memory>
#include <physfs.h>
#include <sstream>
#include <stdexcept>
#ifdef HAVE_LIBCURL
# include <curl/curl.h>
# include <curl/easy.h>
-# include <curl/types.h>
#endif
#include "addon/addon.hpp"
}
#endif
-AddonManager&
-AddonManager::get_instance()
-{
- static AddonManager instance;
- return instance;
-}
-
AddonManager::AddonManager() :
addons(),
ignored_addon_filenames()
#ifdef HAVE_LIBCURL
char error_buffer[CURL_ERROR_SIZE+1];
- const char* baseUrl = "http://supertux.berlios.de/addons/index.nfo";
+ const char* baseUrl = "http://addons.supertux.googlecode.com/git/index-0_3_5.nfo";
std::string addoninfos = "";
CURL *curl_handle;
if(!addons_lisp) throw std::runtime_error("Downloaded file is not an Add-on list");
lisp::ListIterator iter(addons_lisp);
- while(iter.next()) {
+ while(iter.next())
+ {
const std::string& token = iter.item();
- if(token != "supertux-addoninfo") {
+ if(token != "supertux-addoninfo")
+ {
log_warning << "Unknown token '" << token << "' in Add-on list" << std::endl;
continue;
}
- Addon* addon_ptr = new Addon();
- Addon& addon = *addon_ptr;
- addon.parse(*(iter.lisp()));
- addon.installed = false;
- addon.loaded = false;
+ std::unique_ptr<Addon> addon(new Addon());
+ addon->parse(*(iter.lisp()));
+ addon->installed = false;
+ addon->loaded = false;
- // make sure the list of known Add-ons does not already contain this one
+ // make sure the list of known Add-ons does not already contain this one
bool exists = false;
for (std::vector<Addon*>::const_iterator i = addons.begin(); i != addons.end(); i++) {
- if (**i == addon) {
- exists = true;
- break;
+ if (**i == *addon) {
+ exists = true;
+ break;
}
- }
- if (exists) {
- delete addon_ptr;
- continue;
}
- // make sure the Add-on's file name does not contain weird characters
- if (addon.suggested_filename.find_first_not_of("match.quiz-proxy_gwenblvdjfks0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos) {
- log_warning << "Add-on \"" << addon.title << "\" contains unsafe file name. Skipping." << std::endl;
- delete addon_ptr;
- continue;
+ if (exists)
+ {
+ // do nothing
+ }
+ else if (addon->suggested_filename.find_first_not_of("match.quiz-proxy_gwenblvdjfks0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos)
+ {
+ // make sure the Add-on's file name does not contain weird characters
+ log_warning << "Add-on \"" << addon->title << "\" contains unsafe file name. Skipping." << std::endl;
+ }
+ else
+ {
+ addons.push_back(addon.release());
}
-
- addons.push_back(addon_ptr);
}
} catch(std::exception& e) {
std::stringstream msg;
if (addon->get_md5() != addon->stored_md5) {
addon->installed = false;
PHYSFS_delete(fileName.c_str());
- std::string why = "MD5 checksums differ";
+ std::string why = "MD5 checksums differ";
throw std::runtime_error("Downloading Add-on failed: " + why);
}
// Search for infoFiles
std::string infoFileName = "";
char** rc2 = PHYSFS_enumerateFiles("/");
- for(char** i = rc2; *i != 0; ++i) {
+ for(char** j = rc2; *j != 0; ++j) {
// get filename of potential infoFile
- std::string potentialInfoFileName = *i;
+ std::string potentialInfoFileName = *j;
// make sure it looks like an infoFile
static const std::string infoExt = ".nfo";
addon->loaded = true;
addons.push_back(addon);
- // check if the Addon is disabled
+ // check if the Addon is disabled
if (std::find(ignored_addon_filenames.begin(), ignored_addon_filenames.end(), fileName) != ignored_addon_filenames.end()) {
unload(addon);
}
void
AddonManager::read(const Reader& lisp)
{
- lisp.get("disabled-addons", ignored_addon_filenames);
+ lisp.get("disabled-addons", ignored_addon_filenames);
}
void
AddonManager::write(lisp::Writer& writer)
{
- writer.write("disabled-addons", ignored_addon_filenames);
+ writer.write("disabled-addons", ignored_addon_filenames);
}
/* EOF */