Fixed addons management (deleting), which I broke in r12581: Addons used

their id as directory name (and since the id was changed to have addon_
as prefix, this didn't work anymore).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12587 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2013-03-27 21:01:05 +00:00
parent 2ed38db288
commit b967e5a492
5 changed files with 46 additions and 18 deletions

View File

@@ -66,9 +66,10 @@ Addon::Addon(const XMLNode &xml)
std::string designer;
xml.get("name", &name );
m_name = StringUtils::decodeFromHtmlEntities(name);
m_id = StringUtils::toLowerCase(name);
xml.get("id", &m_id );
m_name = StringUtils::decodeFromHtmlEntities(name);
m_dir_name = StringUtils::toLowerCase(name);
xml.get("id", &m_dir_name );
m_id = createAddonId(m_dir_name);
xml.get("designer", &designer );
xml.get("status", &m_status );
@@ -116,6 +117,7 @@ Addon::Addon(const XMLNode &xml)
void Addon::copyInstallData(const Addon &addon)
{
m_description = addon.m_description;
m_dir_name = addon.m_dir_name;
m_revision = addon.m_revision;
m_zip_file = addon.m_zip_file;
m_icon_url = addon.m_icon_url;
@@ -139,10 +141,11 @@ void Addon::copyInstallData(const Addon &addon)
*/
void Addon::writeXML(std::ofstream *out_stream)
{
// We write m_dir_name as 'id' to stay backwards compatible
(*out_stream) << " <" << m_type
<< " name=\""
<< StringUtils::encodeToHtmlEntities(m_name)
<< "\" id=\"" << m_id
<< "\" id=\"" << m_dir_name
<< "\" designer=\""
<< StringUtils::encodeToHtmlEntities(m_designer)
<< "\" status=\"" << m_status

View File

@@ -24,12 +24,13 @@
* Handles add-ons that can be downloaded
*/
#include "io/file_manager.hpp"
#include "utils/string_utils.hpp"
#include "utils/time.hpp"
#include <assert.h>
#include <string>
#include "io/file_manager.hpp"
#include "utils/time.hpp"
class XMLNode;
/**
@@ -57,12 +58,33 @@ public:
SO_DATE // Sorted by date, newest first
};
// ------------------------------------------------------------------------
/** A static function that checks if the given ID is an addon. This is
* done by testing if the directory name is in the addons directory.
*/
static bool isAddon(const std::string &directory)
{
return StringUtils::startsWith(directory,file_manager->getAddonsDir());
} // isAddon
// ------------------------------------------------------------------------
/** Create an addon id by adding a 'addon_' prefix to the given id. */
static std::string createAddonId(const std::string &id)
{
return "addon_"+id;
} // createAddonId
// ------------------------------------------------------------------------
private:
/** The name to be displayed. */
core::stringw m_name;
/** Internal id for this addon, which is the name in lower case.
* This is used to create a subdirectory for this addon. */
* This is the name of the subdirectory for this addon with an 'addon_'
* prefix. */
std::string m_id;
/** The directory name (i.d. the internal id without 'addon_' prefix. */
std::string m_dir_name;
/** The name of the designer of the addon. */
core::stringw m_designer;
/** The (highest) revision number available online. */
@@ -241,7 +263,7 @@ public:
/** Returns the directory in which this addon is installed. */
std::string getDataDir() const
{
return file_manager->getAddonsFile(getTypeDirectory()+getId());
return file_manager->getAddonsFile(getTypeDirectory()+m_dir_name);
} // getDataDir
// ------------------------------------------------------------------------
/** Compares two addons according to the sort order currently defined.

View File

@@ -829,7 +829,7 @@ const std::string &FileManager::getAddonsDir() const
*/
std::string FileManager::getAddonsFile(const std::string &name)
{
return getAddonsDir()+"/"+name;
return getAddonsDir()+name;
} // getAddonsFile
//-----------------------------------------------------------------------------

View File

@@ -18,10 +18,7 @@
#include "karts/kart_properties.hpp"
#include <iostream>
#include <stdexcept>
#include <string>
#include "addons/addon.hpp"
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
@@ -37,6 +34,11 @@
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include <iostream>
#include <stdexcept>
#include <string>
float KartProperties::UNDEFINED = -99.9f;
/** The constructor initialises all values with invalid values. It can later
@@ -177,8 +179,8 @@ void KartProperties::load(const std::string &filename, const std::string &node)
// If this is an addon kart, add "addon_" to the identifier - just in
// case that an addon kart has the same directory name (and therefore
// identifier) as an included kart.
if(StringUtils::startsWith(filename, file_manager->getAddonsDir()))
m_ident = "addon_"+m_ident;
if(Addon::isAddon(filename))
m_ident = Addon::createAddonId(m_ident);
try
{
root = new XMLNode(filename);

View File

@@ -26,6 +26,7 @@
using namespace irr;
#include "addons/addon.hpp"
#include "audio/music_manager.hpp"
#include "challenges/challenge.hpp"
#include "challenges/unlock_manager.hpp"
@@ -88,8 +89,8 @@ Track::Track(const std::string &filename)
// If this is an addon track, add "addon_" to the identifier - just in
// case that an addon track has the same directory name (and therefore
// identifier) as an included track.
if(StringUtils::startsWith(filename, file_manager->getAddonsDir()))
m_ident = "addon_"+m_ident;
if(Addon::isAddon(filename))
m_ident = Addon::createAddonId(m_ident);
// The directory should always have a '/' at the end, but getBasename
// above returns "" if a "/" is at the end, so we add the "/" here.