summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/initfile.cc
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-12-12 12:17:22 -0600
committerJesse Luehrs <doy@tozt.net>2009-12-12 12:17:22 -0600
commit19ed4e0af0b2fdee6b02e043626b9919daa4d1b0 (patch)
treecd7b2d3e084b1a32ceb7a1d35354f97fd947ea41 /crawl-ref/source/initfile.cc
parent37c0c9ef3041be75b689e53b0a4f7d597971ecf7 (diff)
downloadcrawl-ref-19ed4e0af0b2fdee6b02e043626b9919daa4d1b0.tar.gz
crawl-ref-19ed4e0af0b2fdee6b02e043626b9919daa4d1b0.zip
allow -save-version to take actual filenames too
Diffstat (limited to 'crawl-ref/source/initfile.cc')
-rw-r--r--crawl-ref/source/initfile.cc74
1 files changed, 42 insertions, 32 deletions
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 22a19a20ca..3eb3aefd02 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -3527,49 +3527,56 @@ static void _print_version()
static void _print_save_version(char *name)
{
+ bool need_unlink = false;
std::string basename = get_savedir_filename(name, "", "");
std::string filename = basename + ".sav";
+ FILE *charf = fopen(name, "rb");
+
+ if (!charf) {
#ifdef LOAD_UNPACKAGE_CMD
- std::string zipfile = basename + PACKAGE_SUFFIX;
- FILE *handle = fopen(zipfile.c_str(), "rb+");
- if (handle == NULL)
- {
- fprintf(stderr, "Unable to open %s for reading!\n", zipfile.c_str());
- return;
- }
- else
- {
- fclose(handle);
+ std::string zipfile = basename + PACKAGE_SUFFIX;
+ FILE *handle = fopen(zipfile.c_str(), "rb+");
+ if (handle == NULL)
+ {
+ fprintf(stderr, "Unable to open %s for reading!\n",
+ zipfile.c_str());
+ return;
+ }
+ else
+ {
+ fclose(handle);
- // Create command.
- char cmd_buff[1024];
+ // Create command.
+ char cmd_buff[1024];
- std::string zipname = basename;
- std::string directory = get_savedir();
- std::string savefile = filename;
- savefile.erase(0, savefile.rfind(FILE_SEPARATOR) + 1);
+ std::string zipname = basename;
+ std::string directory = get_savedir();
+ std::string savefile = filename;
+ savefile.erase(0, savefile.rfind(FILE_SEPARATOR) + 1);
- escape_path_spaces(zipname);
- escape_path_spaces(directory);
- escape_path_spaces(savefile);
- snprintf( cmd_buff, sizeof(cmd_buff), UNPACK_SPECIFIC_FILE_CMD,
- zipname.c_str(),
- directory.c_str(),
- savefile.c_str() );
+ escape_path_spaces(zipname);
+ escape_path_spaces(directory);
+ escape_path_spaces(savefile);
+ snprintf( cmd_buff, sizeof(cmd_buff), UNPACK_SPECIFIC_FILE_CMD,
+ zipname.c_str(),
+ directory.c_str(),
+ savefile.c_str() );
- if (system( cmd_buff ) != 0)
- {
- fprintf(stderr, "Warning: Zip command (UNPACK_SPECIFIC_FILE_CMD) "
- "returned non-zero value!" EOL );
+ if (system( cmd_buff ) != 0)
+ {
+ fprintf(stderr, "Warning: Zip command "
+ "(UNPACK_SPECIFIC_FILE_CMD) "
+ "returned non-zero value!" EOL );
+ }
+ need_unlink = true;
}
- }
#endif
-
- FILE *charf = fopen(filename.c_str(), "rb");
+ charf = fopen(filename.c_str(), "rb");
+ }
if (!charf) {
fprintf(stderr, "Unable to open %s for reading!\n", filename.c_str());
- return;
+ goto cleanup;
}
char major, minor;
@@ -3580,8 +3587,11 @@ static void _print_save_version(char *name)
printf("Save file version for %s is %d.%d\n", name, major, minor);
}
+cleanup:
#ifdef LOAD_UNPACKAGE_CMD
- unlink(filename.c_str());
+ if (need_unlink) {
+ unlink(filename.c_str());
+ }
#endif
}