The Battle for Wesnoth  1.15.1+dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
3  2008 - 2015 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 #pragma once
17 
18 class config;
19 class version_info;
20 
21 #include "addon/validation.hpp"
22 
23 #include <string>
24 #include <vector>
25 #include <utility>
26 
27 /**
28  * Exception thrown when the WML parser fails to read a .pbl file.
29  */
30 struct invalid_pbl_exception : public std::exception
31 {
32  /**
33  * Constructor.
34  *
35  * @param pbl_path Path to the faulty .pbl file.
36  * @param msg An error message to display.
37  */
38  invalid_pbl_exception(const std::string& pbl_path, const std::string& msg)
39  : path(pbl_path), message(msg)
40  {}
41 
42  /** Path to the faulty .pbl file. */
43  const std::string path;
44 
45  /** Error message to display. */
46  const std::string message;
47 
48  /** Destructor.
49  * Virtual to allow for subclassing.
50  */
51  virtual ~invalid_pbl_exception() noexcept {}
52 
53  /** Returns a pointer to the (constant) error description.
54  * @return A pointer to a const char*. The underlying memory
55  * is in posession of the Exception object. Callers must
56  * not attempt to free the memory.
57  */
58  virtual const char* what() const noexcept {
59  return message.c_str();
60  }
61 };
62 
63 bool remove_local_addon(const std::string& addon);
64 
65 /**
66  * Returns true if there's a local .pbl file stored for the specified add-on.
67  */
68 bool have_addon_pbl_info(const std::string& addon_name);
69 
70 /**
71  * Returns true if the specified add-ons appear to be managed by a 'supported' VCS.
72  *
73  * Currently supported VCSes are: Subversion, Git, Mercurial.
74  */
75 bool have_addon_in_vcs_tree(const std::string& addon_name);
76 
77 /**
78  * Gets the publish information for an add-on.
79  *
80  * @param addon_name The add-on's main directory/file name.
81  *
82  * @exception invalid_pbl_exception If it is not possible to read the .pbl file
83  * (often due to invalid WML).
84  */
85 config get_addon_pbl_info(const std::string& addon_name);
86 
87 /**
88  * Sets the publish information for an add-on
89  *
90  * @param addon_name The add-on's main directory/file name.
91  * @param cfg A config object from which the add-on's
92  * properties are copied.
93  */
94 void set_addon_pbl_info(const std::string& addon_name, const class config& cfg);
95 
96 /**
97  * Returns true if there is a local installation info (_info.cfg) file for the add-on.
98  */
99 bool have_addon_install_info(const std::string& addon_name);
100 
101 /**
102  * Gets the installation info (_info.cfg) for an add-on.
103  *
104  * @param addon_name The add-on's main directory/file name.
105  * @param cfg A config object to store the add-on's
106  * properties.
107  */
108 void get_addon_install_info(const std::string& addon_name, class config& cfg);
109 
110 /** Returns a list of local add-ons that can be published. */
111 std::vector<std::string> available_addons();
112 
113 /** Retrieves the names of all installed add-ons. */
114 std::vector<std::string> installed_addons();
115 
116 /** Check whether the specified add-on is currently installed. */
117 bool is_addon_installed(const std::string& addon_name);
118 
119 /** Archives an add-on into a config object for campaignd transactions. */
120 void archive_addon(const std::string& addon_name, class config& cfg);
121 
122 /** Unarchives an add-on from campaignd's retrieved config object. */
123 void unarchive_addon(const class config& cfg);
124 
125 /** Refreshes the per-session cache of add-on's version information structs. */
127 
128 /** Returns a particular installed add-on's version information. */
129 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:131
invalid_pbl_exception(const std::string &pbl_path, const std::string &msg)
Constructor.
Definition: manager.hpp:38
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on&#39;s version information structs.
Definition: manager.cpp:283
const std::string path
Path to the faulty .pbl file.
Definition: manager.hpp:43
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 true if the specified add-ons appear to be managed by a &#39;supported&#39; VCS.
Definition: manager.cpp:65
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:99
Exception thrown when the WML parser fails to read a .pbl file.
Definition: manager.hpp:30
bool have_addon_pbl_info(const std::string &addon_name)
Returns true if there&#39;s a local .pbl file stored for the specified add-on.
Definition: manager.cpp:74
bool remove_local_addon(const std::string &addon)
Definition: manager.cpp:117
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:241
const std::string message
Error message to display.
Definition: manager.hpp:46
bool is_addon_installed(const std::string &addon_name)
Check whether the specified add-on is currently installed.
Definition: manager.cpp:163
void unarchive_addon(const class config &cfg)
Unarchives an add-on from campaignd&#39;s retrieved config object.
virtual ~invalid_pbl_exception() noexcept
Destructor.
Definition: manager.hpp:51
version_info get_addon_version_info(const std::string &addon)
Returns a particular installed add-on&#39;s version information.
Definition: manager.cpp:325
virtual const char * what() const noexcept
Returns a pointer to the (constant) error description.
Definition: manager.hpp:58
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:104
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:147
config get_addon_pbl_info(const std::string &addon_name)
Gets the publish information for an add-on.
Definition: manager.cpp:79