The Battle for Wesnoth  1.19.5+dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 <functional>
37 #include <string>
38 #include <vector>
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  * @param do_validate Whether we want to run validation on the .pbl file.
103  *
104  * @exception invalid_pbl_exception If it is not possible to read the .pbl file
105  * (often due to invalid WML).
106  */
107 config get_addon_pbl_info(const std::string& addon_name, bool do_validate);
108 
109 /**
110  * Sets the publish information for an add-on.
111  *
112  * @param addon_name The add-on's main directory/file name.
113  * @param cfg A config object from which the add-on's
114  * properties are copied.
115  */
116 void set_addon_pbl_info(const std::string& addon_name, const class config& cfg);
117 
118 /**
119  * Returns true if there is a local installation info (_info.cfg) file for the add-on.
120  */
121 bool have_addon_install_info(const std::string& addon_name);
122 
123 /**
124  * Gets the installation info (_info.cfg) for an add-on.
125  *
126  * @param addon_name The add-on's main directory/file name.
127  * @param cfg A config object to store the add-on's
128  * properties.
129  */
130 void get_addon_install_info(const std::string& addon_name, class config& cfg);
131 
132 /**
133  * Writes the installation info (_info.cfg) for an add-on to disk.
134  *
135  * @param addon_name The add-on's main directory/file name.
136  * @param cfg A config object containing the add-on's
137  * properties.
138  */
139 void write_addon_install_info(const std::string& addon_name, const class config& cfg);
140 
141 /** Returns a list of local add-ons that can be published. */
142 std::vector<std::string> available_addons();
143 
144 /** Retrieves the names of all installed add-ons. */
145 std::vector<std::string> installed_addons();
146 
147 /** Retrieves the ids and versions of all installed add-ons. */
148 std::map<std::string, std::string> installed_addons_and_versions();
149 
150 /** Check whether the specified add-on is currently installed. */
151 bool is_addon_installed(const std::string& addon_name);
152 
153 /** Archives an add-on into a config object for campaignd transactions. */
154 void archive_addon(const std::string& addon_name, class config& cfg);
155 
156 /** Unarchives an add-on from campaignd's retrieved config object. */
157 void unarchive_addon(const class config& cfg, std::function<void(unsigned)> progress_callback = {});
158 
159 /** Removes the listed files from the addon. */
160 void purge_addon(const config& removelist);
161 
162 /** Refreshes the per-session cache of add-on's version information structs. */
164 
165 /** Returns a particular installed add-on's version information. */
166 version_info get_addon_version_info(const std::string& addon);
bool remove_local_addon(const std::string &addon)
Removes the specified add-on, deleting its full directory structure.
Definition: manager.cpp:144
config get_addon_pbl_info(const std::string &addon_name, bool do_validate)
Gets the publish information for an add-on.
Definition: manager.cpp:71
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:57
void set_addon_pbl_info(const std::string &addon_name, const class config &cfg)
Sets the publish information for an add-on.
void unarchive_addon(const class config &cfg, std::function< void(unsigned)> progress_callback={})
Unarchives an add-on from campaignd's retrieved config object.
void purge_addon(const config &removelist)
Removes the listed files from the addon.
Definition: manager.cpp:377
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:107
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.
std::map< std::string, std::string > installed_addons_and_versions()
Retrieves the ids and versions of all installed add-ons.
Definition: manager.cpp:197
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:66
std::vector< std::string > available_addons()
Returns a list of local add-ons that can be published.
Definition: manager.cpp:187
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:192
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:102
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on's version information structs.
Definition: manager.cpp:387
version_info get_addon_version_info(const std::string &addon)
Returns a particular installed add-on's version information.
Definition: manager.cpp:428
bool is_addon_installed(const std::string &addon_name)
Check whether the specified add-on is currently installed.
Definition: manager.cpp:220
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:296
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Represents version numbers.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
Exception thrown when the WML parser fails to read a .pbl file.
Definition: manager.hpp:45
const std::string path
Path to the faulty .pbl file.
Definition: manager.hpp:57
virtual ~invalid_pbl_exception() noexcept
Destructor.
Definition: manager.hpp:65
virtual const char * what() const noexcept
Returns a pointer to the (constant) error description.
Definition: manager.hpp:72
invalid_pbl_exception(const std::string &pbl_path, const std::string &msg)
Constructor.
Definition: manager.hpp:52
const std::string message
Error message to display.
Definition: manager.hpp:60