#include "../../SDL_internal.h"
#ifdef __APPLE__
#import <Foundation/Foundation.h>
#include "SDL_rwopsbundlesupport.h"
FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
{ @autoreleasepool
{
FILE* fp = NULL;
NSFileManager* file_manager;
NSString* resource_path;
NSString* ns_string_file_component;
NSString* full_path_with_file_to_try;
if(strcmp("r", mode) && strcmp("rb", mode)) {
return fopen(file, mode);
}
file_manager = [NSFileManager defaultManager];
resource_path = [[NSBundle mainBundle] resourcePath];
ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
if([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
} else {
fp = fopen(file, mode);
}
return fp;
}}
#endif