fix crash and re-enable Application Support directory on OS X versions < 10.9

This commit is contained in:
jacob1 2014-08-03 20:36:39 -04:00
parent 92237cad5d
commit ab2dd1ce61

View File

@ -85,15 +85,8 @@ static NSString *getApplicationName(void)
/* The main class of the application, the application's delegate */ /* The main class of the application, the application's delegate */
@implementation SDLMain @implementation SDLMain
/* Set the working directory to the .app's parent directory */ /* Set the working directory to Application Support */
- (void) setupWorkingDirectory:(BOOL)shouldChdir - (void) setupWorkingDirectory:(BOOL)shouldChdir
{
SInt32 versionMajor = 0, versionMinor = 0;
Gestalt(gestaltSystemVersionMajor, &versionMajor);
Gestalt(gestaltSystemVersionMinor, &versionMinor);
/* Set the working directory to Application Support on Mavericks and above */
if (versionMajor > 10 || versionMinor >= 9)
{ {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] < 1) if ([paths count] < 1)
@ -113,23 +106,6 @@ static NSString *getApplicationName(void)
} }
chdir([appPath UTF8String]); chdir([appPath UTF8String]);
} }
/* Set the working directory to the .app's parent directory, because the code above breaks anything below Mavericks? (just a guess) */
else
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN))
{
chdir(parentdir); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}
}
#if SDL_USE_NIB_FILE #if SDL_USE_NIB_FILE
@ -391,7 +367,8 @@ static void CustomApplicationMain (int argc, char **argv)
@end @end
char * readUserPreferences() { char * readUserPreferences()
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *prefDataNSString = [prefs stringForKey:@"powder.pref"]; NSString *prefDataNSString = [prefs stringForKey:@"powder.pref"];
@ -403,12 +380,12 @@ char * readUserPreferences() {
SDL_strlcpy(prefDataCopy, prefData, [prefDataNSString length]+1); SDL_strlcpy(prefDataCopy, prefData, [prefDataNSString length]+1);
[prefDataNSString release]; [prefDataNSString release];
[prefs release];
return prefDataCopy; return prefDataCopy;
} }
void writeUserPreferences(const char * prefData) { void writeUserPreferences(const char * prefData)
{
NSString *prefDataNSString = [NSString stringWithUTF8String:prefData]; NSString *prefDataNSString = [NSString stringWithUTF8String:prefData];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
@ -416,10 +393,10 @@ void writeUserPreferences(const char * prefData) {
[prefs synchronize]; [prefs synchronize];
[prefDataNSString release]; [prefDataNSString release];
[prefs release];
} }
char * readClipboard() { char * readClipboard()
{
NSPasteboard *clipboard = [NSPasteboard generalPasteboard]; NSPasteboard *clipboard = [NSPasteboard generalPasteboard];
NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil]; NSArray *classes = [[NSArray alloc] initWithObjects:[NSString class], nil];
@ -439,7 +416,8 @@ char * readClipboard() {
return clipboardDataCopy; return clipboardDataCopy;
} }
void writeClipboard(const char * clipboardData) { void writeClipboard(const char * clipboardData)
{
NSPasteboard *clipboard = [NSPasteboard generalPasteboard]; NSPasteboard *clipboard = [NSPasteboard generalPasteboard];
NSString *newString = [NSString stringWithUTF8String: clipboardData]; NSString *newString = [NSString stringWithUTF8String: clipboardData];