| 1751 | } |
| 1752 | |
| 1753 | void android_GetNextDir(const char* pdir, char *dir) |
| 1754 | { |
| 1755 | // Attaches the current thread to the JVM. |
| 1756 | jint lResult; |
| 1757 | jint lFlags = 0; |
| 1758 | |
| 1759 | JavaVM* lJavaVM = engine.app->activity->vm; |
| 1760 | JNIEnv* lJNIEnv = engine.app->activity->env; |
| 1761 | |
| 1762 | JavaVMAttachArgs lJavaVMAttachArgs; |
| 1763 | lJavaVMAttachArgs.version = JNI_VERSION_1_6; |
| 1764 | lJavaVMAttachArgs.name = "NativeThread"; |
| 1765 | lJavaVMAttachArgs.group = NULL; |
| 1766 | |
| 1767 | lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); |
| 1768 | if (lResult == JNI_ERR) { |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | // Retrieves NativeActivity. |
| 1773 | jobject lNativeActivity = engine.app->activity->clazz; |
| 1774 | jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity); |
| 1775 | |
| 1776 | jmethodID getClassLoader = lJNIEnv->GetMethodID(ClassNativeActivity,"getClassLoader", "()Ljava/lang/ClassLoader;"); |
| 1777 | jobject cls = lJNIEnv->CallObjectMethod(lNativeActivity, getClassLoader); |
| 1778 | jclass classLoader = lJNIEnv->FindClass("java/lang/ClassLoader"); |
| 1779 | jmethodID findClass = lJNIEnv->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); |
| 1780 | jstring strClassName = lJNIEnv->NewStringUTF("com.garagegames.torque2d.FileWalker"); |
| 1781 | jclass FileWalkerClass = (jclass)lJNIEnv->CallObjectMethod(cls, findClass, strClassName); |
| 1782 | jstring strDirName = lJNIEnv->NewStringUTF(pdir); |
| 1783 | jmethodID MethodFileWalker = lJNIEnv->GetStaticMethodID(FileWalkerClass, "GetNextDir", "(Ljava/lang/String;)Ljava/lang/String;"); |
| 1784 | jstring jpath = (jstring)lJNIEnv->CallStaticObjectMethod(FileWalkerClass, MethodFileWalker, strDirName); |
| 1785 | if (jpath != NULL) |
| 1786 | { |
| 1787 | const char* path = lJNIEnv->GetStringUTFChars(jpath, NULL); |
| 1788 | strcpy(dir, path); |
| 1789 | dir[strlen(path)] = '\0'; |
| 1790 | lJNIEnv->ReleaseStringUTFChars(jpath, path); |
| 1791 | } |
| 1792 | else |
| 1793 | { |
| 1794 | strcpy(dir,""); |
| 1795 | } |
| 1796 | |
| 1797 | lJNIEnv->DeleteLocalRef(strClassName); |
| 1798 | lJNIEnv->DeleteLocalRef(strDirName); |
| 1799 | |
| 1800 | // Finished with the JVM. |
| 1801 | lJavaVM->DetachCurrentThread(); |
| 1802 | } |
| 1803 | |
| 1804 | void android_GetNextFile(const char* pdir, char *file) |
| 1805 | { |