Merge pull request #98397 from adamscott/add-tmp-support

Add temp utilities (alias `OS::get_temp_dir()`, `FileAccess::create_temp()`, and `DirAccess::create_temp()`)
This commit is contained in:
Thaddeus Crews 2024-12-03 14:40:59 -06:00
commit 156bc92282
No known key found for this signature in database
GPG key ID: 62181B86FE9E5D84
26 changed files with 331 additions and 7 deletions

View file

@ -132,6 +132,18 @@ public class GodotIO {
return activity.getCacheDir().getAbsolutePath();
}
public String getTempDir() {
File tempDir = new File(getCacheDir() + "/tmp");
if (!tempDir.exists()) {
if (!tempDir.mkdirs()) {
Log.e(TAG, "Unable to create temp dir");
}
}
return tempDir.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_temp_dir = p_env->GetMethodID(cls, "getTempDir", "()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_temp_dir() {
if (_get_temp_dir) {
JNIEnv *env = get_jni_env();
ERR_FAIL_NULL_V(env, String());
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_temp_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_temp_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_temp_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_temp_path() const {
if (!temp_dir_cache.is_empty()) {
return temp_dir_cache;
}
String temp_dir = godot_io_java->get_temp_dir();
if (!temp_dir.is_empty()) {
temp_dir_cache = _remove_symlink(temp_dir);
return temp_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 temp_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_temp_path() const override;
virtual String get_resource_dir() const override;
virtual String get_locale() const override;
virtual String get_model_name() const override;