summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/files.cc
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-11-22 14:13:50 -0600
committerJesse Luehrs <doy@tozt.net>2009-12-12 11:54:28 -0600
commit37c0c9ef3041be75b689e53b0a4f7d597971ecf7 (patch)
tree875a21f31a5847a4019af95ec25f8d621e393651 /crawl-ref/source/files.cc
parentf2a4951d8eecc3749dedce5d4c8c26f9cc954357 (diff)
downloadcrawl-ref-37c0c9ef3041be75b689e53b0a4f7d597971ecf7.tar.gz
crawl-ref-37c0c9ef3041be75b689e53b0a4f7d597971ecf7.zip
add a --save-version option for checking a player's save file version
Diffstat (limited to 'crawl-ref/source/files.cc')
-rw-r--r--crawl-ref/source/files.cc26
1 files changed, 18 insertions, 8 deletions
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).",