aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/dc
diff options
context:
space:
mode:
authorMarcus Comstedt2007-10-03 22:04:36 +0000
committerMarcus Comstedt2007-10-03 22:04:36 +0000
commit9e8167b10ce21d8286bcdd39a2de30f0da6d3aee (patch)
treeff65e0468869bc53b6bc91e29d15d3c5e402a1de /backends/platform/dc
parent151e0cfa050b0ecfa7ff60f3bc1a99cc9ebef401 (diff)
downloadscummvm-rg350-9e8167b10ce21d8286bcdd39a2de30f0da6d3aee.tar.gz
scummvm-rg350-9e8167b10ce21d8286bcdd39a2de30f0da6d3aee.tar.bz2
scummvm-rg350-9e8167b10ce21d8286bcdd39a2de30f0da6d3aee.zip
* Added removeSavefile()
* New style listSavefiles() using a glob svn-id: r29153
Diffstat (limited to 'backends/platform/dc')
-rw-r--r--backends/platform/dc/vmsave.cpp84
1 files changed, 71 insertions, 13 deletions
diff --git a/backends/platform/dc/vmsave.cpp b/backends/platform/dc/vmsave.cpp
index 39526a48c3..5200cc8a72 100644
--- a/backends/platform/dc/vmsave.cpp
+++ b/backends/platform/dc/vmsave.cpp
@@ -156,13 +156,54 @@ static bool tryLoad(char *&buffer, int &size, const char *filename, int vm)
return false;
}
-static void tryList(const char *prefix, bool *marks, int num, int vm)
+static bool tryDelete(const char *filename, int vm)
+{
+ struct vmsinfo info;
+ struct superblock super;
+
+ if (!vmsfs_check_unit(vm, 0, &info))
+ return false;
+ if (!vmsfs_get_superblock(&info, &super))
+ return false;
+
+#if 0
+ // FIXME: implement this function in vmsfs...
+ if (!vmsfs_delete_file(&super, filename))
+ return false;
+#else
+ return false;
+#endif
+
+ return true;
+}
+
+static bool matches(const char *glob, const char *name)
+{
+ while(*glob)
+ if(*glob == '*') {
+ while(*glob == '*')
+ glob++;
+ do {
+ if((*name == *glob || *glob == '?') &&
+ matches(glob, name))
+ return true;
+ } while(*name++);
+ return false;
+ } else if(!*name)
+ return false;
+ else if(*glob == '?' || *glob == *name) {
+ glob++;
+ name++;
+ }
+ return !*name;
+}
+
+static void tryList(const char *glob, int vm, Common::StringList &list)
{
struct vmsinfo info;
struct superblock super;
struct dir_iterator iter;
struct dir_entry de;
- int pl = strlen(prefix);
if (!vmsfs_check_unit(vm, 0, &info))
return;
@@ -171,15 +212,11 @@ static void tryList(const char *prefix, bool *marks, int num, int vm)
vmsfs_open_dir(&super, &iter);
while (vmsfs_next_dir_entry(&iter, &de))
if (de.entry[0]) {
- char buf[16], *endp = NULL;
+ char buf[16];
strncpy(buf, (char *)de.entry+4, 12);
buf[12] = 0;
- int l = strlen(buf);
- long i = 42;
- if (l > pl && !strncmp(buf, prefix, pl) &&
- (i = strtol(buf+pl, &endp, 10))>=0 && i<num &&
- (endp - buf) == l)
- marks[i] = true;
+ if (matches(glob, buf))
+ list.push_back(buf);
}
}
@@ -217,6 +254,21 @@ bool readSaveGame(char *&buffer, int &size, const char *filename)
return false;
}
+bool deleteSaveGame(const char *filename)
+{
+ if (lastvm >= 0 &&
+ tryDelete(filename, lastvm))
+ return true;
+
+ for (int i=0; i<24; i++)
+ if (tryDelete(filename, i)) {
+ lastvm = i;
+ return true;
+ }
+
+ return false;
+}
+
class InVMSave : public Common::InSaveFile {
private:
@@ -302,7 +354,11 @@ public:
}
}
- virtual void listSavefiles(const char *prefix, bool *marks, int num);
+ virtual bool removeSavefile(const char *filename) {
+ return ::deleteSaveGame(filename);
+ }
+
+ virtual Common::StringList VMSaveManager::listSavefiles(const char *glob);
};
void OutVMSave::finalize()
@@ -394,12 +450,14 @@ uint32 OutVMSave::write(const void *buf, uint32 cnt)
}
-void VMSaveManager::listSavefiles(const char *prefix, bool *marks, int num)
+Common::StringList VMSaveManager::listSavefiles(const char *glob)
{
- memset(marks, false, num*sizeof(bool));
+ Common::StringList list;
for (int i=0; i<24; i++)
- tryList(prefix, marks, num, i);
+ tryList(glob, i, list);
+
+ return list;
}
Common::SaveFileManager *OSystem_Dreamcast::createSavefileManager()