store addon versions in version_info

The recent campaignd rework allowed addons to provide multiple versions. The local version_info will now store all avaible version names in descending order and also keep the current version which will be able to be selected from a menu or may be used to store info for local purposes.

The versions set is guaranteed to have at least one entry, which is current_version.
This commit is contained in:
kabachuha 2020-11-08 23:08:25 +03:00
parent 0cf5c8d7f0
commit 4e66d0a7f1
4 changed files with 25 additions and 13 deletions

View file

@ -79,13 +79,18 @@ void addon_info::read(const config& cfg)
title = cfg["title"].str();
description = cfg["description"].str();
icon = cfg["icon"].str();
version = cfg["version"].str();
current_version = cfg["version"].str();
versions.emplace(cfg["version"].str());
author = cfg["author"].str();
size = cfg["size"];
downloads = cfg["downloads"];
uploads = cfg["uploads"];
type = get_addon_type(cfg["type"].str());
for(const config& version : cfg.child_range("version")) {
versions.emplace(version["version"].str());
}
const config::const_child_itors& locales_as_configs = cfg.child_range("translation");
for(const config& locale : locales_as_configs) {
@ -111,13 +116,18 @@ void addon_info::write(config& cfg) const
cfg["title"] = title;
cfg["description"] = description;
cfg["icon"] = icon;
cfg["version"] = version.str();
cfg["version"] = current_version.str();
cfg["author"] = author;
cfg["size"] = size;
cfg["downloads"] = downloads;
cfg["uploads"] = uploads;
cfg["type"] = get_addon_type_string(type);
for(const version_info& version : versions) {
config& version_cfg = cfg.add_child("version");
version_cfg["version"] = version.str();
}
for(const auto& element : info_translations) {
config& locale = cfg.add_child("translation");
locale["language"] = element.first;
@ -135,7 +145,7 @@ void addon_info::write(config& cfg) const
void addon_info::write_minimal(config& cfg) const
{
cfg["version"] = version.str();
cfg["version"] = current_version.str();
cfg["uploads"] = uploads;
cfg["type"] = get_addon_type_string(type);
cfg["title"] = title;

View file

@ -86,7 +86,8 @@ struct addon_info
std::string icon;
version_info version;
version_info current_version;
std::set<version_info, std::greater<version_info>> versions;
std::string author;
@ -117,8 +118,8 @@ struct addon_info
addon_info()
: id(), title(), description(), icon()
, version(), author(), size(), downloads()
, uploads(), type(), tags(), locales()
, current_version(), versions(), author(), size()
, downloads(), uploads(), type(), tags(), locales()
, core()
, depends()
, feedback_url()
@ -130,8 +131,8 @@ struct addon_info
explicit addon_info(const config& cfg)
: id(), title(), description(), icon()
, version(), author(), size(), downloads()
, uploads(), type(), tags(), locales()
, current_version(), versions(), author(), size()
, downloads(), uploads(), type(), tags(), locales()
, core()
, depends()
, feedback_url()
@ -151,7 +152,8 @@ struct addon_info
this->title = o.title;
this->description = o.description;
this->icon = o.icon;
this->version = o.version;
this->current_version = o.current_version;
this->versions = o.versions;
this->author = o.author;
this->size = o.size;
this->downloads = o.downloads;

View file

@ -33,10 +33,10 @@ addon_tracking_info get_addon_tracking_info(const addon_info& addon)
if(is_addon_installed(id)) {
if(t.can_publish) {
if(addon.local_only) {
t.installed_version = addon.version;
t.installed_version = addon.current_version;
//t.remote_version = version_info();
} else {
t.remote_version = addon.version;
t.remote_version = *addon.versions.begin();
// Try to obtain the version number from the .pbl first.
config pbl = get_addon_pbl_info(id);
@ -50,7 +50,7 @@ addon_tracking_info get_addon_tracking_info(const addon_info& addon)
} else {
// We normally use the _info.cfg version instead.
t.installed_version = get_addon_version_info(id);
t.remote_version = addon.version;
t.remote_version = *addon.versions.begin();
}
if(t.remote_version == t.installed_version) {

View file

@ -203,7 +203,7 @@ void addon_list::set_addons(const addons_list& addons)
ss << tracking_info.installed_version.str() << "\n";
}
ss << addon.version.str();
ss << (*addon.versions.begin()).str();
if(special_version_display) {
ss.str(colorize_addon_state_string(ss.str(), tracking_info.state, false));