Author: shadowmaster
Date: Tue Sep 16 20:22:04 2008
New Revision: 29488

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29488&view=rev
Log:
* Some logic fixes and interface improvements for the add-on removal
* procedure (now any errors are informed to the user in the GUI)


Modified:
    trunk/src/addon_management.cpp
    trunk/src/addon_management.hpp

Modified: trunk/src/addon_management.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_management.cpp?rev=29488&r1=29487&r2=29488&view=diff
==============================================================================
--- trunk/src/addon_management.cpp (original)
+++ trunk/src/addon_management.cpp Tue Sep 16 20:22:04 2008
@@ -74,13 +74,30 @@
        write(*stream, cfg);
 }
 
-void remove_local_addon(const std::string& addon)
-{
+bool remove_local_addon(const std::string& addon, std::string* log)
+{
+       bool ret = true;
+       std::ostringstream messages;
        const std::string addon_dir = get_addon_campaigns_dir() + "/" + addon;
 
-       delete_directory(addon_dir);
-       if (file_exists(addon_dir + ".cfg"))
-               delete_directory(addon_dir + ".cfg");
+       LOG_CFG << "removing local add-on: " << addon << '\n';
+
+       if(file_exists(addon_dir) && !delete_directory(addon_dir)) {
+               messages << "Failed to delete directory/file: " << addon_dir << 
'\n';
+               ret = false;
+       }
+
+       if(file_exists(addon_dir + ".cfg") && !delete_directory(addon_dir + 
".cfg")) {
+               messages << "Failed to delete directory/file: " << addon_dir << 
".cfg\n";
+               ret = false;
+       }
+       
+       if(log != NULL) {
+               *log = messages.str();
+       }
+       ERR_CFG << "removal of add-on " << addon << " failed:\n" << messages;
+
+       return ret;
 }
 
 std::vector<std::string> available_addons()
@@ -617,7 +634,9 @@
 
                // 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);
+               if(!remove_local_addon(addon_id)) {
+                       WRN_CFG << "failed to uninstall existing add-on version 
before installing; add-on may not work properly\n";
+               }
 
                unarchive_addon(cfg);
                LOG_CFG << "addon unpacked successfully\n";
@@ -1106,13 +1125,13 @@
                        res = confirm_dlg.show();
                } while (res != 0);
 
-               // Put underscores back in the name and remove the addon
-               std::string filename = addons.at(index);
-               std::replace(filename.begin(), filename.end(), ' ', '_');
-               bool delete_success = delete_directory(parentdir + filename);
-               delete_success |= delete_directory(parentdir + filename + 
".cfg");
-               // Report results
-               if (delete_success)
+               // Put underscores back in the name
+               std::string addon_id = addons.at(index);
+               std::replace(addon_id.begin(), addon_id.end(), ' ', '_');
+
+               // Try to remove add-on and report results
+               std::string removal_log;
+               if(remove_local_addon(addon_id, &removal_log))
                {
                        std::string message = _("Add-on '$addon|' deleted.");
                        utils::string_map symbols;
@@ -1127,9 +1146,12 @@
                }
                else
                {
+                       const std::string err_msg_title = _("Error");
+                       std::string err_msg = _("Add-on could not be deleted 
properly:");
+                       err_msg += '\n';
+                       err_msg += removal_log;
                        /* GCC-3.3 needs a temp var otherwise compilation fails 
*/
-                       gui::dialog dlg2(disp, _("Error"), _("Add-on could not 
be deleted -- a file was not found."),
-                                       gui::OK_ONLY);
+                       gui::dialog dlg2(disp, err_msg_title, err_msg, 
gui::OK_ONLY);
                        dlg2.show();
                }
        }

Modified: trunk/src/addon_management.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_management.hpp?rev=29488&r1=29487&r2=29488&view=diff
==============================================================================
--- trunk/src/addon_management.hpp (original)
+++ trunk/src/addon_management.hpp Tue Sep 16 20:22:04 2008
@@ -27,7 +27,7 @@
 typedef std::pair< std::string, ADDON_TYPE > addon_list_item;
 class config_changed_exception {};
 
-void remove_local_addon(const std::string& addon);
+bool remove_local_addon(const std::string& addon, std::string* log = NULL);
 
 /**
  * Gets the publish information for an add-on.


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to