aboutsummaryrefslogtreecommitdiff
path: root/backends/fs
diff options
context:
space:
mode:
authorCameron Cawley2019-07-01 17:33:36 +0100
committerFilippos Karapetis2019-08-06 07:17:29 +0300
commit66ef50cfebbcd650a6b57d896a9ba057a23cea35 (patch)
tree4fff70c1ace46f819798461a4250c62452011543 /backends/fs
parent8666e9564f25d2f0923ac6e23b74d107a17d645e (diff)
downloadscummvm-rg350-66ef50cfebbcd650a6b57d896a9ba057a23cea35.tar.gz
scummvm-rg350-66ef50cfebbcd650a6b57d896a9ba057a23cea35.tar.bz2
scummvm-rg350-66ef50cfebbcd650a6b57d896a9ba057a23cea35.zip
BACKENDS: Rename and simplify AbstractFSNode::create()
Diffstat (limited to 'backends/fs')
-rw-r--r--backends/fs/abstract-fs.h8
-rw-r--r--backends/fs/amigaos4/amigaos4-fs.cpp2
-rw-r--r--backends/fs/amigaos4/amigaos4-fs.h2
-rw-r--r--backends/fs/chroot/chroot-fs.cpp2
-rw-r--r--backends/fs/chroot/chroot-fs.h2
-rw-r--r--backends/fs/ds/ds-fs.cpp4
-rw-r--r--backends/fs/ds/ds-fs.h4
-rw-r--r--backends/fs/n64/n64-fs.cpp2
-rw-r--r--backends/fs/n64/n64-fs.h2
-rw-r--r--backends/fs/posix/posix-fs.cpp28
-rw-r--r--backends/fs/posix/posix-fs.h2
-rw-r--r--backends/fs/ps2/ps2-fs.cpp2
-rw-r--r--backends/fs/ps2/ps2-fs.h2
-rw-r--r--backends/fs/psp/psp-fs.cpp2
-rw-r--r--backends/fs/psp/psp-fs.h2
-rw-r--r--backends/fs/riscos/riscos-fs.cpp58
-rw-r--r--backends/fs/riscos/riscos-fs.h7
-rw-r--r--backends/fs/symbian/symbian-fs.cpp2
-rw-r--r--backends/fs/symbian/symbian-fs.h2
-rw-r--r--backends/fs/wii/wii-fs.cpp2
-rw-r--r--backends/fs/wii/wii-fs.h2
-rw-r--r--backends/fs/windows/windows-fs.cpp40
-rw-r--r--backends/fs/windows/windows-fs.h7
23 files changed, 67 insertions, 119 deletions
diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h
index 28ea3bbecd..8b2c1c107d 100644
--- a/backends/fs/abstract-fs.h
+++ b/backends/fs/abstract-fs.h
@@ -193,13 +193,11 @@ public:
virtual Common::WriteStream *createWriteStream() = 0;
/**
- * Creates a file referred by this node.
+ * Creates a directory referred by this node.
*
- * @param isDirectoryFlag true if created file must be a directory
- *
- * @return true if file is created successfully
+ * @return true if the directory is created successfully
*/
- virtual bool create(bool isDirectoryFlag) = 0;
+ virtual bool createDirectory() = 0;
};
diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp
index 134193a65b..fa0ea1453d 100644
--- a/backends/fs/amigaos4/amigaos4-fs.cpp
+++ b/backends/fs/amigaos4/amigaos4-fs.cpp
@@ -443,7 +443,7 @@ Common::WriteStream *AmigaOSFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
-bool AmigaOSFilesystemNode::create(bool isDirectoryFlag) {
+bool AmigaOSFilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/amigaos4/amigaos4-fs.h b/backends/fs/amigaos4/amigaos4-fs.h
index c86bb4c57a..75d8d01362 100644
--- a/backends/fs/amigaos4/amigaos4-fs.h
+++ b/backends/fs/amigaos4/amigaos4-fs.h
@@ -116,7 +116,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
};
diff --git a/backends/fs/chroot/chroot-fs.cpp b/backends/fs/chroot/chroot-fs.cpp
index 3bbee278c9..0fdd14ca9a 100644
--- a/backends/fs/chroot/chroot-fs.cpp
+++ b/backends/fs/chroot/chroot-fs.cpp
@@ -100,7 +100,7 @@ Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
return _realNode->createWriteStream();
}
-bool ChRootFilesystemNode::create(bool isDirectoryFlag) {
+bool ChRootFilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/chroot/chroot-fs.h b/backends/fs/chroot/chroot-fs.h
index 76902bc92a..66cbcbe700 100644
--- a/backends/fs/chroot/chroot-fs.h
+++ b/backends/fs/chroot/chroot-fs.h
@@ -49,7 +49,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
private:
static Common::String addPathComponent(const Common::String &path, const Common::String &component);
diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp
index 8c51f109dc..8498a77751 100644
--- a/backends/fs/ds/ds-fs.cpp
+++ b/backends/fs/ds/ds-fs.cpp
@@ -211,7 +211,7 @@ Common::WriteStream *DSFileSystemNode::createWriteStream() {
return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
}
-bool DSFileSystemNode::create(bool isDirectoryFlag) {
+bool DSFileSystemNode::createDirectory() {
error("Not supported");
return false;
}
@@ -398,7 +398,7 @@ Common::WriteStream *GBAMPFileSystemNode::createWriteStream() {
return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
}
-bool GBAMPFileSystemNode::create(bool isDirectoryFlag) {
+bool GBAMPFileSystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h
index 12dd6d6a59..37708478de 100644
--- a/backends/fs/ds/ds-fs.h
+++ b/backends/fs/ds/ds-fs.h
@@ -91,7 +91,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
/**
* Returns the zip file this node points to.
@@ -157,7 +157,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
};
struct fileHandle {
diff --git a/backends/fs/n64/n64-fs.cpp b/backends/fs/n64/n64-fs.cpp
index 5a131c0305..4a21fb27c4 100644
--- a/backends/fs/n64/n64-fs.cpp
+++ b/backends/fs/n64/n64-fs.cpp
@@ -160,7 +160,7 @@ Common::WriteStream *N64FilesystemNode::createWriteStream() {
return RomfsStream::makeFromPath(getPath(), true);
}
-bool N64FilesystemNode::create(bool isDirectoryFlag) {
+bool N64FilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/n64/n64-fs.h b/backends/fs/n64/n64-fs.h
index b2de8a4bc4..495fd672e8 100644
--- a/backends/fs/n64/n64-fs.h
+++ b/backends/fs/n64/n64-fs.h
@@ -73,7 +73,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
};
#endif
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index 5b724c291f..507f075db4 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -299,33 +299,11 @@ Common::WriteStream *POSIXFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
-bool POSIXFilesystemNode::create(bool isDirectoryFlag) {
- bool success;
-
- if (isDirectoryFlag) {
- success = mkdir(_path.c_str(), 0755) == 0;
- } else {
- int fd = open(_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
- success = fd >= 0;
-
- if (fd >= 0) {
- close(fd);
- }
- }
-
- if (success) {
+bool POSIXFilesystemNode::createDirectory() {
+ if (mkdir(_path.c_str(), 0755) == 0)
setFlags();
- if (_isValid) {
- if (_isDirectory != isDirectoryFlag) warning("failed to create %s: got %s", isDirectoryFlag ? "directory" : "file", _isDirectory ? "directory" : "file");
- return _isDirectory == isDirectoryFlag;
- }
-
- warning("POSIXFilesystemNode: %s() was a success, but stat indicates there is no such %s",
- isDirectoryFlag ? "mkdir" : "creat", isDirectoryFlag ? "directory" : "file");
- return false;
- }
- return false;
+ return _isValid && _isDirectory;
}
namespace Posix {
diff --git a/backends/fs/posix/posix-fs.h b/backends/fs/posix/posix-fs.h
index 5ad26ff027..9751ab74f6 100644
--- a/backends/fs/posix/posix-fs.h
+++ b/backends/fs/posix/posix-fs.h
@@ -68,7 +68,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
private:
/**
diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp
index b6f184fbbf..ec75f1e2d2 100644
--- a/backends/fs/ps2/ps2-fs.cpp
+++ b/backends/fs/ps2/ps2-fs.cpp
@@ -443,7 +443,7 @@ Common::WriteStream *Ps2FilesystemNode::createWriteStream() {
return PS2FileStream::makeFromPath(getPath(), true);
}
-bool Ps2FilesystemNode::create(bool isDirectoryFlag) {
+bool Ps2FilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/ps2/ps2-fs.h b/backends/fs/ps2/ps2-fs.h
index ca476eca9f..16463fd312 100644
--- a/backends/fs/ps2/ps2-fs.h
+++ b/backends/fs/ps2/ps2-fs.h
@@ -96,7 +96,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
int getDev() { return 0; }
};
diff --git a/backends/fs/psp/psp-fs.cpp b/backends/fs/psp/psp-fs.cpp
index c69592ea99..01884dea97 100644
--- a/backends/fs/psp/psp-fs.cpp
+++ b/backends/fs/psp/psp-fs.cpp
@@ -239,7 +239,7 @@ Common::WriteStream *PSPFilesystemNode::createWriteStream() {
return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
}
-bool PSPFilesystemNode::create(bool isDirectoryFlag) {
+bool PSPFilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/psp/psp-fs.h b/backends/fs/psp/psp-fs.h
index 47c6d04a70..3d70face0b 100644
--- a/backends/fs/psp/psp-fs.h
+++ b/backends/fs/psp/psp-fs.h
@@ -65,7 +65,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
};
#endif
diff --git a/backends/fs/riscos/riscos-fs.cpp b/backends/fs/riscos/riscos-fs.cpp
index 6f195691a0..810be2b417 100644
--- a/backends/fs/riscos/riscos-fs.cpp
+++ b/backends/fs/riscos/riscos-fs.cpp
@@ -52,23 +52,27 @@ bool RISCOSFilesystemNode::isWritable() const {
return access(_path.c_str(), W_OK) == 0;
}
+void RISCOSFilesystemNode::setFlags() {
+ int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(_path).c_str());
+ if (type == 0) {
+ _isDirectory = false;
+ _isValid = false;
+ } else if (type == 2) {
+ _isDirectory = true;
+ _isValid = true;
+ } else {
+ _isDirectory = false;
+ _isValid = true;
+ }
+}
+
RISCOSFilesystemNode::RISCOSFilesystemNode(const Common::String &p) {
_path = p;
if (p == "/") {
_isDirectory = true;
_isValid = true;
} else {
- int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(_path).c_str());
- if (type == 0) {
- _isDirectory = false;
- _isValid = false;
- } else if (type == 2) {
- _isDirectory = true;
- _isValid = true;
- } else {
- _isDirectory = false;
- _isValid = true;
- }
+ setFlags();
}
}
@@ -198,33 +202,11 @@ Common::WriteStream *RISCOSFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
-bool RISCOSFilesystemNode::create(bool isDirectoryFlag) {
- bool success;
-
- if (isDirectoryFlag) {
- success = _swix(OS_File, _INR(0,1), 8, RISCOS_Utils::toRISCOS(_path).c_str()) == NULL;
- } else {
- int fd = open(_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
- success = fd >= 0;
-
- if (fd >= 0) {
- close(fd);
- }
- }
-
- if (success) {
- if (exists()) {
- _isDirectory = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(_path).c_str()) == 2;
- if (_isDirectory != isDirectoryFlag) warning("failed to create %s: got %s", isDirectoryFlag ? "directory" : "file", _isDirectory ? "directory" : "file");
- return _isDirectory == isDirectoryFlag;
- }
-
- warning("RISCOSFilesystemNode: Attempting to create a %s was a success, but access indicates there is no such %s",
- isDirectoryFlag ? "directory" : "file", isDirectoryFlag ? "directory" : "file");
- return false;
- }
+bool RISCOSFilesystemNode::createDirectory() {
+ if (_swix(OS_File, _INR(0,1), 8, RISCOS_Utils::toRISCOS(_path).c_str()) == NULL)
+ setFlags();
- return false;
+ return _isValid && _isDirectory;
}
namespace Riscos {
@@ -270,7 +252,7 @@ bool assureDirectoryExists(const Common::String &dir, const char *prefix) {
}
node = new RISCOSFilesystemNode(path);
- if (!node->create(true)) {
+ if (!node->createDirectory()) {
if (node->exists()) {
if (!node->isDirectory()) {
return false;
diff --git a/backends/fs/riscos/riscos-fs.h b/backends/fs/riscos/riscos-fs.h
index 99fa1d59be..f068022a9e 100644
--- a/backends/fs/riscos/riscos-fs.h
+++ b/backends/fs/riscos/riscos-fs.h
@@ -67,7 +67,12 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
+private:
+ /**
+ * Tests and sets the _isValid and _isDirectory flags, using OS_File 20.
+ */
+ virtual void setFlags();
};
namespace Riscos {
diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp
index c6d5cc4955..7759f329d7 100644
--- a/backends/fs/symbian/symbian-fs.cpp
+++ b/backends/fs/symbian/symbian-fs.cpp
@@ -232,7 +232,7 @@ Common::WriteStream *SymbianFilesystemNode::createWriteStream() {
return SymbianStdioStream::makeFromPath(getPath(), true);
}
-bool SymbianFilesystemNode::create(bool isDirectoryFlag) {
+bool SymbianFilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/symbian/symbian-fs.h b/backends/fs/symbian/symbian-fs.h
index 0f8212035f..cd255f7ec0 100644
--- a/backends/fs/symbian/symbian-fs.h
+++ b/backends/fs/symbian/symbian-fs.h
@@ -66,7 +66,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
};
#endif
diff --git a/backends/fs/wii/wii-fs.cpp b/backends/fs/wii/wii-fs.cpp
index c3fdbc07b2..3b276e9838 100644
--- a/backends/fs/wii/wii-fs.cpp
+++ b/backends/fs/wii/wii-fs.cpp
@@ -213,7 +213,7 @@ Common::WriteStream *WiiFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
-bool WiiFilesystemNode::create(bool isDirectoryFlag) {
+bool WiiFilesystemNode::createDirectory() {
error("Not supported");
return false;
}
diff --git a/backends/fs/wii/wii-fs.h b/backends/fs/wii/wii-fs.h
index 491c8d1d2c..7c04ee53ec 100644
--- a/backends/fs/wii/wii-fs.h
+++ b/backends/fs/wii/wii-fs.h
@@ -69,7 +69,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
};
#endif
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index caf0e31360..e69e72a746 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -134,6 +134,12 @@ WindowsFilesystemNode::WindowsFilesystemNode(const Common::String &p, const bool
_displayName = lastPathComponent(_path, '\\');
+ setFlags();
+
+ _isPseudoRoot = false;
+}
+
+void WindowsFilesystemNode::setFlags() {
// Check whether it is a directory, and whether the file actually exists
DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
@@ -148,7 +154,6 @@ WindowsFilesystemNode::WindowsFilesystemNode(const Common::String &p, const bool
_path += '\\';
}
}
- _isPseudoRoot = false;
}
AbstractFSNode *WindowsFilesystemNode::getChild(const Common::String &n) const {
@@ -244,36 +249,11 @@ Common::WriteStream *WindowsFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
-bool WindowsFilesystemNode::create(bool isDirectoryFlag) {
- bool success;
-
- if (isDirectoryFlag) {
- success = CreateDirectory(toUnicode(_path.c_str()), NULL) != 0;
- } else {
- success = CreateFile(toUnicode(_path.c_str()), GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) != INVALID_HANDLE_VALUE;
- }
-
- if (success) {
- //this piece is copied from constructor, it checks that file exists and detects whether it's a directory
- DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
- if (fileAttribs != INVALID_FILE_ATTRIBUTES) {
- _isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
- _isValid = true;
- // Add a trailing slash, if necessary.
- if (_isDirectory && _path.lastChar() != '\\') {
- _path += '\\';
- }
-
- if (_isDirectory != isDirectoryFlag) warning("failed to create %s: got %s", isDirectoryFlag ? "directory" : "file", _isDirectory ? "directory" : "file");
- return _isDirectory == isDirectoryFlag;
- }
-
- warning("WindowsFilesystemNode: Create%s() was a success, but GetFileAttributes() indicates there is no such %s",
- isDirectoryFlag ? "Directory" : "File", isDirectoryFlag ? "directory" : "file");
- return false;
- }
+bool WindowsFilesystemNode::createDirectory() {
+ if (CreateDirectory(toUnicode(_path.c_str()), NULL) != 0)
+ setFlags();
- return false;
+ return _isValid && _isDirectory;
}
#endif //#ifdef WIN32
diff --git a/backends/fs/windows/windows-fs.h b/backends/fs/windows/windows-fs.h
index f907a4d047..e2404dacbc 100644
--- a/backends/fs/windows/windows-fs.h
+++ b/backends/fs/windows/windows-fs.h
@@ -84,7 +84,7 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
- virtual bool create(bool isDirectoryFlag);
+ virtual bool createDirectory();
private:
/**
@@ -114,6 +114,11 @@ private:
* @return str in Unicode format.
*/
static const TCHAR* toUnicode(const char *str);
+
+ /**
+ * Tests and sets the _isValid and _isDirectory flags, using the GetFileAttributes() function.
+ */
+ virtual void setFlags();
};
#endif