From cba258b8c4d2219590a3e9f3f2d61b3135bf9777 Mon Sep 17 00:00:00 2001 From: Matt Hardcastle Date: Fri, 30 Aug 2019 11:53:59 -0700 Subject: [PATCH] Error handling for Launcher's update Before this change the update helper app in the Mac version of HQ Launcher silently ignored errors. This change adds error handling to aid troubleshooting. --- launchers/darwin/src/updater/main.m | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/launchers/darwin/src/updater/main.m b/launchers/darwin/src/updater/main.m index 7c7ace6f70..f8fe5a598c 100644 --- a/launchers/darwin/src/updater/main.m +++ b/launchers/darwin/src/updater/main.m @@ -21,15 +21,39 @@ int main(int argc, char const* argv[]) { for (int index = 0; index < argc; index++) { NSLog(@"argv at index %d = %s", index, argv[index]); } + + NSError *error = nil; + NSString* oldLauncher = [NSString stringWithUTF8String:argv[1]]; NSString* newLauncher = [NSString stringWithUTF8String:argv[2]]; NSURL* destinationUrl = [UpdaterHelper NSStringToNSURL:newLauncher]; NSFileManager* fileManager = [NSFileManager defaultManager]; - [fileManager replaceItemAtURL:[UpdaterHelper NSStringToNSURL:oldLauncher] withItemAtURL:[UpdaterHelper NSStringToNSURL:newLauncher] backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&destinationUrl error:nil]; + [fileManager replaceItemAtURL:[UpdaterHelper NSStringToNSURL:oldLauncher] + withItemAtURL:[UpdaterHelper NSStringToNSURL:newLauncher] + backupItemName:nil + options:NSFileManagerItemReplacementUsingNewMetadataOnly + resultingItemURL:&destinationUrl + error:&error]; + if (error != nil) { + NSLog(@"couldn't update launcher: %@", error); + return 1; + } + NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSURL* applicationURL = [UpdaterHelper NSStringToNSURL: [oldLauncher stringByAppendingString: @"/Contents/MacOS/HQ Launcher"]]; NSArray* arguments =@[]; NSLog(@"Launcher agruments: %@", arguments); - [workspace launchApplicationAtURL:applicationURL options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:nil]; + + NSDictionary *configuration = [NSDictionary dictionaryWithObject:arguments + forKey:NSWorkspaceLaunchConfigurationArguments]; + [workspace launchApplicationAtURL:applicationURL + options:NSWorkspaceLaunchNewInstance + configuration:configuration + error:&error]; + if (error != nil) { + NSLog(@"couldn't start launcher: %@", error); + return 1; + } + return 0; }