summaryrefslogtreecommitdiffstats
path: root/drivers/windows
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/windows')
-rw-r--r--drivers/windows/dir_access_windows.cpp10
-rw-r--r--drivers/windows/dir_access_windows.h2
-rw-r--r--drivers/windows/file_access_windows.cpp127
-rw-r--r--drivers/windows/file_access_windows.h9
4 files changed, 143 insertions, 5 deletions
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index 8bf83823a0..43dd62cdf6 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -31,6 +31,7 @@
#if defined(WINDOWS_ENABLED)
#include "dir_access_windows.h"
+#include "file_access_windows.h"
#include "core/config/project_settings.h"
#include "core/os/memory.h"
@@ -67,7 +68,7 @@ struct DirAccessWindowsPrivate {
WIN32_FIND_DATAW fu; // Unicode version.
};
-String DirAccessWindows::fix_path(String p_path) const {
+String DirAccessWindows::fix_path(const String &p_path) const {
String r_path = DirAccess::fix_path(p_path);
if (r_path.is_absolute_path() && !r_path.is_network_share_path() && r_path.length() > MAX_PATH) {
r_path = "\\\\?\\" + r_path.replace("/", "\\");
@@ -177,6 +178,13 @@ Error DirAccessWindows::make_dir(String p_dir) {
p_dir = fix_path(p_dir);
}
+ if (FileAccessWindows::is_path_invalid(p_dir)) {
+#ifdef DEBUG_ENABLED
+ WARN_PRINT("The path :" + p_dir + " is a reserved Windows system pipe, so it can't be used for creating directories.");
+#endif
+ return ERR_INVALID_PARAMETER;
+ }
+
p_dir = p_dir.simplify_path().replace("/", "\\");
bool success;
diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h
index 1dcab84c9d..576ba18d9a 100644
--- a/drivers/windows/dir_access_windows.h
+++ b/drivers/windows/dir_access_windows.h
@@ -54,7 +54,7 @@ class DirAccessWindows : public DirAccess {
bool _cishidden = false;
protected:
- virtual String fix_path(String p_path) const override;
+ virtual String fix_path(const String &p_path) const override;
public:
virtual Error list_dir_begin() override; ///< This starts dir listing
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 9d21073f19..aae06505cd 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -60,12 +60,12 @@ void FileAccessWindows::check_errors() const {
bool FileAccessWindows::is_path_invalid(const String &p_path) {
// Check for invalid operating system file.
- String fname = p_path;
+ String fname = p_path.get_file().to_lower();
+
int dot = fname.find(".");
if (dot != -1) {
fname = fname.substr(0, dot);
}
- fname = fname.to_lower();
return invalid_files.has(fname);
}
@@ -284,6 +284,72 @@ uint8_t FileAccessWindows::get_8() const {
return b;
}
+uint16_t FileAccessWindows::get_16() const {
+ ERR_FAIL_NULL_V(f, 0);
+
+ if (flags == READ_WRITE || flags == WRITE_READ) {
+ if (prev_op == WRITE) {
+ fflush(f);
+ }
+ prev_op = READ;
+ }
+
+ uint16_t b = 0;
+ if (fread(&b, 1, 2, f) != 2) {
+ check_errors();
+ }
+
+ if (big_endian) {
+ b = BSWAP16(b);
+ }
+
+ return b;
+}
+
+uint32_t FileAccessWindows::get_32() const {
+ ERR_FAIL_NULL_V(f, 0);
+
+ if (flags == READ_WRITE || flags == WRITE_READ) {
+ if (prev_op == WRITE) {
+ fflush(f);
+ }
+ prev_op = READ;
+ }
+
+ uint32_t b = 0;
+ if (fread(&b, 1, 4, f) != 4) {
+ check_errors();
+ }
+
+ if (big_endian) {
+ b = BSWAP32(b);
+ }
+
+ return b;
+}
+
+uint64_t FileAccessWindows::get_64() const {
+ ERR_FAIL_NULL_V(f, 0);
+
+ if (flags == READ_WRITE || flags == WRITE_READ) {
+ if (prev_op == WRITE) {
+ fflush(f);
+ }
+ prev_op = READ;
+ }
+
+ uint64_t b = 0;
+ if (fread(&b, 1, 8, f) != 8) {
+ check_errors();
+ }
+
+ if (big_endian) {
+ b = BSWAP64(b);
+ }
+
+ return b;
+}
+
uint64_t FileAccessWindows::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
ERR_FAIL_NULL_V(f, -1);
@@ -326,6 +392,63 @@ void FileAccessWindows::store_8(uint8_t p_dest) {
fwrite(&p_dest, 1, 1, f);
}
+void FileAccessWindows::store_16(uint16_t p_dest) {
+ ERR_FAIL_NULL(f);
+
+ if (flags == READ_WRITE || flags == WRITE_READ) {
+ if (prev_op == READ) {
+ if (last_error != ERR_FILE_EOF) {
+ fseek(f, 0, SEEK_CUR);
+ }
+ }
+ prev_op = WRITE;
+ }
+
+ if (big_endian) {
+ p_dest = BSWAP16(p_dest);
+ }
+
+ fwrite(&p_dest, 1, 2, f);
+}
+
+void FileAccessWindows::store_32(uint32_t p_dest) {
+ ERR_FAIL_NULL(f);
+
+ if (flags == READ_WRITE || flags == WRITE_READ) {
+ if (prev_op == READ) {
+ if (last_error != ERR_FILE_EOF) {
+ fseek(f, 0, SEEK_CUR);
+ }
+ }
+ prev_op = WRITE;
+ }
+
+ if (big_endian) {
+ p_dest = BSWAP32(p_dest);
+ }
+
+ fwrite(&p_dest, 1, 4, f);
+}
+
+void FileAccessWindows::store_64(uint64_t p_dest) {
+ ERR_FAIL_NULL(f);
+
+ if (flags == READ_WRITE || flags == WRITE_READ) {
+ if (prev_op == READ) {
+ if (last_error != ERR_FILE_EOF) {
+ fseek(f, 0, SEEK_CUR);
+ }
+ }
+ prev_op = WRITE;
+ }
+
+ if (big_endian) {
+ p_dest = BSWAP64(p_dest);
+ }
+
+ fwrite(&p_dest, 1, 8, f);
+}
+
void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_NULL(f);
ERR_FAIL_COND(!p_src && p_length > 0);
diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h
index 73143009fc..173423fb06 100644
--- a/drivers/windows/file_access_windows.h
+++ b/drivers/windows/file_access_windows.h
@@ -50,10 +50,11 @@ class FileAccessWindows : public FileAccess {
void _close();
- static bool is_path_invalid(const String &p_path);
static HashSet<String> invalid_files;
public:
+ static bool is_path_invalid(const String &p_path);
+
virtual String fix_path(const String &p_path) const override;
virtual Error open_internal(const String &p_path, int p_mode_flags) override; ///< open a file
virtual bool is_open() const override; ///< true when file is open
@@ -69,12 +70,18 @@ public:
virtual bool eof_reached() const override; ///< reading passed EOF
virtual uint8_t get_8() const override; ///< get a byte
+ virtual uint16_t get_16() const override;
+ virtual uint32_t get_32() const override;
+ virtual uint64_t get_64() const override;
virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const override;
virtual Error get_error() const override; ///< get last error
virtual void flush() override;
virtual void store_8(uint8_t p_dest) override; ///< store a byte
+ virtual void store_16(uint16_t p_dest) override;
+ virtual void store_32(uint32_t p_dest) override;
+ virtual void store_64(uint64_t p_dest) override;
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length) override; ///< store an array of bytes
virtual bool file_exists(const String &p_name) override; ///< return true if a file exists