Fixing OpenRead and OpenOverwrite on OS X

This commit is contained in:
Matt Tuttle
2014-06-16 00:11:35 -05:00
committed by Joshua Granick
parent e5364db04e
commit 6c8caee1d7

View File

@@ -126,11 +126,29 @@ FILE *OpenOverwrite(const char *inName); // [ddc]
extern int gFixedOrientation;
#elif defined(HX_MACOS)
} // close namespace nme
extern "C" FILE *OpenRead(const char *inName);
extern "C" bool GetBundleFilename(const char *inName, char *outBuffer,int inBufSize);
extern "C" FILE *OpenOverwrite(const char *inName);
namespace nme {
#include <CoreFoundation/CoreFoundation.h>
FILE *OpenRead(const char *inName)
{
FILE *result = fopen(inName,"rb");
if (!result) {
CFStringRef str = CFStringCreateWithCString(NULL, inName, kCFStringEncodingUTF8);
CFURLRef path = CFBundleCopyResourceURL(CFBundleGetMainBundle(), str, NULL, NULL);
CFRelease(str);
if (path) {
str = CFURLCopyPath(path);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str),kCFStringEncodingUTF8);
char *buffer = (char *)malloc(maxSize);
if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) {
result = fopen(buffer,"rb");
free(buffer);
}
CFRelease(str);
CFRelease(path);
}
}
return result;
}
#define OpenOverwrite(x) fopen(x,"wb")
#else
#ifdef TIZEN
extern int gFixedOrientation;