diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-07-02 11:48:02 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-07-02 11:49:52 -0300 |
commit | 973a12c5f2420b56438086c9a81eaf6bea2b537d (patch) | |
tree | 2d02f987747eab14d30da870a92dc23a91ac2fb6 /platform | |
parent | eade613dc7e83646490477dc188a0cfdf75fa67a (diff) |
Data dir returns a symlink in Android 6.0, which confuses DirAccess on android, this should fix it
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/os_android.cpp | 29 | ||||
-rw-r--r-- | platform/android/os_android.h | 2 |
2 files changed, 29 insertions, 2 deletions
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 4e6dfb2db2..c464caff94 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -708,8 +708,33 @@ void OS_Android::set_need_reload_hooks(bool p_needs_them) { String OS_Android::get_data_dir() const { - if (get_data_dir_func) - return get_data_dir_func(); + if (data_dir_cache!=String()) + return data_dir_cache; + + if (get_data_dir_func) { + String data_dir=get_data_dir_func(); + + //store current dir + char real_current_dir_name[2048]; + getcwd(real_current_dir_name,2048); + + //go to data dir + chdir(data_dir.utf8().get_data()); + + //get actual data dir, so we resolve potential symlink (Android 6.0+ seems to use symlink) + char data_current_dir_name[2048]; + getcwd(data_current_dir_name,2048); + + //cache by parsing utf8 + data_dir_cache.parse_utf8(data_current_dir_name); + + //restore original dir so we don't mess things up + chdir(real_current_dir_name); + + return data_dir_cache + } + + return "."; //return Globals::get_singleton()->get_singleton_object("GodotOS")->call("get_data_dir"); }; diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 843b3c4788..e82e08ea49 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -123,6 +123,8 @@ private: PhysicsServer *physics_server; Physics2DServer *physics_2d_server; + mutable String data_dir_cache; + #if 0 AudioDriverAndroid audio_driver_android; #else |