From b9106b9adeedfd10a902a3817e64f3a766445f88 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Fri, 2 Aug 2019 11:26:41 -0700 Subject: [PATCH] making requested changes --- launchers/darwin/src/DownloadLauncher.m | 28 ++++++++----------- launchers/darwin/src/LatestBuildRequest.m | 20 ++++++------- .../darwin/src/LauncherCommandlineArgs.m | 3 +- launchers/darwin/src/updater/main.m | 10 +++---- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/launchers/darwin/src/DownloadLauncher.m b/launchers/darwin/src/DownloadLauncher.m index d2538c897b..e7d293be43 100644 --- a/launchers/darwin/src/DownloadLauncher.m +++ b/launchers/darwin/src/DownloadLauncher.m @@ -4,8 +4,7 @@ @implementation DownloadLauncher -- (void) downloadLauncher:(NSString *)launcherUrl -{ +- (void) downloadLauncher:(NSString*)launcherUrl { NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:launcherUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; @@ -22,20 +21,15 @@ } --(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { - // unused in this example -} - --(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { +-(void)URLSession:(NSURLSession*)session downloadTask:(NSURLSessionDownloadTask*)downloadTask didFinishDownloadingToURL:(NSURL*)location { NSLog(@"Did finish downloading to url"); - NSError *error = nil; - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; + NSError* error = nil; + NSFileManager* fileManager = [NSFileManager defaultManager]; + NSString* destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString* finalFilePath = [[[Launcher sharedLauncher] getDownloadPathForContentAndScripts] stringByAppendingPathComponent:destinationFileName]; NSURL *destinationURL = [NSURL URLWithString: [finalFilePath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]] relativeToURL: [NSURL URLWithString:@"file://"]]; NSLog(@"desintation %@", destinationURL); - if([fileManager fileExistsAtPath:[destinationURL path]]) - { + if([fileManager fileExistsAtPath:[destinationURL path]]) { [fileManager removeItemAtURL:destinationURL error:nil]; } @@ -51,21 +45,21 @@ NSLog(@"Download Launcher: failed to move file to destintation -> error: %@", error); [sharedLauncher displayErrorPage]; return; - } - NSLog(@"extracting domain content file"); - BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[sharedLauncher getDownloadPathForContentAndScripts] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:destinationFileName]]; + } + NSLog(@"extracting Launcher file"); + BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[sharedLauncher getDownloadPathForContentAndScripts] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"HQ Launcher.zip"]]; if (!extractionSuccessful) { [sharedLauncher displayErrorPage]; return; } - NSLog(@"finished extracting content file"); + NSLog(@"finished extracting Launcher file"); [[Launcher sharedLauncher] runAutoupdater]; } -- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { +- (void)URLSession:(NSURLSession*)session task:(NSURLSessionTask*)task didCompleteWithError:(NSError*)error { NSLog(@"completed; error: %@", error); if (error) { [[Launcher sharedLauncher] displayErrorPage]; diff --git a/launchers/darwin/src/LatestBuildRequest.m b/launchers/darwin/src/LatestBuildRequest.m index a2650a194f..a663200089 100644 --- a/launchers/darwin/src/LatestBuildRequest.m +++ b/launchers/darwin/src/LatestBuildRequest.m @@ -9,8 +9,8 @@ NSInteger currentVersion; @try { NSString* interfaceAppPath = [[Launcher.sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]; - NSError * error = nil; - Interface * interface = [[Interface alloc] initWith:interfaceAppPath]; + NSError* error = nil; + Interface* interface = [[Interface alloc] initWith:interfaceAppPath]; currentVersion = [interface getVersion:&error]; if (currentVersion == 0 && error != nil) { NSLog(@"can't get version from interface, falling back to settings: %@", error); @@ -24,17 +24,17 @@ } - (void) requestLatestBuildInfo { - NSMutableURLRequest *request = [NSMutableURLRequest new]; + NSMutableURLRequest* request = [NSMutableURLRequest new]; [request setURL:[NSURL URLWithString:@"https://thunder.highfidelity.com/builds/api/tags/latest?format=json"]]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; // We're using an ephermeral session here to ensure the tags api response is never cached. - NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration]; + NSURLSession* session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration]; NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSLog(@"Latest Build Request error: %@", error); NSLog(@"Latest Build Request Data: %@", data); - NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; + NSHTTPURLResponse* ne = (NSHTTPURLResponse *)response; NSLog(@"Latest Build Request Response: %ld", [ne statusCode]); Launcher* sharedLauncher = [Launcher sharedLauncher]; @@ -47,9 +47,9 @@ NSMutableData* webData = [NSMutableData data]; [webData appendData:data]; NSString* jsonString = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[data length] encoding:NSUTF8StringEncoding]; - NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; + NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"Latest Build Request -> json string: %@", jsonString); - NSError *jsonError = nil; + NSError* jsonError = nil; id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError]; if (jsonError) { @@ -57,9 +57,9 @@ } NSFileManager* fileManager = [NSFileManager defaultManager]; - NSArray *values = [json valueForKey:@"results"]; - NSDictionary *launcherValues = [json valueForKey:@"launcher"]; - NSDictionary *value = [values objectAtIndex:0]; + NSArray* values = [json valueForKey:@"results"]; + NSDictionary* launcherValues = [json valueForKey:@"launcher"]; + NSDictionary* value = [values objectAtIndex:0]; NSString* launcherVersion = [launcherValues valueForKey:@"version"]; NSString* launcherUrl = [[launcherValues valueForKey:@"mac"] valueForKey:@"url"]; diff --git a/launchers/darwin/src/LauncherCommandlineArgs.m b/launchers/darwin/src/LauncherCommandlineArgs.m index 0c53da2b71..4229c91205 100644 --- a/launchers/darwin/src/LauncherCommandlineArgs.m +++ b/launchers/darwin/src/LauncherCommandlineArgs.m @@ -1,8 +1,7 @@ #import "LauncherCommandlineArgs.h" @implementation LauncherCommandlineArgs -+(NSDictionary*) arguments -{ ++(NSDictionary*) arguments { NSArray* arguments = [[NSProcessInfo processInfo] arguments]; if (arguments.count < 2) diff --git a/launchers/darwin/src/updater/main.m b/launchers/darwin/src/updater/main.m index 31b333c5d9..7c7ace6f70 100644 --- a/launchers/darwin/src/updater/main.m +++ b/launchers/darwin/src/updater/main.m @@ -12,10 +12,8 @@ } @end -int main(int argc, char const* argv[]) -{ - if (argc < 3) - { +int main(int argc, char const* argv[]) { + if (argc < 3) { NSLog(@"Error: wrong number of arguments"); return 0; } @@ -25,9 +23,9 @@ int main(int argc, char const* argv[]) } NSString* oldLauncher = [NSString stringWithUTF8String:argv[1]]; NSString* newLauncher = [NSString stringWithUTF8String:argv[2]]; + NSURL* destinationUrl = [UpdaterHelper NSStringToNSURL:newLauncher]; NSFileManager* fileManager = [NSFileManager defaultManager]; - [fileManager removeItemAtURL:[UpdaterHelper NSStringToNSURL:oldLauncher] error:nil]; - [fileManager moveItemAtURL: [UpdaterHelper NSStringToNSURL: newLauncher] toURL: [UpdaterHelper NSStringToNSURL:oldLauncher] error:nil]; + [fileManager replaceItemAtURL:[UpdaterHelper NSStringToNSURL:oldLauncher] withItemAtURL:[UpdaterHelper NSStringToNSURL:newLauncher] backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&destinationUrl error:nil]; NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSURL* applicationURL = [UpdaterHelper NSStringToNSURL: [oldLauncher stringByAppendingString: @"/Contents/MacOS/HQ Launcher"]]; NSArray* arguments =@[];