summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-11-26 22:25:02 +0100
committerGitHub <noreply@github.com>2017-11-26 22:25:02 +0100
commit90f9f123fd4a79440d21557d4f56ef35be318fad (patch)
tree9032870c3a2e7f470401580203e6c7727aa6eb4b /core/os
parent4a1d1cbbb4e462a016d87acb316b5ae12984fe81 (diff)
parentaf9c67db0c998bbd6f0de1ab0af98f9e615e6029 (diff)
Merge pull request #13317 from akien-mga/custom_user_dir
Allow customizing user:// path (folder in OS::get_data_path())
Diffstat (limited to 'core/os')
-rw-r--r--core/os/os.cpp22
-rw-r--r--core/os/os.h2
2 files changed, 16 insertions, 8 deletions
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..c72696fe37 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -338,7 +338,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;