2024-03-05 17:07:21 +01:00
|
|
|
#include <dirent.h>
|
2022-10-02 23:06:56 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/stat.h>
|
2024-05-25 20:43:33 +02:00
|
|
|
#include <sys/types.h>
|
2022-10-02 23:06:56 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
#include <androidfw/androidfw_c_api.h>
|
2022-12-27 17:22:49 +01:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
#include "../api-impl-jni/defines.h"
|
|
|
|
|
#include "../api-impl-jni/util.h"
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-03-05 17:07:21 +01:00
|
|
|
struct AAssetDir {
|
2024-05-25 20:43:33 +02:00
|
|
|
struct AssetDir *asset_dir;
|
|
|
|
|
size_t curr_index;
|
2024-03-05 17:07:21 +01:00
|
|
|
};
|
|
|
|
|
|
2022-10-12 17:23:19 +02:00
|
|
|
#define ASSET_DIR "assets/"
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
int AAsset_openFileDescriptor(struct Asset *asset, off_t *out_start, off_t *out_length)
|
2022-11-24 16:05:38 +01:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
return Asset_openFileDescriptor(asset, out_start, out_length);
|
2022-11-24 16:05:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
struct Asset* AAssetManager_open(struct AssetManager *asset_manager, const char *file_name, int mode)
|
2022-10-02 23:06:56 +02:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
char *path = malloc(strlen(ASSET_DIR) + strlen(file_name) + 1);
|
|
|
|
|
sprintf(path, "%s%s", ASSET_DIR, file_name);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-06-22 14:35:56 +02:00
|
|
|
android_log_printf(ANDROID_LOG_VERBOSE, "["__FILE__"]", "AAssetManager_open called for %s\n", file_name);
|
2024-05-25 20:43:33 +02:00
|
|
|
struct Asset *asset = AssetManager_openNonAsset(asset_manager, path, mode);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
|
|
|
|
free(path);
|
|
|
|
|
|
|
|
|
|
return asset;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
const void * AAsset_getBuffer(struct Asset *asset)
|
2024-03-05 17:07:21 +01:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
return Asset_getBuffer(asset, false);
|
2024-03-05 17:07:21 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
off64_t AAsset_getLength64(struct Asset *asset)
|
2024-03-05 17:07:21 +01:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
return Asset_getLength(asset);
|
|
|
|
|
}
|
2024-03-05 17:07:21 +01:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
off_t AAsset_getLength(struct Asset *asset)
|
|
|
|
|
{
|
|
|
|
|
return Asset_getLength(asset);
|
|
|
|
|
}
|
2024-03-05 17:07:21 +01:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
int AAsset_read(struct Asset *asset, void *buf, size_t count) {
|
|
|
|
|
return Asset_read(asset, buf, count);
|
|
|
|
|
}
|
2024-03-05 17:07:21 +01:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
off_t AAsset_seek(struct Asset *asset, off_t offset, int whence) {
|
|
|
|
|
return Asset_seek(asset, offset, whence);
|
2024-03-05 17:07:21 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
off64_t AAsset_seek64(struct Asset *asset, off64_t offset, int whence) {
|
|
|
|
|
return Asset_seek(asset, offset, whence);
|
|
|
|
|
}
|
2024-03-05 17:07:21 +01:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
off_t AAsset_getRemainingLength(struct Asset *asset)
|
2024-03-05 17:07:21 +01:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
return Asset_getRemainingLength(asset);
|
2024-03-05 17:07:21 +01:00
|
|
|
}
|
2024-05-25 20:43:33 +02:00
|
|
|
off64_t AAsset_getRemainingLength64(struct Asset *asset)
|
2022-10-02 23:06:56 +02:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
return Asset_getRemainingLength(asset);
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
void AAsset_close(struct Asset *asset)
|
|
|
|
|
{
|
|
|
|
|
Asset_delete(asset);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
struct AAssetDir * AAssetManager_openDir(struct AssetManager *asset_manager, const char *dirname)
|
2022-10-02 23:06:56 +02:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
char* dirpath = malloc(strlen(ASSET_DIR) + strlen(dirname) + 1);
|
|
|
|
|
sprintf(dirpath, "%s%s", ASSET_DIR, dirname);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
struct AssetDir *asset_dir = AssetManager_openDir(asset_manager, dirname);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
struct AAssetDir* dir = malloc(sizeof(struct AAssetDir));
|
|
|
|
|
dir->asset_dir = asset_dir;
|
|
|
|
|
dir->curr_index = 0;
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-06-22 14:35:56 +02:00
|
|
|
android_log_printf(ANDROID_LOG_VERBOSE, "["__FILE__"]", "AAssetManager_openDir called for %s\n", dirpath);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
return dir;
|
2022-11-04 21:18:44 +05:00
|
|
|
}
|
2024-05-25 20:43:33 +02:00
|
|
|
|
|
|
|
|
const char * AAssetDir_getNextFileName(struct AAssetDir *dir)
|
2022-10-02 23:06:56 +02:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
size_t index = dir->curr_index;
|
|
|
|
|
const size_t max = AssetDir_getFileCount(dir->asset_dir);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
/* skip non-regular files */
|
|
|
|
|
while ((index < max) && AssetDir_getFileType(dir->asset_dir, index) != FILE_TYPE_REGULAR)
|
|
|
|
|
index++;
|
2022-11-04 21:18:44 +05:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
if (index >= max) {
|
|
|
|
|
dir->curr_index = index;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2022-11-02 16:40:15 +05:00
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
dir->curr_index = index + 1;
|
|
|
|
|
return AssetDir_getFileName(dir->asset_dir, index);
|
2022-11-04 21:18:44 +05:00
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
|
|
|
|
|
void AAssetDir_close(struct AAssetDir *dir)
|
2022-11-04 21:18:44 +05:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
AssetDir_delete(dir->asset_dir);
|
|
|
|
|
free(dir);
|
2022-11-02 16:40:15 +05:00
|
|
|
}
|
|
|
|
|
|
2024-05-25 20:43:33 +02:00
|
|
|
struct AssetManager * AAssetManager_fromJava(JNIEnv *env, jobject asset_manager)
|
2022-10-02 23:06:56 +02:00
|
|
|
{
|
2024-05-25 20:43:33 +02:00
|
|
|
return _PTR(_GET_LONG_FIELD(asset_manager, "mObject"));
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|