18 #include "addon/manager.hpp"
42 #define ERR_ADDONS LOG_STREAM(err , log_addons_client)
43 #define WRN_ADDONS LOG_STREAM(warn, log_addons_client)
44 #define LOG_ADDONS LOG_STREAM(info, log_addons_client)
45 #define DBG_ADDONS LOG_STREAM(debug, log_addons_client)
58 , server_capabilities_()
64 }
catch(
const std::runtime_error&) {
74 i18n_symbols[
"server_address"] =
addr_;
78 const auto&
msg =
VGETTEXT(
"Connecting to $server_address|...", i18n_symbols);
111 LOG_ADDONS <<
"Server " << id_desc <<
" version " << version_desc
149 terms = msg_cfg[
"message"].str();
159 response_message.clear();
163 if(i18n_symbols[
"addon_title"].empty()) {
170 VGETTEXT(
"The add-on <i>$addon_title</i> has an invalid id '$addon_id' "
171 "and cannot be published.", i18n_symbols);
182 VGETTEXT(
"The add-on <i>$addon_title</i> has a file or directory "
183 "containing invalid characters and cannot be published.", i18n_symbols);
187 std::vector<std::string> badnames;
190 VGETTEXT(
"The add-on <i>$addon_title</i> has an invalid file or directory "
191 "name and cannot be published. "
193 "File or directory names may not contain '..' or end with '.' or be longer than 255 characters. "
194 "It also may not contain whitespace, control characters, or any of the following characters:\n\n" * / : < > ? \\ | ~"
201 VGETTEXT(
"The add-on <i>$addon_title</i> contains files or directories with case conflicts. "
202 "File or directory names may not be differently-cased versions of the same string.", i18n_symbols);
208 last_error_ =
VGETTEXT(
"The connection to the remote server is not secure. The add-on <i>$addon_title</i> cannot be uploaded.", i18n_symbols);
214 config hashlist, hash_request;
215 config& request_body = hash_request.
add_child(
"request_campaign_hash");
218 request_body[
"name"] = cfg[
"name"];
226 LOG_ADDONS <<
"making an update pack for the add-on " <<
id;
232 config request_buf, response_buf;
241 response_message = message_cfg[
"message"].str();
242 LOG_ADDONS <<
"server response: " << response_message;
252 config request_buf, response_buf;
262 response_message = message_cfg[
"message"].str();
263 LOG_ADDONS <<
"server response: " << response_message;
272 response_message.clear();
279 if(i18n_symbols[
"addon_title"].empty()) {
283 config request_buf, response_buf;
287 if(cfg[
"passphrase"].empty()) {
289 if(!gui2::dialogs::addon_auth::execute(cfg)) {
292 error[
"message"] =
"Password not provided.";
299 request_body[
"name"] =
id;
300 request_body[
"passphrase"] = cfg[
"passphrase"];
302 request_body[
"uploader"] = cfg[
"uploader"];
310 response_message = message_cfg[
"message"].str();
311 LOG_ADDONS <<
"server response: " << response_message;
324 request_body[
"name"] =
id;
325 request_body[
"increase_downloads"] = increase_downloads;
326 request_body[
"version"] = version.
str();
348 auto progress_cb = [&progress_dlg](
unsigned value) {
349 progress_dlg->update_progress(value);
353 LOG_ADDONS <<
"Received an updatepack for the addon '" <<
info.id <<
"'";
357 if(key ==
"removelist" || key ==
"addlist") {
360 "name and cannot be installed.", i18n_symbols));
365 "with case conflicts. This may cause problems.", i18n_symbols));
371 if(key ==
"removelist") {
373 }
else if(key ==
"addlist") {
382 LOG_ADDONS <<
"Received a full pack for the addon '" <<
info.id <<
"'";
386 "name and cannot be installed.", i18n_symbols));
391 "with case conflicts. This may cause problems.", i18n_symbols));
398 WRN_ADDONS <<
"failed to uninstall previous version of " <<
info.id <<
"; the add-on may not work properly!";
406 info.write_minimal(info_cfg);
421 if(!server_error.empty()) {
423 _(
"The server responded with an error:") +
"\n" + server_error);
437 auto cursor_setter = std::make_unique<cursor::setter>(
cursor::WAIT);
444 std::vector<std::string> missing_deps;
445 std::vector<std::string> broken_deps;
452 for(
const std::string& dep : deps) {
458 missing_deps.push_back(dep);
462 missing_deps.push_back(dep);
464 }
catch(
const std::out_of_range&) {
467 broken_deps.push_back(dep);
472 cursor_setter.reset();
474 if(!broken_deps.empty()) {
475 std::string broken_deps_report;
477 broken_deps_report =
_n(
478 "The selected add-on has the following dependency, which is not currently installed or available from the server. Do you wish to continue?",
479 "The selected add-on has the following dependencies, which are not currently installed or available from the server. Do you wish to continue?",
481 broken_deps_report +=
"\n";
483 for(
const std::string& broken_dep_id : broken_deps) {
493 if(missing_deps.empty()) {
500 for(
const std::string& dep : missing_deps) {
501 options[dep] = addons.at(dep);
504 if(!gui2::dialogs::install_dependencies::execute(options)) {
513 std::vector<std::string> failed_titles;
515 for(
const std::string& dep : missing_deps) {
516 const addon_info& missing_addon = addons.at(dep);
519 failed_titles.push_back(missing_addon.
title);
525 if(!failed_titles.empty()) {
526 const std::string& failed_deps_report =
_n(
527 "The following dependency could not be installed. Do you still wish to continue?",
528 "The following dependencies could not be installed. Do you still wish to continue?",
540 const std::string& addon_id = addon.
id;
552 std::vector<std::string> extra_items;
554 text =
VGETTEXT(
"The add-on '$addon|' is already installed and contains additional information that will be permanently lost if you continue:", symbols);
558 extra_items.push_back(
_(
"Publishing information file (.pbl)"));
562 extra_items.push_back(
_(
"Version control system (VCS) information"));
566 text +=
_(
"Do you really wish to continue?");
600 if(error->has_attribute(
"status_code")) {
633 assert(
conn_ !=
nullptr);
634 if(
conn_ ==
nullptr) {
645 conn_->transfer(request, response);
693 std::unique_ptr<network_transmission::connection_data> cd;
705 throw std::invalid_argument(
"Addon client: invalid transfer mode");
bool remove_local_addon(const std::string &addon)
Removes the specified add-on, deleting its full directory structure.
config get_addon_pbl_info(const std::string &addon_name, bool do_validate)
Gets the publish information for an add-on.
void unarchive_addon(const config &cfg, std::function< void(unsigned)> progress_callback)
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.
void purge_addon(const config &removelist)
Removes the listed files from the addon.
void archive_addon(const std::string &addon_name, config &cfg)
Archives an add-on into a config object for campaignd transactions.
void write_addon_install_info(const std::string &addon_name, const config &cfg)
bool have_addon_pbl_info(const std::string &addon_name)
Returns whether a .pbl file is present for the specified add-on or not.
version_info get_addon_version_info(const std::string &addon)
Returns a particular installed add-on's version information.
bool is_addon_installed(const std::string &addon_name)
Check whether the specified add-on is currently installed.
Add-ons (campaignd) client class.
bool update_last_error(config &response_cfg)
void disconnect()
Disconnects from the add-on server.
install_result install_addon_with_checks(const addons_list &addons, const addon_info &addon)
Performs an add-on download and install cycle.
bool delete_remote_addon(const std::string &id, std::string &response_message)
Requests the specified add-on to be removed from the server.
bool do_check_before_overwriting_addon(const addon_info &addon)
Checks whether the given add-on has local .pbl or VCS information and asks before overwriting it.
void wait_for_transfer_done(const std::string &status_message, transfer_mode mode=transfer_mode::download)
Waits for a network transfer, displaying a status window.
std::unique_ptr< network_asio::connection > conn_
@ success
The add-on was correctly installed.
@ failure
The add-on could not be downloaded from the server.
@ abort
User aborted the operation because of an issue with dependencies or chose not to overwrite the add-on...
bool download_addon(config &archive_cfg, const std::string &id, const std::string &title, const version_info &version, bool increase_downloads=true)
Downloads the specified add-on from the server.
void send_request(const config &request, config &response)
Sends a request to the add-ons server.
bool request_addons_list(config &cfg)
Request the add-ons list from the server.
bool try_fetch_addon(const addon_info &addon)
void check_connected() const
Makes sure the add-ons server connection is working.
std::set< std::string > server_capabilities_
bool install_addon(config &archive_cfg, const addon_info &info)
Installs the specified add-on using an archive received from the server.
std::string license_notice_
addons_client(const addons_client &)=delete
std::string last_error_data_
std::string server_version_
void connect()
Tries to establish a connection to the add-ons server.
void send_simple_request(const std::string &request_string, config &response)
Sends a simple request message to the add-ons server.
bool request_distribution_terms(std::string &terms)
Request the add-ons server distribution terms message.
install_result do_resolve_addon_dependencies(const addons_list &addons, const addon_info &addon)
Warns the user about unresolved dependencies and installs them if they choose to do so.
const std::string & get_last_server_error() const
Returns the last error message sent by the server, or an empty string.
bool upload_addon(const std::string &id, std::string &response_message, config &cfg, bool local_only)
Uploads an add-on to the server.
A config object defines a single node in a WML file, with access to child nodes.
void append(const config &cfg)
Append data from another config object to this one.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
auto all_children_view() const
In-order iteration over all children.
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
static auto display(T &&... args)
@ yes_no_buttons
Shows a yes and no button.
bool show(const unsigned auto_close_time=0)
Shows the window.
Dialog that tracks network transmissions.
A class that represents a TCP/IP connection.
std::size_t bytes_to_write() const
std::size_t bytes_read() const
std::size_t poll()
Handle all pending asynchronous events and return.
std::size_t bytes_to_read() const
std::size_t bytes_written() const
bool done() const
True if connected and no high-level operation is in progress.
void set_password(const std::string &server, const std::string &login, const std::string &key)
std::string password(const std::string &server, const std::string &login)
Thrown by operations encountering invalid UTF-8 data.
Represents version numbers.
std::string str() const
Serializes the version number into string form.
static lg::log_domain log_addons_client("addons-client")
Networked add-ons (campaignd) client interface.
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
static std::string _n(const char *str1, const char *str2, int n)
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
std::string make_addon_title(const std::string &id)
Replaces underscores to dress up file or dirnames as add-on titles.
std::map< std::string, addon_info > addons_list
Standard logging facilities (interface).
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
const std::string unicode_bullet
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
@ OK
Dialog was closed with the OK button.
std::string bullet_list(const T &v, std::size_t indent=4, const std::string &bullet=font::unicode_bullet)
Generates a new string containing a bullet list.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::pair< std::string, std::string > parse_network_address(const std::string &address, const std::string &default_port)
Parse a host:port style network address, supporting [] notation for ipv6 addresses.
addon_tracking_info get_addon_tracking_info(const addon_info &addon)
Get information about an add-on comparing its local state with the add-ons server entry.
@ ADDON_NONE
Add-on is not installed.
@ ADDON_INSTALLED_UPGRADABLE
Version in the server is newer than local installation.
version_info current_version
std::string display_title_full() const
std::set< std::string > resolve_dependencies(const addons_list &addons) const
Resolve an add-on's dependency tree in a recursive fashion.
Stores additional status information about add-ons.
Contains the outcome of an add-on install operation.
install_outcome outcome
Overall outcome of the operation.
bool wml_changed
Specifies if WML on disk was altered and needs to be reloaded.
connect_connection_data(network_asio::connection &conn, addons_client &client)
std::size_t total() override
network_asio::connection & conn_
std::size_t current() override
network_asio::connection & conn_
virtual void poll() override
virtual void cancel() override
virtual std::size_t current() override
virtual bool finished() override
read_addon_connection_data(network_asio::connection &conn, addons_client &client)
std::size_t total() override
virtual void poll() override
virtual bool finished() override
std::size_t total() override
write_addon_connection_data(network_asio::connection &conn, addons_client &client)
virtual void cancel() override
virtual std::size_t current() override
network_asio::connection & conn_
bool addon_name_legal(const std::string &name)
Checks whether an add-on id/name is legal or not.
void make_updatepack(config &pack, const config &from, const config &to)
&from, &to are the top directories of their structures; addlist/removelist tag is treated as [dir]
bool check_names_legal(const config &dir, std::vector< std::string > *badlist)
Scans an add-on archive for illegal names.
bool contains_hashlist(const config &from, const config &to)
const unsigned short default_campaignd_port
Default port number for the addon server.
std::string translated_addon_check_status(unsigned int code)
bool check_case_insensitive_duplicates(const config &dir, std::vector< std::string > *badlist)
Scans an add-on archive for case-conflicts.