diff --git a/OpenRA.Game/Download.cs b/OpenRA.Game/Download.cs index f3bfdb12d7..e69396235d 100644 --- a/OpenRA.Game/Download.cs +++ b/OpenRA.Game/Download.cs @@ -19,33 +19,13 @@ namespace OpenRA WebClient wc; bool cancelled; - public Download(string url, string path, Action onProgress, Action onComplete) - { - wc = new WebClient(); - wc.Proxy = null; - - wc.DownloadProgressChanged += (_,a) => onProgress(a); - wc.DownloadFileCompleted += (_,a) => onComplete(a, cancelled); - - Game.OnQuit += () => Cancel(); - wc.DownloadFileCompleted += (_,a) => {Game.OnQuit -= () => Cancel();}; - - wc.DownloadFileAsync(new Uri(url), path); - } - - public void Cancel() - { - Game.OnQuit -= () => Cancel(); - wc.CancelAsync(); - cancelled = true; - } - public static string FormatErrorMessage(Exception e) { var ex = e as System.Net.WebException; - if (ex == null) return e.Message; + if (ex == null) + return e.Message; - switch(ex.Status) + switch (ex.Status) { case WebExceptionStatus.NameResolutionFailure: case WebExceptionStatus.Timeout: @@ -57,5 +37,26 @@ namespace OpenRA return ex.Message; } } + + public Download(string url, string path, Action onProgress, Action onComplete) + { + wc = new WebClient(); + wc.Proxy = null; + + wc.DownloadProgressChanged += (_, a) => onProgress(a); + wc.DownloadFileCompleted += (_, a) => onComplete(a, cancelled); + + Game.OnQuit += () => Cancel(); + wc.DownloadFileCompleted += (_, a) => { Game.OnQuit -= () => Cancel(); }; + + wc.DownloadFileAsync(new Uri(url), path); + } + + public void Cancel() + { + Game.OnQuit -= () => Cancel(); + wc.CancelAsync(); + cancelled = true; + } } } \ No newline at end of file diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 35ce9c3272..b49c2f8320 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -93,7 +93,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallLogic.cs deleted file mode 100644 index 349f543ebf..0000000000 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncInstallLogic.cs +++ /dev/null @@ -1,52 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; -using OpenRA.Widgets; - -namespace OpenRA.Mods.Cnc.Widgets.Logic -{ - public class CncInstallLogic - { - [ObjectCreator.UseCtor] - public CncInstallLogic(Widget widget, Dictionary installData, Action continueLoading) - { - var panel = widget.Get("INSTALL_PANEL"); - var args = new WidgetArgs() - { - { "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } }, - { "installData", installData } - }; - - panel.Get("DOWNLOAD_BUTTON").OnClick = () => - Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); - - panel.Get("INSTALL_BUTTON").OnClick = () => - Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs(args) - { - { "filesToCopy", new[] { "CONQUER.MIX", "DESERT.MIX", "SCORES.MIX", - "SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX" } }, - { "filesToExtract", new[] { "speech.mix", "tempicnh.mix", "transit.mix" } }, - }); - - panel.Get("QUIT_BUTTON").OnClick = Game.Exit; - - panel.Get("MODS_BUTTON").OnClick = () => - { - Ui.OpenWindow("MODS_PANEL", new WidgetArgs() - { - { "onExit", () => { } }, - { "onSwitch", Ui.CloseWindow }, - }); - }; - } - } -} diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index b4b95a7d13..01d307f517 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -76,9 +76,7 @@ - - diff --git a/OpenRA.Mods.D2k/Widgets/Logic/D2kDownloadPackagesLogic.cs b/OpenRA.Mods.D2k/Widgets/Logic/D2kDownloadPackagesLogic.cs deleted file mode 100644 index a515dc8801..0000000000 --- a/OpenRA.Mods.D2k/Widgets/Logic/D2kDownloadPackagesLogic.cs +++ /dev/null @@ -1,111 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Net; -using OpenRA.FileFormats; -using OpenRA.Widgets; - -namespace OpenRA.Mods.D2k.Widgets.Logic -{ - public class D2kDownloadPackagesLogic - { - Widget panel; - Dictionary installData; - ProgressBarWidget progressBar; - LabelWidget statusLabel; - Action afterInstall; - - [ObjectCreator.UseCtor] - public D2kDownloadPackagesLogic(Widget widget, Dictionary installData, Action afterInstall) - { - this.installData = installData; - this.afterInstall = afterInstall; - - panel = widget.Get("INSTALL_DOWNLOAD_PANEL"); - progressBar = panel.Get("PROGRESS_BAR"); - statusLabel = panel.Get("STATUS_LABEL"); - - ShowDownloadDialog(); - } - - void ShowDownloadDialog() - { - statusLabel.GetText = () => "Initializing..."; - progressBar.SetIndeterminate(true); - var retryButton = panel.Get("RETRY_BUTTON"); - retryButton.IsVisible = () => false; - - var cancelButton = panel.Get("CANCEL_BUTTON"); - - // Save the package to a temp file - var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - var dest = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mods[0] }.Aggregate(Path.Combine); - - Action onDownloadProgress = i => - { - if (progressBar.Indeterminate) - progressBar.SetIndeterminate(false); - - progressBar.Percentage = i.ProgressPercentage; - statusLabel.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived / 1024, i.TotalBytesToReceive / 1024); - }; - - Action onExtractProgress = s => - { - Game.RunAfterTick(() => statusLabel.GetText = () => s); - }; - - Action onError = s => - { - Game.RunAfterTick(() => - { - statusLabel.GetText = () => "Error: " + s; - retryButton.IsVisible = () => true; - }); - }; - - Action onDownloadComplete = (i, cancelled) => - { - if (i.Error != null) - { - onError(Download.FormatErrorMessage(i.Error)); - return; - } - else if (cancelled) - { - onError("Download cancelled"); - return; - } - - // Automatically extract - statusLabel.GetText = () => "Extracting..."; - progressBar.SetIndeterminate(true); - if (InstallUtils.ExtractZip(file, dest, onExtractProgress, onError)) - { - Game.RunAfterTick(() => - { - Ui.CloseWindow(); - afterInstall(); - }); - } - }; - - var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete); - - cancelButton.OnClick = () => { dl.Cancel(); Ui.CloseWindow(); }; - retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); }; - } - } -} diff --git a/OpenRA.Mods.D2k/Widgets/Logic/D2kInstallLogic.cs b/OpenRA.Mods.D2k/Widgets/Logic/D2kInstallLogic.cs deleted file mode 100644 index 5eaf77340f..0000000000 --- a/OpenRA.Mods.D2k/Widgets/Logic/D2kInstallLogic.cs +++ /dev/null @@ -1,48 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; -using OpenRA.Widgets; - -namespace OpenRA.Mods.D2k.Widgets.Logic -{ - public class D2kInstallLogic - { - [ObjectCreator.UseCtor] - public D2kInstallLogic(Widget widget, Dictionary installData, Action continueLoading) - { - var panel = widget.Get("INSTALL_PANEL"); - var args = new WidgetArgs() - { - { "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } }, - { "installData", installData }, - { "continueLoading", continueLoading } - }; - - panel.Get("DOWNLOAD_BUTTON").OnClick = () => - Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); - - panel.Get("COPY_BUTTON").OnClick = () => - Ui.OpenWindow("INSTALL_FROMCD_PANEL", args); - - panel.Get("QUIT_BUTTON").OnClick = Game.Exit; - - panel.Get("MODS_BUTTON").OnClick = () => - { - Ui.OpenWindow("MODS_PANEL", new WidgetArgs() - { - { "onExit", () => { } }, - { "onSwitch", Ui.CloseWindow }, - }); - }; - } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 7ecb94e6dc..33fdb70e73 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -400,7 +400,6 @@ - @@ -471,6 +470,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs similarity index 69% rename from OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs rename to OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs index cc51e0becc..0ce853ab48 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs @@ -14,10 +14,10 @@ using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic { - public class RAInstallLogic + public class InstallLogic : Widget { [ObjectCreator.UseCtor] - public RAInstallLogic(Widget widget, Dictionary installData, Action continueLoading) + public InstallLogic(Widget widget, Dictionary installData, Action continueLoading) { var panel = widget.Get("INSTALL_PANEL"); var args = new WidgetArgs() @@ -30,6 +30,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic panel.Get("DOWNLOAD_BUTTON").OnClick = () => Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); + if (installData.ContainsKey("FilesToCopy") && !string.IsNullOrEmpty(installData["FilesToCopy"]) && + installData.ContainsKey("FilesToExtract") && !string.IsNullOrEmpty(installData["FilesToExtract"])) + { + args = new WidgetArgs(args) + { + { "filesToCopy", installData["FilesToCopy"].Split(',') }, + { "filesToExtract", installData["FilesToExtract"].Split(',') }, + }; + } panel.Get("INSTALL_BUTTON").OnClick = () => Ui.OpenWindow("INSTALL_FROMCD_PANEL", args); diff --git a/mods/cnc/chrome/install.yaml b/mods/cnc/chrome/install.yaml index 70fb3e36a1..0947ae84b2 100644 --- a/mods/cnc/chrome/install.yaml +++ b/mods/cnc/chrome/install.yaml @@ -25,7 +25,7 @@ Container@INSTALL_BACKGROUND: Background:shellmapborder Container@INSTALL_PANEL: - Logic:CncInstallLogic + Logic:InstallLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - 150)/2 Width:640 diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 897e8fdb99..36f1d46b36 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -111,6 +111,8 @@ TileSets: LoadScreen: CncLoadScreen InstallerMenuWidget: INSTALL_PANEL + FilesToCopy: CONQUER.MIX, DESERT.MIX, SCORES.MIX, SOUNDS.MIX, TEMPERAT.MIX, WINTER.MIX + FilesToExtract: speech.mix, tempicnh.mix, transit.mix InstallerBackgroundWidget: INSTALL_BACKGROUND TestFile: conquer.mix PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages diff --git a/mods/d2k/chrome/gameinit.yaml b/mods/d2k/chrome/gameinit.yaml index e521aa3c73..26b2cf06cc 100644 --- a/mods/d2k/chrome/gameinit.yaml +++ b/mods/d2k/chrome/gameinit.yaml @@ -1,5 +1,5 @@ Background@INSTALL_PANEL: - Logic:D2kInstallLogic + Logic:InstallLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:630 @@ -41,7 +41,7 @@ Background@INSTALL_PANEL: Height:25 Text:Download Font:Bold - Button@COPY_BUTTON: + Button@INSTALL_BUTTON: X:140 Y:PARENT_BOTTOM - 45 Width:110 @@ -64,7 +64,7 @@ Background@INSTALL_PANEL: Font:Bold Background@INSTALL_DOWNLOAD_PANEL: - Logic:D2kDownloadPackagesLogic + Logic:DownloadPackagesLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:500 diff --git a/mods/ra/chrome/gameinit.yaml b/mods/ra/chrome/gameinit.yaml index 4f7d72e988..181abdb605 100644 --- a/mods/ra/chrome/gameinit.yaml +++ b/mods/ra/chrome/gameinit.yaml @@ -1,5 +1,5 @@ Background@INSTALL_PANEL: - Logic:RAInstallLogic + Logic:InstallLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:510 diff --git a/mods/ts/chrome/gameinit.yaml b/mods/ts/chrome/gameinit.yaml index 1765a3d4e7..be199ca45b 100644 --- a/mods/ts/chrome/gameinit.yaml +++ b/mods/ts/chrome/gameinit.yaml @@ -1,5 +1,5 @@ Background@INSTALL_PANEL: - Logic:RAInstallLogic + Logic:InstallLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:510