aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2008-09-03 12:56:46 +0000
committerMax Horn2008-09-03 12:56:46 +0000
commit7f18aaf8ec92a7ec7cd837db92b93dfada87eef3 (patch)
treee1510dfc5cd2b50b0d77c5a384307174687c4116
parent320a5dc99fa416d63a5fb8ec63c07463c80dc633 (diff)
downloadscummvm-rg350-7f18aaf8ec92a7ec7cd837db92b93dfada87eef3.tar.gz
scummvm-rg350-7f18aaf8ec92a7ec7cd837db92b93dfada87eef3.tar.bz2
scummvm-rg350-7f18aaf8ec92a7ec7cd837db92b93dfada87eef3.zip
Pushed AbstractFilesystemNode::openForReading() / openForWriting() impls out to backends
svn-id: r34304
-rw-r--r--backends/fs/abstract-fs.cpp20
-rw-r--r--backends/fs/abstract-fs.h4
-rw-r--r--backends/fs/amigaos4/amigaos4-fs.cpp14
-rw-r--r--backends/fs/ds/ds-fs.cpp17
-rw-r--r--backends/fs/ds/ds-fs.h6
-rw-r--r--backends/fs/palmos/palmos-fs.cpp12
-rw-r--r--backends/fs/posix/posix-fs.cpp9
-rw-r--r--backends/fs/posix/posix-fs.h3
-rw-r--r--backends/fs/ps2/ps2-fs.cpp11
-rw-r--r--backends/fs/psp/psp-fs.cpp12
-rw-r--r--backends/fs/stdiostream.cpp7
-rw-r--r--backends/fs/stdiostream.h7
-rw-r--r--backends/fs/symbian/symbian-fs.cpp12
-rw-r--r--backends/fs/wii/wii-fs.cpp12
-rw-r--r--backends/fs/windows/windows-fs.cpp12
-rw-r--r--backends/platform/dc/dc-fs.cpp13
16 files changed, 149 insertions, 22 deletions
diff --git a/backends/fs/abstract-fs.cpp b/backends/fs/abstract-fs.cpp
index 80ff2b05c5..6daad7152a 100644
--- a/backends/fs/abstract-fs.cpp
+++ b/backends/fs/abstract-fs.cpp
@@ -23,9 +23,9 @@
*/
#include "backends/fs/abstract-fs.h"
-#include "backends/fs/stdiostream.h"
const char *AbstractFilesystemNode::lastPathComponent(const Common::String &str, const char sep) {
+ // TODO: Get rid of this eventually! Use Common::lastPathComponent instead
if(str.empty())
return "";
@@ -38,21 +38,3 @@ const char *AbstractFilesystemNode::lastPathComponent(const Common::String &str,
return cur + 1;
}
-
-Common::SeekableReadStream *AbstractFilesystemNode::openForReading() {
- // FIXME: Until openForReading is supported by all AbstractFilesystemNode
- // implementations, we provide this "generic" one, using Common::File.
- FILE *handle = fopen(getPath().c_str(), "rb");
- if (handle)
- return new StdioStream(handle);
- return 0;
-}
-
-Common::WriteStream *AbstractFilesystemNode::openForWriting() {
- // FIXME: Until openForWriting is supported by all AbstractFilesystemNode
- // implementations, we provide this "generic" one.
- FILE *handle = fopen(getPath().c_str(), "wb");
- if (handle)
- return new StdioStream(handle);
- return 0;
-}
diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h
index a2a1aa8ac3..b3a652f2ae 100644
--- a/backends/fs/abstract-fs.h
+++ b/backends/fs/abstract-fs.h
@@ -169,7 +169,7 @@ public:
*
* @return pointer to the stream object, 0 in case of a failure
*/
- virtual Common::SeekableReadStream *openForReading();
+ virtual Common::SeekableReadStream *openForReading() = 0;
/**
* Creates a WriteStream instance corresponding to the file
@@ -178,7 +178,7 @@ public:
*
* @return pointer to the stream object, 0 in case of a failure
*/
- virtual Common::WriteStream *openForWriting();
+ virtual Common::WriteStream *openForWriting() = 0;
};
diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp
index 4f6bce39b3..816fb34679 100644
--- a/backends/fs/amigaos4/amigaos4-fs.cpp
+++ b/backends/fs/amigaos4/amigaos4-fs.cpp
@@ -36,8 +36,9 @@
#endif
#include "common/util.h"
-#include "engines/engine.h"
+#include "engines/engine.h" // FIXME: Why is this here????
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#define ENTER() /* debug(6, "Enter") */
#define LEAVE() /* debug(6, "Leave") */
@@ -107,6 +108,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
/**
* Creates a list with all the volumes present in the root node.
*/
@@ -566,4 +570,12 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const {
return myList;
}
+Common::SeekableReadStream *AmigaOSFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *AmigaOSFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif //defined(__amigaos4__)
diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp
index db6a63cad7..d482109fdb 100644
--- a/backends/fs/ds/ds-fs.cpp
+++ b/backends/fs/ds/ds-fs.cpp
@@ -24,6 +24,7 @@
#include "common/util.h"
//#include <NDS/ARM9/console.h> //basic print funcionality
#include "backends/fs/ds/ds-fs.h"
+#include "backends/fs/stdiostream.h"
#include "dsmain.h"
#include "fat/gba_nds_fat.h"
@@ -204,6 +205,14 @@ AbstractFilesystemNode* DSFileSystemNode::getParent() const {
return p;
}
+Common::SeekableReadStream *DSFileSystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *DSFileSystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
//////////////////////////////////////////////////////////////////////////
// GBAMPFileSystemNode - File system using GBA Movie Player and CF card //
//////////////////////////////////////////////////////////////////////////
@@ -367,6 +376,14 @@ AbstractFilesystemNode* GBAMPFileSystemNode::getParent() const {
return p;
}
+Common::SeekableReadStream *GBAMPFileSystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *GBAMPFileSystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
// Stdio replacements
#define MAX_FILE_HANDLES 32
diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h
index 2856ec4903..2c1924a2fb 100644
--- a/backends/fs/ds/ds-fs.h
+++ b/backends/fs/ds/ds-fs.h
@@ -90,6 +90,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
/**
* Returns the zip file this node points to.
* TODO: check this documentation.
@@ -151,6 +154,9 @@ public:
virtual AbstractFilesystemNode *getChild(const Common::String& name) const;
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
};
struct fileHandle {
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp
index 522d7682cc..7c415aa320 100644
--- a/backends/fs/palmos/palmos-fs.cpp
+++ b/backends/fs/palmos/palmos-fs.cpp
@@ -28,6 +28,7 @@
#include "globals.h"
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
/**
* Implementation of the ScummVM file system API based on PalmOS VFS API.
@@ -67,6 +68,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
private:
/**
* Adds a single WindowsFilesystemNode to a given list.
@@ -204,4 +208,12 @@ AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const {
return p;
}
+Common::SeekableReadStream *PalmOSFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *PalmOSFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif // PALMOS_MODE
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index 992d54456b..72f45a5b27 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -25,6 +25,7 @@
#if defined(UNIX)
#include "backends/fs/posix/posix-fs.h"
+#include "backends/fs/stdiostream.h"
#include "common/algorithm.h"
#include <sys/param.h>
@@ -231,4 +232,12 @@ AbstractFilesystemNode *POSIXFilesystemNode::getParent() const {
return new POSIXFilesystemNode(Common::String(start, end), true);
}
+Common::SeekableReadStream *POSIXFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *POSIXFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif //#if defined(UNIX)
diff --git a/backends/fs/posix/posix-fs.h b/backends/fs/posix/posix-fs.h
index df50fc16af..9459b38010 100644
--- a/backends/fs/posix/posix-fs.h
+++ b/backends/fs/posix/posix-fs.h
@@ -70,6 +70,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
private:
/**
* Tests and sets the _isValid and _isDirectory flags, using the stat() function.
diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp
index 65ea86826c..3d7656e9f0 100644
--- a/backends/fs/ps2/ps2-fs.cpp
+++ b/backends/fs/ps2/ps2-fs.cpp
@@ -23,6 +23,7 @@
*/
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#include <kernel.h>
#include <stdio.h>
#include <stdlib.h>
@@ -98,6 +99,9 @@ public:
virtual AbstractFilesystemNode *getChild(const Common::String &n) const;
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
};
Ps2FilesystemNode::Ps2FilesystemNode() {
@@ -337,3 +341,10 @@ char *Ps2FilesystemNode::getDeviceDescription(const char *path) const {
return "Harddisk";
}
+Common::SeekableReadStream *Ps2FilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *Ps2FilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
diff --git a/backends/fs/psp/psp-fs.cpp b/backends/fs/psp/psp-fs.cpp
index e5d66d7350..13cd63903b 100644
--- a/backends/fs/psp/psp-fs.cpp
+++ b/backends/fs/psp/psp-fs.cpp
@@ -26,6 +26,7 @@
#include "engines/engine.h"
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#include <sys/stat.h>
#include <unistd.h>
@@ -69,6 +70,9 @@ public:
virtual AbstractFilesystemNode *getChild(const Common::String &n) const;
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
};
PSPFilesystemNode::PSPFilesystemNode() {
@@ -157,4 +161,12 @@ AbstractFilesystemNode *PSPFilesystemNode::getParent() const {
return new PSPFilesystemNode(Common::String(start, end - start), false);
}
+Common::SeekableReadStream *PSPFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *PSPFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif //#ifdef __PSP__
diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp
index 8fde1b1eb8..dfb01362e1 100644
--- a/backends/fs/stdiostream.cpp
+++ b/backends/fs/stdiostream.cpp
@@ -191,3 +191,10 @@ void StdioStream::flush() {
// check errno and set an error flag.
fflush((FILE *)_handle);
}
+
+StdioStream *StdioStream::makeFromPath(const Common::String &path, bool writeMode) {
+ FILE *handle = fopen(path.c_str(), writeMode ? "wb" : "rb");
+ if (handle)
+ return new StdioStream(handle);
+ return 0;
+}
diff --git a/backends/fs/stdiostream.h b/backends/fs/stdiostream.h
index fc2d68d7b3..02e5463f63 100644
--- a/backends/fs/stdiostream.h
+++ b/backends/fs/stdiostream.h
@@ -29,6 +29,7 @@
#include "common/scummsys.h"
#include "common/noncopyable.h"
#include "common/stream.h"
+#include "common/str.h"
class StdioStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
protected:
@@ -36,6 +37,12 @@ protected:
void *_handle;
public:
+ /**
+ * Given a path, invokes fopen on that path and wrap the result in a
+ * StdioStream instance.
+ */
+ static StdioStream *makeFromPath(const Common::String &path, bool writeMode);
+
StdioStream(void *handle);
virtual ~StdioStream();
diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp
index a59f06b9eb..a6f359a4ae 100644
--- a/backends/fs/symbian/symbian-fs.cpp
+++ b/backends/fs/symbian/symbian-fs.cpp
@@ -24,6 +24,7 @@
#if defined (__SYMBIAN32__)
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#include "backends/platform/symbian/src/SymbianOS.h"
#include <dirent.h>
@@ -76,6 +77,9 @@ public:
virtual AbstractFilesystemNode *getChild(const Common::String &n) const;
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
};
/**
@@ -248,4 +252,12 @@ AbstractFilesystemNode *SymbianFilesystemNode::getParent() const {
return p;
}
+Common::SeekableReadStream *SymbianFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *SymbianFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif //#if defined (__SYMBIAN32__)
diff --git a/backends/fs/wii/wii-fs.cpp b/backends/fs/wii/wii-fs.cpp
index 0d489d3a99..a620df5471 100644
--- a/backends/fs/wii/wii-fs.cpp
+++ b/backends/fs/wii/wii-fs.cpp
@@ -23,6 +23,7 @@
#if defined(__WII__)
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#include <sys/dir.h>
@@ -67,6 +68,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
private:
virtual void setFlags();
};
@@ -168,5 +172,13 @@ AbstractFilesystemNode *WiiFilesystemNode::getParent() const {
return new WiiFilesystemNode(Common::String(start, end - start), true);
}
+Common::SeekableReadStream *WiiFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *WiiFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif //#if defined(__WII__)
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index 5d8c2f009c..c59c7dbe71 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -31,6 +31,7 @@
#undef GetCurrentDirectory
#endif
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
@@ -98,6 +99,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
private:
/**
* Adds a single WindowsFilesystemNode to a given list.
@@ -303,4 +307,12 @@ AbstractFilesystemNode *WindowsFilesystemNode::getParent() const {
return p;
}
+Common::SeekableReadStream *WindowsFilesystemNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *WindowsFilesystemNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
#endif //#ifdef WIN32
diff --git a/backends/platform/dc/dc-fs.cpp b/backends/platform/dc/dc-fs.cpp
index c1b31d4815..c4f1d76f10 100644
--- a/backends/platform/dc/dc-fs.cpp
+++ b/backends/platform/dc/dc-fs.cpp
@@ -24,6 +24,7 @@
#include "dc.h"
#include "backends/fs/abstract-fs.h"
+#include "backends/fs/stdiostream.h"
#include <ronin/cdfs.h>
#include <stdio.h>
@@ -52,6 +53,9 @@ public:
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const { return false; }
virtual AbstractFilesystemNode *getParent() const;
+ virtual Common::SeekableReadStream *openForReading();
+ virtual Common::WriteStream *openForWriting();
+
static AbstractFilesystemNode *makeFileNodePath(const Common::String &path);
};
@@ -143,6 +147,15 @@ AbstractFilesystemNode *RoninCDFileNode::getParent() const {
return new RoninCDDirectoryNode(Common::String(start, end - start));
}
+
+Common::SeekableReadStream *RoninCDFileNode::openForReading() {
+ return StdioStream::makeFromPath(getPath().c_str(), false);
+}
+
+Common::WriteStream *RoninCDFileNode::openForWriting() {
+ return StdioStream::makeFromPath(getPath().c_str(), true);
+}
+
AbstractFilesystemNode *OSystem_Dreamcast::makeRootFileNode() const {
return new RoninCDDirectoryNode("/");
}