|
| 1 | +/* Copyright (C) 2016 LiveCode Ltd. |
| 2 | + |
| 3 | + This file is part of LiveCode. |
| 4 | + |
| 5 | + LiveCode is free software; you can redistribute it and/or modify it under |
| 6 | + the terms of the GNU General Public License v3 as published by the Free |
| 7 | + Software Foundation. |
| 8 | + |
| 9 | + LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | + WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + for more details. |
| 13 | + |
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +#import <Foundation/Foundation.h> |
| 20 | + |
| 21 | + |
| 22 | +// This file is a simple stub executable for launching the AppleScript that |
| 23 | +// opens a Finder window showing the contents of the DMG. It is used by the |
| 24 | +// auto-updater to display the contents of the DMG so the user can copy the new |
| 25 | +// app bundle to their Applications folder. |
| 26 | +// |
| 27 | +// Previously, we used a shell script to do the launching. However, as of OSX |
| 28 | +// 10.11.4, the `codesign` tool generates signatures that cannot be verified on |
| 29 | +// earlier versions of OSX when asked to sign a non-MachO executable as code. |
| 30 | +// |
| 31 | +// Therefore, we use this executable in place of the shell script so that the |
| 32 | +// object being signed is one that doesn't cause problems. |
| 33 | + |
| 34 | + |
| 35 | +int main(int argc, char* argv[]) |
| 36 | +{ |
| 37 | + // Get the main bundle for the application |
| 38 | + NSBundle* mainBundle = [NSBundle mainBundle]; |
| 39 | + |
| 40 | + // Path to the subdirectory containing the bundle's resources |
| 41 | + NSString* resourcePath = [mainBundle resourcePath]; |
| 42 | + |
| 43 | + // Append the path to the AppleScript that opens a Finder window |
| 44 | + NSString* scriptPath = [resourcePath stringByAppendingPathComponent:@"Installer/ShowDmgWindow.scpt"]; |
| 45 | + |
| 46 | + // Turn the path into a URL and load it into an AppleScript object |
| 47 | + NSURL* scriptURL = [[NSURL alloc] initFileURLWithPath:scriptPath]; |
| 48 | + NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:scriptURL error:nil]; |
| 49 | + |
| 50 | + // Generate the "run" AppleEvent to send to the script. It needs to be given |
| 51 | + // an array containing 1 item which is the POSIX path to the DMG folder. |
| 52 | + NSString* dmgPath = [[mainBundle bundlePath] stringByDeletingLastPathComponent]; |
| 53 | + NSAppleEventDescriptor* pathDescriptor = [NSAppleEventDescriptor descriptorWithString:dmgPath]; |
| 54 | + NSAppleEventDescriptor* argvList = [NSAppleEventDescriptor listDescriptor]; |
| 55 | + NSAppleEventDescriptor* appleEvent = [NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass |
| 56 | + eventID:kAEOpenApplication |
| 57 | + targetDescriptor:nil |
| 58 | + returnID:kAutoGenerateReturnID |
| 59 | + transactionID:kAnyTransactionID ]; |
| 60 | + [argvList insertDescriptor:pathDescriptor atIndex:1]; |
| 61 | + [appleEvent setParamDescriptor:argvList forKeyword:keyDirectObject]; |
| 62 | + |
| 63 | + // Execute the script |
| 64 | + [appleScript executeAppleEvent:appleEvent error:nil]; |
| 65 | + |
| 66 | + // Cleanup |
| 67 | + [appleEvent release]; |
| 68 | + [argvList release]; |
| 69 | + [pathDescriptor release]; |
| 70 | + [dmgPath release]; |
| 71 | + [appleScript release]; |
| 72 | + [scriptURL release]; |
| 73 | + [scriptPath release]; |
| 74 | + [resourcePath release]; |
| 75 | + [mainBundle release]; |
| 76 | + |
| 77 | + // All done |
| 78 | + return 0; |
| 79 | +} |
0 commit comments