aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorRobert Göffringmann2006-06-07 06:53:41 +0000
committerRobert Göffringmann2006-06-07 06:53:41 +0000
commit93718ebef945695422242e6bacd0e84954b0b77a (patch)
treee37da1870d2105baed392110c132ffce5eb306ad /backends
parent939ebbb80d038622f70b59c4a55ee16b8b52e897 (diff)
downloadscummvm-rg350-93718ebef945695422242e6bacd0e84954b0b77a.tar.gz
scummvm-rg350-93718ebef945695422242e6bacd0e84954b0b77a.tar.bz2
scummvm-rg350-93718ebef945695422242e6bacd0e84954b0b77a.zip
updated fs implementation
svn-id: r22974
Diffstat (limited to 'backends')
-rw-r--r--backends/fs/ps2/ps2-fs.cpp190
1 files changed, 133 insertions, 57 deletions
diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp
index 0286a72831..9fe021f355 100644
--- a/backends/fs/ps2/ps2-fs.cpp
+++ b/backends/fs/ps2/ps2-fs.cpp
@@ -19,15 +19,16 @@
* $Id$
*/
-#include "common/stdafx.h"
#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#include <kernel.h>
#include <stdio.h>
#include <stdlib.h>
-#include <cdvd_rpc.h>
+#include "asyncfio.h"
+#include "systemps2.h"
-#define MAX_LIST_ENTRIES 64
+extern AsyncFio fio;
+extern OSystem_PS2 *g_systemPs2;
class Ps2FilesystemNode : public AbstractFilesystemNode {
protected:
@@ -37,26 +38,27 @@ protected:
String _path;
public:
- Ps2FilesystemNode();
+ Ps2FilesystemNode(void);
+ Ps2FilesystemNode(const Ps2FilesystemNode *node);
Ps2FilesystemNode(const String &path);
virtual String displayName() const { return _displayName; }
- virtual bool isValid() const { return true; }
+ virtual bool isValid() const { return !_isRoot; }
virtual bool isDirectory() const { return _isDirectory; }
virtual String path() const { return _path; }
+ //virtual FSList listDir(ListMode) const;
virtual bool listDir(AbstractFSList &list, ListMode mode) const;
virtual AbstractFilesystemNode *parent() const;
- virtual AbstractFilesystemNode *child(const String &name) const;
-
virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); }
+ virtual AbstractFilesystemNode *child(const String &name) const;
};
AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() {
return AbstractFilesystemNode::getRoot();
}
-AbstractFilesystemNode *AbstractFilesystemNode::getRoot() {
+AbstractFilesystemNode *AbstractFilesystemNode::getRoot(void) {
return new Ps2FilesystemNode();
}
@@ -64,68 +66,114 @@ AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &pat
return new Ps2FilesystemNode(path);
}
-Ps2FilesystemNode::Ps2FilesystemNode() {
+Ps2FilesystemNode::Ps2FilesystemNode(void) {
_isDirectory = true;
_isRoot = true;
- _displayName = "CD Root";
- _path = "cdfs:";
+ _displayName = "PlayStation 2";
+ _path = "";
}
Ps2FilesystemNode::Ps2FilesystemNode(const String &path) {
- if (strcmp(path.c_str(), "cdfs:") == 0)
- _isRoot = true;
_path = path;
- const char *dsplName = NULL, *pos = path.c_str();
- while (*pos)
- if (*pos++ == '/')
- dsplName = pos;
- _displayName = String(dsplName);
_isDirectory = true;
-}
-
-bool Ps2FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
- assert(_isDirectory);
-
- struct TocEntry tocEntries[MAX_LIST_ENTRIES];
- int files;
- char listDir[512];
- sprintf(listDir, "%s/", _path.c_str() + 5);
-
- switch(mode) {
- case FilesystemNode::kListFilesOnly:
- files = CDVD_GetDir(listDir, NULL, CDVD_GET_FILES_ONLY, tocEntries, MAX_LIST_ENTRIES, NULL);
- break;
- case FilesystemNode::kListDirectoriesOnly:
- files = CDVD_GetDir(listDir, NULL, CDVD_GET_DIRS_ONLY, tocEntries, MAX_LIST_ENTRIES, NULL);
- break;
- default:
- files = CDVD_GetDir(listDir, NULL, CDVD_GET_FILES_AND_DIRS, tocEntries, MAX_LIST_ENTRIES, NULL);
- break;
+ if (strcmp(path.c_str(), "") == 0) {
+ _isRoot = true;
+ _displayName = String("PlayStation 2");
+ } else {
+ _isRoot = false;
+ const char *dsplName = NULL, *pos = path.c_str();
+ while (*pos)
+ if (*pos++ == '/')
+ dsplName = pos;
+ if (dsplName)
+ _displayName = String(dsplName);
+ else {
+ if (strncmp(path.c_str(), "cdfs", 4) == 0)
+ _displayName = "DVD Drive";
+ else if (strncmp(path.c_str(), "mass", 4) == 0)
+ _displayName = "USB Mass Storage";
+ else
+ _displayName = "Harddisk";
+ }
}
+}
- Ps2FilesystemNode dirEntry;
- for (int fCnt = 0; fCnt < files; fCnt++) {
- if (tocEntries[fCnt].filename[0] != '.') { // skip .. directory
- dirEntry._isDirectory = (bool)(tocEntries[fCnt].fileProperties & 2);
- dirEntry._isRoot = false;
+Ps2FilesystemNode::Ps2FilesystemNode(const Ps2FilesystemNode *node) {
+ _displayName = node->_displayName;
+ _isDirectory = node->_isDirectory;
+ _path = node->_path;
+ _isRoot = node->_isRoot;
+}
- dirEntry._path = _path;
- dirEntry._path += "/";
- dirEntry._path += tocEntries[fCnt].filename;
+bool Ps2FilesystemNode::listDir(AbstractFSList &list, ListMode mode) const {
+ if (!_isDirectory)
+ return false;
+
+ if (_isRoot) {
+ Ps2FilesystemNode dirEntry;
+ dirEntry._isDirectory = true;
+ dirEntry._isRoot = false;
+ dirEntry._path = "cdfs:";
+ dirEntry._displayName = "DVD Drive";
+ list.push_back(new Ps2FilesystemNode(&dirEntry));
+
+ if (g_systemPs2->hddPresent()) {
+ dirEntry._path = "pfs0:";
+ dirEntry._displayName = "Harddisk";
+ list.push_back(new Ps2FilesystemNode(&dirEntry));
+ }
- dirEntry._displayName = tocEntries[fCnt].filename;
- myList.push_back(new Ps2FilesystemNode(dirEntry));
+ if (g_systemPs2->usbMassPresent()) {
+ dirEntry._path = "mass:";
+ dirEntry._displayName = "USB Mass Storage";
+ list.push_back(new Ps2FilesystemNode(&dirEntry));
}
+ return true;
+ } else {
+ char listDir[256];
+ int fd;
+ if (_path.lastChar() == '/')
+ fd = fio.dopen(_path.c_str());
+ else {
+ sprintf(listDir, "%s/", _path.c_str());
+ fd = fio.dopen(listDir);
+ }
+
+ if (fd >= 0) {
+ iox_dirent_t dirent;
+ Ps2FilesystemNode dirEntry;
+ int dreadRes;
+ while ((dreadRes = fio.dread(fd, &dirent)) > 0) {
+ if (dirent.name[0] == '.')
+ continue; // ignore '.' and '..'
+ if (((mode == FilesystemNode::kListDirectoriesOnly) && (dirent.stat.mode & FIO_S_IFDIR)) ||
+ ((mode == FilesystemNode::kListFilesOnly) && !(dirent.stat.mode & FIO_S_IFDIR)) ||
+ (mode == FilesystemNode::kListAll)) {
+
+ dirEntry._isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR);
+ dirEntry._isRoot = false;
+
+ dirEntry._path = _path;
+ if (_path.lastChar() != '/')
+ dirEntry._path += "/";
+ dirEntry._path += dirent.name;
+
+ dirEntry._displayName = dirent.name;
+
+ list.push_back(new Ps2FilesystemNode(&dirEntry));
+ }
+ }
+ fio.dclose(fd);
+ return true;
+ } else
+ return false;
}
- return true;
}
AbstractFilesystemNode *Ps2FilesystemNode::parent() const {
if (_isRoot)
return new Ps2FilesystemNode(this);
- Ps2FilesystemNode *p = new Ps2FilesystemNode();
-
const char *slash = NULL;
const char *cnt = _path.c_str();
@@ -135,13 +183,41 @@ AbstractFilesystemNode *Ps2FilesystemNode::parent() const {
cnt++;
}
- p->_path = String(_path.c_str(), slash - _path.c_str());
- p->_isDirectory = true;
- p->_displayName = slash + 1;
- return p;
+ if (slash)
+ return new Ps2FilesystemNode(String(_path.c_str(), slash - _path.c_str()));
+ else
+ return new Ps2FilesystemNode();
}
-
AbstractFilesystemNode *Ps2FilesystemNode::child(const String &name) const {
- TODO
+ if (!_isDirectory)
+ return NULL;
+
+ char listDir[256];
+ sprintf(listDir, "%s/", _path.c_str());
+ int fd = fio.dopen(listDir);
+
+ if (fd >= 0) {
+ iox_dirent_t dirent;
+
+ while (fio.dread(fd, &dirent) > 0) {
+ if (strcmp(name.c_str(), dirent.name) == 0) {
+ Ps2FilesystemNode *dirEntry = new Ps2FilesystemNode();
+
+ dirEntry->_isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR);
+ dirEntry->_isRoot = false;
+
+ dirEntry->_path = _path;
+ dirEntry->_path += "/";
+ dirEntry->_path += dirent.name;
+
+ dirEntry->_displayName = dirent.name;
+
+ fio.dclose(fd);
+ return dirEntry;
+ }
+ }
+ fio.dclose(fd);
+ }
+ return NULL;
}