From 3915d6c312822f521bfff631bb17e8b537655b3f Mon Sep 17 00:00:00 2001 From: Alex Dunn Date: Thu, 6 Jul 2017 12:47:56 -0700 Subject: [PATCH] macOS: use HTTPS for downloads (#326) --- osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m b/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m index 054e37e62..31082c1ed 100644 --- a/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m +++ b/osx/osx-vcmibuilder/vcmibuilder/AppDelegate.m @@ -7,7 +7,7 @@ installationCompleted = NO; outputDir = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/../../Data"]; tempDir = NSTemporaryDirectory(); - + // Output to Application Support NSArray* appSupportDirs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]; outputDir = [[appSupportDirs[0] path] stringByAppendingString:@"/vcmi"]; @@ -69,7 +69,7 @@ if (![executable hasPrefix:@"/usr/"]) { executable = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:executable]; } - + NSTask* task = [[NSTask alloc] init]; [task setLaunchPath:executable]; if (workingDir != nil) { @@ -79,10 +79,10 @@ [task setStandardOutput:pipe]; } [task setArguments:args]; - + [task launch]; [task waitUntilExit]; - + return [task terminationStatus]; } @@ -92,12 +92,12 @@ if (![[NSFileManager defaultManager] fileExistsAtPath:[self.cd1TextField stringValue]]) { return [self showErrorText:@"Please select existing file"]; } - + // Show progress controls [self.progressIndicator setHidden:NO]; [self.progressIndicator startAnimation:self]; [self showProgressText:@"Installing VCMI..."]; - + [self nextAction]; } @@ -108,7 +108,7 @@ dispatch_async(dispatch_get_main_queue(), ^{ self->currentArchiveName = @"WoG"; self->currentArchiveFilename = @"/wog.zip"; - NSURL* url = [NSURL URLWithString:@"http://download.vcmi.eu/WoG/wog.zip"]; + NSURL* url = [NSURL URLWithString:@"https://download.vcmi.eu/WoG/wog.zip"]; self.download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:url] delegate:self]; }); } @@ -120,7 +120,7 @@ if ([self runTask:@"/usr/bin/unzip" withArgs:@[@"-qo", [tempDir stringByAppendingString:currentArchiveFilename], @"-d", outputDir] withWorkingDir:nil withPipe:nil] != 0) { return [self showErrorText:@"Failed to unzip WoG archive"]; } - + [self nextAction]; } @@ -131,7 +131,7 @@ dispatch_async(dispatch_get_main_queue(), ^{ self->currentArchiveName = @"VCMI"; self->currentArchiveFilename = @"/core.zip"; - NSURL* url = [NSURL URLWithString:@"http://download.vcmi.eu/core.zip"]; + NSURL* url = [NSURL URLWithString:@"https://download.vcmi.eu/core.zip"]; self.download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:url] delegate:self]; }); } @@ -143,7 +143,7 @@ if ([self runTask:@"/usr/bin/unzip" withArgs:@[@"-qo", [tempDir stringByAppendingString:currentArchiveFilename], @"-d", outputDir, @"-x", @"*.json", @"*.txt", @"*.PAL"] withWorkingDir:nil withPipe:nil] != 0) { return [self showErrorText:@"Failed to unzip VCMI archive"]; } - + [self nextAction]; } @@ -155,7 +155,7 @@ } else { [self unshield]; } - + [self nextAction]; } @@ -166,27 +166,27 @@ if ([self runTask:@"/innoextract" withArgs:@[[self.cd1TextField stringValue]] withWorkingDir:tempDir withPipe:nil] != 0) { [self showErrorText:@"Failed to exctract game data using innoextract"]; } - + dataDir = [tempDir stringByAppendingString:@"/app"]; } - (NSString*)attachDiskImage:(NSString*)path { [self showProgressText:[NSString stringWithFormat:@"Mounting image \"%@\"", path]]; - + // Run hdiutil to mount specified disk image NSPipe* pipe = [NSPipe pipe]; if ([self runTask:@"/usr/bin/hdiutil" withArgs:@[@"attach", path] withWorkingDir:nil withPipe:pipe] != 0) { [NSException raise:[NSString stringWithFormat:@"Failed to mount \"%@\"", path] format:nil]; } - + // Capture hdiutil output to get mounted disk image filesystem path NSFileHandle* file = [pipe fileHandleForReading]; NSString* output = [[NSString alloc] initWithData:[file readDataToEndOfFile] encoding:NSUTF8StringEncoding]; - + NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"(/Volumes/.*)$" options:0 error:nil]; NSTextCheckingResult* match = [regex firstMatchInString:output options:0 range:NSMakeRange(0, [output length])]; - + return [output substringWithRange:[match range]]; } @@ -203,7 +203,7 @@ // If CD2 is not specified use the same path as for CD1 NSString* cd1 = [self attachDiskImage:[self.cd1TextField stringValue]]; NSString* cd2 = [[self.cd2TextField stringValue] isEqualToString:@""] ? cd1 : [self attachDiskImage:[self.cd2TextField stringValue]]; - + // Extract [self showProgressText:@"Extracting game data using unshield..."]; @@ -217,24 +217,24 @@ NSString* cabLocation = [cd1 stringByAppendingString:location]; if ([[NSFileManager defaultManager] fileExistsAtPath:cabLocation]) { int result = [self runTask:@"/unshield" withArgs:@[@"-d", tempDir, @"x", cabLocation] withWorkingDir:tempDir withPipe:nil]; - + if (result == 0) { success = true; break; } } } - + if (!success) { return [self showErrorText:@"Failed to extract game data using unshield"]; } - + NSArray* knownDataDirs = @[ @"/Heroes3", @"/Program_Files", @"/Data", ]; - + success = false; for (NSString* knownDir in knownDataDirs) { dataDir = [tempDir stringByAppendingString:knownDir]; @@ -243,11 +243,11 @@ break; } } - + if (!success) { return [self showErrorText:@"Failed to extract game data using unshield"]; } - + // Unmount CD1. Unmount CD2 if needed [self detachDiskImage:cd1]; if (![cd1 isEqualToString:cd2]) { @@ -259,34 +259,34 @@ { // After game data is extracted we should move it to destination place [self showProgressText:@"Moving items into place"]; - + NSFileManager* fileManager = [NSFileManager defaultManager]; - + [fileManager moveItemAtPath:[dataDir stringByAppendingString:@"/Data"] toPath:[outputDir stringByAppendingString:@"/Data"] error:nil]; [fileManager moveItemAtPath:[dataDir stringByAppendingString:@"/Maps"] toPath:[outputDir stringByAppendingString:@"/Maps"] error:nil]; - + if ([fileManager fileExistsAtPath:[dataDir stringByAppendingString:@"/MP3"] isDirectory:nil]) { [fileManager moveItemAtPath:[dataDir stringByAppendingString:@"/MP3"] toPath:[outputDir stringByAppendingString:@"/Mp3"] error:nil]; } else { [fileManager moveItemAtPath:[dataDir stringByAppendingString:@"/Mp3"] toPath:[outputDir stringByAppendingString:@"/Mp3"] error:nil]; } - + // After everythin is complete we create marker file. VCMI will look for this file to exists on startup and // will run this setup otherwise system([[NSString stringWithFormat:@"touch \"%@/game_data_prepared\"", outputDir] UTF8String]); - + [self showProgressText:@"Installation complete"]; [self.installButton setTitle:@"Run VCMI"]; [self.progressIndicator stopAnimation:self]; - + // Notify user that installation completed [self showNotification:@"Installation completed"]; - + // Hide all progress related controls [self.progressIndicator setHidden:YES]; [self.progressIndicator stopAnimation:self]; [self.progressLabel setHidden:YES]; - + [self.installButton setEnabled:YES]; installationCompleted = YES; } @@ -297,7 +297,7 @@ [openPanel setCanChooseFiles:YES]; [openPanel setAllowedFileTypes:fileTypes]; [openPanel setAllowsMultipleSelection:NO]; - + if ([openPanel runModal] == NSOKButton) { NSString* path = [[openPanel URL] path]; [textField setStringValue:path]; @@ -325,7 +325,7 @@ [self.cd1Button setEnabled:NO]; [self.cd2Button setEnabled:NO]; [self.installButton setEnabled:NO]; - + actions = [NSMutableArray arrayWithObjects: @"validateAction", @"downloadWogArchive", @@ -336,7 +336,7 @@ @"extractionCompleted", nil ]; - + [self nextAction]; } } @@ -350,7 +350,7 @@ notification.informativeText = text; notification.deliveryDate = [NSDate dateWithTimeInterval:0 sinceDate:[NSDate date]]; notification.soundName = NSUserNotificationDefaultSoundName; - + [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification]; } else { // On older OS X version force dock icon to jump @@ -372,7 +372,7 @@ // All GUI updates should be done on main thread dispatch_async(dispatch_get_main_queue(), ^{ [self showNotification:@"Installation failed"]; - + // Show error alert NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:@"Error"]; @@ -383,11 +383,11 @@ [self.cd1Button setEnabled:YES]; [self.cd2Button setEnabled:YES]; [self.installButton setEnabled:YES]; - + // Hide all progress related controls [self.progressIndicator setHidden:YES]; [self.progressIndicator stopAnimation:self]; - + [self.progressLabel setHidden:YES]; }); }