summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/files.cc
diff options
context:
space:
mode:
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).",