SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AddonsManager Class Reference

Public Member Functions

 AddonsManager ()
 Initialises the non-online component of the addons manager (i.e.
 
 ~AddonsManager ()
 The destructor saves the installed addons file again.
 
void init (const XMLNode *xml, bool force_refresh)
 This init function is called from a separate thread (started in news_manager, since the news.xml file contains the address of the addons.xml URL).
 
void initAddons (const XMLNode *xml)
 This initialises the online portion of the addons manager.
 
void checkInstalledAddons ()
 This function checks if the information in the installed addons file is consistent with what is actually available.
 
AddongetAddon (const std::string &id)
 Returns an addon with a given id.
 
int getAddonIndex (const std::string &id) const
 Returns the index of the addon with the given id, or -1 if no such addon exist.
 
bool install (const Addon &addon)
 Installs or updates (i.e.
 
bool uninstall (const Addon &addon)
 Removes all files froma login.
 
void reInit ()
 Reinitialises the addon manager, which happens when the user selects 'reload' in the addon manager.
 
bool anyAddonsInstalled () const
 
void downloadIconForAddon (const std::string &addon_id, std::weak_ptr< bool > result)
 Download icon for specific addon.
 
bool onlineReady () const
 Returns true if the list of online addons has been downloaded.
 
bool wasError () const
 
bool isLoading () const
 
void setErrorState ()
 Marks addon as not being available.
 
void saveInstalled ()
 Saves the information about installed addons and cached icons to addons_installed.xml.
 
unsigned int getNumAddons () const
 Returns the list of addons (installed and uninstalled).
 
const AddongetAddon (unsigned int i)
 Returns the i-th addons.
 
bool hasDownloadedIcons () const
 
bool hasNewAddons () const
 

Private Types

enum  STATE_TYPE { STATE_INIT , STATE_READY , STATE_ERROR }
 Which state the addons manager is: INIT: Waiting to download the list of addons. More...
 

Private Member Functions

void loadInstalledAddons ()
 Loads the installed addons from .../addons/addons_installed.xml.
 

Private Attributes

Synchronised< std::vector< Addon > > m_addons_list
 The list of all addons - installed or uninstalled.
 
std::string m_file_installed
 Full filename of the addons_installed.xml file.
 
std::vector< std::string > m_icon_list
 List of loaded icons.
 
Synchronised< STATE_TYPEm_state
 
bool m_downloaded_icons
 
std::atomic_bool m_has_new_addons
 

Member Enumeration Documentation

◆ STATE_TYPE

Which state the addons manager is: INIT: Waiting to download the list of addons.

READY: List is downloaded, manager is ready. ERROR: Error downloading the list, no addons available.

Constructor & Destructor Documentation

◆ AddonsManager()

AddonsManager::AddonsManager ( )

Initialises the non-online component of the addons manager (i.e.

handling the list of already installed addons). The online component is initialised later from a separate thread started from the news manager (see NewsManager::init() ).

◆ ~AddonsManager()

AddonsManager::~AddonsManager ( )

The destructor saves the installed addons file again.

This is necessary so that information about downloaded icons is saved for the next run.

Member Function Documentation

◆ checkInstalledAddons()

void AddonsManager::checkInstalledAddons ( )

This function checks if the information in the installed addons file is consistent with what is actually available.

This avoids e.g. that an addon is installed, but not marked here (and therefore shows up as not installed in the addons GUI), see bug #455.

◆ getAddon()

Addon * AddonsManager::getAddon ( const std::string &  id)

Returns an addon with a given id.

Raises an assertion if the id is not found!

Parameters
idThe id to search for.

◆ getAddonIndex()

int AddonsManager::getAddonIndex ( const std::string &  id) const

Returns the index of the addon with the given id, or -1 if no such addon exist.

Parameters
idThe (unique) identifier of the addon.

◆ init()

void AddonsManager::init ( const XMLNode xml,
bool  force_refresh 
)

This init function is called from a separate thread (started in news_manager, since the news.xml file contains the address of the addons.xml URL).

Parameters
xmlThe news.xml file, which inclues the data about the addons.xml file (in the 'include' node).
force_refreshDownload addons.xml, even if the usual waiting period between downloads hasn't passed yet.

◆ initAddons()

void AddonsManager::initAddons ( const XMLNode xml)

This initialises the online portion of the addons manager.

It uses the downloaded list of available addons. It is called from init(), which is called from a separate thread, so blocking download requests can be used without blocking the GUI. This function will update the state variable.

Parameters
xmlThe xml tree of addons.xml with information about all available addons.

◆ install()

bool AddonsManager::install ( const Addon addon)

Installs or updates (i.e.

remove old and then install a new) an addon. It checks for the directories and then unzips the file (which must already have been downloaded).

Parameters
addonAddon data for the addon to install.
Returns
true if installation was successful.

◆ onlineReady()

bool AddonsManager::onlineReady ( ) const
inline

Returns true if the list of online addons has been downloaded.

This is used to grey out the 'addons' entry till a network connections could be established.

◆ saveInstalled()

void AddonsManager::saveInstalled ( )

Saves the information about installed addons and cached icons to addons_installed.xml.

If this is not called, information about downloaded icons is lost (and will trigger a complete redownload when STK is started next time).

◆ uninstall()

bool AddonsManager::uninstall ( const Addon addon)

Removes all files froma login.

Parameters
addonThe addon to be removed.
Returns
True if uninstallation was successful.

Member Data Documentation

◆ m_addons_list

Synchronised<std::vector<Addon> > AddonsManager::m_addons_list
private

The list of all addons - installed or uninstalled.

The list is combined from the addons_installed.xml file first, then information from the downloaded list of items is merged/added to that.


The documentation for this class was generated from the following files: