aboutsummaryrefslogtreecommitdiff
path: root/backends/fs/ds
diff options
context:
space:
mode:
authorDavid Corrales2007-10-07 00:28:38 +0000
committerDavid Corrales2007-10-07 00:28:38 +0000
commitaba30d7ea8541f7260ec7b96a8d33dd7dc06ed74 (patch)
tree86915d69c1463c4ff6fda79ab849b0f62432647b /backends/fs/ds
parent0fab64817fd027a8321e047c1007d0e7e9e135fc (diff)
downloadscummvm-rg350-aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74.tar.gz
scummvm-rg350-aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74.tar.bz2
scummvm-rg350-aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74.zip
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
Diffstat (limited to 'backends/fs/ds')
-rw-r--r--backends/fs/ds/ds-fs.cpp94
-rw-r--r--backends/fs/ds/ds-fs.h2
2 files changed, 43 insertions, 53 deletions
diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp
index 891f0df636..c5d0107f7b 100644
--- a/backends/fs/ds/ds-fs.cpp
+++ b/backends/fs/ds/ds-fs.cpp
@@ -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;
@@ -227,7 +217,20 @@ 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;
}
diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h
index ead0acc05e..70228f5e38 100644
--- a/backends/fs/ds/ds-fs.h
+++ b/backends/fs/ds/ds-fs.h
@@ -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
/**