summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authormarynate <mary.w.nate@gmail.com>2014-05-25 11:34:51 +0800
committermarynate <mary.w.nate@gmail.com>2014-05-25 14:50:54 +0800
commite6c1689b69e9e0ec530902b550c9e1e2d1cd0aae (patch)
treeec9350bef9fc1c0bf6bedd73cc5768115dd6efec /platform
parent71355aaab7eca64bec694918c6b911a412ad17f0 (diff)
Add DirAccess:dir_exist api
Diffstat (limited to 'platform')
-rw-r--r--platform/android/dir_access_jandroid.cpp26
-rw-r--r--platform/android/dir_access_jandroid.h1
-rw-r--r--platform/flash/dir_access_flash.cpp20
-rw-r--r--platform/flash/dir_access_flash.h1
4 files changed, 48 insertions, 0 deletions
diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp
index 0c8a5785f8..f32e16e7d8 100644
--- a/platform/android/dir_access_jandroid.cpp
+++ b/platform/android/dir_access_jandroid.cpp
@@ -179,6 +179,32 @@ bool DirAccessJAndroid::file_exists(String p_file){
return exists;
}
+bool DirAccessJAndroid::dir_exists(String p_dir) {
+
+ JNIEnv *env = ThreadAndroid::get_env();
+
+ String sd;
+ if (current_dir=="")
+ sd=p_dir;
+ else
+ sd=current_dir+"/"+p_dir;
+
+ String path=fix_path(sd).simplify_path();
+ if (path.begins_with("/"))
+ path=path.substr(1,path.length());
+ 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);
+ if (res<=0)
+ return false;
+
+ env->CallVoidMethod(io,_dir_close,res);
+ env->DeleteLocalRef(js);
+
+ return true;
+}
Error DirAccessJAndroid::make_dir(String p_dir){
diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h
index b6e3fe393f..958ea34891 100644
--- a/platform/android/dir_access_jandroid.h
+++ b/platform/android/dir_access_jandroid.h
@@ -70,6 +70,7 @@ public:
virtual bool file_exists(String p_file);
+ virtual bool dir_exists(String p_dir);
virtual Error make_dir(String p_dir);
diff --git a/platform/flash/dir_access_flash.cpp b/platform/flash/dir_access_flash.cpp
index a0f1679243..4b8992f9d6 100644
--- a/platform/flash/dir_access_flash.cpp
+++ b/platform/flash/dir_access_flash.cpp
@@ -156,6 +156,26 @@ bool DirAccessFlash::file_exists(String p_file) {
return success;
};
+bool DirAccessFlash::dir_exists(String p_dir) {
+
+ GLOBAL_LOCK_FUNCTION
+
+
+ if (p_dir.is_rel_path())
+ p_dir=current_dir+"/"+p_dir;
+ else
+ p_dir=fix_path(p_dir);
+
+ struct stat flags;
+ bool success = (stat(p_dir.utf8().get_data(),&flags)==0);
+
+ if (success && S_ISDIR(flags.st_mode)) {
+ return true;
+ }
+
+ return false;
+};
+
size_t DirAccessFlash::get_space_left() {
return 0;
diff --git a/platform/flash/dir_access_flash.h b/platform/flash/dir_access_flash.h
index 09e0b844ce..1378a6e56f 100644
--- a/platform/flash/dir_access_flash.h
+++ b/platform/flash/dir_access_flash.h
@@ -45,6 +45,7 @@ public:
Error make_dir(String p_dir);
bool file_exists(String p_file);
+ bool dir_exists(String p_dir);
size_t get_space_left();