Преглед изворни кода

Merge pull request #65093 from m4gr3d/update_get_current_dir_3x

[3.x] Additional fixes to the Android `get_current_dir()` implementation.
Rémi Verschelde пре 3 година
родитељ
комит
4b066320f4
3 измењених фајлова са 17 додато и 4 уклоњено
  1. 1 1
      core/os/dir_access.h
  2. 13 3
      platform/android/dir_access_jandroid.cpp
  3. 3 0
      platform/android/dir_access_jandroid.h

+ 1 - 1
core/os/dir_access.h

@@ -54,7 +54,7 @@ private:
 
 
 protected:
 protected:
 	String _get_root_path() const;
 	String _get_root_path() const;
-	String _get_root_string() const;
+	virtual String _get_root_string() const;
 
 
 	AccessType get_access_type() const;
 	AccessType get_access_type() const;
 	String fix_path(String p_path) const;
 	String fix_path(String p_path) const;

+ 13 - 3
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 DirAccessJAndroid::get_current_dir() {
 	String base = _get_root_path();
 	String base = _get_root_path();
 	String bd = current_dir;
 	String bd = current_dir;
@@ -141,10 +148,13 @@ String DirAccessJAndroid::get_current_dir() {
 		bd = current_dir.replace_first(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 {
 	} else {
-		return _get_root_string() + bd;
+		return root_string + bd;
 	}
 	}
 }
 }
 
 

+ 3 - 0
platform/android/dir_access_jandroid.h

@@ -91,6 +91,9 @@ public:
 	DirAccessJAndroid();
 	DirAccessJAndroid();
 	~DirAccessJAndroid();
 	~DirAccessJAndroid();
 
 
+protected:
+	String _get_root_string() const override;
+
 private:
 private:
 	int id = 0;
 	int id = 0;