Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Additional fixes to the Android get_current_dir() implementation. #65093

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/os/dir_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DirAccess {

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;
Expand Down
16 changes: 13 additions & 3 deletions platform/android/dir_access_jandroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,27 @@ 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;
if (base != "") {
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;
}
}

Expand Down
3 changes: 3 additions & 0 deletions platform/android/dir_access_jandroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class DirAccessJAndroid : public DirAccessUnix {
DirAccessJAndroid();
~DirAccessJAndroid();

protected:
String _get_root_string() const override;

private:
int id = 0;

Expand Down