android: Different approach to SDL_GetPathInfo() for assets.

Reference Issue #13050.
This commit is contained in:
Ryan C. Gordon
2025-07-29 12:14:04 -04:00
parent beea8d604e
commit 774c0b36ea

View File

@@ -1890,14 +1890,6 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
}
// this is sort of messy, but there isn't a stat()-like interface to the Assets.
AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
if (adir) { // it's a directory!
AAssetDir_close(adir);
info->type = SDL_PATHTYPE_DIRECTORY;
info->size = 0;
return true;
}
AAsset *aasset = AAssetManager_open(asset_manager, path, AASSET_MODE_UNKNOWN);
if (aasset) { // it's a file!
info->type = SDL_PATHTYPE_FILE;
@@ -1906,6 +1898,17 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
return true;
}
AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
if (adir) { // This does _not_ return NULL for a missing directory! Treat empty directories as missing. Better than nothing. :/
const bool contains_something = (AAssetDir_getNextFileName(adir) != NULL); // if not NULL, there are files in this directory, so it's _definitely_ a directory.
AAssetDir_close(adir);
if (contains_something) {
info->type = SDL_PATHTYPE_DIRECTORY;
info->size = 0;
return true;
}
}
return SDL_SetError("Couldn't open asset '%s'", path);
}