diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 8640d51349..0136ccbd86 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -78,7 +78,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncDownloadPackagesLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncDownloadPackagesLogic.cs deleted file mode 100644 index 2927722afe..0000000000 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncDownloadPackagesLogic.cs +++ /dev/null @@ -1,113 +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 System.ComponentModel; -using System.IO; -using System.Linq; -using System.Net; -using OpenRA.FileFormats; -using OpenRA.Widgets; - -namespace OpenRA.Mods.Cnc.Widgets.Logic -{ - public class CncDownloadPackagesLogic - { - Widget panel; - Dictionary installData; - ProgressBarWidget progressBar; - LabelWidget statusLabel; - Action afterInstall; - - [ObjectCreator.UseCtor] - public CncDownloadPackagesLogic([ObjectCreator.Param] Widget widget, - [ObjectCreator.Param] Dictionary installData, - [ObjectCreator.Param] Action afterInstall) - { - this.installData = installData; - this.afterInstall = afterInstall; - - panel = widget.GetWidget("INSTALL_DOWNLOAD_PANEL"); - progressBar = panel.GetWidget("PROGRESS_BAR"); - statusLabel = panel.GetWidget("STATUS_LABEL"); - - ShowDownloadDialog(); - } - - void ShowDownloadDialog() - { - statusLabel.GetText = () => "Initializing..."; - progressBar.SetIndeterminate(true); - var retryButton = panel.GetWidget("RETRY_BUTTON"); - retryButton.IsVisible = () => false; - - var cancelButton = panel.GetWidget("CANCEL_BUTTON"); - - // Save the package to a temp file - var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.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(() => - { - Widget.CloseWindow(); - afterInstall(); - }); - } - }; - - var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete); - - cancelButton.OnClick = () => { dl.Cancel(); Widget.CloseWindow(); }; - retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); }; - } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index d8c9d1c648..3d41de7a98 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -343,7 +343,6 @@ - @@ -363,6 +362,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/Logic/RADownloadPackagesLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs similarity index 89% rename from OpenRA.Mods.RA/Widgets/Logic/RADownloadPackagesLogic.cs rename to OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs index d829e0b9da..13f5f08ffc 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/RADownloadPackagesLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs @@ -19,21 +19,21 @@ using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic { - public class RADownloadPackagesLogic + public class DownloadPackagesLogic { Widget panel; Dictionary installData; ProgressBarWidget progressBar; LabelWidget statusLabel; - Action continueLoading; + Action afterInstall; [ObjectCreator.UseCtor] - public RADownloadPackagesLogic([ObjectCreator.Param] Widget widget, + public DownloadPackagesLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] Dictionary installData, - [ObjectCreator.Param] Action continueLoading) + [ObjectCreator.Param] Action afterInstall) { this.installData = installData; - this.continueLoading = continueLoading; + this.afterInstall = afterInstall; panel = widget.GetWidget("INSTALL_DOWNLOAD_PANEL"); progressBar = panel.GetWidget("PROGRESS_BAR"); @@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic // Save the package to a temp file var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - var dest = new string[] { Platform.SupportDir, "Content", "ra" }.Aggregate(Path.Combine); + var dest = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mods[0] }.Aggregate(Path.Combine); Action onDownloadProgress = i => { @@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.RunAfterTick(() => { Widget.CloseWindow(); - continueLoading(); + afterInstall(); }); } }; diff --git a/OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs index 19e48186d2..685445d529 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var panel = widget.GetWidget("INSTALL_PANEL"); var args = new WidgetArgs() { - { "continueLoading", () => { Widget.CloseWindow(); continueLoading(); } }, + { "afterInstall", () => { Widget.CloseWindow(); continueLoading(); } }, { "installData", installData } }; diff --git a/mods/cnc/chrome/install.yaml b/mods/cnc/chrome/install.yaml index 03ecb391ea..d684dcb1b1 100644 --- a/mods/cnc/chrome/install.yaml +++ b/mods/cnc/chrome/install.yaml @@ -176,7 +176,7 @@ Container@INSTALL_FROMCD_PANEL: Container@INSTALL_DOWNLOAD_PANEL: Id:INSTALL_DOWNLOAD_PANEL - Logic:CncDownloadPackagesLogic + Logic:DownloadPackagesLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - 150)/2 Width:640 @@ -227,4 +227,4 @@ Container@INSTALL_DOWNLOAD_PANEL: Y:149 Width:140 Height:35 - Text:Retry \ No newline at end of file + Text:Retry diff --git a/mods/ra/chrome/gameinit.yaml b/mods/ra/chrome/gameinit.yaml index 053a66d930..4cc5b3c69e 100644 --- a/mods/ra/chrome/gameinit.yaml +++ b/mods/ra/chrome/gameinit.yaml @@ -55,7 +55,7 @@ Background@INSTALL_PANEL: Background@INSTALL_DOWNLOAD_PANEL: Id:INSTALL_DOWNLOAD_PANEL - Logic:RADownloadPackagesLogic + Logic:DownloadPackagesLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:500