diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/dir_access.cpp | 3 | ||||
-rw-r--r-- | core/os/file_access.h | 2 | ||||
-rw-r--r-- | core/os/os.cpp | 22 | ||||
-rw-r--r-- | core/os/os.h | 8 |
4 files changed, 24 insertions, 11 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 6d4b46f4da..e19c8e8ea5 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -333,6 +333,9 @@ Error DirAccess::copy(String p_from, String p_to, int chmod_flags) { if (err == OK && chmod_flags != -1) { fdst->close(); err = fdst->_chmod(p_to, chmod_flags); + // If running on a platform with no chmod support (i.e., Windows), don't fail + if (err == ERR_UNAVAILABLE) + err = OK; } memdelete(fsrc); diff --git a/core/os/file_access.h b/core/os/file_access.h index 455dd1ea99..6fda3d9668 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -141,7 +141,7 @@ public: virtual Error reopen(const String &p_path, int p_mode_flags); ///< does not change the AccessType - virtual Error _chmod(const String &p_path, int p_mod) { return FAILED; } + virtual Error _chmod(const String &p_path, int p_mod) { return ERR_UNAVAILABLE; } static FileAccess *create(AccessType p_access); /// Create a file access (for the current platform) this is the only portable way of accessing files. static FileAccess *create_for_path(const String &p_path); diff --git a/core/os/os.cpp b/core/os/os.cpp index a39dfcc003..8088a6fa74 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -279,14 +279,22 @@ String OS::get_locale() const { return "en"; } -// Helper function used by OS_Unix and OS_Windows -String OS::get_safe_application_name() const { - String an = ProjectSettings::get_singleton()->get("application/config/name"); - Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" "); - for (int i = 0; i < invalid_char.size(); i++) { - an = an.replace(invalid_char[i], "-"); +// Helper function to ensure that a dir name/path will be valid on the OS +String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const { + + Vector<String> invalid_chars = String(": * ? \" < > |").split(" "); + if (p_allow_dir_separator) { + // Dir separators are allowed, but disallow ".." to avoid going up the filesystem + invalid_chars.push_back(".."); + } else { + invalid_chars.push_back("/"); + } + + String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges(); + for (int i = 0; i < invalid_chars.size(); i++) { + safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-"); } - return an; + return safe_dir_name; } // Path to data, config, cache, etc. OS-specific folders diff --git a/core/os/os.h b/core/os/os.h index d7a1512e39..979ad7e92a 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -92,14 +92,16 @@ public: bool resizable; bool borderless_window; bool maximized; + bool use_vsync; float get_aspect() const { return (float)width / (float)height; } - VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false) { + VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_use_vsync = false) { width = p_width; height = p_height; fullscreen = p_fullscreen; resizable = p_resizable; borderless_window = p_borderless_window; maximized = p_maximized; + use_vsync = p_use_vsync; } }; @@ -195,7 +197,7 @@ public: virtual void set_ime_position(const Point2 &p_pos) {} virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {} - virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; } + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) { return ERR_UNAVAILABLE; } virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; } virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; } @@ -338,7 +340,7 @@ public: virtual String get_locale() const; - String get_safe_application_name() const; + String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const; virtual String get_godot_dir_name() const; virtual String get_data_path() const; |