From 22ad729bccab7d52f06e71a02fbcd6816a36da9e Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Wed, 5 Dec 2007 17:27:08 +0000 Subject: [PATCH] Added gzip write support. Updated changelogs and other documentation about new gzip featue. Some cosmetic cleanups. --- INSTALL | 6 +++++- RELEASE_NOTES | 5 +++++ changelog | 30 ++++++++++++++++------------ data/_main.cfg | 2 +- players_changelog | 4 ++++ src/filesystem.cpp | 11 +++++++++- src/filesystem.hpp | 7 +++++-- src/gamestatus.cpp | 7 ++++++- src/menu_events.cpp | 12 ++++++++++- src/replay.cpp | 7 ++++++- src/serialization/binary_or_text.cpp | 22 ++++++++++++-------- src/serialization/binary_or_text.hpp | 8 +++++--- 12 files changed, 89 insertions(+), 32 deletions(-) diff --git a/INSTALL b/INSTALL index 5236b6ad814..32da3d21827 100644 --- a/INSTALL +++ b/INSTALL @@ -7,16 +7,20 @@ You'll need to have these libraries (with equivalent devel versions) to build We libsdl-mixer1.2 (with Vorbis support) libsdl-net libfreetype2 + libz + boost_iostreams >= 1.33.0 Recommended (can be deactivated via ./configure --disable-python): python2.4 SDL* libraries can be found at http://www.libsdl.org . libfreetype can be found -at http://www.freetype.org/ . python can be found at http://www.python.org +at http://www.freetype.org/ . python can be found at http://www.python.org . +The boost libraries can be found at http://www.boost.org . You will also need to have a working installation of gettext to build the translations. + The .tar.bz2 file is distributed with a working set of configure files. They are not in the SVN repository. Consequently, if you are building from SVN, you will need autoconf (>= 2.59) and automake (>= 1.9). Run './autogen.sh' diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 07a599874a3..28ebe143c74 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -11,6 +11,11 @@ is making sure that spelling/grammer/whatever is usable and that you are using The release team should empty this file after each release. +The old save option 'Binary Saves' has been replaced with 'Compressed Saves'. +This uses the standard gzip compression. Shadow_Master tested with his savegame +archive and the following results where found for 687 files: +before 1018.1 MB +after 79.3 MB diff --git a/changelog b/changelog index a8de065b435..8bb60080a54 100644 --- a/changelog +++ b/changelog @@ -1,19 +1,23 @@ Version 1.3.12+svn: * language and i18n: - * updated translations: Chinese, Danish, Italian + * updated translations: Chinese, Danish, Italian * WML engine: - * new event trigger: pre_die, will be triggered when a unit dies, but - before the animation is played - * allow ThemeWML to display the race. - * new "random_gender=" key (boolean) to single units declarations in WML; - the engine will generate a random gender for the spawned unit just like - when it's recruited - * updated {GENERIC_UNIT ...} macro to take advantage of random_gender - * User interface - * display the race in the unit preview panel. - * allow to use team labels also for 1-player-teams (bug #9747) - * changing the langugage now sets the version number in the title - properly. + * new event trigger: pre_die, will be triggered when a unit dies, but + before the animation is played + * allow ThemeWML to display the race. + * new "random_gender=" key (boolean) to single units declarations in WML; + the engine will generate a random gender for the spawned unit just like + when it's recruited + * updated {GENERIC_UNIT ...} macro to take advantage of random_gender + * User interface + * display the race in the unit preview panel. + * allow to use team labels also for 1-player-teams (bug #9747) + * changing the langugage now sets the version number in the title + properly. + * miscellaneous and bug fixes: + * added gzip and gunzip command line parameters + * replaced the 'Binary Saves' option with 'Compressed Saves' and now + writes gzip files Version 1.3.12: * campaigns: diff --git a/data/_main.cfg b/data/_main.cfg index c3f2eb98ac1..ccc22cafa96 100644 --- a/data/_main.cfg +++ b/data/_main.cfg @@ -33,7 +33,7 @@ [advanced_preference] field=compress_saves - name=_"Binary Saves" + name=_"Compressed Saves" type=boolean default=yes [/advanced_preference] diff --git a/players_changelog b/players_changelog index a272bb4ba70..a364214ac70 100644 --- a/players_changelog +++ b/players_changelog @@ -9,6 +9,10 @@ Version 1.3.12+svn: * Display the race in the unit preview panel. * Allow to use team labels also for 1-player-teams (bug #9747). + * Miscellaneous and bug fixes + * Replaced the 'Binary Saves' option with 'Compressed Saves' and now + writes gzip files. + Version 1.3.12: * campaigns * The Rise of Wesnoth diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 69081d3c52c..a6ec9914199 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -808,8 +808,8 @@ time_t file_create_time(const std::string& fname) return buf.st_mtime; } +//! Return the next ordered full filename within this directory. std::string next_filename(const std::string &dirname, unsigned int max) -// Return the next ordered full filename within this directory { std::vector files; std::stringstream fname; @@ -841,6 +841,15 @@ std::string next_filename(const std::string &dirname, unsigned int max) return dirname + "/" + fname.str(); } +//! Returns true if the file ends with '.gz'. +//! +//! @param filename The name to test. +bool is_gzip_file(const std::string& filename) +{ + return (filename.length() > 3 + && filename.substr(filename.length() - 3) == ".gz"); +} + file_tree_checksum::file_tree_checksum() : nfiles(0), sum_size(0), modified(0) {} diff --git a/src/filesystem.hpp b/src/filesystem.hpp index 870bc1e0a69..498207b753d 100644 --- a/src/filesystem.hpp +++ b/src/filesystem.hpp @@ -79,10 +79,10 @@ void write_file(const std::string& fname, const std::string& data); std::string read_map(const std::string& name); -//! Returns true iff the given file is a directory. +//! Returns true if the given file is a directory. bool is_directory(const std::string& fname); -//! Returns true iff file with name already exists. +//! Returns true if file with name already exists. bool file_exists(const std::string& name); //! Get the creation time of a file. @@ -91,6 +91,9 @@ time_t file_create_time(const std::string& fname); //! Return the next ordered full filename within this directory. std::string next_filename(const std::string &dirname, unsigned int max = 0); +//! Returns true if the file ends with '.gz'. +bool is_gzip_file(const std::string& filename); + struct file_tree_checksum { file_tree_checksum(); diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index d381352015a..d2e482ac34a 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -809,7 +809,12 @@ void finish_save_game(config_writer &out, const game_state& gamestate, const std // Throws game::save_game_failed void save_game(const game_state& gamestate) { - scoped_ostream os(open_save_game(gamestate.label)); + std::string filename = gamestate.label; + if(preferences::compress_saves()) { + filename += ".gz"; + } + + scoped_ostream os(open_save_game(filename)); config_writer out(*os, preferences::compress_saves(), PACKAGE); write_game(out, gamestate); finish_save_game(out, gamestate, gamestate.label); diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 8bee06df9c7..09451489a6f 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -703,7 +703,17 @@ private: if(res == 0) { if(std::count_if(label.begin(),label.end(),is_illegal_file_char)) { - gui::message_dialog(*gui_,_("Error"),_("Save names may not contain colons, slashes, or backslashes. Please choose a different name.")).show(); + gui::message_dialog(*gui_, _("Error"), + _("Save names may not contain colons, slashes, or backslashes. " + "Please choose a different name.")).show(); + save_game(message,dialog_type); + return; + } + + if(is_gzip_file(label)) { + gui::message_dialog(*gui_, _("Error"), + _("Save names should not end on '.gz'. " + "Please choose a different name.")).show(); save_game(message,dialog_type); return; } diff --git a/src/replay.cpp b/src/replay.cpp index e2aede2b614..cad812fd28d 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -193,7 +193,12 @@ void replay::save_game(const std::string& label, const config& snapshot, saveInfo_.label = label; - scoped_ostream os(open_save_game(label)); + std::string filename = label; + if(preferences::compress_saves()) { + filename += ".gz"; + } + + scoped_ostream os(open_save_game(filename)); config_writer out(*os, preferences::compress_saves(), PACKAGE); ::write_game(out, saveInfo_); finish_save_game(out, saveInfo_, saveInfo_.label); diff --git a/src/serialization/binary_or_text.cpp b/src/serialization/binary_or_text.cpp index 29189dd7154..ffee1059dfe 100644 --- a/src/serialization/binary_or_text.cpp +++ b/src/serialization/binary_or_text.cpp @@ -26,6 +26,9 @@ #include +#include +#include + bool detect_format_and_read(config &cfg, std::istream &in, std::string* error_log) { unsigned char c = in.peek(); @@ -46,9 +49,18 @@ void write_possibly_compressed(std::ostream &out, config &cfg, bool compress) write(out, cfg); } -config_writer::config_writer(std::ostream &out, bool compress, const std::string &textdomain) - : out_(out), compress_(compress), level_(0), textdomain_(textdomain) +config_writer::config_writer( + std::ostream &out, bool compress, const std::string &textdomain) : + filter_(), + out_(compress ? filter_ : out), + compress_(compress), + level_(0), + textdomain_(textdomain) { + if(compress_) { + filter_.push(boost::iostreams::gzip_compressor()); + filter_.push(out); + } } void config_writer::write(const config &cfg) @@ -83,9 +95,3 @@ bool config_writer::good() const return out_.good(); } -bool is_gzip_file(const std::string& filename) -{ - return (filename.length() > 3 - && filename.substr(filename.length() - 3) == ".gz"); -} - diff --git a/src/serialization/binary_or_text.hpp b/src/serialization/binary_or_text.hpp index df8ed52f0f8..25653d9e3c1 100644 --- a/src/serialization/binary_or_text.hpp +++ b/src/serialization/binary_or_text.hpp @@ -22,6 +22,8 @@ #include #include +#include + class config; //! Reads a file, and detects it is compressed before reading it. @@ -47,13 +49,13 @@ public: bool good() const; private: + boost::iostreams::filtering_stream filter_; + std::ostream &out_; bool compress_; unsigned int level_; std::string textdomain_; + }; -bool is_gzip_file(const std::string& filename); - - #endif