Android bindings for OS::get_tmp_dir()

This commit is contained in:
Alex 2024-10-22 21:04:09 +02:00 committed by Adam Scott
parent 152e24c7de
commit de6002fabd
No known key found for this signature in database
GPG Key ID: F6BA2A0302E21A77
5 changed files with 41 additions and 0 deletions

View File

@ -131,6 +131,18 @@ public class GodotIO {
return activity.getCacheDir().getAbsolutePath();
}
public String getTmpDir() {
File tmpDir = new File(getCacheDir() + "/tmp");
if (!tmpDir.exists()) {
if (!tmpDir.mkdirs()) {
Log.e(TAG, "Unable to create tmp dir");
}
}
return tmpDir.getAbsolutePath();
}
public String getDataDir() {
return activity.getFilesDir().getAbsolutePath();
}

View File

@ -52,6 +52,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
_open_URI = p_env->GetMethodID(cls, "openURI", "(Ljava/lang/String;)I");
_get_cache_dir = p_env->GetMethodID(cls, "getCacheDir", "()Ljava/lang/String;");
_get_tmp_dir = p_env->GetMethodID(cls, "getTmpDir", "()Ljava/lang/String;");
_get_data_dir = p_env->GetMethodID(cls, "getDataDir", "()Ljava/lang/String;");
_get_display_cutouts = p_env->GetMethodID(cls, "getDisplayCutouts", "()[I"),
_get_display_safe_area = p_env->GetMethodID(cls, "getDisplaySafeArea", "()[I"),
@ -106,6 +107,17 @@ String GodotIOJavaWrapper::get_cache_dir() {
}
}
String GodotIOJavaWrapper::get_tmp_dir() {
if (_get_tmp_dir) {
JNIEnv *env = get_jni_env();
ERR_FAIL_NULL_V(env, String());
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_tmp_dir);
return jstring_to_string(s, env);
} else {
return String();
}
}
String GodotIOJavaWrapper::get_user_data_dir() {
if (_get_data_dir) {
JNIEnv *env = get_jni_env();

View File

@ -48,6 +48,7 @@ private:
jmethodID _open_URI = 0;
jmethodID _get_cache_dir = 0;
jmethodID _get_data_dir = 0;
jmethodID _get_tmp_dir = 0;
jmethodID _get_display_cutouts = 0;
jmethodID _get_display_safe_area = 0;
jmethodID _get_locale = 0;
@ -71,6 +72,7 @@ public:
Error open_uri(const String &p_uri);
String get_cache_dir();
String get_tmp_dir();
String get_user_data_dir();
String get_locale();
String get_model();

View File

@ -677,6 +677,19 @@ String OS_Android::get_cache_path() const {
return ".";
}
String OS_Android::get_tmp_path() const {
if (!tmp_dir_cache.is_empty()) {
return tmp_dir_cache;
}
String tmp_dir = godot_io_java->get_tmp_dir();
if (!tmp_dir.is_empty()) {
tmp_dir_cache = _remove_symlink(tmp_dir);
return tmp_dir_cache;
}
return ".";
}
String OS_Android::get_unique_id() const {
String unique_id = godot_io_java->get_unique_id();
if (!unique_id.is_empty()) {

View File

@ -58,6 +58,7 @@ private:
mutable String data_dir_cache;
mutable String cache_dir_cache;
mutable String tmp_dir_cache;
mutable String remote_fs_dir;
AudioDriverOpenSL audio_driver_android;
@ -148,6 +149,7 @@ public:
virtual String get_user_data_dir() const override;
virtual String get_data_path() const override;
virtual String get_cache_path() const override;
virtual String get_tmp_path() const override;
virtual String get_resource_dir() const override;
virtual String get_locale() const override;
virtual String get_model_name() const override;