test/automated/rwops/TestSupportRWops_Cocoa.m
changeset 6832 156e608ec4ef
parent 4451 033c455bbe99
child 6848 478ecc8a58b3
equal deleted inserted replaced
6831:935b871e1ffe 6832:156e608ec4ef
    19 FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode)
    19 FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode)
    20 {
    20 {
    21     FILE* fp = NULL;
    21     FILE* fp = NULL;
    22 
    22 
    23 	// If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only.
    23 	// If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only.
    24 	if(strcmp("r", mode) && strcmp("rb", mode))
    24 	if (strcmp("r", mode) && strcmp("rb", mode)) {
    25 	{
       
    26 		return fopen(file, mode);
    25 		return fopen(file, mode);
    27 	}
    26 	}
    28 	
    27 	
    29 	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
    28 	@autoreleasepool {
       
    29         NSFileManager* file_manager = [NSFileManager defaultManager];
       
    30         NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    30 
    31 
       
    32         NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    31 
    33 
    32 	NSFileManager* file_manager = [NSFileManager defaultManager];
    34         NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    33 	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    35         if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
    34 
    36             fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    35 	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    37         } else {
    36 
    38             fp = fopen(file, mode);
    37 	NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    39         }
    38 	if([file_manager fileExistsAtPath:full_path_with_file_to_try])
    40     }
    39 	{
       
    40 		fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
       
    41 	}
       
    42 	else
       
    43 	{
       
    44 		fp = fopen(file, mode);
       
    45 	}
       
    46 
       
    47 	[autorelease_pool drain];
       
    48 
    41 
    49 	return fp;
    42 	return fp;
    50 }
    43 }
    51 
    44 
    52 FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode)
    45 FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode)
    53 {
    46 {
    54     FILE* fp = NULL;
    47     FILE* fp = NULL;
    55 	
    48 	
    56 	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
    49 	@autoreleasepool {
    57 	
    50         NSFileManager* file_manager = [NSFileManager defaultManager];
    58 	NSFileManager* file_manager = [NSFileManager defaultManager];
    51         NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    59 	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    52         NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
    60 	NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
       
    61 
    53 
    62 	fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    54         fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    63 	
    55     }
    64 	[autorelease_pool drain];
    56     
    65 	
       
    66 	return fp;
    57 	return fp;
    67 }
    58 }
    68 
    59 
    69 SDL_RWops* TestSupportRWops_OpenRWopsFromReadDir(const char *file, const char *mode)
    60 SDL_RWops* TestSupportRWops_OpenRWopsFromReadDir(const char *file, const char *mode)
    70 {
    61 {
    73 
    64 
    74 SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *mode)
    65 SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *mode)
    75 {
    66 {
    76 	SDL_RWops* rw = NULL;
    67 	SDL_RWops* rw = NULL;
    77 
    68 
    78 	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
    69 	@autoreleasepool {
    79 	
    70         NSFileManager* file_manager = [NSFileManager defaultManager];
    80 	NSFileManager* file_manager = [NSFileManager defaultManager];
    71         NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    81 	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    72         NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
    82 	NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
    73         
    83 	
    74         rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
    84 	rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
    75     }
    85 
    76     
    86 	[autorelease_pool drain];
       
    87 	return rw;
    77 	return rw;
    88 }
    78 }
    89 
    79