7#include <Cocoa/Cocoa.h>
8#include <CoreServices/CoreServices.h>
9#include <crt_externs.h>
21#elif defined(__x86_64__)
31 posix_spawnattr_t spawnattr;
32 if (posix_spawnattr_init(&spawnattr) != 0) {
33 printf(
"Failed to init posix spawn attribute.");
38 size_t attr_count = 2;
39 size_t attr_ocount = 0;
40 if (posix_spawnattr_setbinpref_np(&spawnattr, attr_count,
pref_cpu_types, &attr_ocount) != 0 ||
41 attr_ocount != attr_count) {
42 printf(
"Failed to set binary preference on posix spawn attribute.");
43 posix_spawnattr_destroy(&spawnattr);
49 char** argv_copy = (
char**)malloc((argc + 1) *
sizeof(
char*));
51 printf(
"Failed to allocate memory for arguments.");
52 posix_spawnattr_destroy(&spawnattr);
55 for (
int i = 0;
i < argc;
i++) {
56 argv_copy[
i] = argv[
i];
58 argv_copy[argc] =
NULL;
62 char*** cocoaEnvironment = _NSGetEnviron();
63 if (cocoaEnvironment) {
64 envp = *cocoaEnvironment;
67 int result = posix_spawnp(
NULL, argv_copy[0],
NULL, &spawnattr, argv_copy, envp);
70 posix_spawnattr_destroy(&spawnattr);
73 printf(
"Process spawn failed with code %d!",
result);
82 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]
init];
84 NSString* iniPath = [NSString stringWithUTF8String:aAppBundle];
86 [iniPath stringByAppendingPathComponent:
@"Contents/Resources/updater.ini"];
88 NSFileManager* fileManager = [NSFileManager defaultManager];
89 if (![fileManager fileExistsAtPath:iniPath]) {
98 "ExeRelPath\0ExeArg\0",
107 NSString *exeRelPath = [NSString stringWithUTF8String:
values[0]];
108 NSString *exeArg = [NSString stringWithUTF8String:
values[1]];
109 if (!exeArg || !exeRelPath) {
114 NSString* exeFullPath = [NSString stringWithUTF8String:aAppBundle];
115 exeFullPath = [exeFullPath stringByAppendingPathComponent:exeRelPath];
124 NSTask *task = [[NSTask alloc]
init];
125 [task setLaunchPath:exeFullPath];
126 [task setArguments:[NSArray arrayWithObject:exeArg]];
129 NSString *exeAsync = [NSString stringWithUTF8String:optVals[0]];
130 if ([exeAsync isEqualToString:
@"false"]) {
131 [task waitUntilExit];
FILE * init(int, char **)
static cpu_type_t pref_cpu_types[2]
void LaunchChild(int argc, char **argv)
void LaunchMacPostProcess(const char *aAppBundle)
std::vector< char * > values
int ReadStrings(const NS_tchar *path, const char *keyList, unsigned int numStrings, char results[][MAX_TEXT_LEN], const char *section)
A very basic parser for updater.ini taken mostly from nsINIParser.cpp that can be used by standalone ...