Skip to content

Commit 774c0b3

Browse files
committed
android: Different approach to SDL_GetPathInfo() for assets.
Reference Issue #13050.
1 parent beea8d6 commit 774c0b3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/core/android/SDL_android.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,14 +1890,6 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
18901890
}
18911891

18921892
// this is sort of messy, but there isn't a stat()-like interface to the Assets.
1893-
AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
1894-
if (adir) { // it's a directory!
1895-
AAssetDir_close(adir);
1896-
info->type = SDL_PATHTYPE_DIRECTORY;
1897-
info->size = 0;
1898-
return true;
1899-
}
1900-
19011893
AAsset *aasset = AAssetManager_open(asset_manager, path, AASSET_MODE_UNKNOWN);
19021894
if (aasset) { // it's a file!
19031895
info->type = SDL_PATHTYPE_FILE;
@@ -1906,6 +1898,17 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
19061898
return true;
19071899
}
19081900

1901+
AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
1902+
if (adir) { // This does _not_ return NULL for a missing directory! Treat empty directories as missing. Better than nothing. :/
1903+
const bool contains_something = (AAssetDir_getNextFileName(adir) != NULL); // if not NULL, there are files in this directory, so it's _definitely_ a directory.
1904+
AAssetDir_close(adir);
1905+
if (contains_something) {
1906+
info->type = SDL_PATHTYPE_DIRECTORY;
1907+
info->size = 0;
1908+
return true;
1909+
}
1910+
}
1911+
19091912
return SDL_SetError("Couldn't open asset '%s'", path);
19101913
}
19111914

0 commit comments

Comments
 (0)