The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
state.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2017 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "addon/state.hpp"
16 #include "config.hpp"
17 
18 #include "addon/manager.hpp"
19 #include "log.hpp"
20 
21 static lg::log_domain log_addons_client("addons-client");
22 #define LOG_AC LOG_STREAM(info, log_addons_client)
23 
25 {
26  const std::string& id = addon.id;
28 
31  //t.installed_version = version_info();
32 
33  if(is_addon_installed(id)) {
34  if(t.can_publish) {
35  if(addon.local_only) {
36  t.installed_version = addon.version;
37  //t.remote_version = version_info();
38  } else {
39  t.remote_version = addon.version;
40 
41  // Try to obtain the version number from the .pbl first.
42  config pbl = get_addon_pbl_info(id);
43 
44  if(pbl.has_attribute("version")) {
45  t.installed_version = pbl["version"].str();
46  } else {
48  }
49  }
50  } else {
51  // We normally use the _info.cfg version instead.
53  t.remote_version = addon.version;
54  }
55 
58  } else if(t.remote_version > t.installed_version) {
60  } else if(t.remote_version == version_info()) {
61  // Remote version not set.
63  } else /* if(remote_version < t.installed_version) */ {
65  }
66  } else {
67  t.state = ADDON_NONE;
68  }
69 
70  return t;
71 }
72 
ADDON_STATUS state
Definition: state.hpp:56
std::vector< char_t > string
bool is_addon_installed(const std::string &addon_name)
Check whether the specified add-on is currently installed.
Definition: manager.cpp:164
bool have_addon_in_vcs_tree(const std::string &addon_name)
Returns true if the specified add-ons appear to be managed by a 'supported' VCS.
Definition: manager.cpp:66
Definitions for the interface to Wesnoth Markup Language (WML).
version_info installed_version
Definition: state.hpp:59
version_info get_addon_version_info(const std::string &addon)
Returns a particular installed add-on's version information.
Definition: manager.cpp:383
Add-on is not installed.
Definition: state.hpp:23
Version in the server is older than local installation.
Definition: state.hpp:29
std::string id
Definition: info.hpp:31
Version in the server is newer than local installation.
Definition: state.hpp:27
bool in_version_control
Definition: state.hpp:58
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:80
bool has_attribute(config_key_type key) const
Definition: config.cpp:196
bool local_only
Definition: info.hpp:66
bool have_addon_pbl_info(const std::string &addon_name)
Returns true if there's a local .pbl file stored for the specified add-on.
Definition: manager.cpp:75
No version in the server.
Definition: state.hpp:31
Represents version numbers.
Definition: version.hpp:43
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:24
double t
Definition: astarsearch.cpp:64
Standard logging facilities (interface).
version_info version
Definition: info.hpp:37
Stores additional status information about add-ons.
Definition: state.hpp:45
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
version_info remote_version
Definition: state.hpp:60
Version in the server matches local installation.
Definition: state.hpp:25