Commit of patch #1804861. It implements a static lastPathComponent() function in each backend, used to extract the last path component of a given path, returned by getName().
svn-id: r29159
This commit is contained in:
parent
0fab64817f
commit
aba30d7ea8
13 changed files with 144 additions and 99 deletions
|
@ -103,7 +103,13 @@ public:
|
|||
virtual String getDisplayName() const { return getName(); }
|
||||
|
||||
/**
|
||||
* Returns a string with an architecture dependent path description.
|
||||
* Returns the last component of the path pointed by this FilesystemNode.
|
||||
*
|
||||
* Examples (POSIX):
|
||||
* /foo/bar.txt would return /bar.txt
|
||||
* /foo/bar/ would return /bar/
|
||||
*
|
||||
* @note This method is very architecture dependent, please check the concrete implementation for more information.
|
||||
*/
|
||||
virtual String getName() const = 0;
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ public:
|
|||
virtual String getPath() const { return _sPath; };
|
||||
virtual bool isDirectory() const { return _bIsDirectory; };
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _bIsValid; };
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -106,9 +105,6 @@ public:
|
|||
virtual AbstractFSList listVolumes() const;
|
||||
};
|
||||
|
||||
// TODO: this is ripped of
|
||||
// AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p)
|
||||
// maybe change it to use this function instead?
|
||||
/**
|
||||
* Returns the last component of a given path.
|
||||
*
|
||||
|
@ -117,6 +113,12 @@ public:
|
|||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
int offset = str.size();
|
||||
|
||||
if (offset <= 0) {
|
||||
debug(6, "Bad offset");
|
||||
return;
|
||||
}
|
||||
|
||||
const char *p = str.c_str();
|
||||
|
||||
while (offset > 0 && (p[offset-1] == '/' || p[offset-1] == ':'))
|
||||
|
@ -151,19 +153,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) {
|
|||
}
|
||||
|
||||
_sPath = p;
|
||||
|
||||
// Extract last component from path
|
||||
const char *str = p.c_str();
|
||||
|
||||
while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':'))
|
||||
offset--;
|
||||
|
||||
while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) {
|
||||
len++;
|
||||
offset--;
|
||||
}
|
||||
|
||||
_sDisplayName = String(str + offset, len);
|
||||
_sDisplayName = lastPathComponent(_sPath);
|
||||
_pFileLock = 0;
|
||||
_bIsDirectory = false;
|
||||
|
||||
|
@ -352,7 +342,12 @@ bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b
|
|||
if (lock) {
|
||||
AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name);
|
||||
if (entry) {
|
||||
if (entry->isValid())
|
||||
//FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode
|
||||
// specification, the following call had to be changed:
|
||||
// if (entry->isValid())
|
||||
// Please verify that the logic of the code remains coherent. Also, remember
|
||||
// that the isReadable() and isWritable() methods are available.
|
||||
if (entry->exists())
|
||||
myList.push_back(entry);
|
||||
else
|
||||
delete entry;
|
||||
|
@ -453,7 +448,12 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const {
|
|||
|
||||
AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(volumeLock, buffer);
|
||||
if (entry) {
|
||||
if (entry->isValid())
|
||||
//FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode
|
||||
// specification, the following call had to be changed:
|
||||
// if (entry->isValid())
|
||||
// Please verify that the logic of the code remains coherent. Also, remember
|
||||
// that the isReadable() and isWritable() methods are available.
|
||||
if(entry->exists())
|
||||
myList.push_back(entry);
|
||||
else
|
||||
delete entry;
|
||||
|
|
|
@ -62,7 +62,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -81,6 +80,9 @@ public:
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
|
|
@ -36,12 +36,30 @@ namespace DS {
|
|||
ZipFile* DSFileSystemNode::_zipFile = NULL;
|
||||
char currentDir[128];
|
||||
|
||||
const char *lastPathComponentDS(const Common::String &str) {
|
||||
if (str.empty())
|
||||
return "";
|
||||
|
||||
char disp[128];
|
||||
char* pathStr = (char *) str.c_str();
|
||||
int lastSlash = 3;
|
||||
|
||||
for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
|
||||
if (path[r] == '\\') {
|
||||
lastSlash = r;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(disp, pathStr + lastSlash + 1);
|
||||
|
||||
return disp;
|
||||
}
|
||||
|
||||
DSFileSystemNode::DSFileSystemNode() {
|
||||
_displayName = "ds:/";
|
||||
_path = "ds:/";
|
||||
_displayName = "ds:/";
|
||||
_isValid = true;
|
||||
_isDirectory = true;
|
||||
_path = "ds:/";
|
||||
|
||||
/* if (!_archive) {
|
||||
_archive = (GBFS_FILE *) find_first_gbfs_file(scummdata);
|
||||
|
@ -56,23 +74,12 @@ DSFileSystemNode::DSFileSystemNode() {
|
|||
DSFileSystemNode::DSFileSystemNode(const String& path) {
|
||||
// consolePrintf("--%s ",path.c_str());
|
||||
|
||||
char disp[128];
|
||||
char* pathStr = (char *) path.c_str();
|
||||
|
||||
int lastSlash = 3;
|
||||
for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
|
||||
if (path[r] == '\\') {
|
||||
lastSlash = r;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(disp, pathStr + lastSlash + 1);
|
||||
|
||||
_displayName = String(disp);
|
||||
_path = path;
|
||||
_displayName = lastPathComponentDS(_path);
|
||||
// _isValid = true;
|
||||
// _isDirectory = false;
|
||||
|
||||
char* pathStr = (char *) path.c_str();
|
||||
if (!strncmp(pathStr, "ds:/", 4)) {
|
||||
pathStr += 4;
|
||||
}
|
||||
|
@ -99,19 +106,8 @@ DSFileSystemNode::DSFileSystemNode(const String& path) {
|
|||
DSFileSystemNode::DSFileSystemNode(const String& path, bool isDir) {
|
||||
// consolePrintf("--%s ",path.c_str());
|
||||
|
||||
char disp[128];
|
||||
char* pathStr = (char *) path.c_str();
|
||||
int lastSlash = 3;
|
||||
for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
|
||||
if (path[r] == '\\') {
|
||||
lastSlash = r;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(disp, pathStr + lastSlash + 1);
|
||||
|
||||
_displayName = String(disp);
|
||||
_path = path;
|
||||
_displayName = lastPathComponentDS(_path);
|
||||
_isValid = true;
|
||||
_isDirectory = isDir;
|
||||
|
||||
|
@ -206,20 +202,14 @@ AbstractFilesystemNode* DSFileSystemNode::getParent() const {
|
|||
// GBAMPFileSystemNode - File system using GBA Movie Player and CF card //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GBAMPFileSystemNode::GBAMPFileSystemNode() {
|
||||
_displayName = "mp:/";
|
||||
_path = "mp:/";
|
||||
_isValid = true;
|
||||
_isDirectory = true;
|
||||
_path = "mp:/";
|
||||
}
|
||||
|
||||
GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) {
|
||||
// consolePrintf("'%s'",path.c_str());
|
||||
const char *lastPathComponentGBAMP(const Common::String &str) {
|
||||
if (str.empty())
|
||||
return "";
|
||||
|
||||
char disp[128];
|
||||
char* pathStr = (char *) path.c_str();
|
||||
char* pathStr = (char *) str.c_str();
|
||||
int lastSlash = 3;
|
||||
|
||||
for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
|
||||
if ((path[r] == '\\') || (path[r] == '/')) {
|
||||
lastSlash = r;
|
||||
|
@ -228,6 +218,19 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) {
|
|||
|
||||
strcpy(disp, pathStr + lastSlash + 1);
|
||||
|
||||
return disp;
|
||||
}
|
||||
|
||||
GBAMPFileSystemNode::GBAMPFileSystemNode() {
|
||||
_path = "mp:/";
|
||||
_displayName = "mp:/";
|
||||
_isValid = true;
|
||||
_isDirectory = true;
|
||||
}
|
||||
|
||||
GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) {
|
||||
// consolePrintf("'%s'",path.c_str());
|
||||
|
||||
char check[128];
|
||||
int success;
|
||||
|
||||
|
@ -243,8 +246,8 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) {
|
|||
}
|
||||
// consolePrintf("Path: %s (%d)\n", check, success);
|
||||
|
||||
_displayName = String(disp);
|
||||
_path = path;
|
||||
_displayName = lastPathComponentGBAMP(_path);
|
||||
_isValid = success == FT_FILE;
|
||||
_isDirectory = success == FT_DIR;
|
||||
}
|
||||
|
@ -252,19 +255,8 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) {
|
|||
GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path, bool isDirectory) {
|
||||
// consolePrintf("'%s'",path.c_str());
|
||||
|
||||
char disp[128];
|
||||
char* pathStr = (char *) path.c_str();
|
||||
int lastSlash = 3;
|
||||
for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
|
||||
if ((path[r] == '\\') || (path[r] == '/')) {
|
||||
lastSlash = r;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(disp, pathStr + lastSlash + 1);
|
||||
|
||||
_displayName = String(disp);
|
||||
_path = path;
|
||||
_displayName = lastPathComponentGBAMP(_path);
|
||||
_isValid = true;
|
||||
_isDirectory = isDirectory;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
/**
|
||||
|
@ -149,7 +148,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,7 +60,6 @@ public:
|
|||
// FIXME: isValid should return false if this Node can't be used!
|
||||
// so client code can rely on the return value.
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return true; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -82,6 +81,9 @@ const char gpRootPath[] = "gp:\\";
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &name) const;
|
||||
|
@ -93,12 +92,33 @@ public:
|
|||
static AbstractFSList getRootChildren();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the last component of a given path.
|
||||
*
|
||||
* @param str String containing the path.
|
||||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if (str.empty())
|
||||
return "";
|
||||
|
||||
const char *str = _path.c_str();
|
||||
while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') )
|
||||
offset--;
|
||||
while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) {
|
||||
len++;
|
||||
offset--;
|
||||
}
|
||||
|
||||
return str + offset;
|
||||
}
|
||||
|
||||
ABoxFilesystemNode::ABoxFilesystemNode()
|
||||
{
|
||||
_path = "";
|
||||
_displayName = "Mounted Volumes";
|
||||
_isValid = true;
|
||||
_isDirectory = true;
|
||||
_path = "";
|
||||
_lock = NULL;
|
||||
}
|
||||
|
||||
|
@ -108,16 +128,7 @@ ABoxFilesystemNode::ABoxFilesystemNode(const String &p) {
|
|||
assert(offset > 0);
|
||||
|
||||
_path = p;
|
||||
|
||||
// Extract last component from path
|
||||
const char *str = p.c_str();
|
||||
while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') )
|
||||
offset--;
|
||||
while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) {
|
||||
len++;
|
||||
offset--;
|
||||
}
|
||||
_displayName = String(str + offset, len);
|
||||
_displayName = lastPathComponent(_path);
|
||||
_lock = NULL;
|
||||
_isDirectory = false;
|
||||
|
||||
|
@ -212,10 +223,10 @@ ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name)
|
|||
|
||||
ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node)
|
||||
{
|
||||
_path = node._path;
|
||||
_displayName = node._displayName;
|
||||
_isValid = node._isValid;
|
||||
_isDirectory = node._isDirectory;
|
||||
_path = node._path;
|
||||
_lock = DupLock(node._lock);
|
||||
}
|
||||
|
||||
|
@ -299,7 +310,12 @@ bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool h
|
|||
entry = new ABoxFilesystemNode(lock, fib->fib_FileName);
|
||||
if (entry)
|
||||
{
|
||||
if (entry->isValid())
|
||||
//FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode
|
||||
// specification, the following call had to be changed:
|
||||
// if (entry->isValid())
|
||||
// Please verify that the logic of the code remains coherent. Also, remember
|
||||
// that the isReadable() and isWritable() methods are available.
|
||||
if (entry->exists())
|
||||
list.push_back(entry);
|
||||
else
|
||||
delete entry;
|
||||
|
@ -378,7 +394,12 @@ AbstractFSList ABoxFilesystemNode::getRootChildren()
|
|||
entry = new ABoxFilesystemNode(volume_lock, name);
|
||||
if (entry)
|
||||
{
|
||||
if (entry->isValid())
|
||||
//FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode
|
||||
// specification, the following call had to be changed:
|
||||
// if (entry->isValid())
|
||||
// Please verify that the logic of the code remains coherent. Also, remember
|
||||
// that the isReadable() and isWritable() methods are available.
|
||||
if (entry->exists())
|
||||
list.push_back(entry);
|
||||
else
|
||||
delete entry;
|
||||
|
|
|
@ -61,7 +61,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -92,6 +91,9 @@ private:
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
@ -136,7 +138,7 @@ PalmOSFilesystemNode::PalmOSFilesystemNode() {
|
|||
|
||||
PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) {
|
||||
_path = p;
|
||||
_displayName = lastPathComponent(p);
|
||||
_displayName = lastPathComponent(_path);
|
||||
|
||||
UInt32 attr;
|
||||
FileRef handle;
|
||||
|
|
|
@ -91,6 +91,9 @@ private:
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return !_isRoot; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); }
|
||||
|
@ -77,6 +76,22 @@ public:
|
|||
virtual AbstractFilesystemNode *getParent() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the last component of a given path.
|
||||
*
|
||||
* @param str String containing the path.
|
||||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
//FIXME: implement this method properly.
|
||||
// This code is probably around the constructors,
|
||||
// but I couldn't figure it out without having
|
||||
// doubts on the correctness of my assumptions.
|
||||
// Therefore, I leave it to the porter to correctly
|
||||
// implement this method.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
Ps2FilesystemNode::Ps2FilesystemNode() {
|
||||
_isDirectory = true;
|
||||
_isRoot = true;
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -83,6 +82,9 @@ public:
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
@ -170,8 +172,6 @@ bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool
|
|||
}
|
||||
|
||||
AbstractFilesystemNode *PSPFilesystemNode::getParent() const {
|
||||
assert(_isValid);
|
||||
|
||||
if (_path == ROOT_PATH)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -83,6 +82,9 @@ public:
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
|
|
@ -92,7 +92,6 @@ public:
|
|||
virtual String getPath() const { return _path; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; }
|
||||
virtual bool isValid() const { return _isValid; }
|
||||
virtual bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; }
|
||||
|
||||
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
||||
|
@ -139,6 +138,9 @@ private:
|
|||
* @return Pointer to the first char of the last component inside str.
|
||||
*/
|
||||
const char *lastPathComponent(const Common::String &str) {
|
||||
if(str.empty())
|
||||
return "";
|
||||
|
||||
const char *start = str.c_str();
|
||||
const char *cur = start + str.size() - 2;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue