Mercurial > sdl-ios-xcode
annotate test/automated/rwops/Test_rwopsbundlesupport.m @ 4449:8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 08 May 2010 04:52:17 -0700 |
parents | 947201caa46e |
children |
rev | line source |
---|---|
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1 #ifdef __APPLE__ |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 #import <Foundation/Foundation.h> |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 /* For proper OS X applications, the resources are contained inside the application bundle. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 So the strategy is to first check the application bundle for the file, then fallback to the current working directory. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 Note: One additional corner-case is if the resource is in a framework's resource bundle instead of the app. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 We might want to use bundle identifiers, e.g. org.libsdl.sdl to get the bundle for the framework, |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 but we would somehow need to know what the bundle identifiers we need to search are. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9 Also, note the bundle layouts are different for iPhone and Mac. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 */ |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 FILE* Test_OpenFPFromBundleOrFallback(const char *file, const char *mode) |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 FILE* fp = NULL; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14 |
4449
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
15 // If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
16 if(strcmp("r", mode) && strcmp("rb", mode)) |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
17 { |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
18 return fopen(file, mode); |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
19 } |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
20 |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 NSFileManager* file_manager = [NSFileManager defaultManager]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 NSString* resource_path = [[NSBundle mainBundle] resourcePath]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 if([file_manager fileExistsAtPath:full_path_with_file_to_try]) |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 else |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 fp = fopen(file, mode); |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 [autorelease_pool drain]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 return fp; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 FILE* Test_OpenFPFromTemporaryDir(const char *file, const char *mode) |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 FILE* fp = NULL; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 NSFileManager* file_manager = [NSFileManager defaultManager]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 [autorelease_pool drain]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 return fp; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 #endif |