wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src preferences.cpp preferences.hpp con...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src preferences.cpp preferences.hpp con...
Date: Sun, 20 Feb 2005 10:27:25 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    05/02/20 15:27:25

Modified files:
        src            : preferences.cpp preferences.hpp config.cpp 
                         config.hpp gamestatus.cpp game.cpp 

Log message:
        made saves stored in binary WML by default

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/preferences.cpp.diff?tr1=1.131&tr2=1.132&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/preferences.hpp.diff?tr1=1.47&tr2=1.48&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/config.cpp.diff?tr1=1.124&tr2=1.125&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/config.hpp.diff?tr1=1.52&tr2=1.53&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.cpp.diff?tr1=1.53&tr2=1.54&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.192&tr2=1.193&r1=text&r2=text

Patches:
Index: wesnoth/src/config.cpp
diff -u wesnoth/src/config.cpp:1.124 wesnoth/src/config.cpp:1.125
--- wesnoth/src/config.cpp:1.124        Sat Feb 19 23:40:07 2005
+++ wesnoth/src/config.cpp      Sun Feb 20 15:27:25 2005
@@ -1,4 +1,4 @@
-/* $Id: config.cpp,v 1.124 2005/02/19 23:40:07 ydirson Exp $ */
+/* $Id: config.cpp,v 1.125 2005/02/20 15:27:25 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1063,6 +1063,19 @@
 {
        clear();
        read_compressed_internal(data.begin(),data.end(),schema,0);
+}
+
+bool config::detect_format_and_read(const std::string& data)
+{
+       try {
+               compression_schema schema;
+               read_compressed(data,schema);
+               return true;
+       } catch(config::error&) {
+       }
+
+       read(data);
+       return false;
 }
 
 config::child_itors config::child_range(const std::string& key)
Index: wesnoth/src/config.hpp
diff -u wesnoth/src/config.hpp:1.52 wesnoth/src/config.hpp:1.53
--- wesnoth/src/config.hpp:1.52 Fri Dec 31 21:01:37 2004
+++ wesnoth/src/config.hpp      Sun Feb 20 15:27:25 2005
@@ -1,4 +1,4 @@
-/* $Id: config.hpp,v 1.52 2004/12/31 21:01:37 isaaccp Exp $ */
+/* $Id: config.hpp,v 1.53 2005/02/20 15:27:25 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -111,7 +111,22 @@
        //you can re-use the same schema on the sending end, and the receiver 
can store the schema,
        //meaning that the entire schema won't have to be transmitted each time.
        std::string write_compressed(compression_schema& schema) const;
-       void read_compressed(const std::string& data, compression_schema& 
schema); //throws config::error
+       void read_compressed(const std::string& data, compression_schema& 
schema); //throws config::error
+
+       std::string write_compressed() const {
+               compression_schema schema;
+               return write_compressed(schema);
+       }
+
+       void read_compressed(const std::string& data) {
+               compression_schema schema;
+               read_compressed(data,schema);
+       }
+
+       //function which reads a file, and automatically detects whether it's 
compressed or not before
+       //reading it. If it's not a valid file at all, it will throw an error 
as if it was trying to
+       //read it as text WML. Returns true iff the format is compressed
+       bool detect_format_and_read(const std::string& data); //throws 
config::error
 
        typedef std::vector<config*> child_list;
        typedef std::map<std::string,child_list> child_map;
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.192 wesnoth/src/game.cpp:1.193
--- wesnoth/src/game.cpp:1.192  Sun Feb 20 00:32:38 2005
+++ wesnoth/src/game.cpp        Sun Feb 20 15:27:25 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.192 2005/02/20 00:32:38 ydirson Exp $ */
+/* $Id: game.cpp,v 1.193 2005/02/20 15:27:25 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1470,7 +1470,7 @@
                        << "  --nocache         Disables caching of game 
data\n";
                        return 0;
                } else if(val == "--version" || val == "-v") {
-                       std::cout << "Battle for Wesnoth " << 
game_config::version
+                       std::cout << _("Battle for Wesnoth") << " " << 
game_config::version
                                  << "\n";
                        return 0;
                } else if(val == "--path") {
@@ -1503,6 +1503,44 @@
                                }
                                p = q;
                        }
+               } else if(val == "--compress" || val == "--decompress") {
+                       if(argc != arg+3) {
+                               std::cerr << "format of " << val << " command: 
" << val << " <input file> <output file>\n";
+                               return 0;
+                       }
+
+                       const std::string input(argv[arg+1]);
+                       const std::string output(argv[arg+2]);
+
+                       const std::string in(read_file(input));
+                       if(in == "") {
+                               std::cerr << "could not read file '" << input 
<< "'\n";
+                               return 0;
+                       }
+
+                       config cfg;
+
+                       const bool compress = val == "--compress";
+                       try {
+                               const bool is_compressed = 
cfg.detect_format_and_read(in);
+                               if(is_compressed && compress) {
+                                       std::cerr << input << " is already 
compressed\n";
+                                       return 0;
+                               } else if(!is_compressed && !compress) {
+                                       std::cerr << input << " is already 
decompressed\n";
+                                       return 0;
+                               }
+
+                               const std::string res(compress ? 
cfg.write_compressed() : cfg.write());
+                               write_file(output,res);
+
+                       } catch(config::error& e) {
+                               std::cerr << input << " is not a valid Wesnoth 
file: " << e.message << "\n";
+                       } catch(io_exception& e) {
+                               std::cerr << "IO error: " << e.what() << "\n";
+                       }
+
+                       return 0;
                }
        }
 
@@ -1655,8 +1693,8 @@
                //just means the game should quit
        } catch(end_level_exception&) {
                std::cerr << "caught end_level_exception (quitting)\n";
-       } catch(std::bad_alloc&) {
-               std::cerr << "ran out of memory: game aborted\n";
+       } catch(std::bad_alloc&) {
+               std::cerr << "Ran out of memory. Aborted.\n";
        } /*catch(...) {
                std::cerr << "Unhandled exception. Exiting\n";
        }*/
