aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/saves/default/default-saves.cpp25
-rw-r--r--backends/saves/default/default-saves.h2
2 files changed, 21 insertions, 6 deletions
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index 1898a23f2a..8c9b0ffd2a 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -28,6 +28,7 @@
#include "common/stdafx.h"
#include "common/savefile.h"
#include "common/util.h"
+#include "common/fs.h"
#include "backends/saves/default/default-saves.h"
#include "backends/saves/compressed/compressed-saves.h"
@@ -179,11 +180,25 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename)
return wrapInSaveFile(sf);
}
-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));
+void DefaultSaveFileManager::listSavefiles(const char *prefix , bool *marks, int num) {
+ FilesystemNode savePath(getSavePath());
+ FSList savefiles;
+ Common::String search(prefix);
+ search += '*'; //match all files that start with the given prefix
+ search.c_str(); //FIXME: subtle bug? removing this line will break things. Looks like the string isn't getting updated.
+
+ memset(marks, false, num * sizeof(bool)); //assume no savegames for this title
+
+ if(savePath.lookupFile(savefiles, savePath, search, false, true)) {
+ char slot[2];
+ for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) {
+ //TODO: check if this is the behavior for all engines
+ //Obtain the last 2 digits of the filename, since they correspond to the save slot
+ slot[0] = file->getName()[file->getName().size()-2];
+ slot[1] = file->getName()[file->getName().size()-1];
+ marks[atoi(slot)] = true; //mark this slot as valid
+ }
+ }
}
#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
diff --git a/backends/saves/default/default-saves.h b/backends/saves/default/default-saves.h
index 3aea1495a4..a3e2037a5c 100644
--- a/backends/saves/default/default-saves.h
+++ b/backends/saves/default/default-saves.h
@@ -33,7 +33,7 @@ class DefaultSaveFileManager : public Common::SaveFileManager {
public:
virtual Common::OutSaveFile *openForSaving(const char *filename);
virtual Common::InSaveFile *openForLoading(const char *filename);
- virtual void listSavefiles(const char * /* prefix */, bool *marks, int num);
+ virtual void listSavefiles(const char *prefix, bool *marks, int num);
};
#endif