Added gzip write support.

Updated changelogs and other documentation about new gzip featue.

Some cosmetic cleanups.
This commit is contained in:
Mark de Wever 2007-12-05 17:27:08 +00:00
parent 80e16c3d9e
commit 22ad729bcc
12 changed files with 89 additions and 32 deletions

View File

@ -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'

View File

@ -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

View File

@ -14,6 +14,10 @@ Version 1.3.12+svn:
* 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:

View File

@ -33,7 +33,7 @@
[advanced_preference]
field=compress_saves
name=_"Binary Saves"
name=_"Compressed Saves"
type=boolean
default=yes
[/advanced_preference]

View File

@ -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

View File

@ -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<std::string> 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)
{}

View File

@ -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();

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -26,6 +26,9 @@
#include <sstream>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
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");
}

View File

@ -22,6 +22,8 @@
#include <iosfwd>
#include <string>
#include <boost/iostreams/filtering_stream.hpp>
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<boost::iostreams::output> filter_;
std::ostream &out_;
bool compress_;
unsigned int level_;
std::string textdomain_;
};
bool is_gzip_file(const std::string& filename);
#endif