Disallow loading versions prior to 1.3.1 (changelog entry will follow)

This commit is contained in:
Mark de Wever 2007-04-29 14:33:52 +00:00
parent 2163329f4d
commit 6ad1e04ae4
6 changed files with 118 additions and 4 deletions

View file

@ -39,6 +39,13 @@ AC_CONFIG_COMMANDS([src/wesconfig.h],
* releases the chat messages
*/
#define WML_ERROR_DIALOG 0
/**
* Some older savegames of Wesnoth can't be loaded anymore this
* variable defines the minimum required version
*/
#define MIN_SAVEGAME_VERSION "1.3.1"
#endif
EOF
])

View file

@ -692,6 +692,11 @@ bool game_controller::load_game()
state_ = game_state(units_data_,cfg);
if(state_.version != game_config::version) {
if(state_.version < game_config::min_savegame_version) {
gui::show_dialog(disp(), NULL, "", _("This save is from a version too old to be loaded."), gui::OK_ONLY);
return false;
}
const int res = gui::show_dialog(disp(),NULL,"",
_("This save is from a different version of the game. Do you want to try to load it?"),
gui::YES_NO);

View file

@ -17,6 +17,7 @@
#include "log.hpp"
#include "gettext.hpp"
#include "game_config.hpp"
#include "util.hpp"
#include "wesconfig.h"
#include "serialization/string_utils.hpp"
@ -71,7 +72,10 @@ namespace game_config
std::map<std::string, std::string > team_rgb_name;
std::map<std::string, std::vector<Uint32> > team_rgb_colors;
const struct game_version wesnoth_version(VERSION);
const struct game_version min_savegame_version(MIN_SAVEGAME_VERSION);
namespace sounds {
const std::string turn_bell = "UI/bell.wav",
receive_message = "UI/receive.wav",
@ -219,4 +223,63 @@ namespace game_config
}
return i->second;
}
game_version::game_version(std::string str) :
major_nr(0), minor_nr(0), patch(0), full(str)
{
size_t offset = str.find_first_not_of("0123456789");
major_nr = lexical_cast_default<unsigned int>(std::string(str, 0, offset), 0);
str.erase(0, offset + 1);
if(! str.empty()) {
offset = str.find_first_not_of("0123456789");
minor_nr = lexical_cast_default<unsigned int>(std::string(str, 0, offset ), 0);
str.erase(0, offset + 1);
}
if(! str.empty()) {
offset = str.find_first_not_of("0123456789");
patch = lexical_cast_default<unsigned int>(std::string(str, 0, offset ), 0);
if(offset != std::string::npos) {
extra = std::string(str, offset);
}
}
}
bool operator<(const struct game_version& a, const struct game_version& b)
{
if(a.major_nr != b.major_nr) return a.major_nr < b.major_nr;
if(a.minor_nr != b.minor_nr) return a.minor_nr < b.minor_nr;
return a.patch < b.patch;
}
bool operator<=(const struct game_version& a, const struct game_version& b)
{
return a < b || a == b;
}
bool operator>(const struct game_version& a, const struct game_version& b)
{
return !(a <= b);
}
bool operator>=(const struct game_version& a, const struct game_version& b)
{
return !(a < b);
}
bool operator==(const struct game_version& a, const struct game_version& b)
{
return a.full == b.full;
}
bool operator!=(const struct game_version& a, const struct game_version& b)
{
return a.full != b.full;
}
}

View file

@ -53,8 +53,8 @@ namespace game_config
extern int title_logo_x, title_logo_y, title_buttons_x, title_buttons_y, title_buttons_padding, title_tip_x, title_tip_width, title_tip_padding;
extern std::map<std::string, color_range> team_rgb_range;
extern std::map<std::string, std::string> team_rgb_name;
extern std::map<std::string, color_range> team_rgb_range;
extern std::map<std::string, std::string> team_rgb_name;
extern std::map<std::string, std::vector<Uint32> > team_rgb_colors;
namespace sounds {
@ -65,8 +65,34 @@ namespace game_config
void load_config(const config* cfg);
const void add_color_info(const config& v);
const void add_color_info(const config& v);
const std::vector<Uint32>& tc_info(const std::string& name);
struct game_version {
game_version(std::string str);
//Note gcc 4.1.2(prerelease) as shipped in Debian etch doesn't
//like the name major and minor :( so make gcc happy
unsigned int major_nr;
unsigned int minor_nr;
unsigned int patch;
std::string extra;
std::string full;
};
// Note the < <= > and >= operator ignore the extra version the == and != do
// use the extra version.
bool operator<(const struct game_version& a, const struct game_version& b);
bool operator<=(const struct game_version& a, const struct game_version& b);
bool operator>(const struct game_version& a, const struct game_version& b);
bool operator>=(const struct game_version& a, const struct game_version& b);
bool operator==(const struct game_version& a, const struct game_version& b);
bool operator!=(const struct game_version& a, const struct game_version& b);
extern const struct game_version wesnoth_version;
extern const struct game_version min_savegame_version;
}
#endif

View file

@ -1252,6 +1252,12 @@ void connect::load_game()
}
if(state_.version != game_config::version) {
if(state_.version < game_config::min_savegame_version) {
gui::show_dialog(disp(), NULL, "", _("This save is from a version too old to be loaded."), gui::OK_ONLY);
set_result(QUIT);
return;
}
const int res = gui::show_dialog(disp(), NULL, "",
_("This save is from a different version of the game. Do you want to try to load it?"),
gui::YES_NO);

View file

@ -18,4 +18,11 @@
* releases the chat messages
*/
#define WML_ERROR_DIALOG 0
/**
* Some older savegames of Wesnoth can't be loaded anymore this
* variable defines the minimum required version
*/
#define MIN_SAVEGAME_VERSION "1.3.1"
#endif