From 2fc88e439dcaf9d75ab5bf2073553105550f1098 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 20 Nov 2010 13:05:30 +1300 Subject: [PATCH] Progress towards in-launcher download ui. Works, but is very fragile. --- OpenRA.Launcher.Mac/Download.h | 12 +---- OpenRA.Launcher.Mac/Download.m | 10 ++-- OpenRA.Launcher.Mac/JSBridge.m | 12 +++-- mods/cnc/mod.html | 95 +++++++++++++++++++++++----------- 4 files changed, 80 insertions(+), 49 deletions(-) diff --git a/OpenRA.Launcher.Mac/Download.h b/OpenRA.Launcher.Mac/Download.h index 102fab0ea6..92c32863de 100644 --- a/OpenRA.Launcher.Mac/Download.h +++ b/OpenRA.Launcher.Mac/Download.h @@ -8,14 +8,6 @@ #import -typedef enum { - Initializing, - Downloading, - Complete, - Cancelled, - Error -} DownloadStatus; - @class GameInstall; @interface Download : NSObject { @@ -24,12 +16,12 @@ typedef enum { NSString *filename; GameInstall *game; NSTask *task; - DownloadStatus status; + NSString * status; int bytesCompleted; int bytesTotal; } @property(readonly) NSString *key; -@property(readonly) DownloadStatus status; +@property(readonly) NSString *status; @property(readonly) int bytesCompleted; @property(readonly) int bytesTotal; diff --git a/OpenRA.Launcher.Mac/Download.m b/OpenRA.Launcher.Mac/Download.m index 670820eb70..17b8fa91e5 100644 --- a/OpenRA.Launcher.Mac/Download.m +++ b/OpenRA.Launcher.Mac/Download.m @@ -32,7 +32,7 @@ filename = [aFilename retain]; key = [aKey retain]; game = [aGame retain]; - status = Initializing; + status = @"Initializing"; bytesCompleted = -1; bytesTotal = -1; @@ -65,17 +65,17 @@ if ([type isEqualToString:@"Error"]) { - status = Error; + status = @"Error"; } else if ([type isEqualToString:@"Status"]) { if ([message isEqualToString:@"Initializing"]) { - status = Initializing; + status = @"Initializing"; } else if ([message isEqualToString:@"Completed"]) { - status = Complete; + status = @"Complete"; } // Parse download status info @@ -97,7 +97,7 @@ - (void)cancel { NSLog(@"Cancelling"); - status = Cancelled; + status = @"Cancelled"; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc removeObserver:self name:NSFileHandleReadCompletionNotification object:[[task standardOutput] fileHandleForReading]]; [nc removeObserver:self name:NSTaskDidTerminateNotification object:task]; diff --git a/OpenRA.Launcher.Mac/JSBridge.m b/OpenRA.Launcher.Mac/JSBridge.m index 40b394319e..96c101eb9d 100644 --- a/OpenRA.Launcher.Mac/JSBridge.m +++ b/OpenRA.Launcher.Mac/JSBridge.m @@ -42,13 +42,13 @@ static JSBridge *SharedInstance; methods = [[NSDictionary dictionaryWithObjectsAndKeys: @"launchMod", NSStringFromSelector(@selector(launchMod:)), @"log", NSStringFromSelector(@selector(log:)), - @"existsInMod", NSStringFromSelector(@selector(exists:inMod:)), + @"existsInMod", NSStringFromSelector(@selector(fileExists:inMod:)), // File downloading @"existsInCache", NSStringFromSelector(@selector(existsInCache:)), @"downloadToCache", NSStringFromSelector(@selector(downloadUrl:withName:key:)), @"cancelDownload", NSStringFromSelector(@selector(cancelDownload:)), - @"isDownloading", NSStringFromSelector(@selector(isDownloading:)), + @"downloadStatus", NSStringFromSelector(@selector(downloadStatus:)), @"bytesCompleted", NSStringFromSelector(@selector(bytesCompleted:)), @"bytesTotal", NSStringFromSelector(@selector(bytesTotal:)), nil] retain]; @@ -124,9 +124,13 @@ static JSBridge *SharedInstance; [controller cancelDownload:key]; } -- (BOOL)isDownloading:(NSString *)key +- (NSString *)downloadStatus:(NSString *)key { - return [controller downloadWithKey:key] != nil; + Download *d = [controller downloadWithKey:key]; + if (d == nil) + return @"Invalid"; + + return [d status]; } - (int)bytesCompleted:(NSString *)key diff --git a/mods/cnc/mod.html b/mods/cnc/mod.html index 2f2f334973..875274d73a 100644 --- a/mods/cnc/mod.html +++ b/mods/cnc/mod.html @@ -90,10 +90,9 @@ // Returns 2 if basic files plus music are installed function packagesInstalled() { - if (window.external.existsInMod('packages/conquer.mix','cnc') != 1) + if (window.external.existsInMod("packages/conquer.mix","cnc") != 1) return 0; - - return (window.external.existsInMod('packages/scores.mix','cnc') == 1) ? 2 : 1; + return (window.external.existsInMod("packages/scores.mix","cnc") == 1) ? 2 : 1; } function play() @@ -101,39 +100,71 @@ window.external.launchMod("cnc"); } - function download1() + function download() { - window.external.downloadToCache("http://localhost/~paul/cnc-packages.zip","test.zip","cnc-packages"); + window.external.downloadToCache("http://localhost/~paul/cnc-packages.zip","cnc-packages.zip","cnc-packages"); + document.getElementById("install-download").style.display = "none"; + document.getElementById("install-downloading").style.display = ""; } - - function download2() - { - window.external.downloadToCache("http://localhost/~paul/ra-packages.zip","test2.zip","ra-packages"); - } - - function cancel1() + + function cancel() { window.external.cancelDownload("cnc-packages"); + // TODO: Remove incomplete file from cache + // TODO: Restore buttons to the before-downloading state } - function cancel2() + function extract() { - window.external.cancelDownload("ra-packages"); + window.external.log("Todo: Extract package"); } function onLoad() { - document.getElementById("buttons-install").style.display = (packagesInstalled() == 0) ? "" : "none"; - document.getElementById("buttons-upgrade").style.display = (packagesInstalled() == 1) ? "" : "none"; - document.getElementById("buttons-play").style.display = (packagesInstalled() == 2) ? "" : "none"; + var installed = packagesInstalled(); + 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 downloaded = window.external.existsInCache("cnc-packages.zip"); + window.external.log("downloaded: "+downloaded); + document.getElementById("install-extract").style.display = downloaded ? "" : "none"; + document.getElementById("install-download").style.display = !downloaded ? "" : "none"; + } } function downloadProgressed(file) { - var total = window.external.bytesTotal(file); - var downloaded = window.external.bytesCompleted(file); - var percent = (100*downloaded/total).toPrecision(3); - window.external.log("file: "+file+" "+downloaded+"/"+total+" ("+percent+"%)"); + if (file != "cnc-packages") + return; + + var status = window.external.downloadStatus(file); + if (status == "Complete") + { + document.getElementById("install-extract").style.display = ""; + document.getElementById("install-downloading").style.display = "none"; + } + var total = window.external.bytesTotal(file); + var downloaded = window.external.bytesCompleted(file); + + var multiplier = 1/1024.0; + var unit = "kB"; + + var max = max(total,downloaded); // total may be -1 if the server doesn't supply a size + if (max > 1.1*1024*1024) + { + multiplier /= 1024; + unit = "MB"; + } + total = (total*multiplier).toPrecision(2); + downloaded = (downloaded*multiplier).toPrecision(2); + + document.getElementById("download-status").value = downloaded+"/"+total+" "+unit; + window.external.log("file: "+file+" "+downloaded+"/"+total+" ("+percent+"%)"); } @@ -144,7 +175,7 @@
-
+
The original game data is required before you can play this mod.
- Installing from web will install the minimal files required to play.
- Installing from CD will also install the music and movie files for an improved game experience. + Installing from web will install the minimal files required to play. +
+
+ +
+ +
+
- - - - -