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