diff options
| author | volzhs | 2016-06-03 03:39:37 +0900 |
|---|---|---|
| committer | volzhs | 2016-06-03 03:39:37 +0900 |
| commit | 9073dc99634285edc3b4886467871c14100f8233 (patch) | |
| tree | dfb5f44ef5513ac40739c7109d641c3018d33df5 | |
| parent | 182ee80b7d0e187053150add897931363e5caab4 (diff) | |
| download | godot-9073dc99634285edc3b4886467871c14100f8233.tar.gz godot-9073dc99634285edc3b4886467871c14100f8233.tar.zst godot-9073dc99634285edc3b4886467871c14100f8233.zip | |
change invalid characters when get user data dir on Windows & Unix
Can't create user data folder when project name has ``\ / : * ? " < > |`` characters on OS_Windows & OS_Unix.
So, change it to ``-`` to be able to make folder.
fixes #4928 and it's altanative to #4986.
| -rw-r--r-- | core/os/os.cpp | 9 | ||||
| -rw-r--r-- | core/os/os.h | 1 | ||||
| -rw-r--r-- | drivers/unix/os_unix.cpp | 2 | ||||
| -rw-r--r-- | platform/windows/os_windows.cpp | 2 |
4 files changed, 12 insertions, 2 deletions
diff --git a/core/os/os.cpp b/core/os/os.cpp index 6910b368d..4daf41e68 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -306,6 +306,15 @@ String OS::get_system_dir(SystemDir p_dir) const { return "."; } +String OS::get_safe_application_name() const { + String an = Globals::get_singleton()->get("application/name"); + Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" "); + for (int i=0;i<invalid_char.size();i++) { + an = an.replace(invalid_char[i],"-"); + } + return an; +} + String OS::get_data_dir() const { return "."; diff --git a/core/os/os.h b/core/os/os.h index 76dd235d2..a1047bd48 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -326,6 +326,7 @@ public: virtual String get_locale() const; + String get_safe_application_name() const; virtual String get_data_dir() const; virtual String get_resource_dir() const; diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 4fa46b16c..8cb7c7b69 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -464,7 +464,7 @@ int OS_Unix::get_processor_count() const { String OS_Unix::get_data_dir() const { - String an = Globals::get_singleton()->get("application/name"); + String an = get_safe_application_name(); if (an!="") { diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 4f2bfd46a..aff48c718 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2243,7 +2243,7 @@ String OS_Windows::get_system_dir(SystemDir p_dir) const { } String OS_Windows::get_data_dir() const { - String an = Globals::get_singleton()->get("application/name"); + String an = get_safe_application_name(); if (an!="") { if (has_environment("APPDATA")) { |