Index: wesnoth/src/gamestatus.cpp
diff -u wesnoth/src/gamestatus.cpp:1.53 wesnoth/src/gamestatus.cpp:1.54
--- wesnoth/src/gamestatus.cpp:1.53     Fri Jan 28 20:17:46 2005
+++ wesnoth/src/gamestatus.cpp  Sun Feb 20 15:27:25 2005
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.cpp,v 1.53 2005/01/28 20:17:46 silene Exp $ */
+/* $Id: gamestatus.cpp,v 1.54 2005/02/20 15:27:25 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -17,7 +17,8 @@
 #include "game_config.hpp"
 #include "gamestatus.hpp"
 #include "language.hpp"
-#include "log.hpp"
+#include "log.hpp"
+#include "preferences.hpp"
 #include "statistics.hpp"
 #include "util.hpp"
 
@@ -418,7 +419,7 @@
        }
 
        cfg.clear();
-       cfg.read(file_data);
+       cfg.detect_format_and_read(file_data);
 
        if(cfg.empty()) {
                std::cerr << "Could not parse file data into config\n";
@@ -450,8 +451,7 @@
 
                const std::string fname = get_saves_dir() + "/" + name;
 
-               write_file(fname,cfg.write());
-
+               write_file(fname,preferences::compress_saves() ? 
cfg.write_compressed() : cfg.write());
 
                config& summary = save_summary(state.label);
                extract_summary_data_from_save(state,summary);
@@ -474,7 +474,7 @@
 {
        if(save_index_loaded == false) {
                try {
-                       save_index_cfg.read(read_file(get_save_index_file()));
+                       
save_index_cfg.detect_format_and_read(read_file(get_save_index_file()));
                } catch(io_exception& e) {
                        std::cerr << "error reading save index: '" << e.what() 
<< "'\n";
                } catch(config::error&) {
@@ -515,7 +515,7 @@
 {
        log_scope("write_save_index()");
        try {
-               write_file(get_save_index_file(),save_index().write());
+               
write_file(get_save_index_file(),save_index().write_compressed());
        } catch(io_exception& e) {
                std::cerr << "error writing to save index file: '" << e.what() 
<< "'\n";
        }
Index: wesnoth/src/preferences.cpp
diff -u wesnoth/src/preferences.cpp:1.131 wesnoth/src/preferences.cpp:1.132
--- wesnoth/src/preferences.cpp:1.131   Sun Feb  6 10:40:12 2005
+++ wesnoth/src/preferences.cpp Sun Feb 20 15:27:25 2005
@@ -1,4 +1,4 @@
-/* $Id: preferences.cpp,v 1.131 2005/02/06 10:40:12 isaaccp Exp $ */
+/* $Id: preferences.cpp,v 1.132 2005/02/20 15:27:25 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -714,6 +714,11 @@
 void set_show_fps(bool value)
 {
        fps = value;
+}
+
+bool compress_saves()
+{
+       return prefs["compress_saves"] != "no";
 }
 
 std::set<std::string> &encountered_units() {
Index: wesnoth/src/preferences.hpp
diff -u wesnoth/src/preferences.hpp:1.47 wesnoth/src/preferences.hpp:1.48
--- wesnoth/src/preferences.hpp:1.47    Sun Feb  6 10:40:12 2005
+++ wesnoth/src/preferences.hpp Sun Feb 20 15:27:25 2005
@@ -1,4 +1,4 @@
-/* $Id: preferences.hpp,v 1.47 2005/02/06 10:40:12 isaaccp Exp $ */
+/* $Id: preferences.hpp,v 1.48 2005/02/20 15:27:25 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -147,7 +147,9 @@
        void set_show_haloes(bool value);
 
        bool show_fps();
-       void set_show_fps(bool value);
+       void set_show_fps(bool value);
+
+       bool compress_saves();
 
        std::set<std::string> &encountered_units();
        std::set<std::string> &encountered_terrains();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]