Merge pull request #8170 from DSUK/master

TFD Installer for Tiberian dawn, Red Alert and Tiberian Sun
This commit is contained in:
Matthias Mailänder
2015-07-29 15:25:59 +02:00
8 changed files with 614 additions and 0 deletions

View File

@@ -39,6 +39,12 @@ namespace OpenRA.Mods.Common
public readonly string MusicPackageMirrorList = null;
public readonly int ShippedSoundtracks = 0;
/// <summary> InstallShield .cab File Ids, used to extract Mod specific files </summary>
public readonly int[] InstallShieldCABFileIds = { };
/// <summary> InstallShield .cab File Ids, used to extract Mod specific archives and extract contents of ExtractFilesFromCD </summary>
public readonly string[] InstallShieldCABFilePackageIds = { };
public static Dictionary<string, string[]> LoadFilesToExtract(MiniYaml yaml)
{
var md = yaml.ToDictionary();

View File

@@ -12,6 +12,7 @@ using System;
using System.IO;
using System.Linq;
using System.Threading;
using OpenRA.FileSystem;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
@@ -51,12 +52,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return installData.DiskTestFiles.All(f => File.Exists(Path.Combine(diskRoot, f)));
}
bool IsTFD(string diskpath)
{
var test = File.Exists(Path.Combine(diskpath, "data1.hdr"));
var i = 0;
while (test && i < 14)
test &= File.Exists(Path.Combine(diskpath, "data{0}.cab".F(++i)));
return test;
}
void CheckForDisk()
{
var path = InstallUtils.GetMountedDisk(IsValidDisk);
if (path != null)
Install(path);
else if ((installData.InstallShieldCABFileIds.Length != 0 || installData.InstallShieldCABFilePackageIds.Length != 0)
&& (path = InstallUtils.GetMountedDisk(IsTFD)) != null)
InstallTFD(Platform.ResolvePath(path, "data1.hdr"));
else
{
insertDiskContainer.IsVisible = () => true;
@@ -64,6 +79,63 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
void InstallTFD(string source)
{
backButton.IsDisabled = () => true;
retryButton.IsDisabled = () => true;
insertDiskContainer.IsVisible = () => false;
installingContainer.IsVisible = () => true;
progressBar.Percentage = 0;
new Thread(() =>
{
using (var cabExtractor = new InstallShieldCABExtractor(source))
{
var denom = installData.InstallShieldCABFileIds.Length;
var extractFiles = installData.ExtractFilesFromCD;
if (installData.InstallShieldCABFilePackageIds.Length > 0)
denom += extractFiles.SelectMany(x => x.Value).Count();
var installPercent = 100 / denom;
foreach (uint index in installData.InstallShieldCABFileIds)
{
var filename = cabExtractor.FileName(index);
statusLabel.GetText = () => "Extracting {0}".F(filename);
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, filename.ToLowerInvariant());
cabExtractor.ExtractFile(index, dest);
progressBar.Percentage += installPercent;
}
var ArchivesToExtract = installData.InstallShieldCABFilePackageIds.Select(x => x.Split(':'));
var destDir = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id);
var onError = (Action<string>)(s => { });
var overwrite = installData.OverwriteFiles;
var onProgress = (Action<string>)(s => Game.RunAfterTick(() =>
{
progressBar.Percentage += installPercent;
statusLabel.GetText = () => s;
}));
foreach (var archive in ArchivesToExtract)
{
var filename = cabExtractor.FileName(uint.Parse(archive[0]));
statusLabel.GetText = () => "Extracting {0}".F(filename);
var destFile = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, filename.ToLowerInvariant());
cabExtractor.ExtractFile(uint.Parse(archive[0]), destFile);
var annotation = archive.Length > 1 ? archive[1] : null;
InstallUtils.ExtractFromPackage(source, destFile, annotation, extractFiles, destDir, overwrite, onProgress, onError);
progressBar.Percentage += installPercent;
}
}
continueLoading();
}) { IsBackground = true }.Start();
}
void Install(string source)
{
backButton.IsDisabled = () => true;