summaryrefslogtreecommitdiff
path: root/platform/android/dir_access_jandroid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/dir_access_jandroid.cpp')
-rw-r--r--platform/android/dir_access_jandroid.cpp64
1 files changed, 35 insertions, 29 deletions
diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp
index 5461a3aefa..5b9eee8117 100644
--- a/platform/android/dir_access_jandroid.cpp
+++ b/platform/android/dir_access_jandroid.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "dir_access_jandroid.h"
+
#include "core/string/print_string.h"
#include "file_access_android.h"
#include "string_android.h"
@@ -41,7 +42,7 @@ jmethodID DirAccessJAndroid::_dir_next = nullptr;
jmethodID DirAccessJAndroid::_dir_close = nullptr;
jmethodID DirAccessJAndroid::_dir_is_dir = nullptr;
-DirAccess *DirAccessJAndroid::create_fs() {
+Ref<DirAccess> DirAccessJAndroid::create_fs() {
return memnew(DirAccessJAndroid);
}
@@ -51,9 +52,9 @@ Error DirAccessJAndroid::list_dir_begin() {
jstring js = env->NewStringUTF(current_dir.utf8().get_data());
int res = env->CallIntMethod(io, _dir_open, js);
- if (res <= 0)
+ if (res <= 0) {
return ERR_CANT_OPEN;
-
+ }
id = res;
return OK;
@@ -64,9 +65,9 @@ String DirAccessJAndroid::get_next() {
JNIEnv *env = get_jni_env();
jstring str = (jstring)env->CallObjectMethod(io, _dir_next, id);
- if (!str)
+ if (!str) {
return "";
-
+ }
String ret = jstring_to_string((jstring)str, env);
env->DeleteLocalRef((jobject)str);
return ret;
@@ -83,9 +84,9 @@ bool DirAccessJAndroid::current_is_hidden() const {
}
void DirAccessJAndroid::list_dir_end() {
- if (id == 0)
+ if (id == 0) {
return;
-
+ }
JNIEnv *env = get_jni_env();
env->CallVoidMethod(io, _dir_close, id);
id = 0;
@@ -102,22 +103,25 @@ String DirAccessJAndroid::get_drive(int p_drive) {
Error DirAccessJAndroid::change_dir(String p_dir) {
JNIEnv *env = get_jni_env();
- if (p_dir.is_empty() || p_dir == "." || (p_dir == ".." && current_dir.is_empty()))
+ if (p_dir.is_empty() || p_dir == "." || (p_dir == ".." && current_dir.is_empty())) {
return OK;
+ }
String new_dir;
- if (p_dir != "res://" && p_dir.length() > 1 && p_dir.ends_with("/"))
+ if (p_dir != "res://" && p_dir.length() > 1 && p_dir.ends_with("/")) {
p_dir = p_dir.substr(0, p_dir.length() - 1);
+ }
- if (p_dir.begins_with("/"))
+ if (p_dir.begins_with("/")) {
new_dir = p_dir.substr(1, p_dir.length());
- else if (p_dir.begins_with("res://"))
+ } else if (p_dir.begins_with("res://")) {
new_dir = p_dir.substr(6, p_dir.length());
- else if (current_dir.is_empty())
+ } else if (current_dir.is_empty()) {
new_dir = p_dir;
- else
+ } else {
new_dir = current_dir.plus_file(p_dir);
+ }
//test if newdir exists
new_dir = new_dir.simplify_path();
@@ -125,8 +129,9 @@ Error DirAccessJAndroid::change_dir(String p_dir) {
jstring js = env->NewStringUTF(new_dir.utf8().get_data());
int res = env->CallIntMethod(io, _dir_open, js);
env->DeleteLocalRef(js);
- if (res <= 0)
+ if (res <= 0) {
return ERR_INVALID_PARAMETER;
+ }
env->CallVoidMethod(io, _dir_close, res);
@@ -135,20 +140,21 @@ Error DirAccessJAndroid::change_dir(String p_dir) {
return OK;
}
-String DirAccessJAndroid::get_current_dir(bool p_include_drive) {
+String DirAccessJAndroid::get_current_dir(bool p_include_drive) const {
return "res://" + current_dir;
}
bool DirAccessJAndroid::file_exists(String p_file) {
String sd;
- if (current_dir.is_empty())
+ if (current_dir.is_empty()) {
sd = p_file;
- else
+ } else {
sd = current_dir.plus_file(p_file);
+ }
- FileAccessAndroid *f = memnew(FileAccessAndroid);
+ Ref<FileAccessAndroid> f;
+ f.instantiate();
bool exists = f->file_exists(sd);
- memdelete(f);
return exists;
}
@@ -158,27 +164,30 @@ bool DirAccessJAndroid::dir_exists(String p_dir) {
String sd;
- if (current_dir.is_empty())
+ if (current_dir.is_empty()) {
sd = p_dir;
- else {
- if (p_dir.is_relative_path())
+ } else {
+ if (p_dir.is_relative_path()) {
sd = current_dir.plus_file(p_dir);
- else
+ } else {
sd = fix_path(p_dir);
+ }
}
String path = sd.simplify_path();
- if (path.begins_with("/"))
+ if (path.begins_with("/")) {
path = path.substr(1, path.length());
- else if (path.begins_with("res://"))
+ } else if (path.begins_with("res://")) {
path = path.substr(6, path.length());
+ }
jstring js = env->NewStringUTF(path.utf8().get_data());
int res = env->CallIntMethod(io, _dir_open, js);
env->DeleteLocalRef(js);
- if (res <= 0)
+ if (res <= 0) {
return false;
+ }
env->CallVoidMethod(io, _dir_close, res);
@@ -216,12 +225,9 @@ void DirAccessJAndroid::setup(jobject p_io) {
_dir_next = env->GetMethodID(cls, "dir_next", "(I)Ljava/lang/String;");
_dir_close = env->GetMethodID(cls, "dir_close", "(I)V");
_dir_is_dir = env->GetMethodID(cls, "dir_is_dir", "(I)Z");
-
- //(*env)->CallVoidMethod(env,obj,aMethodID, myvar);
}
DirAccessJAndroid::DirAccessJAndroid() {
- id = 0;
}
DirAccessJAndroid::~DirAccessJAndroid() {