diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 509c736075..35370560fc 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -355,6 +355,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/Logic/GameInitLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/GameInitLogic.cs index ed05608262..77182f9058 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/GameInitLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/GameInitLogic.cs @@ -79,42 +79,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic void ShowInstallMethodDialog() { var window = Widget.OpenWindow("INIT_CHOOSEINSTALL"); + + var args = new WidgetArgs() + { + { "continueLoading", () => { Widget.CloseWindow(); TestAndContinue(); } }, + }; + window.GetWidget("DOWNLOAD").OnClick = () => ShowDownloadDialog(); - window.GetWidget("FROMCD").OnClick = () => PromptForCD(); - - window.GetWidget("QUIT").OnClick = () => Game.Exit(); - } - - void PromptForCD() - { - // TODO: Automatically search for cds - } - - void InstallFromCD(string path) - { - var window = Widget.OpenWindow("INIT_COPY"); - var progress = window.GetWidget("PROGRESS"); - progress.Indeterminate = true; - - // TODO: Handle cancelling copy - window.GetWidget("CANCEL").IsVisible = () => false; - window.GetWidget("CANCEL").OnClick = () => ShowInstallMethodDialog(); - window.GetWidget("RETRY").OnClick = () => PromptForCD(); + window.GetWidget("FROMCD").OnClick = () => + Widget.OpenWindow("INSTALL_FROMCD_PANEL", args); - var t = new Thread( _ => - { - switch (Info.InstallMode) - { -// case "ra": -// if (InstallPackages(window, path, Info.ResolvedPackagePath)) -// Game.RunAfterTick(TestAndContinue); -// break; - default: - ShowError(window, "Installing from CD not supported"); - break; - } - }) { IsBackground = true }; - t.Start(); + window.GetWidget("QUIT").OnClick = () => Game.Exit(); } void ShowDownloadDialog() @@ -169,42 +144,5 @@ namespace OpenRA.Mods.RA.Widgets.Logic s => status.GetText = () => s, e => ShowError(window, e)); } - - bool ExtractFromPackage(Widget window, string srcPath, string package, string[] files, string destPath) - { - var status = window.GetWidget("STATUS"); - - return InstallUtils.ExtractFromPackage(srcPath, package, files, destPath, - s => status.GetText = () => s, - e => ShowError(window, e)); - } - - bool CopyFiles(Widget window, string srcPath, string[] files, string destPath) - { - var status = window.GetWidget("STATUS"); - return InstallUtils.CopyFiles(srcPath, files, destPath, - s => status.GetText = () => s, - e => ShowError(window, e)); - } - - bool InstallPackages(Widget window, string source, string dest) - { - if (!CopyFiles(window, Path.Combine(source, "INSTALL"), new string[] {"REDALERT.MIX"}, dest)) - return false; - return ExtractFromPackage(window, source, "MAIN.MIX", - new string[] { "conquer.mix", "russian.mix", "allies.mix", "sounds.mix", - "scores.mix", "snow.mix", "interior.mix", "temperat.mix" }, dest); - } - - bool InstallCncPackages(Widget window, string source, string dest) - { - if (!CopyFiles(window, source, - new string[] { "CONQUER.MIX", "DESERT.MIX", "GENERAL.MIX", "SCORES.MIX", - "SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX"}, - dest)) - return false; - return ExtractFromPackage(window, source, "INSTALL/SETUP.Z", - new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix" }, dest); - } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/RAInstallFromCDLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/RAInstallFromCDLogic.cs new file mode 100644 index 0000000000..8570177fb0 --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/Logic/RAInstallFromCDLogic.cs @@ -0,0 +1,118 @@ +#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.IO; +using System.Linq; +using System.Threading; +using OpenRA.FileFormats; +using OpenRA.FileFormats.Graphics; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA.Widgets.Logic +{ + public class RAInstallFromCDLogic + { + Widget panel; + ProgressBarWidget progressBar; + LabelWidget statusLabel; + Action continueLoading; + ButtonWidget retryButton, backButton; + Widget installingContainer, insertDiskContainer; + + [ObjectCreator.UseCtor] + public RAInstallFromCDLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] Action continueLoading) + { + this.continueLoading = continueLoading; + panel = widget.GetWidget("INSTALL_FROMCD_PANEL"); + progressBar = panel.GetWidget("PROGRESS_BAR"); + statusLabel = panel.GetWidget("STATUS_LABEL"); + + backButton = panel.GetWidget("BACK_BUTTON"); + backButton.OnClick = Widget.CloseWindow; + + retryButton = panel.GetWidget("RETRY_BUTTON"); + retryButton.OnClick = CheckForDisk; + + installingContainer = panel.GetWidget("INSTALLING"); + insertDiskContainer = panel.GetWidget("INSERT_DISK"); + CheckForDisk(); + } + + void CheckForDisk() + { + var path = InstallUtils.GetMountedDisk(new [] { "CD1", "CD2" }); + + if (path != null) + Install(path); + else + { + insertDiskContainer.IsVisible = () => true; + installingContainer.IsVisible = () => false; + } + } + + void Install(string source) + { + backButton.IsDisabled = () => true; + retryButton.IsDisabled = () => true; + insertDiskContainer.IsVisible = () => false; + installingContainer.IsVisible = () => true; + + var dest = new string[] { Platform.SupportDir, "Content", "ra" }.Aggregate(Path.Combine); + var copyFiles = new string[] { "INSTALL/REDALERT.MIX" }; + + var extractPackage = "MAIN.MIX"; + var extractFiles = new string[] { "conquer.mix", "russian.mix", "allies.mix", "sounds.mix", + "scores.mix", "snow.mix", "interior.mix", "temperat.mix" }; + + var installCounter = 0; + var installTotal = copyFiles.Count() + extractFiles.Count(); + var onProgress = (Action)(s => Game.RunAfterTick(() => + { + progressBar.Percentage = installCounter*100/installTotal; + installCounter++; + + statusLabel.GetText = () => s; + })); + + var onError = (Action)(s => Game.RunAfterTick(() => + { + statusLabel.GetText = () => "Error: "+s; + backButton.IsDisabled = () => false; + retryButton.IsDisabled = () => false; + })); + + var t = new Thread( _ => + { + try + { + if (!InstallUtils.CopyFiles(source, copyFiles, dest, onProgress, onError)) + return; + + if (!InstallUtils.ExtractFromPackage(source, extractPackage, extractFiles, dest, onProgress, onError)) + return; + + Game.RunAfterTick(() => + { + Widget.CloseWindow(); + continueLoading(); + }); + } + catch + { + onError("Installation failed"); + } + }) { IsBackground = true }; + t.Start(); + } + } +} diff --git a/mods/ra/chrome/gameinit.yaml b/mods/ra/chrome/gameinit.yaml index a541ad7f31..b9d541483a 100644 --- a/mods/ra/chrome/gameinit.yaml +++ b/mods/ra/chrome/gameinit.yaml @@ -24,7 +24,7 @@ Background@INIT_CHOOSEINSTALL: Font:Bold Label@DESC1: X:0 - Y:65 + Y:50 Width:PARENT_RIGHT Height:25 Text:OpenRA requires the original Red Alert game content. @@ -35,7 +35,6 @@ Background@INIT_CHOOSEINSTALL: Width:PARENT_RIGHT Height:25 Text:Content can be downloaded, or copied from the install CD. - Visible:false Align:Center Button@DOWNLOAD: Id:DOWNLOAD @@ -52,7 +51,6 @@ Background@INIT_CHOOSEINSTALL: Width:120 Height:25 Text:From CD - Visible:false Font:Bold Button@QUIT: Id:QUIT @@ -108,18 +106,10 @@ Background@INIT_DOWNLOAD: Height:25 Text:Cancel Font:Bold - Button@EXTRACT: - Id:EXTRACT - X:PARENT_RIGHT - 140 - Y:PARENT_BOTTOM - 45 - Width:120 - Height:25 - Visible: false - Text:Extract - Font:Bold -Background@INIT_COPY: - Id:INIT_COPY +Background@INSTALL_FROMCD_PANEL: + Id:INSTALL_FROMCD_PANEL + Logic:RAInstallFromCDLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:500 @@ -130,33 +120,56 @@ Background@INIT_COPY: Y:20 Width:PARENT_RIGHT Height:25 - Text:Copying Red Alert Content + Text:Installing from CD Align:Center Font:Bold - 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 + Container@INSTALLING: + Id:INSTALLING + Width:PARENT_RIGHT + Height:PARENT_BOTTOM + Visible: false + Children: + ProgressBar@PROGRESS_BAR: + Id:PROGRESS_BAR + X:50 + Y:55 + Width:PARENT_RIGHT - 100 + Height:25 + Label@STATUS_LABEL: + Id:STATUS_LABEL + X:50 + Y:80 + Width:PARENT_RIGHT - 100 + Height:25 + Align:Left + Container@INSERT_DISK: + Id:INSERT_DISK + Width:PARENT_RIGHT + Height:PARENT_BOTTOM + Visible: false + Children: + Label@INFO: + Y:50 + Width:PARENT_RIGHT + Height:25 + Text:Disk not found. + Align:Center + Label@INFO2: + Y:70 + Width:PARENT_RIGHT + Height:25 + Text:Please insert one of the Red Alert install CDs then click Retry. + Align:Center + Button@RETRY_BUTTON: + Id:RETRY_BUTTON X:PARENT_RIGHT - 280 Y:PARENT_BOTTOM - 45 Width:120 Height:25 - Visible: false Text:Retry Font:Bold - Button@CANCEL: - Id:CANCEL + Button@BACK_BUTTON: + Id:BACK_BUTTON X:PARENT_RIGHT - 140 Y:PARENT_BOTTOM - 45 Width:120