[Scummvm-cvs-logs] SF.net SVN: scummvm:[35504] scummvm/trunk/backends/fs/wii/wii-fs.cpp

dhewg at users.sourceforge.net dhewg at users.sourceforge.net
Tue Dec 23 20:23:12 CET 2008


Revision: 35504
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35504&view=rev
Author:   dhewg
Date:     2008-12-23 19:23:11 +0000 (Tue, 23 Dec 2008)

Log Message:
-----------
changes for the new libfat version. the root node now yields a list of all mounted devices

Modified Paths:
--------------
    scummvm/trunk/backends/fs/wii/wii-fs.cpp

Modified: scummvm/trunk/backends/fs/wii/wii-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/wii/wii-fs.cpp	2008-12-23 19:20:20 UTC (rev 35503)
+++ scummvm/trunk/backends/fs/wii/wii-fs.cpp	2008-12-23 19:23:11 UTC (rev 35504)
@@ -25,12 +25,14 @@
 #include "backends/fs/abstract-fs.h"
 #include "backends/fs/stdiostream.h"
 
+#include <sys/iosupport.h>
 #include <sys/dir.h>
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <gctypes.h>
+
 /**
  * Implementation of the ScummVM file system API based on Wii.
  *
@@ -42,6 +44,9 @@
 	Common::String _path;
 	bool _isDirectory, _isReadable, _isWritable;
 
+	virtual void initRootNode();
+	virtual bool getDevopChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
+
 public:
 	/**
 	 * Creates a WiiFilesystemNode with the root node as path.
@@ -70,43 +75,67 @@
 
 	virtual Common::SeekableReadStream *openForReading();
 	virtual Common::WriteStream *openForWriting();
-
-private:
-	virtual void setFlags();
 };
 
-void WiiFilesystemNode::setFlags() {
-	struct stat st;
+// gets all registered devoptab devices
+bool WiiFilesystemNode::getDevopChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
+	u8 i;
+	const devoptab_t* dt;
 
-	_isDirectory = false;
-	_isReadable = false;
-	_isWritable = false;
+	if (mode == Common::FSNode::kListFilesOnly)
+		return true;
 
-	if (!stat(_path.c_str(), &st)) {
-		_isDirectory = S_ISDIR(st.st_mode);
-		_isReadable = (st.st_mode & S_IRUSR) > 0;
-		_isWritable = (st.st_mode & S_IWUSR) > 0;
+	// skip in, out and err
+	for (i = 3; i < STD_MAX; ++i) {
+		dt = devoptab_list[i];
+
+		if (!dt || !dt->name || !dt->open_r || !dt->diropen_r)
+			continue;
+	
+		list.push_back(new WiiFilesystemNode(Common::String(dt->name) + ":/", true));
 	}
+
+	return true;
 }
 
+void WiiFilesystemNode::initRootNode() {
+	_path.clear();
+	_displayName = "<devices>";
 
+	_isDirectory = true;
+	_isReadable = false;
+	_isWritable = false;
+}
+
 WiiFilesystemNode::WiiFilesystemNode() {
-	// The root dir.
-	_path = "fat:/";
-	_displayName = _path;
-
-	setFlags();
+	initRootNode();
 }
 
 WiiFilesystemNode::WiiFilesystemNode(const Common::String &p, bool verify) {
-	assert(p.size() > 0);
+	if (p.empty()) {
+		initRootNode();
+		return;
+	}
 
 	_path = p;
 
-	_displayName = lastPathComponent(_path, '/');
+	if (_path.hasSuffix(":/"))
+		_displayName = _path;
+	else
+		_displayName = lastPathComponent(_path, '/');
 
-	if (verify)
-		setFlags();
+	if (verify) {
+		_isDirectory = false;
+		_isReadable = false;
+		_isWritable = false;
+
+		struct stat st;
+		if (!stat(_path.c_str(), &st)) {
+			_isDirectory = S_ISDIR(st.st_mode);
+			_isReadable = (st.st_mode & S_IRUSR) > 0;
+			_isWritable = (st.st_mode & S_IWUSR) > 0;
+		}
+	}
 }
 
 bool WiiFilesystemNode::exists() const {
@@ -119,15 +148,18 @@
 
 	Common::String newPath(_path);
 	if (newPath.lastChar() != '/')
-			newPath += '/';
+		newPath += '/';
 	newPath += n;
 
 	return new WiiFilesystemNode(newPath, true);
 }
 
-bool WiiFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
+bool WiiFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
 	assert(_isDirectory);
 
+	if (_path.empty())
+		return getDevopChildren(list, mode, hidden);
+
 	DIR_ITER* dp = diropen (_path.c_str());
 
 	if (dp == NULL)
@@ -142,7 +174,7 @@
 
 		Common::String newPath(_path);
 		if (newPath.lastChar() != '/')
-				newPath += '/';
+			newPath += '/';
 		newPath += filename;
 
 		bool isDir = S_ISDIR(st.st_mode);
@@ -154,7 +186,7 @@
 		if (isDir)
 			newPath += '/';
 
-		myList.push_back(new WiiFilesystemNode(newPath, true));
+		list.push_back(new WiiFilesystemNode(newPath, true));
 	}
 
 	dirclose(dp);
@@ -163,8 +195,8 @@
 }
 
 AbstractFSNode *WiiFilesystemNode::getParent() const {
-	if (_path == "/")
-		return 0;
+	if (_path.empty())
+		return NULL;
 
 	const char *start = _path.c_str();
 	const char *end = lastPathComponent(_path, '/');


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list