aboutsummaryrefslogtreecommitdiff
path: root/backends/saves/default
diff options
context:
space:
mode:
authorMax Horn2007-01-21 15:17:28 +0000
committerMax Horn2007-01-21 15:17:28 +0000
commitaaf706a43df127b4134c23313f02177525f86e78 (patch)
treef7a3e951272eaabe6836471bdeeb0fda84f1f38f /backends/saves/default
parente0aa34bc514183761c80362a6cbf2978b899b8e1 (diff)
downloadscummvm-rg350-aaf706a43df127b4134c23313f02177525f86e78.tar.gz
scummvm-rg350-aaf706a43df127b4134c23313f02177525f86e78.tar.bz2
scummvm-rg350-aaf706a43df127b4134c23313f02177525f86e78.zip
Don't mkdir the default savepath whenever we startup; rather, mkdir (on Unix/Symbian, at least) the savedir just before we need it, i.e. just before saving. Fixes bug #1504398
svn-id: r25150
Diffstat (limited to 'backends/saves/default')
-rw-r--r--backends/saves/default/default-saves.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index d62cdb6cb0..8537d4c2b6 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -22,6 +22,7 @@
#include "common/stdafx.h"
#include "common/savefile.h"
+#include "common/util.h"
#include "backends/saves/default/default-saves.h"
#include <stdio.h>
@@ -31,6 +32,12 @@
#include <zlib.h>
#endif
+#if defined(UNIX) || defined(__SYMBIAN32__)
+#include <errno.h>
+#include <sys/stat.h>
+#endif
+
+
class StdioSaveFile : public Common::InSaveFile, public Common::OutSaveFile {
private:
FILE *fh;
@@ -170,7 +177,47 @@ static void join_paths(const char *filename, const char *directory,
Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) {
char buf[256];
- join_paths(filename, getSavePath(), buf, sizeof(buf));
+
+ // Ensure that the savepath exists and is writeable. If not, generate
+ // an appropriate error
+ const char *savePath = getSavePath();
+#if defined(UNIX) || defined(__SYMBIAN32__)
+ struct stat sb;
+
+ // Check whether the dir exists
+ if (stat(savePath, &sb) == -1) {
+ // The dir does not exist, or stat failed for some other reason.
+ // If the problem was that the path pointed to nothing, try
+ // to create the dir.
+ if (errno == ENOENT) {
+ if (mkdir(savePath, 0755) != 0) {
+ // mkdir could fail for various reasons: The parent dir doesn't exist,
+ // or is not writeable, the path could be completly bogus, etc.
+ warning("mkdir for '%s' failed!", savePath);
+ perror("mkdir");
+ // TODO: Specify an error code here so that callers can
+ // determine what exactly went wrong.
+ return 0;
+ }
+ } else {
+ // Unknown error, abort.
+ // TODO: Specify an error code here so that callers can
+ // determine what exactly went wrong.
+ return 0;
+ }
+ } else {
+ // So stat() succeeded. But is the path actually pointing to a
+ // directory?
+ if (!S_ISDIR(sb.st_mode)) {
+ // TODO: Specify an error code here so that callers can
+ // determine what exactly went wrong.
+ return 0;
+ }
+ }
+#endif
+
+
+ join_paths(filename, savePath, buf, sizeof(buf));
#ifdef USE_ZLIB
GzipSaveFile *sf = new GzipSaveFile(buf, true);
@@ -203,5 +250,8 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename)
}
void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) {
+ // TODO: Implement this properly, at least on systems that support
+ // opendir/readdir.
+ // Even better, replace this with a better design...
memset(marks, true, num * sizeof(bool));
}