| 1608 | } |
| 1609 | |
| 1610 | bool android_DumpPath(const char* dir, Vector<Platform::FileInfo>& fileVector, U32 depth) |
| 1611 | { |
| 1612 | if (dumpPathBackup.size() > 0) |
| 1613 | { |
| 1614 | return loadDumpPathFromCache(dir, fileVector, depth); |
| 1615 | } |
| 1616 | |
| 1617 | // Attaches the current thread to the JVM. |
| 1618 | jint lResult; |
| 1619 | jint lFlags = 0; |
| 1620 | JavaVM* lJavaVM = engine.app->activity->vm; |
| 1621 | JNIEnv* lJNIEnv = engine.app->activity->env; |
| 1622 | |
| 1623 | JavaVMAttachArgs lJavaVMAttachArgs; |
| 1624 | lJavaVMAttachArgs.version = JNI_VERSION_1_6; |
| 1625 | lJavaVMAttachArgs.name = "NativeThread"; |
| 1626 | lJavaVMAttachArgs.group = NULL; |
| 1627 | |
| 1628 | lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); |
| 1629 | if (lResult == JNI_ERR) { |
| 1630 | return false; |
| 1631 | } |
| 1632 | |
| 1633 | // Retrieves NativeActivity. |
| 1634 | jobject lNativeActivity = engine.app->activity->clazz; |
| 1635 | jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity); |
| 1636 | |
| 1637 | jmethodID getClassLoader = lJNIEnv->GetMethodID(ClassNativeActivity,"getClassLoader", "()Ljava/lang/ClassLoader;"); |
| 1638 | jobject cls = lJNIEnv->CallObjectMethod(lNativeActivity, getClassLoader); |
| 1639 | jclass classLoader = lJNIEnv->FindClass("java/lang/ClassLoader"); |
| 1640 | jmethodID findClass = lJNIEnv->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); |
| 1641 | jstring strClassName = lJNIEnv->NewStringUTF("com.garagegames.torque2d.FileWalker"); |
| 1642 | jclass FileWalkerClass = (jclass)lJNIEnv->CallObjectMethod(cls, findClass, strClassName); |
| 1643 | jstring strDirName = lJNIEnv->NewStringUTF(dir); |
| 1644 | jmethodID MethodFileWalker = lJNIEnv->GetStaticMethodID(FileWalkerClass, "DumpPath", "(Landroid/content/Context;Ljava/lang/String;Z)[Ljava/lang/String;"); |
| 1645 | jobjectArray stringArray = (jobjectArray)lJNIEnv->CallStaticObjectMethod(FileWalkerClass, MethodFileWalker, lNativeActivity, strDirName, depth != 0); |
| 1646 | |
| 1647 | bool ret = false; |
| 1648 | |
| 1649 | if (stringArray) |
| 1650 | { |
| 1651 | int stringCount = lJNIEnv->GetArrayLength(stringArray); |
| 1652 | |
| 1653 | for (int i=0; i<stringCount; i++) { |
| 1654 | jstring string = (jstring) lJNIEnv->GetObjectArrayElement(stringArray, i); |
| 1655 | const char *rawString = lJNIEnv->GetStringUTFChars(string, 0); |
| 1656 | std::string str = rawString; |
| 1657 | lJNIEnv->ReleaseStringUTFChars(string, rawString); |
| 1658 | |
| 1659 | const U32 fileSize = Platform::getFileSize(str.c_str()); |
| 1660 | fileVector.increment(); |
| 1661 | Platform::FileInfo& rInfo = fileVector.last(); |
| 1662 | std::string fileName = std::string( |
| 1663 | std::find_if( str.rbegin(), str.rend(), |
| 1664 | MatchPathSeparator() ).base(), |
| 1665 | str.end() ); |
| 1666 | rInfo.pFullPath = StringTable->insert(str.substr(0,str.find(fileName)-1).c_str()); |
| 1667 | rInfo.pFileName = StringTable->insert(fileName.c_str()); |
no test coverage detected