Merge pull request #137 from triplef/android-assets-directory-improvements

Android assets improvements to support directories
This commit is contained in:
rfm 2020-06-06 12:13:53 +01:00 committed by GitHub
commit de4552d754
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View file

@ -1,3 +1,10 @@
2020-06-06 Frederik Seiffert <frederik@algoriddim.com>
* Source/NSBundle.m: Extend NSBundle resources support to handle
directories in Android assets.
* Source/NSFileManager.m: Fix NSFileManager -isReadableFileAtPath:
to also support directories in Android assets.
2020-06-05 Frederik Seiffert <frederik@algoriddim.com>
* Tests/base/NSMapTable/weakObjects.m,

View file

@ -2228,6 +2228,22 @@ IF_NO_GC(
}
}
#ifdef __ANDROID__
/* Android: check for directory resources by passing file path as subpath,
* as AAssetDir and thereby NSDirectoryEnumerator doesn't list directories
*/
subPath = subPath ? [subPath stringByAppendingPathComponent: file] : file;
pathlist = [[self _bundleResourcePathsWithRootPath: rootPath
subPath: subPath localization: nil] objectEnumerator];
while ((path = [pathlist nextObject]) != nil)
{
if (YES == [mgr isReadableFileAtPath: path])
{
return path;
}
}
#endif /* __ANDROID__ */
return nil;
}

View file

@ -1806,8 +1806,8 @@ static NSStringEncoding defaultEncoding;
{
#ifdef __ANDROID__
/* Android: try using asset manager if path is in
* main bundle resources
*/
* main bundle resources
*/
AAsset *asset = [NSBundle assetForPath: path];
if (asset)
{
@ -1877,13 +1877,22 @@ static NSStringEncoding defaultEncoding;
}
#ifdef __ANDROID__
// Android: try using asset manager if path is in main bundle resources
/* Android: try using asset manager if path is in
* main bundle resources
*/
AAsset *asset = [NSBundle assetForPath: path];
if (asset)
{
AAsset_close(asset);
return YES;
}
AAssetDir *assetDir = [NSBundle assetDirForPath: path];
if (assetDir)
{
AAssetDir_close(assetDir);
return YES;
}
#endif
return NO;