mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-13 01:45:45 +00:00
filesystem: Fix Android asset enumeration
Passes expected relative paths to Android's AssetManager API instead of absolute ones + fixes some indexing logic with trailing slashes.
This commit is contained in:
parent
2aacf018f0
commit
6583134365
1 changed files with 5 additions and 10 deletions
|
|
@ -83,26 +83,22 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
|
|||
|
||||
// trim down to a single path separator at the end, in case the caller added one or more.
|
||||
pathwithseplen--;
|
||||
while ((pathwithseplen > 0) && (pathwithsep[pathwithseplen] == '/')) {
|
||||
while ((pathwithseplen > 0) && (pathwithsep[pathwithseplen - 1] == '/')) {
|
||||
pathwithsep[pathwithseplen--] = '\0';
|
||||
}
|
||||
|
||||
DIR *dir = opendir(pathwithsep);
|
||||
if (!dir) {
|
||||
#ifdef SDL_PLATFORM_ANDROID // Maybe it's an asset...?
|
||||
const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep, cb, userdata);
|
||||
#ifdef SDL_PLATFORM_ANDROID // Maybe it's an asset...?
|
||||
const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep + extralen, cb, userdata);
|
||||
SDL_free(pathwithsep);
|
||||
return retval;
|
||||
#else
|
||||
#else
|
||||
SDL_free(pathwithsep);
|
||||
return SDL_SetError("Can't open directory: %s", strerror(errno));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// make sure there's a path separator at the end now for the actual callback.
|
||||
pathwithsep[++pathwithseplen] = '/';
|
||||
pathwithsep[++pathwithseplen] = '\0';
|
||||
|
||||
SDL_EnumerationResult result = SDL_ENUM_CONTINUE;
|
||||
struct dirent *ent;
|
||||
while ((result == SDL_ENUM_CONTINUE) && ((ent = readdir(dir)) != NULL)) {
|
||||
|
|
@ -454,4 +450,3 @@ char *SDL_SYS_GetCurrentDirectory(void)
|
|||
}
|
||||
|
||||
#endif // SDL_FSOPS_POSIX
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue