From efad699d4b2f8c04b3bbd7a5af83d5f5430d84f2 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Nov 2010 13:46:06 +1300 Subject: [PATCH] Prompt user when quitting with active downloads. Remove js debug logging. --- OpenRA.Launcher.Mac/Controller.m | 27 +++++++++++++++++++++++++-- OpenRA.Launcher.Mac/Download.m | 4 ++++ mods/cnc/mod.html | 26 ++++++++------------------ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index d3c33b2bce..19967954d7 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -195,8 +195,31 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - // Todo: show a sheet if downloads are in progress - return NSTerminateNow; + int count = 0; + for (NSString *key in downloads) + if ([[(Download *)[downloads objectForKey:key] status] isEqualToString:@"DOWNLOADING"]) + count++; + + if (count == 0) + return NSTerminateNow; + + NSString *format = count == 1 ? @"1 download is" : [NSString stringWithFormat:@"%d downloads are",count]; + NSAlert *alert = [NSAlert alertWithMessageText:@"Are you sure you want to quit?" + defaultButton:@"Cancel" + alternateButton:@"Quit" + otherButton:nil + informativeTextWithFormat:@"%@ in progress and will be cancelled.", format]; + + [alert beginSheetModalForWindow:[webView window] modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:NULL]; + return NSTerminateLater; +} + +- (void)alertEnded:(NSAlert *)alert + code:(int)button + context:(void *)v +{ + NSApplicationTerminateReply reply = (button == NSAlertDefaultReturn) ? NSTerminateCancel : NSTerminateNow; + [[NSApplication sharedApplication] replyToApplicationShouldTerminate:reply]; } - (void)applicationWillTerminate:(NSNotification *)aNotification diff --git a/OpenRA.Launcher.Mac/Download.m b/OpenRA.Launcher.Mac/Download.m index 8558c0d43d..67e07e4841 100644 --- a/OpenRA.Launcher.Mac/Download.m +++ b/OpenRA.Launcher.Mac/Download.m @@ -114,6 +114,10 @@ { status = @"ERROR"; error = @"Download Cancelled"; + + [[NSFileManager defaultManager] removeItemAtPath:filename error:NULL]; + bytesCompleted = bytesTotal = -1; + [[JSBridge sharedInstance] notifyDownloadProgress:self]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadCompletionNotification diff --git a/mods/cnc/mod.html b/mods/cnc/mod.html index b75d6123d7..daeb1e9103 100644 --- a/mods/cnc/mod.html +++ b/mods/cnc/mod.html @@ -124,20 +124,13 @@ function refreshSections() { var installed = packagesInstalled(); - window.external.log("installed: "+installed); - document.getElementById("buttons-install").style.display = (installed == 0) ? "" : "none"; document.getElementById("buttons-upgrade").style.display = (installed == 1) ? "" : "none"; document.getElementById("buttons-play").style.display = (installed == 2) ? "" : "none"; - window.external.log("installed: "+installed); - // Select the correct subsection if (installed == 0) { - //var url = "http://localhost/~paul/cnc-packages.zip"; - //var url = "http://localhost/~paul/cnc-packages.bogus"; - var url = "http://open-ra.org/get-dependency.php?file=cnc-packages"; - window.external.registerDownload("cnc-packages", url, "cnc-packages.zip"); + window.external.registerDownload("cnc-packages", "http://open-ra.org/get-dependency.php?file=cnc-packages", "cnc-packages.zip"); refreshDownloadButtons(); } } @@ -148,23 +141,24 @@ document.getElementById("download-downloading").style.display = "none"; document.getElementById("download-extract").style.display = "none"; document.getElementById("download-error").style.display = "none"; - // status can be NOT_REGISTERED, AVAILABLE, DOWNLOADING, COMPLETE, ERROR var status = window.external.downloadStatus("cnc-packages"); - window.external.log("status: "+status); // Download complete, offer button to extract it if (status == "COMPLETE") - document.getElementById("download-extract").style.display = ""; - + { + document.getElementById("download-extract").style.display = ""; + } // Show the download progress else if (status == "DOWNLOADING") + { document.getElementById("download-downloading").style.display = ""; - + } // Show the download button else if (status == "AVAILABLE") + { document.getElementById("download-available").style.display = ""; - + } else if (status == "ERROR") { var message = window.external.downloadError("cnc-packages"); @@ -180,19 +174,15 @@ var total = window.external.bytesTotal(file); var downloaded = window.external.bytesCompleted(file); - window.external.log(file+" = total: "+total+" downloaded: "+downloaded); - if (downloaded > 0) { var multiplier = 1/1048576.0; total = (total*multiplier).toPrecision(2); downloaded = (downloaded*multiplier).toPrecision(2); - document.getElementById("download-status").value = downloaded+"/"+total+" MB"; } refreshDownloadButtons(); } -