AndroidAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters, AAssetDir *asset, const QString &path) : QAbstractFileEngineIterator(filters, nameFilters) { AAssetDir_rewind(asset); const char *fileName; while ((fileName = AAssetDir_getNextFileName(asset))) m_items << fileName; m_index = -1; m_path = path; }
static int engine_init_shaders(struct engine* engine) { LOGI("from engine_init_shaders \n"); setupGraphics(engine->width, engine->height); AAssetDir* assetDir = AAssetManager_openDir(engine->assetManager, ""); AAssetDir_rewind(assetDir); const char* name=NULL; const char* vert=NULL, *frag=NULL; while ( (name = AAssetDir_getNextFileName(assetDir)) != NULL) { if (frag == NULL && NULL != strstr(name, gTagFrag)) //if we haven't found the fragment shader and 'name' is the fragment shader, save it. frag = name; if (vert == NULL && NULL != strstr(name, gTagVert)) //if we haven't found the vertex shader and the 'name' is the vertex shader, save it. vert = name; if (!vert && !frag) //if we found both files, we're done break; } //open the shader assets AAsset* fragAsset = AAssetManager_open(engine->assetManager, frag, AASSET_MODE_BUFFER); if (!fragAsset) { LOGE(" error opening %s\n", fragAsset); return; } AAsset* vertAsset = AAssetManager_open(engine->assetManager, vert, AASSET_MODE_BUFFER); if (!vertAsset) { LOGE(" error opening %s\n", vertAsset); return; } //access the shader asset buffer in preperation for reading const char* fragBuff = (const char*)AAsset_getBuffer(fragAsset); const char* vertBuff = (const char*)AAsset_getBuffer(vertAsset); setupGraphics(engine->width, engine->height); //minimaly initialize client graphics state LoadShaders(fragBuff, AAsset_getLength(fragAsset), vertBuff, AAsset_getLength(vertAsset)); //load the shaders AAssetDir_close(assetDir); }
bool FileSystem::listFiles(const char* dirPath, std::vector<std::string>& files) { #ifdef WIN32 std::string path(FileSystem::getResourcePath()); if (dirPath && strlen(dirPath) > 0) { path.append(dirPath); } path.append("/*"); // Convert char to wchar std::basic_string<TCHAR> wPath; wPath.assign(path.begin(), path.end()); WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(wPath.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { return false; } do { // Add to the list if this is not a directory if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { // Convert wchar to char std::basic_string<TCHAR> wfilename(FindFileData.cFileName); std::string filename; filename.assign(wfilename.begin(), wfilename.end()); files.push_back(filename); } } while (FindNextFile(hFind, &FindFileData) != 0); FindClose(hFind); return true; #else std::string path(FileSystem::getResourcePath()); if (dirPath && strlen(dirPath) > 0) { path.append(dirPath); } path.append("/."); bool result = false; struct dirent* dp; DIR* dir = opendir(path.c_str()); if (dir != NULL) { while ((dp = readdir(dir)) != NULL) { std::string filepath(path); filepath.append("/"); filepath.append(dp->d_name); struct stat buf; if (!stat(filepath.c_str(), &buf)) { // Add to the list if this is not a directory if (!S_ISDIR(buf.st_mode)) { files.push_back(dp->d_name); } } } closedir(dir); result = true; } #ifdef __ANDROID__ // List the files that are in the android APK at this path AAssetDir* assetDir = AAssetManager_openDir(__assetManager, dirPath); if (assetDir != NULL) { AAssetDir_rewind(assetDir); const char* file = NULL; while ((file = AAssetDir_getNextFileName(assetDir)) != NULL) { std::string filename(file); // Check if this file was already added to the list because it was copied to the SD card. if (find(files.begin(), files.end(), filename) == files.end()) { files.push_back(filename); } } AAssetDir_close(assetDir); result = true; } #endif return result; #endif }