The Battle for Wesnoth  1.19.5+dev
state.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2024
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 
30  t.can_publish = have_addon_pbl_info(id);
31  t.in_version_control = have_addon_in_vcs_tree(id);
32 
33  if(is_addon_installed(id)) {
34  if(t.can_publish) {
35  if(addon.local_only) {
36  t.installed_version = addon.current_version;
37  } else {
38  if(addon.versions.size() > 0) {
39  t.remote_version = *addon.versions.begin();
40  }
41 
42  // Try to obtain the version number from the .pbl first.
43  // Just grabbing the version, no need to validate.
44  config pbl = get_addon_pbl_info(id, false);
45 
46  if(pbl.has_attribute("version")) {
47  t.installed_version = pbl["version"].str();
48  } else {
49  t.installed_version = get_addon_version_info(id);
50  }
51  }
52  } else {
53  // We normally use the _info.cfg version instead.
54  t.installed_version = get_addon_version_info(id);
55  if(addon.versions.size() > 0) {
56  t.remote_version = *addon.versions.begin();
57  }
58  }
59 
60  if(addon.local_only) {
62  } else if(t.remote_version == t.installed_version) {
63  t.state = ADDON_INSTALLED;
64  } else if(t.remote_version > t.installed_version) {
66  } else {
68  }
69  } else {
70  t.state = ADDON_NONE;
71  }
72 
73  return t;
74 }
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
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
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
double t
Definition: astarsearch.cpp:63
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
bool has_attribute(config_key_type key) const
Definition: config.cpp:157
Definitions for the interface to Wesnoth Markup Language (WML).
Standard logging facilities (interface).
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
static lg::log_domain log_addons_client("addons-client")
@ ADDON_INSTALLED_OUTDATED
Version in the server is older than local installation.
Definition: state.hpp:30
@ ADDON_NONE
Add-on is not installed.
Definition: state.hpp:24
@ ADDON_INSTALLED_UPGRADABLE
Version in the server is newer than local installation.
Definition: state.hpp:28
@ ADDON_INSTALLED
Version in the server matches local installation.
Definition: state.hpp:26
@ ADDON_INSTALLED_LOCAL_ONLY
No version in the server.
Definition: state.hpp:32
version_info current_version
Definition: info.hpp:81
bool local_only
Definition: info.hpp:107
std::set< version_info, std::greater< version_info > > versions
Definition: info.hpp:82
std::string id
Definition: info.hpp:75
Stores additional status information about add-ons.
Definition: state.hpp:47