aboutsummaryrefslogtreecommitdiff
path: root/backends/fs/windows
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/windows
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/windows')
-rw-r--r--backends/fs/windows/windows-fs.cpp40
-rw-r--r--backends/fs/windows/windows-fs.h7
2 files changed, 16 insertions, 31 deletions
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