aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/saves/savefile.cpp36
-rw-r--r--common/savefile.h8
2 files changed, 44 insertions, 0 deletions
diff --git a/backends/saves/savefile.cpp b/backends/saves/savefile.cpp
index 499edb0b28..8466130151 100644
--- a/backends/saves/savefile.cpp
+++ b/backends/saves/savefile.cpp
@@ -32,6 +32,42 @@
namespace Common {
+bool SaveFileManager::renameSavefile(const char *oldFilename, const char *newFilename) {
+
+ InSaveFile *inFile = 0;
+ OutSaveFile *outFile = 0;
+ uint32 size = 0;
+ void *buffer = 0;
+ bool success = false;
+
+ inFile = openForLoading(oldFilename);
+
+ if (inFile) {
+ size = inFile->size();
+ buffer = malloc(size);
+ assert(buffer);
+
+ outFile = openForSaving(newFilename);
+
+ if (buffer && outFile) {
+ inFile->read(buffer, size);
+ if (!inFile->ioFailed()) {
+ outFile->write(buffer, size);
+ outFile->finalize();
+ if (!outFile->ioFailed()) {
+ success = removeSavefile(oldFilename);
+ }
+ }
+ }
+
+ free(buffer);
+ delete outFile;
+ delete inFile;
+ }
+
+ return success;
+}
+
const char *SaveFileManager::getSavePath() const {
#if defined(PALMOS_MODE) || defined(__PSP__)
diff --git a/common/savefile.h b/common/savefile.h
index 31a9d98a19..e551455ce4 100644
--- a/common/savefile.h
+++ b/common/savefile.h
@@ -132,6 +132,14 @@ public:
virtual bool removeSavefile(const char *filename) = 0;
/**
+ * Renames the given savefile.
+ * @param oldFilename Old filename.
+ * @param newFilename New filename.
+ * @return true if no error ocurred. false otherwise.
+ */
+ virtual bool renameSavefile(const char *oldFilename, const char *newFilename);
+
+ /**
* Request a list of available savegames with a given regex.
* @param regex Regular expression to match. Wildcards like * or ? are available.
* returns a list of strings for all present file names.