diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-08-31 09:00:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 09:00:53 +0200 |
commit | c80ea41e3bb49d9198c69e297c67ad0f9d38bb86 (patch) | |
tree | 0f740f2e1ccc4ee7b7aba982c336a8ace2d330bd | |
parent | d58a1d65a9e36ea4eeb3e8039da2dda6ffae95c0 (diff) | |
parent | f916dff26d3f9255aece2a4121a23fce15881747 (diff) |
Merge pull request #65095 from m4gr3d/update_get_current_dir_main
Additional fixes to the Android `get_current_dir()` implementation.
-rw-r--r-- | core/io/dir_access.h | 2 | ||||
-rw-r--r-- | platform/android/dir_access_jandroid.cpp | 16 | ||||
-rw-r--r-- | platform/android/dir_access_jandroid.h | 3 |
3 files changed, 17 insertions, 4 deletions
diff --git a/core/io/dir_access.h b/core/io/dir_access.h index d5318dfb45..2469c2a080 100644 --- a/core/io/dir_access.h +++ b/core/io/dir_access.h @@ -55,7 +55,7 @@ private: protected: String _get_root_path() const; - String _get_root_string() const; + virtual String _get_root_string() const; AccessType get_access_type() const; String fix_path(String p_path) const; diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 373c6e37f1..4f1ac16975 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -135,6 +135,13 @@ String DirAccessJAndroid::get_drive(int p_drive) { } } +String DirAccessJAndroid::_get_root_string() const { + if (get_access_type() == ACCESS_FILESYSTEM) { + return "/"; + } + return DirAccessUnix::_get_root_string(); +} + String DirAccessJAndroid::get_current_dir(bool p_include_drive) const { String base = _get_root_path(); String bd = current_dir; @@ -142,10 +149,13 @@ String DirAccessJAndroid::get_current_dir(bool p_include_drive) const { bd = current_dir.replace_first(base, ""); } - if (bd.begins_with("/")) { - return _get_root_string() + bd.substr(1, bd.length()); + String root_string = _get_root_string(); + if (bd.begins_with(root_string)) { + return bd; + } else if (bd.begins_with("/")) { + return root_string + bd.substr(1, bd.length()); } else { - return _get_root_string() + bd; + return root_string + bd; } } diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h index 5b7b4a9c4d..5c4f1852a9 100644 --- a/platform/android/dir_access_jandroid.h +++ b/platform/android/dir_access_jandroid.h @@ -91,6 +91,9 @@ public: DirAccessJAndroid(); ~DirAccessJAndroid(); +protected: + String _get_root_string() const override; + private: int id = 0; |