Reimplement installing from CD in RA.

This commit is contained in:
Paul Chote
2011-07-23 01:35:44 +12:00
parent bf6be0424f
commit 2d269155b1
4 changed files with 174 additions and 104 deletions

View File

@@ -355,6 +355,7 @@
<Compile Include="Lint\CheckActorReferences.cs" />
<Compile Include="StrategicVictoryConditions.cs" />
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -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<ButtonWidget>("DOWNLOAD").OnClick = () => ShowDownloadDialog();
window.GetWidget<ButtonWidget>("FROMCD").OnClick = () => PromptForCD();
window.GetWidget<ButtonWidget>("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<ProgressBarWidget>("PROGRESS");
progress.Indeterminate = true;
// TODO: Handle cancelling copy
window.GetWidget<ButtonWidget>("CANCEL").IsVisible = () => false;
window.GetWidget<ButtonWidget>("CANCEL").OnClick = () => ShowInstallMethodDialog();
window.GetWidget<ButtonWidget>("RETRY").OnClick = () => PromptForCD();
window.GetWidget<ButtonWidget>("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<ButtonWidget>("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<LabelWidget>("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<LabelWidget>("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);
}
}
}

View File

@@ -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<ProgressBarWidget>("PROGRESS_BAR");
statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON");
backButton.OnClick = Widget.CloseWindow;
retryButton = panel.GetWidget<ButtonWidget>("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<string>)(s => Game.RunAfterTick(() =>
{
progressBar.Percentage = installCounter*100/installTotal;
installCounter++;
statusLabel.GetText = () => s;
}));
var onError = (Action<string>)(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();
}
}
}