From 37c0c9ef3041be75b689e53b0a4f7d597971ecf7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 22 Nov 2009 14:13:50 -0600 Subject: add a --save-version option for checking a player's save file version --- crawl-ref/source/files.cc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source/files.cc') diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 7836f63a1b..87f3984fb5 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -2149,26 +2149,36 @@ bool apply_to_all_dungeons(bool (*applicator)()) return (success); } -static bool _get_and_validate_version(FILE *restoreFile, char &major, - char &minor, std::string* reason) +bool get_save_version(FILE *file, char &major, char &minor) { - std::string dummy; - if (reason == 0) - reason = &dummy; - // Read first two bytes. char buf[2]; - if (read2(restoreFile, buf, 2) != 2) + if (read2(file, buf, 2) != 2) { // Empty file? major = minor = -1; - *reason = "File is corrupt."; return (false); } major = buf[0]; minor = buf[1]; + return (true); +} + +static bool _get_and_validate_version(FILE *restoreFile, char &major, + char &minor, std::string* reason) +{ + std::string dummy; + if (reason == 0) + reason = &dummy; + + if (!get_save_version(restoreFile, major, minor)) + { + *reason = "File is corrupt."; + return (false); + } + if (major != TAG_MAJOR_VERSION) { *reason = make_stringf("Major version mismatch: %d (want %d).", -- cgit v1.2.3-54-g00ecf