The Battle for Wesnoth  1.17.0-dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
3  Copyright (C) 2008 - 2020 by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Local add-on content management interface.
19  *
20  * This API only concerns local functionality dealing with enumerating and
21  * manipulating installed add-ons, as well as extracting add-ons in WML pack
22  * form, usually but not necessarily obtained through the networked client.
23  *
24  * It also includes functions for the handling of add-on versioning
25  * information (_info.cfg) and publishing information (_server.pbl).
26  */
27 
28 #pragma once
29 
30 class config;
31 class version_info;
32 
33 #include "addon/validation.hpp"
34 
35 #include <string>
36 #include <vector>
37 #include <utility>
38 #include <map>
39 
40 /**
41  * Exception thrown when the WML parser fails to read a .pbl file.
42  */
43 struct invalid_pbl_exception : public std::exception
44 {
45  /**
46  * Constructor.
47  *
48  * @param pbl_path Path to the faulty .pbl file.
49  * @param msg An error message to display.
50  */
51  invalid_pbl_exception(const std::string& pbl_path, const std::string& msg)
52  : path(pbl_path), message(msg)
53  {}
54 
55  /** Path to the faulty .pbl file. */
56  const std::string path;
57 
58  /** Error message to display. */
59  const std::string message;
60 
61  /** Destructor.
62  * Virtual to allow for subclassing.
63  */
64  virtual ~invalid_pbl_exception() noexcept {}
65 
66  /** Returns a pointer to the (constant) error description.
67  * @return A pointer to a const char*. The underlying memory
68  * is in posession of the Exception object. Callers must
69  * not attempt to free the memory.
70  */
71  virtual const char* what() const noexcept {
72  return message.c_str();
73  }
74 };
75 
76 /**
77  * Removes the specified add-on, deleting its full directory structure.
78  */
79 bool remove_local_addon(const std::string& addon);
80 
81 /**
82  * Returns whether a .pbl file is present for the specified add-on or not.
83  */
84 bool have_addon_pbl_info(const std::string& addon_name);
85 
86 /**
87  * Returns whether the specified add-on appears to be managed by a VCS or not.
88  *
89  * This is used by the add-ons client to prompt the user before overwriting
90  * add-ons that may currently be managed externally instead of through the
91  * built-in campaignd client.
92  *
93  * Currently supported VCSes are: Subversion, Git, Mercurial.
94  */
95 bool have_addon_in_vcs_tree(const std::string& addon_name);
96 
97 /**
98  * Gets the publish information for an add-on.
99  *
100  * @param addon_name The add-on's main directory/file name.
101  *
102  * @exception invalid_pbl_exception If it is not possible to read the .pbl file
103  * (often due to invalid WML).
104  */
105 config get_addon_pbl_info(const std::string& addon_name);
106 
107 /**
108  * Sets the publish information for an add-on.
109  *
110  * @param addon_name The add-on's main directory/file name.
111  * @param cfg A config object from which the add-on's
112  * properties are copied.
113  */
114 void set_addon_pbl_info(const std::string& addon_name, const class config& cfg);
115 
116 /**
117  * Returns true if there is a local installation info (_info.cfg) file for the add-on.
118  */
119 bool have_addon_install_info(const std::string& addon_name);
120 
121 /**
122  * Gets the installation info (_info.cfg) for an add-on.
123  *
124  * @param addon_name The add-on's main directory/file name.
125  * @param cfg A config object to store the add-on's
126  * properties.
127  */
128 void get_addon_install_info(const std::string& addon_name, class config& cfg);
129 
130 /**
131  * Writes the installation info (_info.cfg) for an add-on to disk.
132  *
133  * @param addon_name The add-on's main directory/file name.
134  * @param cfg A config object containing the add-on's
135  * properties.
136  */
137 void write_addon_install_info(const std::string& addon_name, const class config& cfg);
138 
139 /** Returns a list of local add-ons that can be published. */
140 std::vector<std::string> available_addons();
141 
142 /** Retrieves the names of all installed add-ons. */
143 std::vector<std::string> installed_addons();
144 
145 /** Retrieves the ids and versions of all installed add-ons. */
146 std::map<std::string, std::string> installed_addons_and_versions();
147 
148 /** Check whether the specified add-on is currently installed. */
149 bool is_addon_installed(const std::string& addon_name);
150 
151 /** Archives an add-on into a config object for campaignd transactions. */
152 void archive_addon(const std::string& addon_name, class config& cfg);
153 
154 /** Unarchives an add-on from campaignd's retrieved config object. */
155 void unarchive_addon(const class config& cfg);
156 
157 /** Removes the listed files from the addon. */
158 void purge_addon(const config& removelist);
159 
160 /** Refreshes the per-session cache of add-on's version information structs. */
162 
163 /** Returns a particular installed add-on's version information. */
164 version_info get_addon_version_info(const std::string& addon);
std::vector< std::string > available_addons()
Returns a list of local add-ons that can be published.
Definition: manager.cpp:172
invalid_pbl_exception(const std::string &pbl_path, const std::string &msg)
Constructor.
Definition: manager.hpp:51
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on&#39;s version information structs.
Definition: manager.cpp:355
const std::string path
Path to the faulty .pbl file.
Definition: manager.hpp:56
void set_addon_pbl_info(const std::string &addon_name, const class config &cfg)
Sets the publish information for an add-on.
bool have_addon_in_vcs_tree(const std::string &addon_name)
Returns whether the specified add-on appears to be managed by a VCS or not.
Definition: manager.cpp:53
bool have_addon_install_info(const std::string &addon_name)
Returns true if there is a local installation info (_info.cfg) file for the add-on.
Definition: manager.cpp:87
Exception thrown when the WML parser fails to read a .pbl file.
Definition: manager.hpp:43
bool have_addon_pbl_info(const std::string &addon_name)
Returns whether a .pbl file is present for the specified add-on or not.
Definition: manager.cpp:62
bool remove_local_addon(const std::string &addon)
Removes the specified add-on, deleting its full directory structure.
Definition: manager.cpp:129
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
void archive_addon(const std::string &addon_name, class config &cfg)
Archives an add-on into a config object for campaignd transactions.
Definition: manager.cpp:282
std::map< std::string, std::string > installed_addons_and_versions()
Retrieves the ids and versions of all installed add-ons.
Definition: manager.cpp:182
void purge_addon(const config &removelist)
Removes the listed files from the addon.
Definition: manager.cpp:345
const std::string message
Error message to display.
Definition: manager.hpp:59
bool is_addon_installed(const std::string &addon_name)
Check whether the specified add-on is currently installed.
Definition: manager.cpp:204
void unarchive_addon(const class config &cfg)
Unarchives an add-on from campaignd&#39;s retrieved config object.
void write_addon_install_info(const std::string &addon_name, const class config &cfg)
Writes the installation info (_info.cfg) for an add-on to disk.
virtual ~invalid_pbl_exception() noexcept
Destructor.
Definition: manager.hpp:64
version_info get_addon_version_info(const std::string &addon)
Returns a particular installed add-on&#39;s version information.
Definition: manager.cpp:396
virtual const char * what() const noexcept
Returns a pointer to the (constant) error description.
Definition: manager.hpp:71
Represents version numbers.
void get_addon_install_info(const std::string &addon_name, class config &cfg)
Gets the installation info (_info.cfg) for an add-on.
Definition: manager.cpp:92
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:177
config get_addon_pbl_info(const std::string &addon_name)
Gets the publish information for an add-on.
Definition: manager.cpp:67