Try opening relative path files from internal storage.
authorSam Lantinga <slouken@libsdl.org>
Fri, 02 Nov 2012 03:08:40 -0700
changeset 6633e36b94438fcf
parent 6632 147f85ac2e4b
child 6634 b14b66ed5718
Try opening relative path files from internal storage.

I'm not falling back to external storage because the application should be
aware of whether external storage is available and choose whether or not to
use it.
src/file/SDL_rwops.c
     1.1 --- a/src/file/SDL_rwops.c	Fri Nov 02 03:03:55 2012 -0700
     1.2 +++ b/src/file/SDL_rwops.c	Fri Nov 02 03:08:40 2012 -0700
     1.3 @@ -429,13 +429,28 @@
     1.4  #if defined(ANDROID)
     1.5  #ifdef HAVE_STDIO_H
     1.6      /* Try to open the file on the filesystem first */
     1.7 -    {
     1.8 +    if (*file == '/') {
     1.9          FILE *fp = fopen(file, mode);
    1.10          if (fp) {
    1.11              return SDL_RWFromFP(fp, 1);
    1.12          }
    1.13 +    } else {
    1.14 +        /* Try opening it from internal storage if it's a relative path */
    1.15 +        char *path;
    1.16 +        FILE *fp;
    1.17 +
    1.18 +        path = SDL_stack_alloc(char, PATH_MAX);
    1.19 +        if (path) {
    1.20 +            SDL_snprintf(path, PATH_MAX, "%s/%s",
    1.21 +                         SDL_AndroidGetInternalStoragePath(), file);
    1.22 +            fp = fopen(path, mode);
    1.23 +            SDL_stack_free(path);
    1.24 +            if (fp) {
    1.25 +                return SDL_RWFromFP(fp, 1);
    1.26 +            }
    1.27 +        }
    1.28      }
    1.29 -#endif
    1.30 +#endif /* HAVE_STDIO_H */
    1.31  
    1.32      /* Try to open the file from the asset system */
    1.33      rwops = SDL_AllocRW();