src/filesystem/cocoa/SDL_sysfilesystem.m
branchiOS-improvements
changeset 9487 f9fbc2d1edb0
parent 8149 681eb46b8ac4
child 9515 63f5d07c7d70
     1.1 --- a/src/filesystem/cocoa/SDL_sysfilesystem.m	Sun Jul 13 09:04:55 2014 -0700
     1.2 +++ b/src/filesystem/cocoa/SDL_sysfilesystem.m	Mon Jul 14 16:50:25 2014 -0300
     1.3 @@ -36,67 +36,69 @@
     1.4  char *
     1.5  SDL_GetBasePath(void)
     1.6  {
     1.7 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     1.8 -    NSBundle *bundle = [NSBundle mainBundle];
     1.9 -    const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
    1.10 -    const char *base = NULL;
    1.11      char *retval = NULL;
    1.12 -    if (baseType == NULL) {
    1.13 -        baseType = "resource";
    1.14 -    }
    1.15 -    if (SDL_strcasecmp(baseType, "bundle")==0) {
    1.16 -        base = [[bundle bundlePath] fileSystemRepresentation];
    1.17 -    } else if (SDL_strcasecmp(baseType, "parent")==0) {
    1.18 -        base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
    1.19 -    } else {
    1.20 -        /* this returns the exedir for non-bundled  and the resourceDir for bundled apps */
    1.21 -        base = [[bundle resourcePath] fileSystemRepresentation];
    1.22 -    }
    1.23 -    if (base) {
    1.24 -        const size_t len = SDL_strlen(base) + 2;
    1.25 -        retval = (char *) SDL_malloc(len);
    1.26 -        if (retval == NULL) {
    1.27 -            SDL_OutOfMemory();
    1.28 +
    1.29 +    @autoreleasepool {
    1.30 +        const char *base = NULL;
    1.31 +        NSBundle *bundle = [NSBundle mainBundle];
    1.32 +        const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
    1.33 +        if (baseType == NULL) {
    1.34 +            baseType = "resource";
    1.35 +        }
    1.36 +        if (SDL_strcasecmp(baseType, "bundle")==0) {
    1.37 +            base = [[bundle bundlePath] fileSystemRepresentation];
    1.38 +        } else if (SDL_strcasecmp(baseType, "parent")==0) {
    1.39 +            base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
    1.40          } else {
    1.41 -            SDL_snprintf(retval, len, "%s/", base);
    1.42 +            /* this returns the exedir for non-bundled  and the resourceDir for bundled apps */
    1.43 +            base = [[bundle resourcePath] fileSystemRepresentation];
    1.44 +        }
    1.45 +
    1.46 +        if (base) {
    1.47 +            const size_t len = SDL_strlen(base) + 2;
    1.48 +            retval = (char *) SDL_malloc(len);
    1.49 +            if (retval == NULL) {
    1.50 +                SDL_OutOfMemory();
    1.51 +            } else {
    1.52 +                SDL_snprintf(retval, len, "%s/", base);
    1.53 +            }
    1.54          }
    1.55      }
    1.56  
    1.57 -    [pool release];
    1.58      return retval;
    1.59  }
    1.60  
    1.61  char *
    1.62  SDL_GetPrefPath(const char *org, const char *app)
    1.63  {
    1.64 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.65 -    NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    1.66      char *retval = NULL;
    1.67  
    1.68 -    if ([array count] > 0) {  /* we only want the first item in the list. */
    1.69 -        NSString *str = [array objectAtIndex:0];
    1.70 -        const char *base = [str fileSystemRepresentation];
    1.71 -        if (base) {
    1.72 -            const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
    1.73 -            retval = (char *) SDL_malloc(len);
    1.74 -            if (retval == NULL) {
    1.75 -                SDL_OutOfMemory();
    1.76 -            } else {
    1.77 -                char *ptr;
    1.78 -                SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
    1.79 -                for (ptr = retval+1; *ptr; ptr++) {
    1.80 -                    if (*ptr == '/') {
    1.81 -                        *ptr = '\0';
    1.82 -                        mkdir(retval, 0700);
    1.83 -                        *ptr = '/';
    1.84 +    @autoreleasepool {
    1.85 +        NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    1.86 +
    1.87 +        if ([array count] > 0) {  /* we only want the first item in the list. */
    1.88 +            NSString *str = [array objectAtIndex:0];
    1.89 +            const char *base = [str fileSystemRepresentation];
    1.90 +            if (base) {
    1.91 +                const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
    1.92 +                retval = (char *) SDL_malloc(len);
    1.93 +                if (retval == NULL) {
    1.94 +                    SDL_OutOfMemory();
    1.95 +                } else {
    1.96 +                    char *ptr;
    1.97 +                    SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
    1.98 +                    for (ptr = retval+1; *ptr; ptr++) {
    1.99 +                        if (*ptr == '/') {
   1.100 +                            *ptr = '\0';
   1.101 +                            mkdir(retval, 0700);
   1.102 +                            *ptr = '/';
   1.103 +                        }
   1.104                      }
   1.105 +                    mkdir(retval, 0700);
   1.106                  }
   1.107 -                mkdir(retval, 0700);
   1.108              }
   1.109          }
   1.110      }
   1.111 -
   1.112 -    [pool release];
   1.113      return retval;
   1.114  }
   1.115