|
8 | 8 | #import <JoyKit/JoyKit.h> |
9 | 9 | #import <WebKit/WebKit.h> |
10 | 10 | #import <mach-o/dyld.h> |
| 11 | +#include <sys/mount.h> |
| 12 | +#include <sys/xattr.h> |
11 | 13 |
|
12 | 14 | #define UPDATE_SERVER "https://sameboy.github.io" |
13 | 15 |
|
@@ -662,6 +664,14 @@ - (void)performUpgrade |
662 | 664 | } |
663 | 665 | [[NSFileManager defaultManager] removeItemAtPath:_downloadDirectory error:nil]; |
664 | 666 | [[NSFileManager defaultManager] removeItemAtPath:contentsTempPath error:nil]; |
| 667 | + |
| 668 | + // Remove the quarantine flag so we don't have to escape translocation |
| 669 | + NSString *bundlePath = [NSBundle mainBundle].bundlePath; |
| 670 | + removexattr(bundlePath.UTF8String, "com.apple.quarantine", 0); |
| 671 | + for (NSString *path in [[NSFileManager defaultManager] enumeratorAtPath:bundlePath]) { |
| 672 | + removexattr([bundlePath stringByAppendingPathComponent:path].UTF8String, "com.apple.quarantine", 0); |
| 673 | + }; |
| 674 | + |
665 | 675 | _downloadDirectory = nil; |
666 | 676 | atexit_b(^{ |
667 | 677 | execl(executablePath.UTF8String, executablePath.UTF8String, "--update-launch", NULL); |
@@ -781,4 +791,27 @@ - (void)dealloc |
781 | 791 | - (IBAction)nop:(id)sender |
782 | 792 | { |
783 | 793 | } |
| 794 | + |
| 795 | +/* This runs before C constructors. If we need to escape translocation, we should |
| 796 | + do it ASAP to minimize our launch time. */ |
| 797 | + |
| 798 | ++ (void)load |
| 799 | +{ |
| 800 | + if (@available(macOS 10.12, *)) { |
| 801 | + /* Detect and escape translocation so we can safely update ourselves */ |
| 802 | + if ([[[NSBundle mainBundle] bundlePath] containsString:@"/AppTranslocation/"]) { |
| 803 | + const char *mountPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent].UTF8String; |
| 804 | + struct statfs *mntbuf; |
| 805 | + int mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); |
| 806 | + for (unsigned i = 0; i < mntsize; i++) { |
| 807 | + if (strcmp(mntbuf[i].f_mntonname, mountPath) == 0) { |
| 808 | + NSBundle *origBundle = [NSBundle bundleWithPath:@(mntbuf[i].f_mntfromname)]; |
| 809 | + |
| 810 | + execl(origBundle.executablePath.UTF8String, origBundle.executablePath.UTF8String, NULL); |
| 811 | + break; |
| 812 | + } |
| 813 | + } |
| 814 | + } |
| 815 | + } |
| 816 | +} |
784 | 817 | @end |
0 commit comments