making requested changes

This commit is contained in:
dante ruiz 2019-08-02 11:26:41 -07:00
parent 7ed13a2ba2
commit b9106b9ade
4 changed files with 26 additions and 35 deletions

View file

@ -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];

View file

@ -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"];

View file

@ -1,8 +1,7 @@
#import "LauncherCommandlineArgs.h"
@implementation LauncherCommandlineArgs
+(NSDictionary*) arguments
{
+(NSDictionary*) arguments {
NSArray* arguments = [[NSProcessInfo processInfo] arguments];
if (arguments.count < 2)

View file

@ -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 =@[];