Browse Source

android: Different approach to SDL_GetPathInfo() for assets.

Reference Issue #13050.
Ryan C. Gordon 1 month ago
parent
commit
774c0b36ea
1 changed files with 11 additions and 8 deletions
  1. 11 8
      src/core/android/SDL_android.c

+ 11 - 8
src/core/android/SDL_android.c

@@ -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);
 }