1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

macOS: use HTTPS for downloads (#326)

This commit is contained in:
Alex Dunn 2017-07-06 12:47:56 -07:00 committed by ArseniyShestakov
parent 489fdaefb7
commit 3915d6c312

View File

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