Updated palmos FS based on lastest changes to the base class
svn-id: r22867
This commit is contained in:
parent
ced30c3444
commit
d224f5a6ce
1 changed files with 63 additions and 38 deletions
|
@ -22,7 +22,9 @@
|
||||||
#if defined(PALMOS_MODE)
|
#if defined(PALMOS_MODE)
|
||||||
|
|
||||||
#include "common/stdafx.h"
|
#include "common/stdafx.h"
|
||||||
#include "fs/fs.h"
|
#include "backends/fs/abstract-fs.h"
|
||||||
|
#include "backends/fs/fs.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -40,8 +42,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PalmOSFilesystemNode();
|
PalmOSFilesystemNode();
|
||||||
PalmOSFilesystemNode(const PalmOSFilesystemNode &node);
|
PalmOSFilesystemNode(const String &p);
|
||||||
PalmOSFilesystemNode(const String &path);
|
|
||||||
|
|
||||||
virtual String displayName() const { return _displayName; }
|
virtual String displayName() const { return _displayName; }
|
||||||
virtual bool isValid() const { return _isValid; }
|
virtual bool isValid() const { return _isValid; }
|
||||||
|
@ -56,25 +57,37 @@ private:
|
||||||
static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
|
static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *lastPathComponent(const Common::String &str) {
|
||||||
|
const char *start = str.c_str();
|
||||||
|
const char *cur = start + str.size() - 2;
|
||||||
|
|
||||||
|
while (cur > start && *cur != '/')
|
||||||
|
--cur;
|
||||||
|
|
||||||
|
return cur + 1;
|
||||||
|
}
|
||||||
|
|
||||||
void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) {
|
void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) {
|
||||||
PalmOSFilesystemNode entry;
|
PalmOSFilesystemNode entry;
|
||||||
bool isDirectory;
|
bool isDir;
|
||||||
|
|
||||||
isDirectory = (find_data->attributes & vfsFileAttrDirectory);
|
isDir = (find_data->attributes & vfsFileAttrDirectory);
|
||||||
|
|
||||||
if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) ||
|
if ((!isDir && mode == FilesystemNode::kListDirectoriesOnly) ||
|
||||||
(isDirectory && mode == FilesystemNode::kListFilesOnly))
|
(isDir && mode == FilesystemNode::kListFilesOnly))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
entry._isDirectory = isDirectory;
|
entry._isDirectory = isDir;
|
||||||
entry._displayName = find_data->nameP;
|
entry._displayName = find_data->nameP;
|
||||||
entry._path = base;
|
entry._path = base;
|
||||||
entry._path += find_data->nameP;
|
entry._path += find_data->nameP;
|
||||||
|
|
||||||
if (entry._isDirectory)
|
if (entry._isDirectory)
|
||||||
entry._path += "/";
|
entry._path += "/";
|
||||||
|
|
||||||
entry._isValid = true;
|
entry._isValid = true;
|
||||||
entry._isPseudoRoot = false;
|
entry._isPseudoRoot = false;
|
||||||
|
|
||||||
list.push_back(new PalmOSFilesystemNode(entry));
|
list.push_back(new PalmOSFilesystemNode(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,28 +109,30 @@ PalmOSFilesystemNode::PalmOSFilesystemNode() {
|
||||||
_displayName = "Root";
|
_displayName = "Root";
|
||||||
_isValid = true;
|
_isValid = true;
|
||||||
_path = "/";
|
_path = "/";
|
||||||
_isPseudoRoot = true;
|
_isPseudoRoot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PalmOSFilesystemNode::PalmOSFilesystemNode(const String &path) {
|
PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) {
|
||||||
if (path.size() == 0)
|
_path = p;
|
||||||
_isPseudoRoot = true;
|
_displayName = lastPathComponent(p);
|
||||||
_path = path;
|
|
||||||
const char *dsplName = NULL, *pos = path.c_str();
|
|
||||||
while (*pos)
|
|
||||||
if (*pos++ == '/')
|
|
||||||
dsplName = pos;
|
|
||||||
_displayName = String(dsplName);
|
|
||||||
_isValid = true;
|
|
||||||
_isDirectory = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PalmOSFilesystemNode::PalmOSFilesystemNode(const PalmOSFilesystemNode &node) {
|
UInt32 attr;
|
||||||
_displayName = node._displayName;
|
FileRef handle;
|
||||||
_isDirectory = node._isDirectory;
|
Err e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle);
|
||||||
_isValid = node._isValid;
|
if (!e) {
|
||||||
_isPseudoRoot = node._isPseudoRoot;
|
e = VFSFileGetAttributes(handle, &attr);
|
||||||
_path = node._path;
|
VFSFileClose(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e) {
|
||||||
|
_isValid = false;
|
||||||
|
_isDirectory = false;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_isValid = true;
|
||||||
|
_isDirectory = (attr & vfsFileAttrDirectory);
|
||||||
|
}
|
||||||
|
_isPseudoRoot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
|
bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
|
||||||
|
@ -146,16 +161,6 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *lastPathComponent(const Common::String &str) {
|
|
||||||
const char *start = str.c_str();
|
|
||||||
const char *cur = start + str.size() - 2;
|
|
||||||
|
|
||||||
while (cur > start && *cur != '/') {
|
|
||||||
--cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cur+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
|
AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
|
||||||
PalmOSFilesystemNode *p = 0;
|
PalmOSFilesystemNode *p = 0;
|
||||||
|
@ -176,7 +181,27 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
|
||||||
|
|
||||||
|
|
||||||
AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &name) const {
|
AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &name) const {
|
||||||
TODO
|
assert(_isDirectory);
|
||||||
|
String newPath(_path);
|
||||||
|
|
||||||
|
if (_path.lastChar() != '/')
|
||||||
|
newPath += '/';
|
||||||
|
newPath += name;
|
||||||
|
|
||||||
|
FileRef handle;
|
||||||
|
UInt32 attr;
|
||||||
|
Err e = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle);
|
||||||
|
if (e)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
e = VFSFileGetAttributes(handle, &attr);
|
||||||
|
VFSFileClose(handle);
|
||||||
|
|
||||||
|
if (e || !(attr & vfsFileAttrDirectory))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
PalmOSFilesystemNode *p = new PalmOSFilesystemNode(newPath);
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // PALMOS_MODE
|
#endif // PALMOS_MODE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue