Skip to content

Commit

Permalink
added The First Decade Installation Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DSUK committed Jul 27, 2015
1 parent d7b06b1 commit 38ef304
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
6 changes: 6 additions & 0 deletions OpenRA.Mods.Common/InstallUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class ContentInstaller : IGlobalModData
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using System.Linq;
using System.Threading;
using OpenRA.FileSystem;
using OpenRA.Widgets;

namespace OpenRA.Mods.Common.Widgets.Logic
Expand Down Expand Up @@ -51,19 +52,90 @@ bool IsValidDisk(string diskRoot)
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;
installingContainer.IsVisible = () => false;
}
}

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.ToLower());
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.ToLower());
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;
Expand Down
3 changes: 2 additions & 1 deletion mods/cnc/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ ContentInstaller:
.: conquer.mix, desert.mix, general.mix, scores.mix, sounds.mix, temperat.mix, winter.mix
ShippedSoundtracks: 2
MusicPackageMirrorList: http://www.openra.net/packages/cnc-music-mirrors.txt
InstallShieldCABFileIds: 66, 45, 42, 65, 68, 67, 71, 47, 49, 60, 75, 73, 53

ServerTraits:
LobbyCommands
Expand Down Expand Up @@ -213,4 +214,4 @@ SpriteSequenceFormat: TilesetSpecificSpriteSequence
WINTER: .win
SNOW: .sno
DESERT: .des
JUNGLE: .jun
JUNGLE: .jun
2 changes: 2 additions & 0 deletions mods/ra/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ ContentInstaller:
.: INSTALL/REDALERT.MIX
ShippedSoundtracks: 2
MusicPackageMirrorList: http://www.openra.net/packages/ra-music-mirrors.txt
InstallShieldCABFilePackageIds: 105
InstallShieldCABFileIds: 116

ServerTraits:
LobbyCommands
Expand Down
2 changes: 2 additions & 0 deletions mods/ts/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ ContentInstaller:
.: cache.mix, conquer.mix, isosnow.mix, isotemp.mix, local.mix, sidec01.mix, sidec02.mix, sno.mix, snow.mix, sounds.mix, speech01.mix, tem.mix, temperat.mix
ShippedSoundtracks: 2
MusicPackageMirrorList: http://www.openra.net/packages/ts-music-mirrors.txt
InstallShieldCABFilePackageIds: 332:CRC32
InstallShieldCABFileIds: 323, 364

ServerTraits:
LobbyCommands
Expand Down

0 comments on commit 38ef304

Please sign in to comment.