From fdaa2920eb21fff3320a17e9239e04dfadecdb00 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 18 Apr 2015 14:38:54 -0300 Subject: Updated copyright year in all headers --- platform/android/dir_access_jandroid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'platform/android/dir_access_jandroid.cpp') diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 98f20b263..37aecc77a 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ -- cgit v1.2.3-70-g09d2 From 1de1a04b78b65254aa41d7930947df82a121160c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 18 Apr 2015 20:11:33 -0300 Subject: -fix local and global usage for DirAccess, fixes #791 please test anyway.. --- drivers/unix/dir_access_unix.cpp | 15 +- drivers/windows/dir_access_windows.cpp | 224 ++++++--------------- drivers/windows/dir_access_windows.h | 2 +- platform/android/dir_access_jandroid.cpp | 15 +- .../io_plugins/editor_scene_import_plugin.cpp | 1 - 5 files changed, 87 insertions(+), 170 deletions(-) (limited to 'platform/android/dir_access_jandroid.cpp') diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index a1617eb0b..0c0867e03 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -87,7 +87,7 @@ bool DirAccessUnix::dir_exists(String p_dir) { if (p_dir.is_rel_path()) - p_dir=current_dir+"/"+p_dir; + p_dir=get_current_dir().plus_file(p_dir); else p_dir=fix_path(p_dir); @@ -278,9 +278,16 @@ String DirAccessUnix::get_current_dir() { Error DirAccessUnix::rename(String p_path,String p_new_path) { - p_path=fix_path(p_path); - p_new_path=fix_path(p_new_path); - + if (p_path.is_rel_path()) + p_path=get_current_dir().plus_file(p_path); + else + p_path=fix_path(p_path); + + if (p_new_path.is_rel_path()) + p_new_path=get_current_dir().plus_file(p_new_path); + else + p_new_path=fix_path(p_new_path); + return ::rename(p_path.utf8().get_data(),p_new_path.utf8().get_data())==0?OK:FAILED; } Error DirAccessUnix::remove(String p_path) { diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 30c1b14df..a8fed91d9 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -70,21 +70,11 @@ bool DirAccessWindows::list_dir_begin() { _cisdir=false; _cishidden=false; - if (unicode) { - list_dir_end(); - p->h = FindFirstFileExW((current_dir+"\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0); + list_dir_end(); + p->h = FindFirstFileExW((current_dir+"\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0); - return (p->h==INVALID_HANDLE_VALUE); - } else { - - list_dir_end(); - p->h = FindFirstFileExA((current_dir+"\\*").ascii().get_data(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0); - - return (p->h==INVALID_HANDLE_VALUE); - - } + return (p->h==INVALID_HANDLE_VALUE); - return false; } @@ -93,38 +83,20 @@ String DirAccessWindows::get_next() { if (p->h==INVALID_HANDLE_VALUE) return ""; - if (unicode) { - _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN); + _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN); - String name=p->fu.cFileName; - - if (FindNextFileW(p->h, &p->fu) == 0) { - - FindClose(p->h); - p->h=INVALID_HANDLE_VALUE; - } - - return name; - } else { + String name=p->fu.cFileName; -#ifndef WINRT_ENABLED - _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN); + if (FindNextFileW(p->h, &p->fu) == 0) { - String name=p->f.cFileName; - - if (FindNextFileA(p->h, &p->f) == 0) { + FindClose(p->h); + p->h=INVALID_HANDLE_VALUE; + } - FindClose(p->h); - p->h=INVALID_HANDLE_VALUE; - } + return name; - return name; -#endif - return ""; - } } bool DirAccessWindows::current_is_dir() const { @@ -174,63 +146,37 @@ Error DirAccessWindows::change_dir(String p_dir) { p_dir=fix_path(p_dir); - if (unicode) { - wchar_t real_current_dir_name[2048]; - GetCurrentDirectoryW(2048,real_current_dir_name); - String prev_dir=real_current_dir_name; + wchar_t real_current_dir_name[2048]; + GetCurrentDirectoryW(2048,real_current_dir_name); + String prev_dir=real_current_dir_name; - SetCurrentDirectoryW(current_dir.c_str()); - bool worked=(SetCurrentDirectoryW(p_dir.c_str())!=0); + SetCurrentDirectoryW(current_dir.c_str()); + bool worked=(SetCurrentDirectoryW(p_dir.c_str())!=0); - String base = _get_root_path(); - if (base!="") { + String base = _get_root_path(); + if (base!="") { - GetCurrentDirectoryW(2048,real_current_dir_name); - String new_dir; - new_dir = String(real_current_dir_name).replace("\\","/"); - if (!new_dir.begins_with(base)) { - worked=false; - } + GetCurrentDirectoryW(2048,real_current_dir_name); + String new_dir; + new_dir = String(real_current_dir_name).replace("\\","/"); + if (!new_dir.begins_with(base)) { + worked=false; } + } - if (worked) { - - GetCurrentDirectoryW(2048,real_current_dir_name); - current_dir=real_current_dir_name; // TODO, utf8 parser - current_dir=current_dir.replace("\\","/"); - - } //else { - - SetCurrentDirectoryW(prev_dir.c_str()); - //} - - return worked?OK:ERR_INVALID_PARAMETER; - } else { - - char real_current_dir_name[2048]; - GetCurrentDirectoryA(2048,real_current_dir_name); - String prev_dir=real_current_dir_name; - - SetCurrentDirectoryA(current_dir.ascii().get_data()); - bool worked=(SetCurrentDirectory(p_dir.ascii().get_data())!=0); - - if (worked) { - - GetCurrentDirectoryA(2048,real_current_dir_name); - current_dir=real_current_dir_name; // TODO, utf8 parser - current_dir=current_dir.replace("\\","/"); - - }// else { + if (worked) { - SetCurrentDirectoryA(prev_dir.ascii().get_data()); - //} + GetCurrentDirectoryW(2048,real_current_dir_name); + current_dir=real_current_dir_name; // TODO, utf8 parser + current_dir=current_dir.replace("\\","/"); - return worked?OK:ERR_INVALID_PARAMETER; + } //else { - } + SetCurrentDirectoryW(prev_dir.c_str()); + //} - return OK; + return worked?OK:ERR_INVALID_PARAMETER; #endif } @@ -244,36 +190,22 @@ Error DirAccessWindows::make_dir(String p_dir) { #else - p_dir=fix_path(p_dir); + //p_dir=fix_path(p_dir); p_dir.replace("/","\\"); bool success; int err; - if (unicode) { - wchar_t real_current_dir_name[2048]; - GetCurrentDirectoryW(2048,real_current_dir_name); - - SetCurrentDirectoryW(current_dir.c_str()); - - success=CreateDirectoryW(p_dir.c_str(), NULL); - err = GetLastError(); - - SetCurrentDirectoryW(real_current_dir_name); - - } else { - - char real_current_dir_name[2048]; - GetCurrentDirectoryA(2048,real_current_dir_name); + wchar_t real_current_dir_name[2048]; + GetCurrentDirectoryW(2048,real_current_dir_name); - SetCurrentDirectoryA(current_dir.ascii().get_data()); + SetCurrentDirectoryW(current_dir.c_str()); - success=CreateDirectoryA(p_dir.ascii().get_data(), NULL); - err = GetLastError(); + success=CreateDirectoryW(p_dir.c_str(), NULL); + err = GetLastError(); - SetCurrentDirectoryA(real_current_dir_name); - } + SetCurrentDirectoryW(real_current_dir_name); if (success) { return OK; @@ -313,7 +245,7 @@ bool DirAccessWindows::file_exists(String p_file) { GLOBAL_LOCK_FUNCTION if (!p_file.is_abs_path()) - p_file=get_current_dir()+"/"+p_file; + p_file=get_current_dir().plus_file(p_file); p_file=fix_path(p_file); @@ -321,73 +253,52 @@ bool DirAccessWindows::file_exists(String p_file) { WIN32_FILE_ATTRIBUTE_DATA fileInfo; - if (unicode) { - - DWORD fileAttr; - - fileAttr = GetFileAttributesExW(p_file.c_str(), GetFileExInfoStandard, &fileInfo); - if (0 == fileAttr) - return false; - - return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY); - - } else { - DWORD fileAttr; - - fileAttr = GetFileAttributesExA(p_file.ascii().get_data(), GetFileExInfoStandard, &fileInfo); - if (0 == fileAttr) - return false; + DWORD fileAttr; - return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY); + fileAttr = GetFileAttributesExW(p_file.c_str(), GetFileExInfoStandard, &fileInfo); + if (0 == fileAttr) + return false; - } + return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY); - return false; } bool DirAccessWindows::dir_exists(String p_dir) { GLOBAL_LOCK_FUNCTION - if (!p_dir.is_abs_path()) - p_dir=get_current_dir()+"/"+p_dir; - - p_dir=fix_path(p_dir); + if (p_dir.is_rel_path()) + p_dir=get_current_dir().plus_file(p_dir); + else + p_dir=fix_path(p_dir); p_dir.replace("/","\\"); WIN32_FILE_ATTRIBUTE_DATA fileInfo; - if (unicode) { - - DWORD fileAttr; - fileAttr = GetFileAttributesExW(p_dir.c_str(), GetFileExInfoStandard, &fileInfo); - if (0 == fileAttr) - return false; + DWORD fileAttr; - return (fileAttr&FILE_ATTRIBUTE_DIRECTORY); + fileAttr = GetFileAttributesExW(p_dir.c_str(), GetFileExInfoStandard, &fileInfo); + if (0 == fileAttr) + return false; - } else { -#ifndef WINRT_ENABLED - DWORD fileAttr; - - fileAttr = GetFileAttributesExA(p_dir.ascii().get_data(), GetFileExInfoStandard, &fileInfo); - if (0 == fileAttr) - return false; - - return (fileAttr&FILE_ATTRIBUTE_DIRECTORY); + return (fileAttr&FILE_ATTRIBUTE_DIRECTORY); -#endif - } - return false; } Error DirAccessWindows::rename(String p_path,String p_new_path) { - p_path=fix_path(p_path); - p_new_path=fix_path(p_new_path); - + if (p_path.is_rel_path()) + p_path=get_current_dir().plus_file(p_path); + else + p_path=fix_path(p_path); + + if (p_new_path.is_rel_path()) + p_new_path=get_current_dir().plus_file(p_new_path); + else + p_new_path=fix_path(p_new_path); + if (file_exists(p_new_path)) { if (remove(p_new_path) != OK) { return FAILED; @@ -471,13 +382,6 @@ DirAccessWindows::DirAccessWindows() { } } - unicode=true; - - - /* We are running Windows 95/98/ME, so no unicode allowed */ - if ( SetCurrentDirectoryW ( L"." ) == FALSE && GetLastError () == ERROR_CALL_NOT_IMPLEMENTED ) - unicode=false; - change_dir("."); #endif } diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h index 4bf11f3f6..384bc8327 100644 --- a/drivers/windows/dir_access_windows.h +++ b/drivers/windows/dir_access_windows.h @@ -56,7 +56,7 @@ class DirAccessWindows : public DirAccess { String current_dir; - bool unicode; + bool _cisdir; bool _cishidden; diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 37aecc77a..3d2926b4f 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -176,7 +176,7 @@ bool DirAccessJAndroid::file_exists(String p_file){ if (current_dir=="") sd=p_file; else - sd=current_dir+"/"+p_file; + sd=current_dir.plus_file(p_file); FileAccessJAndroid *f = memnew(FileAccessJAndroid); bool exists = f->file_exists(sd); @@ -190,12 +190,19 @@ 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; + else { + if (p_dir.is_rel_path()) + sd=current_dir.plus_file(p_dir); + else + sd=fix_path(p_dir); + } + + String path=sd.simplify_path(); - String path=fix_path(sd).simplify_path(); if (path.begins_with("/")) path=path.substr(1,path.length()); else if (path.begins_with("res://")) diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index f9715cb33..3fb4b06f3 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -734,7 +734,6 @@ void EditorSceneImportDialog::_import(bool p_and_open) { return; } - print_line("PI REFERENCES "+itos(scr->reference_get_count())); } -- cgit v1.2.3-70-g09d2 From c6dce44dd85c4ebae791756a76f6afbfbb0a5c28 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 28 Apr 2015 09:38:07 -0300 Subject: fixes in handling of DirAccess for resource path on Android, fixes #1447 --- platform/android/dir_access_jandroid.cpp | 53 +++++++++------------- platform/android/dir_access_jandroid.h | 1 + platform/android/file_access_jandroid.cpp | 1 - .../java/src/com/android/godot/GodotIO.java | 35 +++++++++++++- 4 files changed, 57 insertions(+), 33 deletions(-) (limited to 'platform/android/dir_access_jandroid.cpp') diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 3d2926b4f..2b5fc6a50 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -31,11 +31,15 @@ #include "dir_access_jandroid.h" #include "file_access_jandroid.h" #include "thread_jandroid.h" +#include "print_string.h" + + jobject DirAccessJAndroid::io=NULL; jclass DirAccessJAndroid::cls=NULL; jmethodID DirAccessJAndroid::_dir_open=NULL; jmethodID DirAccessJAndroid::_dir_next=NULL; jmethodID DirAccessJAndroid::_dir_close=NULL; +jmethodID DirAccessJAndroid::_dir_is_dir=NULL; DirAccess *DirAccessJAndroid::create_fs() { @@ -67,43 +71,18 @@ String DirAccessJAndroid::get_next(){ if (!str) return ""; - int sl = env->GetStringLength(str); - if (sl==0) { - env->DeleteLocalRef((jobject)str); - return ""; - } - - CharString cs; - cs.resize(sl+1); - env->GetStringRegion(str,0,sl,(jchar*)&cs[0]); - cs[sl]=0; - - String ret; - ret.parse_utf8(&cs[0]); + String ret = String::utf8(env->GetStringUTFChars( (jstring)str, NULL )); env->DeleteLocalRef((jobject)str); - return ret; } bool DirAccessJAndroid::current_is_dir() const{ - JNIEnv *env = ThreadAndroid::get_env(); - String sd; - if (current_dir=="") - sd=current; - else - sd=current_dir+"/"+current; - - jstring js = env->NewStringUTF(sd.utf8().get_data()); - int res = env->CallIntMethod(io,_dir_open,js); - if (res<=0) - return false; - - env->CallObjectMethod(io,_dir_close,res); + JNIEnv *env = ThreadAndroid::get_env(); + return env->CallBooleanMethod(io,_dir_is_dir,id); - return true; } bool DirAccessJAndroid::current_is_hidden() const { @@ -142,24 +121,31 @@ Error DirAccessJAndroid::change_dir(String p_dir){ String new_dir; + 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("/")) new_dir=p_dir.substr(1,p_dir.length()); else if (p_dir.begins_with("res://")) new_dir=p_dir.substr(6,p_dir.length()); - else //relative - new_dir=new_dir+"/"+p_dir; + else if (current_dir=="") + new_dir=p_dir; + else + new_dir=current_dir.plus_file(p_dir); + //print_line("new dir is: "+new_dir); //test if newdir exists new_dir=new_dir.simplify_path(); jstring js = env->NewStringUTF(new_dir.utf8().get_data()); int res = env->CallIntMethod(io,_dir_open,js); + env->DeleteLocalRef(js); if (res<=0) return ERR_INVALID_PARAMETER; env->CallObjectMethod(io,_dir_close,res); - + current_dir=new_dir; return OK; } @@ -210,6 +196,7 @@ bool DirAccessJAndroid::dir_exists(String p_dir) { jstring js = env->NewStringUTF(path.utf8().get_data()); int res = env->CallIntMethod(io,_dir_open,js); + env->DeleteLocalRef(js); if (res<=0) return false; @@ -263,6 +250,10 @@ void DirAccessJAndroid::setup( jobject p_io) { if(_dir_close != 0) { __android_log_print(ANDROID_LOG_INFO,"godot","*******GOT METHOD _dir_close ok!!"); } + _dir_is_dir = env->GetMethodID(cls, "dir_is_dir", "(I)Z"); + if(_dir_is_dir != 0) { + __android_log_print(ANDROID_LOG_INFO,"godot","*******GOT METHOD _dir_is_dir ok!!"); + } // (*env)->CallVoidMethod(env,obj,aMethodID, myvar); } diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h index dd08a0d21..7b6242ca3 100644 --- a/platform/android/dir_access_jandroid.h +++ b/platform/android/dir_access_jandroid.h @@ -47,6 +47,7 @@ class DirAccessJAndroid : public DirAccess { static jmethodID _dir_open; static jmethodID _dir_next; static jmethodID _dir_close; + static jmethodID _dir_is_dir; int id; diff --git a/platform/android/file_access_jandroid.cpp b/platform/android/file_access_jandroid.cpp index 2e3dd8289..971d4f84a 100644 --- a/platform/android/file_access_jandroid.cpp +++ b/platform/android/file_access_jandroid.cpp @@ -67,7 +67,6 @@ Error FileAccessJAndroid::_open(const String& p_path, int p_mode_flags) { jstring js = env->NewStringUTF(path.utf8().get_data()); int res = env->CallIntMethod(io,_file_open,js,p_mode_flags&WRITE?true:false); - env->DeleteLocalRef(js); if (res<=0) diff --git a/platform/android/java/src/com/android/godot/GodotIO.java b/platform/android/java/src/com/android/godot/GodotIO.java index b793b8850..addceb152 100644 --- a/platform/android/java/src/com/android/godot/GodotIO.java +++ b/platform/android/java/src/com/android/godot/GodotIO.java @@ -271,6 +271,7 @@ public class GodotIO { public String[] files; public int current; + public String path; } public int last_dir_id=1; @@ -281,6 +282,7 @@ public class GodotIO { AssetDir ad = new AssetDir(); ad.current=0; + ad.path=path; try { ad.files = am.list(path); @@ -290,6 +292,7 @@ public class GodotIO { return -1; } + //System.out.printf("Opened dir: %s\n",path); ++last_dir_id; dirs.put(last_dir_id,ad); @@ -297,6 +300,32 @@ public class GodotIO { } + public boolean dir_is_dir(int id) { + if (!dirs.containsKey(id)) { + System.out.printf("dir_next: invalid dir id: %d\n",id); + return false; + } + AssetDir ad = dirs.get(id); + //System.out.printf("go next: %d,%d\n",ad.current,ad.files.length); + int idx = ad.current; + if (idx>0) + idx--; + + if (idx>=ad.files.length) + return false; + String fname = ad.files[idx]; + + try { + if (ad.path.equals("")) + am.open(fname); + else + am.open(ad.path+"/"+fname); + return false; + } catch (Exception e) { + return true; + } + } + public String dir_next(int id) { if (!dirs.containsKey(id)) { @@ -305,8 +334,12 @@ public class GodotIO { } AssetDir ad = dirs.get(id); - if (ad.current>=ad.files.length) + //System.out.printf("go next: %d,%d\n",ad.current,ad.files.length); + + if (ad.current>=ad.files.length) { + ad.current++; return ""; + } String r = ad.files[ad.current]; ad.current++; return r; -- cgit v1.2.3-70-g09d2