From 1e55de9b8b1f85eb70c3b2d3c1b53adbc30e62c4 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 9 Feb 2024 10:47:07 +0200 Subject: [PATCH] [Windows] Fix windows is_path_invalid, and apply it to directory creation. (cherry picked from commit be8f60a78d36542a5da497d3b99f59ca78b093a9) --- drivers/windows/dir_access_windows.cpp | 8 ++++++++ drivers/windows/file_access_windows.cpp | 7 +------ drivers/windows/file_access_windows.h | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 8bf83823a03..9d370e30a52 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" @@ -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/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index 9d21073f190..e0889d5ad03 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -60,12 +60,7 @@ void FileAccessWindows::check_errors() const { bool FileAccessWindows::is_path_invalid(const String &p_path) { // Check for invalid operating system file. - String fname = p_path; - int dot = fname.find("."); - if (dot != -1) { - fname = fname.substr(0, dot); - } - fname = fname.to_lower(); + String fname = p_path.get_file().get_basename().to_lower(); return invalid_files.has(fname); } diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h index 73143009fcf..10f34009f78 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 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