SuperTuxKart
Loading...
Searching...
No Matches
addon.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2010-2015 Lucas Baudin, Joerg Henrichs
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_ADDON_HPP
20#define HEADER_ADDON_HPP
21
27#include "utils/time.hpp"
28
29#include <assert.h>
30#include <string>
31#include "irrString.h"
32
33class XMLNode;
34using namespace irr;
35
39class Addon
40{
41public:
43 enum AddonStatus {AS_APPROVED = 0x0001,
44 AS_ALPHA = 0x0002,
45 AS_BETA = 0x0004,
46 AS_RC = 0x0008,
47 AS_INVISIBLE= 0x0010,
48 //AS_HQ = 0x0020, currently not supported
49 AS_DFSG = 0x0040,
50 AS_FEATURED = 0x0080,
51 AS_LATEST = 0X0100,
52 AS_BAD_DIM = 0x0200
53 };
54
56 enum SortOrder { SO_DEFAULT, // featured first, then alphabetically
57 SO_NAME, // Sorted alphabetically by name
58 SO_DATE // Sorted by date, newest first
59 };
60
61 // ------------------------------------------------------------------------
62 static bool isAddon(const std::string &directory);
63 // ------------------------------------------------------------------------
65 static std::string createAddonId(const std::string &id)
66 {
67 return "addon_"+id;
68 } // createAddonId
69 // ------------------------------------------------------------------------
70
71private:
73 core::stringw m_name;
77 std::string m_id;
79 std::string m_dir_name;
80
82 core::stringw m_designer;
95 StkTime::TimeType m_date;
97 core::stringw m_description;
99 std::string m_icon_url;
101 std::string m_icon_basename;
105 std::string m_zip_file;
111 mutable float m_rating;
113 std::string m_min_include_ver;
115 std::string m_max_include_ver;
117 std::string m_type;
118
121
122public:
124 Addon(const XMLNode &xml);
125
127 // ------------------------------------------------------------------------
130 static void setSortOrder(SortOrder so) { m_sort_order = so; }
131 // ------------------------------------------------------------------------
132 void writeXML(std::ofstream *out_stram);
133 // ------------------------------------------------------------------------
134 void copyInstallData(const Addon &addon);
135 // ------------------------------------------------------------------------
137 const core::stringw& getName() const { return m_name; }
138 // ------------------------------------------------------------------------
140 const std::string& getMinIncludeVer() const {return m_min_include_ver; }
141 // ------------------------------------------------------------------------
143 const std::string& getMaxIncludeVer() const {return m_max_include_ver; }
144 // ------------------------------------------------------------------------
146 const float getRating() const {return m_rating; }
147 // ------------------------------------------------------------------------
149 void setRating(const float rating) const {m_rating = rating; }
150 // ------------------------------------------------------------------------
152 const std::string& getType() const { return m_type; }
153 // ------------------------------------------------------------------------
155 const std::string& getZipFileName() const { return m_zip_file; }
156 // ------------------------------------------------------------------------
158 const std::string& getIconURL() const { return m_icon_url; }
159 // ------------------------------------------------------------------------
161 const std::string& getIconBasename() const { return m_icon_basename; }
162 // ------------------------------------------------------------------------
164 const core::stringw& getDescription() const { return m_description; }
165 // ------------------------------------------------------------------------
168 StkTime::TimeType getDate() const { return m_date; }
169 // ------------------------------------------------------------------------
171 std::string getDateAsString() const;
172 // ------------------------------------------------------------------------
174 bool isInstalled() const { return m_installed; }
175 // ------------------------------------------------------------------------
178 // ------------------------------------------------------------------------
182 int getRevision() const { return m_revision; }
183 // ------------------------------------------------------------------------
185 const std::string& getId() const { return m_id; }
186 // ------------------------------------------------------------------------
188 const core::stringw& getDesigner() const { return m_designer; }
189 // ------------------------------------------------------------------------
191 bool getStillExists() const { return m_still_exists; }
192 // ------------------------------------------------------------------------
195 // ------------------------------------------------------------------------
197 bool needsUpdate() const
198 {
200 } // needsUpdate
201 // ------------------------------------------------------------------------
206 bool iconNeedsUpdate() const
207 {
209 } // iconNeedsUpdate
210 // ------------------------------------------------------------------------
214 void setInstalled(bool state)
215 {
216 m_installed = state;
217 if(state)
219 } // setInstalled
220 // ------------------------------------------------------------------------
223 bool iconReady() const { return m_icon_ready; }
224 // ------------------------------------------------------------------------
227 {
229 m_icon_ready=true;
230 } // setIconReady
231 // ------------------------------------------------------------------------
233 int getSize() const { return m_size; }
234 // ------------------------------------------------------------------------
240 std::string getTypeDirectory() const
241 {
242 if(m_type=="kart")
243 return "karts/";
244 else if(m_type=="track")
245 return "tracks/";
246 else if(m_type=="arena") // arenas are installed as tracks
247 return "tracks/";
248 // It must be one of the two
249 assert(false);
250 return ""; // Ignore compiler warning
251 } // getTypeDirectory
252
253 // ------------------------------------------------------------------------
255 bool testIncluded(const std::string &min_ver, const std::string &max_ver);
256 // ------------------------------------------------------------------------
258 bool testStatus(AddonStatus n) const {return (m_status & n) !=0; }
259 // ------------------------------------------------------------------------
260 std::string getDataDir() const;
261 // ------------------------------------------------------------------------
262 bool filterByWords(const core::stringw words) const;
263 // ------------------------------------------------------------------------
264
268 bool operator<(const Addon &a) const
269 {
270 switch(m_sort_order)
271 {
272 case SO_DEFAULT:
273 if(testStatus(AS_FEATURED) &&
274 !a.testStatus(AS_FEATURED)) return true;
275 if(!testStatus(AS_FEATURED) &&
276 a.testStatus(AS_FEATURED)) return false;
277 // Otherwise fall through to name comparison!
278 case SO_NAME:
279 // m_id is the lower case name
280 return m_id < a.m_id;
281 break;
282 case SO_DATE:
283 return m_date < a.m_date;
284 break;
285 } // switch
286 // Fix compiler warning.
287 return true;
288 } // operator<
289 // ------------------------------------------------------------------------
290 const std::string& getDirName() const { return m_dir_name; }
291}; // Addon
292
293
294#endif
Definition: addon.hpp:40
int m_revision
The (highest) revision number available online.
Definition: addon.hpp:84
bool m_icon_ready
True if the icon is cached/loaded and can be displayed.
Definition: addon.hpp:103
std::string m_type
Type, must be 'kart' or 'track'.
Definition: addon.hpp:117
bool filterByWords(const core::stringw words) const
Filter the add-on with a list of words.
Definition: addon.cpp:187
static void setSortOrder(SortOrder so)
Sets the sort order used in the comparison function.
Definition: addon.hpp:130
int m_icon_revision
The version of the icon that was downloaded.
Definition: addon.hpp:88
const core::stringw & getDescription() const
Returns the name of the addon.
Definition: addon.hpp:164
StkTime::TimeType getDate() const
Returns the date (in seconds since epoch) when the addon was uploaded.
Definition: addon.hpp:168
std::string m_dir_name
The directory name (i.d.
Definition: addon.hpp:79
void writeXML(std::ofstream *out_stram)
Writes information about an installed addon (it is only called for installed addons).
Definition: addon.cpp:142
bool iconNeedsUpdate() const
Returns true if the (cached) icon needs to be updated.
Definition: addon.hpp:206
void setInstalled(bool state)
Marks this addon to be installed.
Definition: addon.hpp:214
void setIconReady()
Marks that the icon for this addon can be displayed.
Definition: addon.hpp:226
const std::string & getId() const
Returns the ID of this addon.
Definition: addon.hpp:185
static std::string createAddonId(const std::string &id)
Create an addon id by adding a 'addon_' prefix to the given id.
Definition: addon.hpp:65
std::string m_icon_url
The URL of the icon (relative to the server)
Definition: addon.hpp:99
core::stringw m_description
A description of this addon.
Definition: addon.hpp:97
bool m_installed
True if the addon is installed.
Definition: addon.hpp:107
const float getRating() const
Returns the rating of an addon.
Definition: addon.hpp:146
const std::string & getMinIncludeVer() const
Returns the minimum version the addon was included with.
Definition: addon.hpp:140
std::string getDataDir() const
Returns the directory in which this addon is installed.
Definition: addon.cpp:243
const std::string & getIconURL() const
Returns the name of the icon of this addon.
Definition: addon.hpp:158
std::string m_id
Internal id for this addon, which is the name in lower case.
Definition: addon.hpp:77
AddonStatus
AddonStatus flags - a bit pattern.
Definition: addon.hpp:43
bool testIncluded(const std::string &min_ver, const std::string &max_ver)
Returns if the current version is between min and max versions.
Definition: addon.cpp:169
void deleteInvalidIconFile()
Deletes the icon file of this addon, and marks it to be re-downloaded (next time AddonsManager::downl...
Definition: addon.cpp:224
bool operator<(const Addon &a) const
Compares two addons according to the sort order currently defined.
Definition: addon.hpp:268
int getInstalledRevision() const
Returns the installed revision number of an addon.
Definition: addon.hpp:177
const std::string & getZipFileName() const
Returns the filename of the zip file with the addon.
Definition: addon.hpp:155
std::string m_max_include_ver
Maximum version addon is included with.
Definition: addon.hpp:115
float m_rating
Rating for thsi addon package.
Definition: addon.hpp:111
const std::string & getType() const
Returns the type of the addon.
Definition: addon.hpp:152
const core::stringw & getName() const
Returns the name of the addon.
Definition: addon.hpp:137
const std::string & getIconBasename() const
Returns the name of the icon (i.e.
Definition: addon.hpp:161
const core::stringw & getDesigner() const
Returns the designer of the addon.
Definition: addon.hpp:188
void setStillExists()
Marks that this addon still exists on the server.
Definition: addon.hpp:194
int m_size
Compressed size of the addon package.
Definition: addon.hpp:109
bool isInstalled() const
Returns if the addon is installed.
Definition: addon.hpp:174
int getSize() const
Returns the size of the compressed package.
Definition: addon.hpp:233
core::stringw m_name
The name to be displayed.
Definition: addon.hpp:73
bool needsUpdate() const
True if this addon needs to be updated.
Definition: addon.hpp:197
StkTime::TimeType m_date
Date when the addon was added.
Definition: addon.hpp:95
std::string getDateAsString() const
Returns a user readable date as a string.
Definition: addon.cpp:163
int getRevision() const
Returns the latest revision number of this addon.
Definition: addon.hpp:182
bool m_still_exists
True if this addon still exists on the server, i.e.
Definition: addon.hpp:93
void setRating(const float rating) const
Sets the rating of an addon.
Definition: addon.hpp:149
bool iconReady() const
Returns true if the icon of this addon was downloaded and is ready to be displayed.
Definition: addon.hpp:223
int m_installed_revision
The currently installed revision.
Definition: addon.hpp:86
void copyInstallData(const Addon &addon)
Copies the installation data (like description, revision, icon) from the downloaded online list to th...
Definition: addon.cpp:117
core::stringw m_designer
The name of the designer of the addon.
Definition: addon.hpp:82
static SortOrder m_sort_order
The sort order to be used in the comparison.
Definition: addon.hpp:120
std::string m_zip_file
The name of the zip file on the addon server.
Definition: addon.hpp:105
std::string m_min_include_ver
Minimum version addon is included with.
Definition: addon.hpp:113
const std::string & getMaxIncludeVer() const
Returns the maximum version the addon was included with.
Definition: addon.hpp:143
std::string getTypeDirectory() const
Returns the directory in which this type of addons is stored (in a separate subdirectory).
Definition: addon.hpp:240
bool getStillExists() const
Returns if this addon still exists on the server.
Definition: addon.hpp:191
bool testStatus(AddonStatus n) const
Returns if a certain status flag is set.
Definition: addon.hpp:258
int m_status
The status flags of this addon.
Definition: addon.hpp:90
std::string m_icon_basename
Name of the icon to use.
Definition: addon.hpp:101
SortOrder
Set the sort order used in the comparison function.
Definition: addon.hpp:56
static bool isAddon(const std::string &directory)
A static function that checks if the given ID is an addon.
Definition: addon.cpp:236
utility class used to parse XML files
Definition: xml_node.hpp:48