mail[Wesnoth-commits] r28279 - in /trunk: data/tools/wesnoth_addon_manager src/addon_management.cpp src/addon_management.hpp src/game.cpp


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

Header


Content

Posted by shadowm2006 on July 31, 2008 - 02:38:
Author: shadowmaster
Date: Thu Jul 31 02:13:03 2008
New Revision: 28279

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28279&view=rev
Log:
* More addon management system refactoring and bugfixing of previous commits
* Addon metainfo is now saved in file _info.cfg instead of info.cfg.
* Added _info.cfg to default upload exclusion list.
* Updated addons management script to be aware of the info.cfg change.

Modified:
    trunk/data/tools/wesnoth_addon_manager
    trunk/src/addon_management.cpp
    trunk/src/addon_management.hpp
    trunk/src/game.cpp

Modified: trunk/data/tools/wesnoth_addon_manager
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth_addon_manager?rev=28279&r1=28278&r2=28279&view=diff
==============================================================================
--- trunk/data/tools/wesnoth_addon_manager (original)
+++ trunk/data/tools/wesnoth_addon_manager Thu Jul 31 02:13:03 2008
@@ -60,7 +60,7 @@
         "directory.")
     optionparser.add_option("-f", "--update",
         help = "Update all installed add-ons in the given directory. " +
-        "This works by comparing the info.cfg file in each addon directory " 
+
+        "This works by comparing the _info.cfg file in each addon directory 
" +
         "with the version on the server.")
     optionparser.add_option("-v", "--validate",
         help = "validate python scripts in an add-on " +
@@ -113,7 +113,7 @@
             print "Unpacking %s..." % name
             cs.unpackdir(mythread.data, cdir,  verbose = options.verbose)
             d = os.path.join(cdir, name)
-            info = os.path.join(d, "info.cfg")
+            info = os.path.join(d, "_info.cfg")
             try:
                 f = file(info, "w")
                 f.write("[info]\nversion=\"%s\"\nuploads=\"%s\"\n[/info]\n" %
@@ -127,7 +127,7 @@
     def get_info(name):
         """
         Get info for a locally installed add-on. It expects a direct path
-        to the info.cfg file.
+        to the _info.cfg file.
         """
         if not os.path.exists(name):
             return None, None
@@ -193,7 +193,7 @@
                         fetchlist.append((name, version, uploads))
 
         for name, version, uploads in fetchlist:
-            info = os.path.join(options.campaigns_dir, name, "info.cfg")
+            info = os.path.join(options.campaigns_dir, name, "_info.cfg")
             local_uploads, local_version = get_info(info)
             if uploads != local_uploads:
                 # The uploads > local_uploads likely means a server reset
@@ -274,7 +274,7 @@
         for d in dirs:
             dirname = os.path.basename(d)
             if dirname in campaigns:
-                info = os.path.join(d, "info.cfg")
+                info = os.path.join(d, "_info.cfg")
                 sversion = campaigns[dirname].get_text_val("version", "")
                 srev = campaigns[dirname].get_text_val("uploads", "")
                 if os.path.exists(info):

Modified: trunk/src/addon_management.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_management.cpp?rev=28279&r1=28278&r2=28279&view=diff
==============================================================================
--- trunk/src/addon_management.cpp (original)
+++ trunk/src/addon_management.cpp Thu Jul 31 02:13:03 2008
@@ -39,9 +39,13 @@
 
 #include <algorithm>
 #include <cstring>
+#include <map>
+#include <stdexcept>
 
 #define DEFAULT_CAMPAIGND_PORT                         15003
 
+#define LOG_CFG LOG_STREAM(info, config)
+#define WRN_CFG LOG_STREAM(warn, config)
 #define LOG_NET LOG_STREAM(info, network)
 
 namespace {
@@ -50,7 +54,7 @@
                make_directory(get_user_data_dir() + "/data");
                make_directory(get_addon_campaigns_dir());
        }
-}
+} // end unnamed namespace 1
 
 void get_addon_info(const std::string& addon_name, config& cfg)
 {
@@ -123,7 +127,7 @@
 
 namespace {
        const char escape_char = '\x01';
-}
+} // end unnamed namespace 2
 
 static bool needs_escaping(char c) {
        switch(c) {
@@ -205,6 +209,7 @@
                patterns.first.push_back("*-bak");
                patterns.first.push_back("*.pbl");
                patterns.first.push_back("*.ign");
+               patterns.first.push_back("_info.cfg");
                /*
                 * Prevent certain potential security compromises.
                 * The idea is to stop bad guys from uploading things
@@ -222,6 +227,8 @@
                patterns.first.push_back("*.o");
                /* Remove junk created by certain file manager ;) */
                patterns.first.push_back("Thumbs.db");
+               /* Don't upload dot-files/dirs */
+               patterns.first.push_back(".*");
                return patterns;
        }
        std::istream *stream = istream_file(ign_file);
@@ -371,13 +378,17 @@
        
                const double k = 1024;
                if(size > 0.0) {
-                       std::string size_postfix = _("B");
+                       std::string size_postfix = _("B");      // bytes
                        if(size > k) {
                                size /= k;
-                               size_postfix = _("KB");
+                               size_postfix = _("KB");                 // 
kilobytes
                                if(size > k) {
                                        size /= k;
-                                       size_postfix = _("MB");
+                                       size_postfix = _("MB");         // 
megabytes
+                                       if(size > k) {
+                                               size /= k;
+                                               size_postfix = _("GB"); // 
gigabytes
+                                       }
                                }
                        }
        
@@ -737,7 +748,7 @@
                        const std::string& download_dlg_title =
                                
utils::interpolate_variables_into_string(_("Downloading add-on: 
$addon_title|..."), &syms);
 
-                       res = 
dialogs::network_receive_dialog(disp,_("Downloading add-on..."), cfg, sock);
+                       res = dialogs::network_receive_dialog(disp, 
download_dlg_title, cfg, sock);
                        if(!res) {
                                return;
                        }
@@ -758,27 +769,38 @@
                        remove_local_addon(addons[index]);
                        
                        // add revision info to the addon archive
-                       config *maindir = cfg.find_child("dir", "name", 
addons[index]);
-                       if (maindir) {
-                               config f;
-                               f["name"] = "info.cfg";
-                               std::string s;
-                               s += "[info]\n";
-                               if(!types[index].empty()) {
-                               s += "    type=\"" + types[index] + "\"\n";
-                               }
-                               s += "    uploads=\"" + uploads[index] + 
"\"\n";
-                               s += "    version=\"" + versions[index] + 
"\"\n";
-                               s += "[/info]\n";
-                               f["contents"] = s;
-                               maindir->add_child("file", f);
-                       }
-                       
+                       config* maindir = cfg.find_child("dir", "name", 
addons[index]);
+                       if(maindir == NULL) {
+                               LOG_CFG << "downloaded addon '" << 
addons[index] << "' is missing its own directory, creating...\n";
+                               maindir = &cfg.add_child("dir");
+                               (*maindir)["name"] = addons[index];
+                       }
+
+                       LOG_CFG << "generating version info for addon '" << 
addons[index] << "'\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(!types[index].empty()) {
+                       s += "    type=\"" + types[index] + "\"\n";
+                       }
+                       s += "    uploads=\"" + uploads[index] + "\"\n";
+                       s += "    version=\"" + versions[index] + "\"\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 '" << 
addons[index] << "' has unchecked scripts\n";
                                warning += "\nUnchecked script files found:";
                                foreach(const config* i, scripts)
                                        warning += "\n" + (*i)["name"];
@@ -789,7 +811,7 @@
                        /* 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;
 
@@ -846,17 +868,14 @@
                        res = gui::dialog(disp, _("Confirm"), 
confirm_message, gui::YES_NO).show();
                } while (res != 0);
 
-               bool delete_success = true;
-
                // Put underscores back in the name and remove the addon
                std::string filename = addons.at(index);
                std::replace(filename.begin(), filename.end(), ' ', '_');
-               delete_success &= delete_directory(parentdir + filename);
+               bool delete_success = delete_directory(parentdir + filename);
+               delete_success |= delete_directory(parentdir + filename + 
".cfg");
                // Report results
                if (delete_success)
                {
-                       delete_success &= delete_directory(parentdir + 
filename + ".cfg");
-
                        std::string message = _("Add-on '$addon|' deleted.");
                        utils::string_map symbols;
                        symbols["addon"] = addons.at(index);
@@ -877,7 +896,7 @@
                }
        }
        
-} // end unnamed namespace
+} // end unnamed namespace 3
 
 void manage_addons(game_display& disp)
 {
@@ -978,11 +997,6 @@
        return *this;
 }
 
-addon_version_info::addon_version_info()
-       : vmajor(0), vminor(0), revision(0), sane(true)
-{
-}
-
 addon_version_info::addon_version_info(const std::string& src_str)
 {
        if(src_str.empty() != true) {
@@ -1010,5 +1024,66 @@
 addon_version_info::addon_version_info(const addon_version_info& src_struct)
        : vmajor(src_struct.vmajor), vminor(src_struct.vminor),
          revision(src_struct.revision), sane(src_struct.sane)
-{
-}
+{}
+
+addon_version_info::addon_version_info(unsigned major, unsigned minor, 
unsigned rev, bool sane_flag)
+       : vmajor(major), vminor(minor), revision(rev), sane(sane_flag)
+{}
+
+addon_version_info::addon_version_info()
+       : vmajor(0), vminor(0), revision(0), sane(true)
+{}
+
+namespace {
+       std::map< std::string, addon_version_info > version_info_cache;
+} // end unnamed namespace 4
+
+void refresh_addon_version_info_cache(void)
+{
+       if(version_info_cache.empty() != true)
+               version_info_cache.clear();
+
+       LOG_CFG << "probing add-ons and refreshing version information 
cache...\n";
+
+       const std::vector<std::string>& addons = installed_addons();
+       if(addons.empty()) {
+               LOG_CFG << "no add-ons found\n";
+               return;
+       }
+       static const std::string parentd = get_addon_campaigns_dir();
+       std::vector<std::string> addon_info_files;
+       foreach(std::string const& dir, addons)
+               addon_info_files.push_back(parentd+"/"+dir+"/_info.cfg");
+
+       size_t i = 0;
+
+       foreach(std::string const& info_file, addon_info_files) {
+               assert(i < addons.size());
+
+               config cfg;
+               std::string const& addon = addons[i];
+               scoped_istream stream = istream_file(info_file);
+
+               read(cfg, *stream);
+               
+               config const* const info_cfg = cfg.child("info");
+               if(info_cfg == NULL) {
+                       ++i;
+                       continue;
+               }
+               std::string const& version = (*info_cfg)["version"];
+               version_info_cache.insert(std::make_pair(addon, 
addon_version_info(version)));
+               
+               ++i;
+       }
+}
+
+const addon_version_info& get_addon_version_info(const std::string& addon)
+{
+       static const addon_version_info nil(0,0,0,false);
+       try {
+               const addon_version_info& ret = version_info_cache.at(addon);
+               return ret;
+       } catch(std::out_of_range const&) { ; }
+       return nil;
+}

Modified: trunk/src/addon_management.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon_management.hpp?rev=28279&r1=28278&r2=28279&view=diff
==============================================================================
--- trunk/src/addon_management.hpp (original)
+++ trunk/src/addon_management.hpp Thu Jul 31 02:13:03 2008
@@ -59,6 +59,9 @@
 /** Unarchives an add-on from campaignd's retrieved config object. */
 void unarchive_addon(const class config& cfg);
 
+/** Shows the game add-ons manager dialog.
+ *  @param disp game_display instance to draw on.
+ */
 void manage_addons(class game_display& disp);
 
 class addon_version_info_not_sane_exception {};
@@ -67,8 +70,16 @@
 struct addon_version_info
 {
        addon_version_info(); //!< Default constructor.
-       addon_version_info(const std::string&); //!< String conversion 
constructor.
+       //! String conversion constructor.
+       //! @param src_str A version string to initialize numbers from. It 
must
+       //!                be in the format "X.Y.Z", where X is the major 
version
+       //!                number, Y the minor and Z the revision level. If 
the
+       //!                string does not match this format, the object's 
sanity
+       //!                flag will be set to false.
+       addon_version_info(const std::string& src_str);
        addon_version_info(const addon_version_info&); //!< Copy constructor.
+       //! List constructor.
+       addon_version_info(unsigned major, unsigned minor, unsigned rev, bool 
sane_flag);
 
        //! Assignment operator.
        addon_version_info& operator=(const addon_version_info&);
@@ -107,12 +118,10 @@
 //! Less-than-or-equal operator for addon_version_info.
 bool operator<=(const addon_version_info&, const addon_version_info&);
 
-#if 0
 //! Refreshes the per-session cache of add-on's version
 //! information structs.
 void refresh_addon_version_info_cache();
 //! Returns a particular installed add-on's version information.
 const addon_version_info& get_addon_version_info(const std::string& addon);
-#endif
 
 #endif /* !ADDON_MANAGEMENT_HPP_INCLUDED */

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=28279&r1=28278&r2=28279&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Thu Jul 31 02:13:03 2008
@@ -1108,43 +1108,13 @@
 }
 #endif
 
-static std::string format_file_size(const std::string& size_str)
-{
-       double size = lexical_cast_default<double>(size_str,0.0);
-
-       const double k = 1024;
-       if(size > 0.0) {
-               std::string size_postfix = _("B");
-               if(size > k) {
-                       size /= k;
-                       size_postfix = _("KB");
-                       if(size > k) {
-                               size /= k;
-                               size_postfix = _("MB");
-                       }
-               }
-
-               std::ostringstream stream;
-#ifdef _MSC_VER
-               // Visual C++ makes 'precision' set the number of decimal 
places.
-               // Other platforms make it set the number of significant 
figures
-               stream.precision(1);
-               stream << std::fixed << size << size_postfix;
-#else
-               if (size < 100) stream.precision(3);
-               else size = static_cast<int>(size);
-               stream << size << size_postfix;
-#endif
-               return stream.str();
-       } else {
-               return "";
-       }
-}
-
 namespace
 {
        void game_controller::reload_changed_game_config()
        {
+               // rebuild addon version info cache
+               refresh_addon_version_info_cache();
+
                //force a reload of configuration information
                old_defines_map_.clear();
                reset_game_cfg();




Related Messages


Powered by MHonArc, Updated Fri Aug 01 00:03:34 2008