zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_rwopsbundlesupport.m
Go to the documentation of this file.
1 #ifdef __APPLE__
2 #import <Foundation/Foundation.h>
3 
5 
6 /* For proper OS X applications, the resources are contained inside the application bundle.
7  So the strategy is to first check the application bundle for the file, then fallback to the current working directory.
8  Note: One additional corner-case is if the resource is in a framework's resource bundle instead of the app.
9  We might want to use bundle identifiers, e.g. org.libsdl.sdl to get the bundle for the framework,
10  but we would somehow need to know what the bundle identifiers we need to search are.
11  Also, note the bundle layouts are different for iPhone and Mac.
12 */
13 FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
14 {
15  FILE* fp = NULL;
16 
17  /* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */
18  if(strcmp("r", mode) && strcmp("rb", mode))
19  {
20  return fopen(file, mode);
21  }
22 
23  NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
24 
25 
26  NSFileManager* file_manager = [NSFileManager defaultManager];
27  NSString* resource_path = [[NSBundle mainBundle] resourcePath];
28 
29  NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
30 
31  NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
32  if([file_manager fileExistsAtPath:full_path_with_file_to_try])
33  {
34  fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
35  }
36  else
37  {
38  fp = fopen(file, mode);
39  }
40 
41  [autorelease_pool drain];
42 
43  return fp;
44 }
45 #endif
#define NULL
Definition: ftobjs.h:61
FILE * file
Definition: visualinfo.c:88
GLenum mode
Definition: glew.h:2394