@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2022 Jonathan Schleifer + * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -35,10 +35,11 @@ #import "OFNotificationCenter.h" #import "OFPair.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSandbox.h" +#import "OFStdIOStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFThread+Private.h" #import "OFThread.h" @@ -52,12 +53,14 @@ #elif defined(OF_WINDOWS) # include extern int _CRT_glob; extern void __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *); #elif defined(OF_AMIGAOS) +# define Class IntuitionClass # include # include +# undef Class #elif !defined(OF_IOS) extern char **environ; #endif #ifdef OF_PSP @@ -82,27 +85,30 @@ andWideArgumentValues: (wchar_t *[])wargv; #endif - (void)of_run; @end +const OFNotificationName OFApplicationDidFinishLaunchingNotification = + @"OFApplicationDidFinishLaunchingNotification"; const OFNotificationName OFApplicationWillTerminateNotification = @"OFApplicationWillTerminateNotification"; static OFApplication *app = nil; static void atexitHandler(void) { id delegate = app.delegate; - - [[OFNotificationCenter defaultCenter] - postNotificationName: OFApplicationWillTerminateNotification + OFNotification *notification = [OFNotification + notificationWithName: OFApplicationWillTerminateNotification object: app]; - if ([delegate respondsToSelector: @selector(applicationWillTerminate)]) - [delegate applicationWillTerminate]; + if ([delegate respondsToSelector: @selector(applicationWillTerminate:)]) + [delegate applicationWillTerminate: notification]; [delegate release]; + + [[OFNotificationCenter defaultCenter] postNotification: notification]; #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_SOCKETS) && \ defined(OF_AMIGAOS) && !defined(OF_MORPHOS) OFSocketDeinit(); #endif @@ -109,22 +115,21 @@ } int OFApplicationMain(int *argc, char **argv[], id delegate) { -#ifdef OF_WINDOWS - wchar_t **wargv, **wenvp; - int wargc, si = 0; -#endif - [[OFLocale alloc] init]; app = [[OFApplication alloc] of_init]; #ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) { + wchar_t **wargv, **wenvp; + int wargc, si = 0; + __wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si); + [app of_setArgumentCount: argc andArgumentValues: argv andWideArgumentCount: wargc andWideArgumentValues: wargv]; } else @@ -258,13 +263,12 @@ continue; } pos = [tmp rangeOfString: @"="].location; if (pos == OFNotFound) { - fprintf(stderr, - "Warning: Invalid environment " - "variable: %s\n", tmp.UTF8String); + OFLog(@"Warning: Invalid environment " + "variable: %@", tmp); continue; } key = [tmp substringToIndex: pos]; value = [tmp substringFromIndex: pos + 1]; @@ -300,13 +304,12 @@ continue; } pos = [tmp rangeOfString: @"="].location; if (pos == OFNotFound) { - fprintf(stderr, - "Warning: Invalid environment " - "variable: %s\n", tmp.UTF8String); + OFLog(@"Warning: Invalid environment " + "variable: %@", tmp); continue; } key = [tmp substringToIndex: pos]; value = [tmp substringFromIndex: pos + 1]; @@ -394,12 +397,12 @@ void *pool = objc_autoreleasePoolPush(); OFString *key, *value; char *sep; if ((sep = strchr(*env, '=')) == NULL) { - fprintf(stderr, "Warning: Invalid " - "environment variable: %s\n", *env); + OFLog(@"Warning: Invalid environment " + "variable: %s", *env); continue; } key = [OFString stringWithCString: *env @@ -578,10 +581,11 @@ - (void)of_run { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop; + OFNotification *notification; #ifdef OF_HAVE_THREADS [OFThread of_createMainThread]; runLoop = [OFRunLoop currentRunLoop]; #else @@ -597,11 +601,19 @@ * of_setMainRunLoop: retained it. However, we only have a weak * reference to it now, whereas we had a strong reference before. */ pool = objc_autoreleasePoolPush(); - [_delegate applicationDidFinishLaunching]; + + notification = [OFNotification + notificationWithName: OFApplicationDidFinishLaunchingNotification + object: app]; + + [[OFNotificationCenter defaultCenter] postNotification: notification]; + + [_delegate applicationDidFinishLaunching: notification]; + objc_autoreleasePoolPop(pool); [runLoop run]; }