From b5e1096c61b8976f193328628b6099ff2830e9c4 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Sun, 14 Aug 2022 19:26:06 -0700 Subject: [PATCH] Fix issue with `get_current_dir()` returning the wrong path on Android --- platform/android/dir_access_jandroid.cpp | 14 ++++++++++++++ platform/android/dir_access_jandroid.h | 1 + 2 files changed, 15 insertions(+) diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 2f5fc5f1aec..94841d51788 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -134,6 +134,20 @@ String DirAccessJAndroid::get_drive(int p_drive) { } } +String DirAccessJAndroid::get_current_dir() { + String base = _get_root_path(); + String bd = current_dir; + if (base != "") { + bd = current_dir.replace_first(base, ""); + } + + if (bd.begins_with("/")) { + return _get_root_string() + bd.substr(1, bd.length()); + } else { + return _get_root_string() + bd; + } +} + Error DirAccessJAndroid::change_dir(String p_dir) { String new_dir = get_absolute_path(p_dir); if (new_dir == current_dir) { diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h index 539fa4d7945..5cde19d3d8d 100644 --- a/platform/android/dir_access_jandroid.h +++ b/platform/android/dir_access_jandroid.h @@ -69,6 +69,7 @@ public: virtual String get_drive(int p_drive) override; virtual Error change_dir(String p_dir) override; ///< can be relative or absolute, return false on success + virtual String get_current_dir() override; ///< return current dir location virtual bool file_exists(String p_file) override; virtual bool dir_exists(String p_dir) override;