Merge pull request #462 from Vultraz/addon_version_validation

Addon version validation
This commit is contained in:
Charles Dang 2015-08-19 12:08:34 +11:00
commit c3c0c9c2fd
4 changed files with 23 additions and 6 deletions

View file

@ -1,4 +1,7 @@
Version 1.13.1+dev:
* Add-ons client:
* Warn user if attempting to upload an addon with a version lesser than or
equal to a published version.
* Campaigns:
* Delfador's Memoirs:
* Added defeat condition for death of the last undead veteran in

View file

@ -145,7 +145,7 @@ struct addon_op_result
bool wml_changed;
};
/** Warns the user about unresolved dependencies and installs them if they choose to do so.
/** Warns the user about unresolved dependencies and installs them if they choose to do so.
* Returns: outcome: ABORT in case the user chose to abort because of an issue
* SUCCESS otherwise
* wml_change: indicates if new wml content was installed
@ -379,13 +379,25 @@ void do_remote_addon_delete(CVideo& video, addons_client& client, const std::str
}
/** Performs all backend and UI actions for publishing the specified add-on. */
void do_remote_addon_publish(CVideo& video, addons_client& client, const std::string& addon_id)
void do_remote_addon_publish(CVideo& video, addons_client& client, const std::string& addon_id, const version_info& remote_version)
{
std::string server_msg;
config cfg;
get_addon_pbl_info(addon_id, cfg);
const version_info& version_to_publish = cfg["version"].str();
if(version_to_publish <= remote_version) {
const int res = gui2::show_message(video, _("Warning"),
_("The remote version of this add-on is greater or equal to the version being uploaded. Do you really wish to continue?"),
gui2::tmessage::yes_no_buttons);
if(res != gui2::twindow::OK) {
return;
}
}
if(!image::exists(cfg["icon"].str())) {
gui2::show_error_message(video, _("Invalid icon path. Please make sure the path points to a valid image."));
} else if(!client.request_distribution_terms(server_msg)) {
@ -908,7 +920,7 @@ void show_addons_manager_dialog(display& disp, addons_client& client, addons_lis
} else if(result >= int(option_ids.size())) {
// Handle remote publishing.
const std::string& id = can_publish_ids[result - int(option_ids.size())];
do_remote_addon_publish(disp.video(), client, id);
do_remote_addon_publish(disp.video(), client, id, tracking[id].remote_version);
return;
}
}

View file

@ -45,11 +45,11 @@ addon_tracking_info get_addon_tracking_info(const addon_info& addon)
t.installed_version = get_addon_version_info(id);
}
const version_info& remote_version = addon.version;
t.remote_version = addon.version;
if(remote_version == t.installed_version) {
if(t.remote_version == t.installed_version) {
t.state = ADDON_INSTALLED;
} else if(remote_version > t.installed_version) {
} else if(t.remote_version > t.installed_version) {
t.state = ADDON_INSTALLED_UPGRADABLE;
} else /* if(remote_version < t.installed_version) */ {
t.state = ADDON_INSTALLED_OUTDATED;

View file

@ -47,6 +47,7 @@ struct addon_tracking_info
, can_publish(false)
, in_version_control(false)
, installed_version()
, remote_version()
{
}
@ -54,6 +55,7 @@ struct addon_tracking_info
bool can_publish;
bool in_version_control;
version_info installed_version;
version_info remote_version;
};
typedef std::map<std::string, addon_tracking_info> addons_tracking_list;