bool addons_client::delete_remote_addon(const std::string& id, std::string& response_message) { response_message.clear(); config cfg; get_addon_pbl_info(id, cfg); utils::string_map i18n_symbols; i18n_symbols["addon_title"] = cfg["title"]; if(i18n_symbols["addon_title"].empty()) { i18n_symbols["addon_title"] = make_addon_title(id); } config request_buf, response_buf; config& request_body = request_buf.add_child("delete"); request_body["name"] = id; request_body["passphrase"] = cfg["passphrase"]; LOG_ADDONS << "requesting server to delete " << id << '\n'; this->send_request(request_buf, response_buf); this->wait_for_transfer_done(vgettext("Removing add-on <i>$addon_title</i> from the server...", i18n_symbols )); if(const config& message_cfg = response_buf.child("message")) { response_message = message_cfg["message"].str(); LOG_ADDONS << "server response: " << response_message << '\n'; } return !this->update_last_error(response_buf); }
bool addons_client::upload_addon(const std::string& id, std::string& response_message) { LOG_ADDONS << "preparing to upload " << id << '\n'; response_message.clear(); config cfg; get_addon_pbl_info(id, cfg); utils::string_map i18n_symbols; i18n_symbols["addon_title"] = cfg["title"]; if(i18n_symbols["addon_title"].empty()) { i18n_symbols["addon_title"] = make_addon_title(id); } std::string passphrase = cfg["passphrase"]; // generate a random passphrase and write it to disk // if the .pbl file doesn't provide one already if(passphrase.empty()) { passphrase.resize(8); for(size_t n = 0; n != 8; ++n) { passphrase[n] = 'a' + (rand()%26); } cfg["passphrase"] = passphrase; set_addon_pbl_info(id, cfg); LOG_ADDONS << "automatically generated an initial passphrase for " << id << '\n'; } cfg["name"] = id; config addon_data; archive_addon(id, addon_data); config request_buf, response_buf; request_buf.add_child("upload", cfg).add_child("data", addon_data); LOG_ADDONS << "sending " << id << '\n'; this->send_request(request_buf, response_buf); this->wait_for_transfer_done(vgettext("Sending add-on <i>$addon_title</i>...", i18n_symbols )); if(const config& message_cfg = response_buf.child("message")) { response_message = message_cfg["message"].str(); LOG_ADDONS << "server response: " << response_message << '\n'; } return !this->update_last_error(response_buf); }
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(0, 0, 0, false); if(is_addon_installed(id)) { if(t.can_publish) { // Try to obtain the version number from the .pbl first. config pbl; get_addon_pbl_info(id, pbl); if(pbl.has_attribute("version")) { t.installed_version = pbl["version"].str(); } } else { // We normally use the _info.cfg version instead. t.installed_version = get_addon_version_info(id); } const version_info& remote_version = addon.version; if(remote_version == t.installed_version) { t.state = ADDON_INSTALLED; } else if(remote_version > t.installed_version) { t.state = ADDON_INSTALLED_UPGRADABLE; } else /* if(remote_version < t.installed_version) */ { t.state = ADDON_INSTALLED_OUTDATED; } } else { t.state = ADDON_NONE; } return t; }