-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
state.cpp
72 lines (59 loc) · 2.05 KB
/
state.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Copyright (C) 2012 - 2018 by Iris Morelle <shadowm2006@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "addon/state.hpp"
#include "config.hpp"
#include "addon/manager.hpp"
#include "log.hpp"
static lg::log_domain log_addons_client("addons-client");
#define LOG_AC LOG_STREAM(info, log_addons_client)
addon_tracking_info get_addon_tracking_info(const addon_info& addon)
{
const std::string& id = addon.id;
addon_tracking_info t;
t.can_publish = have_addon_pbl_info(id);
t.in_version_control = have_addon_in_vcs_tree(id);
//t.installed_version = version_info();
if(is_addon_installed(id)) {
if(t.can_publish) {
if(addon.local_only) {
t.installed_version = addon.version;
//t.remote_version = version_info();
} else {
t.remote_version = addon.version;
// Try to obtain the version number from the .pbl first.
config pbl = get_addon_pbl_info(id);
if(pbl.has_attribute("version")) {
t.installed_version = pbl["version"].str();
} else {
t.installed_version = get_addon_version_info(id);
}
}
} else {
// We normally use the _info.cfg version instead.
t.installed_version = get_addon_version_info(id);
t.remote_version = addon.version;
}
if(t.remote_version == t.installed_version) {
t.state = ADDON_INSTALLED;
} else if(t.remote_version > t.installed_version) {
t.state = ADDON_INSTALLED_UPGRADABLE;
} else if(t.remote_version == version_info()) {
// Remote version not set.
t.state = ADDON_INSTALLED_LOCAL_ONLY;
} else /* if(remote_version < t.installed_version) */ {
t.state = ADDON_INSTALLED_OUTDATED;
}
} else {
t.state = ADDON_NONE;
}
return t;
}