aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorMarcus Comstedt2003-08-10 20:49:13 +0000
committerMarcus Comstedt2003-08-10 20:49:13 +0000
commita5aa5c0d73fa3c9faec0ba167cb88d3595f089e5 (patch)
tree252958493844e9bf628dcaeb84a9e658557af648 /backends
parent9d09512765bcca0a507361297aa70c8f122ce512 (diff)
downloadscummvm-rg350-a5aa5c0d73fa3c9faec0ba167cb88d3595f089e5.tar.gz
scummvm-rg350-a5aa5c0d73fa3c9faec0ba167cb88d3595f089e5.tar.bz2
scummvm-rg350-a5aa5c0d73fa3c9faec0ba167cb88d3595f089e5.zip
Harmonized SaveFile API with File API a bit.
svn-id: r9626
Diffstat (limited to 'backends')
-rw-r--r--backends/PalmOS/Src/palmsave.cpp24
-rw-r--r--backends/dc/vmsave.cpp17
2 files changed, 22 insertions, 19 deletions
diff --git a/backends/PalmOS/Src/palmsave.cpp b/backends/PalmOS/Src/palmsave.cpp
index b19e8494f4..224a5c12a7 100644
--- a/backends/PalmOS/Src/palmsave.cpp
+++ b/backends/PalmOS/Src/palmsave.cpp
@@ -36,10 +36,9 @@ public:
~PalmSaveFile();
bool is_open() { return file != NULL; }
+protected:
int fread(void *buf, int size, int cnt);
- int fwrite(void *buf, int size, int cnt);
-// must be removed
- int feof() { return ::feof(file); }
+ int fwrite(const void *buf, int size, int cnt);
private :
FILE *file;
@@ -71,7 +70,7 @@ int PalmSaveFile::fread(void *buf, int size, int cnt) {
return ::fread(buf, size, cnt, file);
}
-int PalmSaveFile::fwrite(void *buf, int size, int cnt) {
+int PalmSaveFile::fwrite(const void *buf, int size, int cnt) {
UInt32 fullsize = size*cnt;
if (fullsize <= MAX_BLOCK)
@@ -104,8 +103,12 @@ public:
void list_savefiles(const char *prefix, bool *marks, int num);
};
-SaveFile *PalmSaveFileManager::open_savefile(const char *filename, bool saveOrLoad) {
- PalmSaveFile *sf = new PalmSaveFile(filename, (saveOrLoad? "wb":"rb"));
+SaveFile *PalmSaveFileManager::open_savefile(const char *filename, const char *dirname, bool saveOrLoad) {
+ char buf[256];
+
+ join_paths(filename, dirname, buf, sizeof(buf));
+
+ PalmSaveFile *sf = new PalmSaveFile(buf, (saveOrLoad? "wb":"rb"));
if(!sf->is_open()) {
delete sf;
@@ -115,21 +118,20 @@ SaveFile *PalmSaveFileManager::open_savefile(const char *filename, bool saveOrLo
return sf;
}
-void PalmSaveFileManager::list_savefiles(const char *prefix, bool *marks, int num) {
+void PalmSaveFileManager::list_savefiles(const char *prefix, const char *direcory, bool *marks, int num) {
FileRef fileRef;
// try to open the dir
- Err e = VFSFileOpen(gVars->volRefNum, SCUMMVM_SAVEPATH, vfsModeRead, &fileRef);
+ Err e = VFSFileOpen(gVars->volRefNum, directory, vfsModeRead, &fileRef);
memset(marks, false, num*sizeof(bool));
if (e != errNone)
return;
// enumerate all files
- Char *nameonly = strrchr(prefix,'/') + 1;
UInt32 dirEntryIterator = vfsIteratorStart;
Char filename[32];
FileInfoType info = {0, filename, 32};
- UInt16 length = StrLen(nameonly);
+ UInt16 length = StrLen(prefix);
int slot = 0;
while (dirEntryIterator != vfsIteratorStop) {
@@ -138,7 +140,7 @@ void PalmSaveFileManager::list_savefiles(const char *prefix, bool *marks, int nu
if (e != expErrEnumerationEmpty) { // there is something
if (StrLen(info.nameP) == (length + 2)) { // consider max 99, filename length is ok
- if (StrNCaselessCompare(nameonly, info.nameP, length) == 0) { // this seems to be a save file
+ if (StrNCaselessCompare(prefix, info.nameP, length) == 0) { // this seems to be a save file
if (isdigit(info.nameP[length]) && isdigit(info.nameP[length+1])) {
slot = StrAToI(filename + length);
diff --git a/backends/dc/vmsave.cpp b/backends/dc/vmsave.cpp
index fa2c2f566f..8eaf06f83c 100644
--- a/backends/dc/vmsave.cpp
+++ b/backends/dc/vmsave.cpp
@@ -224,6 +224,10 @@ private:
int pos, size;
char filename[16];
+protected:
+ virtual int fread(void *buf, int size, int cnt);
+ virtual int fwrite(const void *buf, int size, int cnt);
+
public:
VMSave(const char *_filename, bool _saveOrLoad)
: issave(_saveOrLoad), pos(0), buffer(NULL)
@@ -235,9 +239,6 @@ public:
~VMSave();
- virtual int fread(void *buf, int size, int cnt);
- virtual int fwrite(void *buf, int size, int cnt);
-
bool readSaveGame()
{ return ::readSaveGame(buffer, size, filename); }
@@ -257,11 +258,11 @@ public:
};
class VMSaveManager : public SaveFileManager {
- virtual SaveFile *open_savefile(const char *filename, bool saveOrLoad);
- virtual void list_savefiles(const char *prefix, bool *marks, int num);
+ virtual SaveFile *open_savefile(const char *filename, const char *directory, bool saveOrLoad);
+ virtual void list_savefiles(const char *prefix, const char *directory, bool *marks, int num);
};
-SaveFile *VMSaveManager::open_savefile(const char *filename,
+SaveFile *VMSaveManager::open_savefile(const char *filename, const char *directory,
bool saveOrLoad)
{
VMSave *s = new VMSave(filename, saveOrLoad);
@@ -314,7 +315,7 @@ int VMSave::fread(void *buf, int sz, int cnt)
return cnt;
}
-int VMSave::fwrite(void *buf, int sz, int cnt)
+int VMSave::fwrite(const void *buf, int sz, int cnt)
{
if (!issave)
return -1;
@@ -331,7 +332,7 @@ int VMSave::fwrite(void *buf, int sz, int cnt)
}
-void VMSaveManager::list_savefiles(const char *prefix,
+void VMSaveManager::list_savefiles(const char *prefix, const char *directory,
bool *marks, int num)
{
memset(marks, false, num*sizeof(bool));