From 9227e09f18501721cd2316b7eea6d125e94b57d6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 20 Jan 2011 17:39:45 +1300 Subject: [PATCH] Refactoring. Add a missing file. --- .../Widgets/Delegates/GameInitDelegate.cs | 67 +++++----- OpenRA.Mods.RA/Widgets/GameInitInfoWidget.cs | 1 - mods/cnc/chrome/gameinit.yaml | 1 - mods/ra/chrome/gameinit.yaml | 116 ++++++++++++++++++ 4 files changed, 147 insertions(+), 38 deletions(-) create mode 100644 mods/ra/chrome/gameinit.yaml diff --git a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs index 7412f6ccf7..2ad138e890 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs @@ -17,8 +17,6 @@ using System.Diagnostics; using System; using System.Net; using System.ComponentModel; -using ICSharpCode.SharpZipLib; -using ICSharpCode.SharpZipLib.Zip; using System.IO; namespace OpenRA.Mods.RA.Widgets.Delegates @@ -86,43 +84,40 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var status = window.GetWidget("STATUS"); status.GetText = () => "Initializing..."; var progress = window.GetWidget("PROGRESS"); - // TODO: Download to a temp location or the support dir - var file = Info.PackageName; - var dl = new Download(Info.PackageURL, file, - i => { - status.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived/1024, i.TotalBytesToReceive/1024); - progress.Percentage = i.ProgressPercentage; - }, - (i, cancelled) => { - System.Console.WriteLine("here"); - if (i.Error != null) - { - System.Console.WriteLine("here2"); - ShowDownloadError(i.Error.Message); - } - else if (!cancelled) - { - System.Console.WriteLine("here3"); - // Automatically extract - status.GetText = () => "Extracting..."; - var error = false; - Game.RunAfterTick(() => ExtractZip(file, Info.PackagePath, - s => - { - if (s.Substring(0,5) == "Error") - { - error = true; - ShowDownloadError(s); - } - if (s.Substring(0,6) == "Status") - window.GetWidget("STATUS").GetText = () => s.Substring(7).Trim(); - }, - () => {if (!error) Game.RunAfterTick(() => ContinueLoading(Info));})); - } + // Save the package to a temp file + var file = Path.GetTempPath() + Path.DirectorySeparatorChar + Path.GetRandomFileName(); + Action onDownloadChange = i => + { + status.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived/1024, i.TotalBytesToReceive/1024); + progress.Percentage = i.ProgressPercentage; + }; + + Action onDownloadComplete = (i, cancelled) => + { + if (i.Error != null) + ShowDownloadError(i.Error.Message); + else if (!cancelled) + { + // Automatically extract + status.GetText = () => "Extracting..."; + var error = false; + Game.RunAfterTick(() => ExtractZip(file, Info.PackagePath, + s => + { + if (s.Substring(0,5) == "Error") + { + error = true; + ShowDownloadError(s); + } + if (s.Substring(0,6) == "Status") + window.GetWidget("STATUS").GetText = () => s.Substring(7).Trim(); + }, + () => {if (!error) Game.RunAfterTick(() => ContinueLoading(Info));})); } - ); + }; + var dl = new Download(Info.PackageURL, file, onDownloadChange, onDownloadComplete); window.GetWidget("CANCEL").OnMouseUp = mi => { dl.Cancel(); ShowInstallMethodDialog(); return true; }; window.GetWidget("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); return true; }; } diff --git a/OpenRA.Mods.RA/Widgets/GameInitInfoWidget.cs b/OpenRA.Mods.RA/Widgets/GameInitInfoWidget.cs index 7f3a095e54..af23c32c5e 100755 --- a/OpenRA.Mods.RA/Widgets/GameInitInfoWidget.cs +++ b/OpenRA.Mods.RA/Widgets/GameInitInfoWidget.cs @@ -19,7 +19,6 @@ namespace OpenRA.Mods.RA.Widgets public string TestFile; public string GameTitle; public string PackageURL; - public string PackageName; public string PackagePath; public override void DrawInner() {} diff --git a/mods/cnc/chrome/gameinit.yaml b/mods/cnc/chrome/gameinit.yaml index 98b37f5a3a..708617861d 100644 --- a/mods/cnc/chrome/gameinit.yaml +++ b/mods/cnc/chrome/gameinit.yaml @@ -3,7 +3,6 @@ GameInitInfo@INIT_SETUP: TestFile: conquer.mix GameTitle: Command & Conquer PackageURL:http://open-ra.org/get-dependency.php?file=cnc-packages - PackageName:cnc-packages.zip PackagePath:cnc/packages/ Delegate:GameInitDelegate diff --git a/mods/ra/chrome/gameinit.yaml b/mods/ra/chrome/gameinit.yaml new file mode 100644 index 0000000000..f520ee03e8 --- /dev/null +++ b/mods/ra/chrome/gameinit.yaml @@ -0,0 +1,116 @@ +GameInitInfo@INIT_SETUP: + Id:INIT_SETUP + TestFile: redalert.mix + GameTitle: Red Alert + PackageURL:http://open-ra.org/get-dependency.php?file=ra-packages + PackagePath:ra/packages/ + Delegate:GameInitDelegate + +Background@INIT_CHOOSEINSTALL: + Id:INIT_CHOOSEINSTALL + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - HEIGHT)/2 + Width:500 + Height:160 + Children: + Label@TITLE: + X:0 + Y:20 + Width:PARENT_RIGHT + Height:25 + Text:Install Required + Align:Center + Bold:True + Label@DESC1: + X:0 + Y:50 + Width:PARENT_RIGHT + Height:25 + Text:OpenRA requires the original Red Alert game content. + Align:Center + Label@DESC2: + X:0 + Y:70 + Width:PARENT_RIGHT + Height:25 + Text:Content can be downloaded automatically or installed from CD. + Align:Center + Button@DOWNLOAD: + Id:DOWNLOAD + X:PARENT_RIGHT - 420 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Text:Download + Bold:True + Button@FROMCD: + Id:FROMCD + X:PARENT_RIGHT - 280 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Text:From CD + Bold:True + Button@QUIT: + Id:QUIT + X:PARENT_RIGHT - 140 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Text:Quit + Bold:True + +Background@INIT_DOWNLOAD: + Id:INIT_DOWNLOAD + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - HEIGHT)/2 + Width:500 + Height:160 + Children: + Label@TITLE: + X:0 + Y:20 + Width:PARENT_RIGHT + Height:25 + Text:Downloading Red Alert Content + Align:Center + Bold:True + ProgressBar@PROGRESS: + Id:PROGRESS + X:50 + Y:55 + Width:PARENT_RIGHT - 100 + Height:25 + Label@STATUS: + Id:STATUS + X:50 + Y:80 + Width:PARENT_RIGHT - 100 + Height:25 + Align:Left + Button@RETRY: + Id:RETRY + X:PARENT_RIGHT - 280 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Visible: false + Text:Retry + Bold:True + Button@CANCEL: + Id:CANCEL + X:PARENT_RIGHT - 140 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Text:Cancel + Bold:True + Button@EXTRACT: + Id:EXTRACT + X:PARENT_RIGHT - 140 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Visible: false + Text:Extract + Bold:True \ No newline at end of file