mail[Wesnoth-commits] r28620 - /trunk/src/addon_management.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by shadowm2006 on August 16, 2008 - 01:15:
Author: shadowmaster
Date: Sat Aug 16 00:40:27 2008
New Revision: 28620

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28620&view=rev
Log:
* More progress in the add-ons updater logic.


Modified:
    trunk/src/addon_management.cpp

Modified: trunk/src/addon_management.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_management.cpp?rev=28620&r1=28619&r2=28620&view=diff
==============================================================================
--- trunk/src/addon_management.cpp (original)
+++ trunk/src/addon_management.cpp Sat Aug 16 00:40:27 2008
@@ -583,9 +583,103 @@
                }
        }
        
-       void addons_update_dlg(game_display& disp, config& /*cfg*/, const 
config::child_list& remote_addons_list,
-                              const network::manager& /*net_manager*/, const 
network::connection& /*sock*/,
-                              bool* /*do_refresh*/)
+       bool install_addon(game_display& disp, config& cfg, const config* 
const addons_tree,
+                          const std::string& addon_id, const std::string& 
addon_title,
+                          const std::string& addon_type_str, const 
std::string& addon_uploads_str,
+                          const std::string& addon_version_str,
+                          const network::manager& /*net_manager*/,
+                          const network::connection& sock, bool* do_refresh,
+                          bool show_result = true)
+       {
+               // Get all dependencies of the addon/campaign selected for 
download.
+               const config * const selected_campaign = 
addons_tree->find_child("campaign", "name", addon_id);
+               assert(selected_campaign != NULL);
+               // Get all dependencies which are not already installed.
+               // TODO: Somehow determine if the version is outdated.
+               std::vector<std::string> dependencies = 
utils::split((*selected_campaign)["dependencies"]);
+               if (!addon_dependencies_met(disp,dependencies)) return false;
+               // Proceed to download and install
+               config request;
+               request.add_child("request_campaign")["name"] = addon_id;
+               network::send_data(request, sock, true);
+
+               utils::string_map syms;
+               syms["addon_title"] = addon_title;
+               const std::string& download_dlg_title =
+                       
utils::interpolate_variables_into_string(_("Downloading add-on: 
$addon_title|..."), &syms);
+
+               network::connection res = 
dialogs::network_receive_dialog(disp, download_dlg_title, cfg, sock);
+               if(!res) {
+                       return false;
+               }
+
+               config const * const dlerror = cfg.child("error");
+               if(dlerror != NULL) {
+                       gui::show_error_message(disp, (*dlerror)["message"]);
+                       return false;
+               }
+
+               if(!check_names_legal(cfg)) {
+                       gui::show_error_message(disp, _("The add-on has an 
invalid file or directory name and can not be installed."));
+                       return false;
+               }
+               
+               // remove any existing versions of the just downloaded add-on,
+               // assuming it consists of a dir and a cfg file
+               remove_local_addon(addon_id);
+
+               // add revision info to the addon archive
+               config* maindir = cfg.find_child("dir", "name", addon_id);
+               if(maindir == NULL) {
+                       LOG_CFG << "downloaded addon '" << addon_id << "' is 
missing its own directory, creating...\n";
+                       maindir = &cfg.add_child("dir");
+                       (*maindir)["name"] = addon_id;
+               }
+
+               LOG_CFG << "generating version info for addon '" << addon_id 
<< "'\n";
+               config f;
+               f["name"] = "_info.cfg";
+               std::string s;
+               s += "#\n"
+                               "# Automatically generated by Wesnoth to keep 
track\n"
+                               "# of version information on installed 
add-ons.\n"
+                               "#\n";
+               s += "[info]\n";
+               if(!addon_type_str.empty()) {
+               s += "    type=\"" + addon_type_str + "\"\n";
+               }
+               s += "    uploads=\"" + addon_uploads_str + "\"\n";
+               s += "    version=\"" + addon_version_str + "\"\n";
+               s += "[/info]\n";
+               f["contents"] = s;
+               maindir->add_child("file", f);
+               LOG_CFG << "generated version info, unpacking...\n";
+               unarchive_addon(cfg);
+               LOG_CFG << "addon unpacked successfully\n";
+
+               std::string warning = "";
+               std::vector<config *> scripts = find_scripts(cfg, 
".unchecked");
+               if(!scripts.empty()) {
+                       WRN_CFG << "downloaded addon '" << addon_title << "' 
has unchecked scripts\n";
+                       warning += "\n";
+                       warning += _("Unchecked script files found:");
+                       foreach(const config* i, scripts)
+                               warning += "\n" + (*i)["name"];
+               }
+
+               const std::string& message =
+                       utils::interpolate_variables_into_string(_("The 
add-on '$addon_title|' has been successfully installed."), &syms);
+               /* GCC-3.3 needs a temp var otherwise compilation fails */
+               gui::message_dialog dlg(disp, _("Add-on Installed"), message);
+               dlg.show();
+
+               if(do_refresh != NULL)
+                       *do_refresh = true;
+       }
+       
+       void addons_update_dlg(game_display& disp, config& cfg, const 
config::child_list& remote_addons_list,
+                              const network::manager& net_manager, const 
network::connection& sock,
+                              bool* do_refresh)
        {
                std::vector< config* > remote_matches_cfgs;
                std::vector< std::string > safe_matches;
@@ -737,101 +831,52 @@
                if(index < 0 && !upd_all)
                        return;
 
+               bool result = true;
+               std::vector<std::string> failed_titles;
+
                if(upd_all) {
-               }
-       }
-
-       void install_addon(game_display& disp, config& cfg, const config* 
const addons_tree,
-                          const std::string& addon_id, const std::string& 
addon_title,
-                          const std::string& addon_type_str, const 
std::string& addon_uploads_str,
-                          const std::string& addon_version_str,
-                          const network::manager& /*net_manager*/,
-                          const network::connection& sock, bool* do_refresh)
-       {
-               // Get all dependencies of the addon/campaign selected for 
download.
-               const config * const selected_campaign = 
addons_tree->find_child("campaign", "name", addon_id);
-               assert(selected_campaign != NULL);
-               // Get all dependencies which are not already installed.
-               // TODO: Somehow determine if the version is outdated.
-               std::vector<std::string> dependencies = 
utils::split((*selected_campaign)["dependencies"]);
-               if (!addon_dependencies_met(disp,dependencies)) return;
-               // Proceed to download and install
-               config request;
-               request.add_child("request_campaign")["name"] = addon_id;
-               network::send_data(request, sock, true);
-
-               utils::string_map syms;
-               syms["addon_title"] = addon_title;
-               const std::string& download_dlg_title =
-                       
utils::interpolate_variables_into_string(_("Downloading add-on: 
$addon_title|..."), &syms);
-
-               network::connection res = 
dialogs::network_receive_dialog(disp, download_dlg_title, cfg, sock);
-               if(!res) {
+                       for(size_t i = 0; i < addons.size(); ++i)
+                       {
+                               if(!install_addon(disp, cfg, 
cfg.child("campaigns"), addons[i], titles[i],
+                                                  
(*remote_matches_cfgs[i])["type"], (*remote_matches_cfgs[i])["uploads"],
+                                                  
(*remote_matches_cfgs[i])["version"], net_manager, sock,
+                                                  do_refresh, false)) {
+                                       result=false;
+                                       failed_titles.push_back(titles[i]);
+                               }
+                       }
+               } else {
+                       assert(index >= 0);
+                       const size_t i = static_cast<size_t>(index);
+                       if(!install_addon(disp, cfg, cfg.child("campaigns"), 
addons[i], titles[i],
+                                              
(*remote_matches_cfgs[i])["type"], (*remote_matches_cfgs[i])["uploads"],
+                                              
(*remote_matches_cfgs[i])["version"], net_manager, sock,
+                                              do_refresh, false)) {
+                               result=false;
+                               failed_titles.push_back(titles[i]);
+                       }
+               }
+               
+               if(!result) {
+                       assert(failed_titles.empty() == false);
+                       std::string failed_titles_list_fmt;
+                       foreach(const std::string& entry, failed_titles) {
+                               failed_titles_list_fmt += '\n';
+                               failed_titles_list_fmt += entry;
+                       }
+                       const std::string err_title = _("Update failed");
+                       const std::string err_message =
+                               _n("The following add-on could not be 
downloaded or updated successfully:",
+                                  "The following add-ons could not be 
downloaded or updated successfully:",
+                                  failed_titles.size()) + 
failed_titles_list_fmt;
+                       gui::dialog(disp, err_title, err_message, 
gui::MESSAGE).show();
                        return;
                }
-
-               config const * const dlerror = cfg.child("error");
-               if(dlerror != NULL) {
-                       gui::show_error_message(disp, (*dlerror)["message"]);
-                       return;
-               }
-
-               if(!check_names_legal(cfg)) {
-                       gui::show_error_message(disp, _("The add-on has an 
invalid file or directory name and can not be installed."));
-                       return;
-               }
                
-               // remove any existing versions of the just downloaded add-on,
-               // assuming it consists of a dir and a cfg file
-               remove_local_addon(addon_id);
-
-               // add revision info to the addon archive
-               config* maindir = cfg.find_child("dir", "name", addon_id);
-               if(maindir == NULL) {
-                       LOG_CFG << "downloaded addon '" << addon_id << "' is 
missing its own directory, creating...\n";
-                       maindir = &cfg.add_child("dir");
-                       (*maindir)["name"] = addon_id;
-               }
-
-               LOG_CFG << "generating version info for addon '" << addon_id 
<< "'\n";
-               config f;
-               f["name"] = "_info.cfg";
-               std::string s;
-               s += "#\n"
-                               "# Automatically generated by Wesnoth to keep 
track\n"
-                               "# of version information on installed 
add-ons.\n"
-                               "#\n";
-               s += "[info]\n";
-               if(!addon_type_str.empty()) {
-               s += "    type=\"" + addon_type_str + "\"\n";
-               }
-               s += "    uploads=\"" + addon_uploads_str + "\"\n";
-               s += "    version=\"" + addon_version_str + "\"\n";
-               s += "[/info]\n";
-               f["contents"] = s;
-               maindir->add_child("file", f);
-               LOG_CFG << "generated version info, unpacking...\n";
-               unarchive_addon(cfg);
-               LOG_CFG << "addon unpacked successfully\n";
-
-               std::string warning = "";
-               std::vector<config *> scripts = find_scripts(cfg, 
".unchecked");
-               if(!scripts.empty()) {
-                       WRN_CFG << "downloaded addon '" << addon_title << "' 
has unchecked scripts\n";
-                       warning += "\n";
-                       warning += _("Unchecked script files found:");
-                       foreach(const config* i, scripts)
-                               warning += "\n" + (*i)["name"];
-               }
-
-               const std::string& message =
-                       utils::interpolate_variables_into_string(_("The 
add-on '$addon_title|' has been successfully installed."), &syms);
-               /* GCC-3.3 needs a temp var otherwise compilation fails */
-               gui::message_dialog dlg(disp, _("Add-on Installed"), message);
-               dlg.show();
-
-               if(do_refresh != NULL)
-                       *do_refresh = true;
+               const std::string msg_title = _("Update succeeded");
+               const std::string msg_message = !upd_all ? _("Add-on updated 
successfully.") :
+                                                          _("All add-ons 
updated successfully.");
+               gui::dialog(disp, msg_title, msg_message, 
gui::MESSAGE).show();
        }
 
        void download_addons(game_display& disp, std::string remote_host, 
bool update_mode, bool* do_refresh)
@@ -1134,10 +1179,11 @@
                                       _("Type the address of a server to 
download add-ons from."),
                                       gui::OK_CANCEL);
                svr_dialog.set_textbox(_("Server: "), default_host);
+
+               // not ready for production yet
 #if 0
-               // not ready for production yet
                svr_dialog.add_button(new gui::dialog_button(disp.video(), 
_("Update add-ons"),
-                                     gui::button::TYPE_PRESS, 
ADDONS_OPT_UPDATE),
+                                     gui::button::TYPE_PRESS, addon_update),
                                      gui::dialog::BUTTON_EXTRA_LEFT);
 #endif
                svr_dialog.add_button(new gui::dialog_button(disp.video(), 
_("Uninstall add-ons"),




Related Messages


Powered by MHonArc, Updated Sat Aug 16 02:41:25 2008