Added option to specify Android asset reading mode.

This commit is contained in:
Frederik Seiffert 2019-05-24 09:29:24 +02:00
parent ba4948fd97
commit 9f01876102
4 changed files with 17 additions and 3 deletions

View file

@ -563,10 +563,19 @@ GS_EXPORT NSString* const NSLoadedClasses;
/**
* Returns the Android asset for the given path if path is in main bundle
* resources and asset exists.
* Uses `AASSET_MODE_UNKNOWN` to open the asset if it exists.
* The returned object must be released using AAsset_close().
*/
+ (AAsset *)assetForPath:(NSString *)path;
/**
* Returns the Android asset for the given path if path is in main bundle
* resources and asset exists.
* Uses the given mode to open the AAsset if it exists.
* The returned object must be released using AAsset_close().
*/
+ (AAsset *)assetForPath:(NSString *)path withMode:(int)mode;
/**
* Returns the Android asset dir for the given path if path is in main bundle
* resources and the asset directory exists.

View file

@ -1091,7 +1091,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
if (d < 0)
{
#ifdef __ANDROID__
asset = [NSBundle assetForPath:path];
asset = [NSBundle assetForPath:path withMode:AASSET_MODE_RANDOM];
if (asset) {
readOK = YES;
return self;

View file

@ -3286,6 +3286,11 @@ IF_NO_GC(
}
+ (AAsset *)assetForPath:(NSString *)path
{
return [self assetForPath:path withMode:AASSET_MODE_UNKNOWN];
}
+ (AAsset *)assetForPath:(NSString *)path withMode:(int)mode
{
AAsset *asset = NULL;
@ -3298,7 +3303,7 @@ IF_NO_GC(
NSString *assetPath = [path substringFromIndex:[resourcePath length]+1];
asset = AAssetManager_open(_assetManager,
[assetPath fileSystemRepresentation], AASSET_MODE_BUFFER);
[assetPath fileSystemRepresentation], mode);
}
}

View file

@ -245,7 +245,7 @@ readContentsOfFile(NSString *path, void **buf, off_t *len, NSZone *zone)
#ifdef __ANDROID__
// Android: try using asset manager if path is in main bundle resources
AAsset *asset = [NSBundle assetForPath:path];
AAsset *asset = [NSBundle assetForPath:path withMode:AASSET_MODE_BUFFER];
if (asset) {
fileLength = AAsset_getLength(asset);