aboutsummaryrefslogtreecommitdiff
path: root/backends/fs
diff options
context:
space:
mode:
authorFabio Battaglia2009-12-30 22:56:19 +0000
committerFabio Battaglia2009-12-30 22:56:19 +0000
commit3a418c13a7ab9790bb9b43bfc435056827a79e64 (patch)
tree14fbf03424597cd89b98b10f189e0b54c97f3326 /backends/fs
parentdc5524bda56007c4ea2006bf5f970f35392beb82 (diff)
downloadscummvm-rg350-3a418c13a7ab9790bb9b43bfc435056827a79e64.tar.gz
scummvm-rg350-3a418c13a7ab9790bb9b43bfc435056827a79e64.tar.bz2
scummvm-rg350-3a418c13a7ab9790bb9b43bfc435056827a79e64.zip
remove bad hackery caused by n64 port and avoid polluting StdioStream using a custom Stream subclass
svn-id: r46777
Diffstat (limited to 'backends/fs')
-rw-r--r--backends/fs/n64/n64-fs.cpp8
-rw-r--r--backends/fs/n64/romfsstream.cpp86
-rw-r--r--backends/fs/n64/romfsstream.h59
-rw-r--r--backends/fs/stdiostream.cpp22
4 files changed, 148 insertions, 27 deletions
diff --git a/backends/fs/n64/n64-fs.cpp b/backends/fs/n64/n64-fs.cpp
index 514e3be02d..4def84afcd 100644
--- a/backends/fs/n64/n64-fs.cpp
+++ b/backends/fs/n64/n64-fs.cpp
@@ -23,12 +23,10 @@
#ifdef __N64__
#include "backends/fs/abstract-fs.h"
-#include "backends/fs/stdiostream.h"
+#include "backends/fs/n64/romfsstream.h"
#include <sys/param.h>
-
#include <unistd.h>
-
#include <n64utils.h>
#define ROOT_PATH "/"
@@ -202,11 +200,11 @@ AbstractFSNode *N64FilesystemNode::getParent() const {
}
Common::SeekableReadStream *N64FilesystemNode::createReadStream() {
- return StdioStream::makeFromPath(getPath(), false);
+ return RomfsStream::makeFromPath(getPath(), false);
}
Common::WriteStream *N64FilesystemNode::createWriteStream() {
- return StdioStream::makeFromPath(getPath(), true);
+ return RomfsStream::makeFromPath(getPath(), true);
}
#endif //#ifdef __N64__
diff --git a/backends/fs/n64/romfsstream.cpp b/backends/fs/n64/romfsstream.cpp
new file mode 100644
index 0000000000..2d30f852ca
--- /dev/null
+++ b/backends/fs/n64/romfsstream.cpp
@@ -0,0 +1,86 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef __N64__
+
+#include <romfs.h>
+#include "backends/fs/n64/romfsstream.h"
+
+RomfsStream::RomfsStream(void *handle) : _handle(handle) {
+ assert(handle);
+}
+
+RomfsStream::~RomfsStream() {
+ romfs_close((ROMFILE *)_handle);
+}
+
+bool RomfsStream::err() const {
+ return romfs_error((ROMFILE *)_handle) != 0;
+}
+
+void RomfsStream::clearErr() {
+ romfs_clearerr((ROMFILE *)_handle);
+}
+
+bool RomfsStream::eos() const {
+ return romfs_eof((ROMFILE *)_handle) != 0;
+}
+
+int32 RomfsStream::pos() const {
+ return romfs_tell((ROMFILE *)_handle);
+}
+
+int32 RomfsStream::size() const {
+ int32 oldPos = romfs_tell((ROMFILE *)_handle);
+ romfs_seek((ROMFILE *)_handle, 0, SEEK_END);
+ int32 length = romfs_tell((ROMFILE *)_handle);
+ romfs_seek((ROMFILE *)_handle, oldPos, SEEK_SET);
+
+ return length;
+}
+
+bool RomfsStream::seek(int32 offs, int whence) {
+ return romfs_seek((ROMFILE *)_handle, offs, whence) == 0;
+}
+
+uint32 RomfsStream::read(void *ptr, uint32 len) {
+ return romfs_read((byte *)ptr, 1, len, (ROMFILE *)_handle);
+}
+
+uint32 RomfsStream::write(const void *ptr, uint32 len) {
+ return romfs_write(ptr, 1, len, (ROMFILE *)_handle);
+}
+
+bool RomfsStream::flush() {
+ return romfs_flush((ROMFILE *)_handle) == 0;
+}
+
+RomfsStream *RomfsStream::makeFromPath(const Common::String &path, bool writeMode) {
+ ROMFILE *handle = romfs_open(path.c_str(), writeMode ? "wb" : "rb");
+
+ if (handle)
+ return new RomfsStream(handle);
+ return 0;
+}
+
+#endif /* __N64__ */
+
diff --git a/backends/fs/n64/romfsstream.h b/backends/fs/n64/romfsstream.h
new file mode 100644
index 0000000000..b0f27db13e
--- /dev/null
+++ b/backends/fs/n64/romfsstream.h
@@ -0,0 +1,59 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_FS_ROMFSSTREAM_H
+#define BACKENDS_FS_ROMFSSTREAM_H
+
+#include "common/scummsys.h"
+#include "common/noncopyable.h"
+#include "common/stream.h"
+#include "common/str.h"
+
+class RomfsStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
+protected:
+ /** File handle to the actual file. */
+ void *_handle;
+
+public:
+ /**
+ * Given a path, invokes fopen on that path and wrap the result in a
+ * RomfsStream instance.
+ */
+ static RomfsStream *makeFromPath(const Common::String &path, bool writeMode);
+
+ RomfsStream(void *handle);
+ virtual ~RomfsStream();
+
+ virtual bool err() const;
+ virtual void clearErr();
+ virtual bool eos() const;
+
+ virtual uint32 write(const void *dataPtr, uint32 dataSize);
+ virtual bool flush();
+
+ virtual int32 pos() const;
+ virtual int32 size() const;
+ virtual bool seek(int32 offs, int whence = SEEK_SET);
+ virtual uint32 read(void *dataPtr, uint32 dataSize);
+};
+
+#endif
diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp
index 73796a31ea..8845d796c6 100644
--- a/backends/fs/stdiostream.cpp
+++ b/backends/fs/stdiostream.cpp
@@ -25,28 +25,6 @@
#include "backends/fs/stdiostream.h"
-#ifdef __N64__
- #include <romfs.h>
-
- #undef feof
- #undef clearerr
- #undef ferror
-
- #undef FILE
- #define FILE ROMFILE
-
- #define fopen(name, mode) romfs_open(name, mode)
- #define fclose(handle) romfs_close(handle)
- #define fread(ptr, size, items, file) romfs_read(ptr, size, items, file)
- #define fwrite(ptr, size, items, file) romfs_write(ptr, size, items, file)
- #define feof(handle) romfs_eof(handle)
- #define ftell(handle) romfs_tell(handle)
- #define fseek(handle, offset, whence) romfs_seek(handle, offset, whence)
- #define clearerr(handle) romfs_clearerr(handle)
- #define fflush(file) romfs_flush(file)
- #define ferror(handle) romfs_error(handle)
-#endif
-
StdioStream::StdioStream(void *handle) : _handle(handle) {
assert(handle);
}