Loading include/utils/AssetManager.h +12 −0 Original line number Original line Diff line number Diff line Loading @@ -152,6 +152,18 @@ public: */ */ AssetDir* openDir(const char* dirName); AssetDir* openDir(const char* dirName); /* * Open a directory within a particular path of the asset manager. * * The contents of the directory are an amalgam of vendor-specific, * locale-specific, and generic assets stored loosely or in asset * packages. Depending on the cache setting and previous accesses, * this call may incur significant disk overhead. * * To open the top-level directory, pass in "". */ AssetDir* openNonAssetDir(void* cookie, const char* dirName); /* /* * Get the type of a file in the asset hierarchy. They will either * Get the type of a file in the asset hierarchy. They will either * be "regular" or "directory". [Currently only works for "regular".] * be "regular" or "directory". [Currently only works for "regular".] Loading libs/utils/AssetManager.cpp +57 −2 Original line number Original line Diff line number Diff line Loading @@ -900,6 +900,60 @@ AssetDir* AssetManager::openDir(const char* dirName) return pDir; return pDir; } } /* * Open a directory in the non-asset namespace. * * An "asset directory" is simply the combination of all files in all * locations, with ".gz" stripped for loose files. With app, locale, and * vendor defined, we have 8 directories and 2 Zip archives to scan. * * Pass in "" for the root dir. */ AssetDir* AssetManager::openNonAssetDir(void* cookie, const char* dirName) { AutoMutex _l(mLock); AssetDir* pDir = NULL; SortedVector<AssetDir::FileInfo>* pMergedInfo = NULL; LOG_FATAL_IF(mAssetPaths.size() == 0, "No assets added to AssetManager"); assert(dirName != NULL); //printf("+++ openDir(%s) in '%s'\n", dirName, (const char*) mAssetBase); if (mCacheMode != CACHE_OFF && !mCacheValid) loadFileNameCacheLocked(); pDir = new AssetDir; pMergedInfo = new SortedVector<AssetDir::FileInfo>; const size_t which = ((size_t)cookie)-1; if (which < mAssetPaths.size()) { const asset_path& ap = mAssetPaths.itemAt(which); if (ap.type == kFileTypeRegular) { LOGV("Adding directory %s from zip %s", dirName, ap.path.string()); scanAndMergeZipLocked(pMergedInfo, ap, NULL, dirName); } else { LOGV("Adding directory %s from dir %s", dirName, ap.path.string()); scanAndMergeDirLocked(pMergedInfo, ap, NULL, dirName); } } #if 0 printf("FILE LIST:\n"); for (i = 0; i < (size_t) pMergedInfo->size(); i++) { printf(" %d: (%d) '%s'\n", i, pMergedInfo->itemAt(i).getFileType(), (const char*) pMergedInfo->itemAt(i).getFileName()); } #endif pDir->setFileList(pMergedInfo); return pDir; } /* /* * Scan the contents of the specified directory and merge them into the * Scan the contents of the specified directory and merge them into the * "pMergedInfo" vector, removing previous entries if we find "exclude" * "pMergedInfo" vector, removing previous entries if we find "exclude" Loading Loading @@ -1143,6 +1197,7 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg LOGE("ARGH: name too long?\n"); LOGE("ARGH: name too long?\n"); continue; continue; } } //printf("Comparing %s in %s?\n", nameBuf, dirName.string()); if (dirNameLen == 0 || if (dirNameLen == 0 || (strncmp(nameBuf, dirName.string(), dirNameLen) == 0 && (strncmp(nameBuf, dirName.string(), dirNameLen) == 0 && nameBuf[dirNameLen] == '/')) nameBuf[dirNameLen] == '/')) Loading @@ -1165,7 +1220,7 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg createZipSourceNameLocked(zipName, dirName, info.getFileName())); createZipSourceNameLocked(zipName, dirName, info.getFileName())); contents.add(info); contents.add(info); //printf("FOUND: file '%s'\n", (const char*) info.mFileName); //printf("FOUND: file '%s'\n", info.getFileName().string()); } else { } else { /* this is a subdir; add it if we don't already have it*/ /* this is a subdir; add it if we don't already have it*/ String8 subdirName(cp, nextSlash - cp); String8 subdirName(cp, nextSlash - cp); Loading @@ -1181,7 +1236,7 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg dirs.add(subdirName); dirs.add(subdirName); } } //printf("FOUND: dir '%s'\n", (const char*) subdirName); //printf("FOUND: dir '%s'\n", subdirName.string()); } } } } } } Loading Loading
include/utils/AssetManager.h +12 −0 Original line number Original line Diff line number Diff line Loading @@ -152,6 +152,18 @@ public: */ */ AssetDir* openDir(const char* dirName); AssetDir* openDir(const char* dirName); /* * Open a directory within a particular path of the asset manager. * * The contents of the directory are an amalgam of vendor-specific, * locale-specific, and generic assets stored loosely or in asset * packages. Depending on the cache setting and previous accesses, * this call may incur significant disk overhead. * * To open the top-level directory, pass in "". */ AssetDir* openNonAssetDir(void* cookie, const char* dirName); /* /* * Get the type of a file in the asset hierarchy. They will either * Get the type of a file in the asset hierarchy. They will either * be "regular" or "directory". [Currently only works for "regular".] * be "regular" or "directory". [Currently only works for "regular".] Loading
libs/utils/AssetManager.cpp +57 −2 Original line number Original line Diff line number Diff line Loading @@ -900,6 +900,60 @@ AssetDir* AssetManager::openDir(const char* dirName) return pDir; return pDir; } } /* * Open a directory in the non-asset namespace. * * An "asset directory" is simply the combination of all files in all * locations, with ".gz" stripped for loose files. With app, locale, and * vendor defined, we have 8 directories and 2 Zip archives to scan. * * Pass in "" for the root dir. */ AssetDir* AssetManager::openNonAssetDir(void* cookie, const char* dirName) { AutoMutex _l(mLock); AssetDir* pDir = NULL; SortedVector<AssetDir::FileInfo>* pMergedInfo = NULL; LOG_FATAL_IF(mAssetPaths.size() == 0, "No assets added to AssetManager"); assert(dirName != NULL); //printf("+++ openDir(%s) in '%s'\n", dirName, (const char*) mAssetBase); if (mCacheMode != CACHE_OFF && !mCacheValid) loadFileNameCacheLocked(); pDir = new AssetDir; pMergedInfo = new SortedVector<AssetDir::FileInfo>; const size_t which = ((size_t)cookie)-1; if (which < mAssetPaths.size()) { const asset_path& ap = mAssetPaths.itemAt(which); if (ap.type == kFileTypeRegular) { LOGV("Adding directory %s from zip %s", dirName, ap.path.string()); scanAndMergeZipLocked(pMergedInfo, ap, NULL, dirName); } else { LOGV("Adding directory %s from dir %s", dirName, ap.path.string()); scanAndMergeDirLocked(pMergedInfo, ap, NULL, dirName); } } #if 0 printf("FILE LIST:\n"); for (i = 0; i < (size_t) pMergedInfo->size(); i++) { printf(" %d: (%d) '%s'\n", i, pMergedInfo->itemAt(i).getFileType(), (const char*) pMergedInfo->itemAt(i).getFileName()); } #endif pDir->setFileList(pMergedInfo); return pDir; } /* /* * Scan the contents of the specified directory and merge them into the * Scan the contents of the specified directory and merge them into the * "pMergedInfo" vector, removing previous entries if we find "exclude" * "pMergedInfo" vector, removing previous entries if we find "exclude" Loading Loading @@ -1143,6 +1197,7 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg LOGE("ARGH: name too long?\n"); LOGE("ARGH: name too long?\n"); continue; continue; } } //printf("Comparing %s in %s?\n", nameBuf, dirName.string()); if (dirNameLen == 0 || if (dirNameLen == 0 || (strncmp(nameBuf, dirName.string(), dirNameLen) == 0 && (strncmp(nameBuf, dirName.string(), dirNameLen) == 0 && nameBuf[dirNameLen] == '/')) nameBuf[dirNameLen] == '/')) Loading @@ -1165,7 +1220,7 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg createZipSourceNameLocked(zipName, dirName, info.getFileName())); createZipSourceNameLocked(zipName, dirName, info.getFileName())); contents.add(info); contents.add(info); //printf("FOUND: file '%s'\n", (const char*) info.mFileName); //printf("FOUND: file '%s'\n", info.getFileName().string()); } else { } else { /* this is a subdir; add it if we don't already have it*/ /* this is a subdir; add it if we don't already have it*/ String8 subdirName(cp, nextSlash - cp); String8 subdirName(cp, nextSlash - cp); Loading @@ -1181,7 +1236,7 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg dirs.add(subdirName); dirs.add(subdirName); } } //printf("FOUND: dir '%s'\n", (const char*) subdirName); //printf("FOUND: dir '%s'\n", subdirName.string()); } } } } } } Loading