From 9910d4681dbeda3dd8c2c1162d955187dfe517d6 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Tue, 30 Aug 2022 08:47:50 -0700 Subject: [PATCH] Additional fixes to the Android `get_current_dir()` implementation. --- core/os/dir_access.h | 2 +- platform/android/dir_access_jandroid.cpp | 16 +++++++++++++--- platform/android/dir_access_jandroid.h | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 5eb8ca6fac6..0769da65cdb 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -54,7 +54,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 94841d51788..0916a22d37b 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -134,6 +134,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() { String base = _get_root_path(); String bd = current_dir; @@ -141,10 +148,13 @@ String DirAccessJAndroid::get_current_dir() { 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 5cde19d3d8d..003eb99ee74 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;