forked from Mirrors/openclonk
Mac: Fix ClonkAppDelegate so installing scenarios etc by opening them with the Clonk app works again
parent
4902679b56
commit
8620eba816
|
@ -7,17 +7,21 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
enum ClonkAppDelegateGameState {
|
||||||
|
GS_NotYetStarted,
|
||||||
|
GS_Running,
|
||||||
|
GS_Finished
|
||||||
|
};
|
||||||
|
|
||||||
@interface ClonkAppDelegate: NSObject
|
@interface ClonkAppDelegate: NSObject
|
||||||
{
|
{
|
||||||
NSMutableArray* gatheredArguments;
|
NSMutableArray* gatheredArguments;
|
||||||
NSString* clonkDirectory;
|
NSString* clonkDirectory;
|
||||||
NSString* addonSupplied;
|
NSString* addonSupplied;
|
||||||
BOOL doNotLaunch;
|
ClonkAppDelegateGameState gameState;
|
||||||
BOOL terminateRequested;
|
|
||||||
BOOL gameLoopFinished;
|
|
||||||
}
|
}
|
||||||
- (NSString*) clonkDirectory;
|
- (NSString*) clonkDirectory;
|
||||||
- (BOOL) argsLookLikeItShouldBeInstallation:(char**)argv argc:(int)argc;
|
- (BOOL) argsLookLikeItShouldBeInstallation;
|
||||||
- (void)makeFakeArgs:(char***)argv argc:(int*)argc;
|
- (void)makeFakeArgs:(char***)argv argc:(int*)argc;
|
||||||
- (BOOL)installAddOn;
|
- (BOOL)installAddOn;
|
||||||
- (void)terminate:(NSApplication*)sender;
|
- (void)terminate:(NSApplication*)sender;
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
gatheredArguments = [[NSMutableArray arrayWithCapacity:10] retain];
|
NSArray* args = [[NSProcessInfo processInfo] arguments];
|
||||||
[gatheredArguments addObject:[[NSBundle mainBundle] executablePath]];
|
gatheredArguments = [args copy];
|
||||||
|
gameState = GS_NotYetStarted;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -23,13 +24,6 @@
|
||||||
forEventClass:kInternetEventClass andEventID:kAEGetURL];
|
forEventClass:kInternetEventClass andEventID:kAEGetURL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) release
|
|
||||||
{
|
|
||||||
if (terminateRequested)
|
|
||||||
[NSApp replyToApplicationShouldTerminate:YES];
|
|
||||||
[super release];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||||
{
|
{
|
||||||
NSString* pathExtension = [[filename pathExtension] lowercaseString];
|
NSString* pathExtension = [[filename pathExtension] lowercaseString];
|
||||||
|
@ -39,19 +33,12 @@
|
||||||
{
|
{
|
||||||
// later decide whether to install or run
|
// later decide whether to install or run
|
||||||
addonSupplied = filename;
|
addonSupplied = filename;
|
||||||
if (YES)
|
if (gameState == GS_Running)
|
||||||
{
|
{
|
||||||
// if application is already running install immediately
|
// if application is already running install immediately
|
||||||
[self installAddOn];
|
[self installAddOn];
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
// still add to gatheredArguments
|
|
||||||
// return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key/Update files or simply arguments: Just pass to engine, will install
|
|
||||||
[gatheredArguments addObject:filename];
|
|
||||||
fflush(0);
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,39 +54,30 @@
|
||||||
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
|
|
||||||
/*if ([self argsLookLikeItShouldBeInstallation:argv argc:argc]) {
|
|
||||||
if ([self installAddOn])
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Hand off to Clonk code
|
// Hand off to Clonk code
|
||||||
char** newArgv;
|
char** newArgv;
|
||||||
int newArgc;
|
int newArgc;
|
||||||
[self makeFakeArgs:&newArgv argc:&newArgc];
|
[self makeFakeArgs:&newArgv argc:&newArgc];
|
||||||
int status = SDL_main(newArgc, newArgv);
|
int status = SDL_main(newArgc, newArgv);
|
||||||
|
for (int i = newArgc-1; i >= 0; i--) {free (newArgv[i]);}
|
||||||
for (int i = newArgc-1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
free (newArgv[i]);
|
|
||||||
}
|
|
||||||
free(newArgv);
|
free(newArgv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when the internal event loop has just started running */
|
/* Called when the internal event loop has just started running */
|
||||||
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
||||||
{
|
{
|
||||||
/* NSDictionary* args = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain];
|
if (!([self argsLookLikeItShouldBeInstallation] && [self installAddOn]))
|
||||||
for (NSString* key in args) {
|
{
|
||||||
[gatheredArguments addObject:[NSString stringWithFormat:@"/%@:%@", key, [args valueForKey:key]]];
|
gameState = GS_Running;
|
||||||
}*/
|
|
||||||
[self gameLoop];
|
[self gameLoop];
|
||||||
gameLoopFinished = YES;
|
gameState = GS_Finished;
|
||||||
|
}
|
||||||
[NSApp terminate:self];
|
[NSApp terminate:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)application
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)application
|
||||||
{
|
{
|
||||||
if (!gameLoopFinished)
|
if (gameState == GS_Running)
|
||||||
{
|
{
|
||||||
[self terminate:application];
|
[self terminate:application];
|
||||||
return NSTerminateCancel; // cancels logoff but it's the only way that does not interrupt the lifecycle of the application
|
return NSTerminateCancel; // cancels logoff but it's the only way that does not interrupt the lifecycle of the application
|
||||||
|
@ -131,13 +109,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for -psn argument which generally is a clue that the application should open a file (double-clicking, calling /usr/bin/open and such)
|
// Look for -psn argument which generally is a clue that the application should open a file (double-clicking, calling /usr/bin/open and such)
|
||||||
- (BOOL) argsLookLikeItShouldBeInstallation:(char**)argv argc:(int)argc
|
- (BOOL) argsLookLikeItShouldBeInstallation
|
||||||
{
|
{
|
||||||
// not having this check leads to deletion of Clonk folder -.-
|
// not having this check leads to deletion of Clonk folder -.-
|
||||||
if (!addonSupplied)
|
if (!addonSupplied)
|
||||||
return NO;
|
return NO;
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < [gatheredArguments count]; i++)
|
||||||
if ([[NSString stringWithUTF8String:argv[i]] hasPrefix:@"-psn"])
|
{
|
||||||
|
NSString* arg = [gatheredArguments objectAtIndex:i];
|
||||||
|
if ([arg hasPrefix:@"-psn"])
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
|
|
Loading…
Reference in New Issue