summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-27 16:00:59 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-27 16:00:59 +0000
commit29faa0a6eb7d70224246e9613a5b9cec4f94dcb5 (patch)
tree106a8722c23cee9f9e3256d9a3a33ffaf8660176
parentf5e094c8c6d4f5947d48510633a74cc3b65bf98b (diff)
downloadcrawl-ref-29faa0a6eb7d70224246e9613a5b9cec4f94dcb5.tar.gz
crawl-ref-29faa0a6eb7d70224246e9613a5b9cec4f94dcb5.zip
[1603062] Fixed save_dir not working when LOAD_PACKAGE_CMD is defined (sartak).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.1.4@509 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/AppHdr.h9
-rw-r--r--crawl-ref/source/files.cc43
-rw-r--r--crawl-ref/source/files.h1
-rw-r--r--crawl-ref/source/newgame.cc7
4 files changed, 35 insertions, 25 deletions
diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h
index 602d351444..198b1819fa 100644
--- a/crawl-ref/source/AppHdr.h
+++ b/crawl-ref/source/AppHdr.h
@@ -318,17 +318,14 @@
// to a command to compress and bundle the save game files into a
// single unit... the two %s will be replaced with the players
// save file name. Define LOAD_UNPACKAGE_CMD to undo this process
- // the %s is the same as above.
+ // the %s is the same as above. The second %s in LOAD_UNPACKAGE_CMD
+ // is for the output directory.
//
// PACKAGE_SUFFIX is used when the package file name is needed
//
// Comment these lines out if you want to leave the save files uncompressed.
#define SAVE_PACKAGE_CMD "/usr/bin/zip -m -q -j -1 %s.zip %s.*"
-#ifdef SAVE_DIR_PATH
- #define LOAD_UNPACKAGE_CMD "/usr/bin/unzip -q -o %s.zip -d" SAVE_DIR_PATH
-#else
- #define LOAD_UNPACKAGE_CMD "/usr/bin/unzip -q -o %s.zip"
-#endif
+ #define LOAD_UNPACKAGE_CMD "/usr/bin/unzip -q -o %s.zip -d %s"
#ifdef SAVE_PACKAGE_CMD
// This is used to unpack specific files from the archive.
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index 25fc3a39a7..f9c3332186 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -468,14 +468,17 @@ std::vector<player> find_saved_characters()
0,
filename.length() - strlen(PACKAGE_SUFFIX));
- std::string zipname = get_savedir_path(basename);
+ const std::string zipname = get_savedir_path(basename);
// This is the filename we actually read ourselves.
filename = basename + ".sav";
+ const std::string dir = get_savedir();
+
char cmd_buff[1024];
snprintf( cmd_buff, sizeof(cmd_buff), UNPACK_SPECIFIC_FILE_CMD,
zipname.c_str(),
+ dir.c_str(),
filename.c_str() );
if (system(cmd_buff) != 0)
@@ -498,6 +501,12 @@ std::vector<player> find_saved_characters()
return (chars);
}
+std::string get_savedir()
+{
+ const std::string &dir = Options.save_dir;
+ return (dir.empty()? "." : dir);
+}
+
std::string get_savedir_filename(const char *prefix, const char *suffix,
const char *extension, bool suppress_uid)
{
@@ -515,8 +524,8 @@ std::string get_savedir_filename(const char *prefix, const char *suffix,
result += suffix;
if ( *extension ) {
- result += '.';
- result += extension;
+ result += '.';
+ result += extension;
}
#ifdef DOS
@@ -1177,7 +1186,7 @@ void save_game(bool leave_game)
if (stashf) {
stashes.save(stashf);
fclose(stashf);
- DO_CHMOD_PRIVATE(stashFile.c_str());
+ DO_CHMOD_PRIVATE(stashFile.c_str());
}
#endif
@@ -1195,7 +1204,7 @@ void save_game(bool leave_game)
if (killf) {
you.kills.save(killf);
fclose(killf);
- DO_CHMOD_PRIVATE(killFile.c_str());
+ DO_CHMOD_PRIVATE(killFile.c_str());
}
/* travel cache */
@@ -1204,25 +1213,25 @@ void save_game(bool leave_game)
if (travelf) {
travel_cache.save(travelf);
fclose(travelf);
- DO_CHMOD_PRIVATE(travelCacheFile.c_str());
+ DO_CHMOD_PRIVATE(travelCacheFile.c_str());
}
/* notes */
std::string notesFile = get_savedir_filename(you.your_name, "", "nts");
FILE *notesf = fopen(notesFile.c_str(), "wb");
if (notesf) {
- save_notes(notesf);
+ save_notes(notesf);
fclose(notesf);
- DO_CHMOD_PRIVATE(notesFile.c_str());
+ DO_CHMOD_PRIVATE(notesFile.c_str());
}
std::string charFile = get_savedir_filename(you.your_name, "", "sav");
FILE *charf = fopen(charFile.c_str(), "wb");
if (!charf) {
- snprintf(info, INFO_SIZE, "Unable to open \"%s\" for writing!\n",
+ snprintf(info, INFO_SIZE, "Unable to open \"%s\" for writing!\n",
charFile.c_str());
- perror(info);
- end(-1);
+ perror(info);
+ end(-1);
}
// 0.0 initial genesis of saved format
@@ -1369,8 +1378,8 @@ void restore_game(void)
FILE *charf = fopen(charFile.c_str(), "rb");
if (!charf )
{
- snprintf(info, INFO_SIZE, "Unable to open %s for reading!\n",
- charFile.c_str() );
+ snprintf(info, INFO_SIZE, "Unable to open %s for reading!\n",
+ charFile.c_str() );
perror(info);
end(-1);
}
@@ -1390,7 +1399,7 @@ void restore_game(void)
if (!feof(charf))
{
snprintf( info, INFO_SIZE, "\nIncomplete read of \"%s\" - aborting.\n",
- charFile.c_str());
+ charFile.c_str());
perror(info);
end(-1);
}
@@ -1428,8 +1437,8 @@ void restore_game(void)
std::string notesFile = get_savedir_filename(you.your_name, "", "nts");
FILE *notesf = fopen(notesFile.c_str(), "rb");
if (notesf) {
- load_notes(notesf);
- fclose(notesf);
+ load_notes(notesf);
+ fclose(notesf);
}
}
@@ -1845,7 +1854,7 @@ unsigned char translate_spell(unsigned char spel)
case SPELL_SUMMON_HORRIBLE_THINGS:
return (MS_LEVEL_SUMMON); /* approximate */
case SPELL_SHADOW_CREATURES:
- return (MS_LEVEL_SUMMON); /* approximate */
+ return (MS_LEVEL_SUMMON); /* approximate */
case SPELL_ANIMATE_DEAD:
return (MS_ANIMATE_DEAD);
case SPELL_PAIN:
diff --git a/crawl-ref/source/files.h b/crawl-ref/source/files.h
index b7fd81a5fd..3bbd358a1e 100644
--- a/crawl-ref/source/files.h
+++ b/crawl-ref/source/files.h
@@ -37,6 +37,7 @@ bool travel_load_map( char branch, int absdepth );
std::vector<player> find_saved_characters();
+std::string get_savedir();
std::string get_savedir_filename(const char *pre, const char *suf,
const char *ext, bool suppress_uid = false);
diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc
index c4ffc8cbd1..5a1c97671c 100644
--- a/crawl-ref/source/newgame.cc
+++ b/crawl-ref/source/newgame.cc
@@ -294,12 +294,15 @@ static bool check_saved_game(void)
// Create command
char cmd_buff[1024];
+ const std::string directory = get_savedir();
+
snprintf( cmd_buff, sizeof(cmd_buff), LOAD_UNPACKAGE_CMD,
- basename.c_str() );
+ basename.c_str(), directory.c_str() );
if (system( cmd_buff ) != 0)
{
- cprintf( EOL "Warning: Zip command (LOAD_UNPACKAGE_CMD) returned non-zero value!" EOL );
+ cprintf( EOL "Warning: Zip command (LOAD_UNPACKAGE_CMD) "
+ "returned non-zero value!" EOL );
}
// Remove save game package