The Battle for Wesnoth  1.17.0-dev
state.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2021
3  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 #include "addon/state.hpp"
17 #include "config.hpp"
18 
19 #include "addon/manager.hpp"
20 #include "log.hpp"
21 
22 static lg::log_domain log_addons_client("addons-client");
23 #define LOG_AC LOG_STREAM(info, log_addons_client)
24 
26 {
27  const std::string& id = addon.id;
29 
32  //t.installed_version = version_info();
33 
34  if(is_addon_installed(id)) {
35  if(t.can_publish) {
36  if(addon.local_only) {
38  //t.remote_version = version_info();
39  } else {
40  t.remote_version = *addon.versions.begin();
41 
42  // Try to obtain the version number from the .pbl first.
43  config pbl = get_addon_pbl_info(id);
44 
45  if(pbl.has_attribute("version")) {
46  t.installed_version = pbl["version"].str();
47  } else {
49  }
50  }
51  } else {
52  // We normally use the _info.cfg version instead.
54  t.remote_version = *addon.versions.begin();
55  }
56 
59  } else if(t.remote_version > t.installed_version) {
61  } else if(t.remote_version == version_info()) {
62  // Remote version not set.
64  } else /* if(remote_version < t.installed_version) */ {
66  }
67  } else {
68  t.state = ADDON_NONE;
69  }
70 
71  return t;
72 }
ADDON_STATUS state
Definition: state.hpp:57
bool has_attribute(config_key_type key) const
Definition: config.cpp:211
bool is_addon_installed(const std::string &addon_name)
Check whether the specified add-on is currently installed.
Definition: manager.cpp:205
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
Definitions for the interface to Wesnoth Markup Language (WML).
version_info installed_version
Definition: state.hpp:60
version_info get_addon_version_info(const std::string &addon)
Returns a particular installed add-on&#39;s version information.
Definition: manager.cpp:397
Add-on is not installed.
Definition: state.hpp:24
Version in the server is older than local installation.
Definition: state.hpp:30
std::string id
Definition: info.hpp:76
Version in the server is newer than local installation.
Definition: state.hpp:28
bool in_version_control
Definition: state.hpp:59
static lg::log_domain log_addons_client("addons-client")
config get_addon_pbl_info(const std::string &addon_name)
Gets the publish information for an add-on.
Definition: manager.cpp:68
bool local_only
Definition: info.hpp:108
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
No version in the server.
Definition: state.hpp:32
std::set< version_info, std::greater< version_info > > versions
Definition: info.hpp:83
Represents version numbers.
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...
Definition: state.cpp:25
double t
Definition: astarsearch.cpp:65
Standard logging facilities (interface).
Stores additional status information about add-ons.
Definition: state.hpp:46
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
version_info current_version
Definition: info.hpp:82
version_info remote_version
Definition: state.hpp:61
Version in the server matches local installation.
Definition: state.hpp:26