Enable mod asset installation from CD from the modchooser

This commit is contained in:
Pavel Penev
2015-09-04 21:14:16 +03:00
parent bdcb0fee58
commit 0e7122acad
4 changed files with 102 additions and 13 deletions

View File

@@ -56,7 +56,8 @@ namespace OpenRA.Mods.Common
foreach (var file in directory.Value) foreach (var file in directory.Value)
{ {
var dest = Path.Combine(destPath, targetDir, file.ToLowerInvariant()); var containingDir = Path.Combine(destPath, targetDir);
var dest = Path.Combine(containingDir, file.ToLowerInvariant());
if (File.Exists(dest)) if (File.Exists(dest))
{ {
if (overwrite) if (overwrite)
@@ -68,6 +69,8 @@ namespace OpenRA.Mods.Common
} }
} }
Directory.CreateDirectory(containingDir);
using (var sourceStream = GlobalFileSystem.Open(file)) using (var sourceStream = GlobalFileSystem.Open(file))
using (var destStream = File.Create(dest)) using (var destStream = File.Create(dest))
{ {
@@ -98,13 +101,16 @@ namespace OpenRA.Mods.Common
} }
var destFile = Path.GetFileName(file); var destFile = Path.GetFileName(file);
var dest = Path.Combine(destPath, targetDir, destFile.ToLowerInvariant()); var containingDir = Path.Combine(destPath, targetDir);
var dest = Path.Combine(containingDir, destFile.ToLowerInvariant());
if (File.Exists(dest) && !overwrite) if (File.Exists(dest) && !overwrite)
{ {
Log.Write("debug", "Skipping {0}".F(dest)); Log.Write("debug", "Skipping {0}".F(dest));
continue; continue;
} }
Directory.CreateDirectory(containingDir);
onProgress("Copying " + destFile); onProgress("Copying " + destFile);
Log.Write("debug", "Copy {0} to {1}".F(sourcePath, dest)); Log.Write("debug", "Copy {0} to {1}".F(sourcePath, dest));
File.Copy(sourcePath, dest, true); File.Copy(sourcePath, dest, true);

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
public class InstallFromCDLogic public class InstallFromCDLogic
{ {
readonly string modId;
readonly Widget panel; readonly Widget panel;
readonly ProgressBarWidget progressBar; readonly ProgressBarWidget progressBar;
readonly LabelWidget statusLabel; readonly LabelWidget statusLabel;
@@ -28,9 +29,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ContentInstaller installData; readonly ContentInstaller installData;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public InstallFromCDLogic(Widget widget, Action continueLoading) public InstallFromCDLogic(Widget widget, Action continueLoading, string modId)
{ {
installData = Game.ModData.Manifest.Get<ContentInstaller>(); this.modId = modId;
installData = ModMetadata.AllMods[modId].Content;
this.continueLoading = continueLoading; this.continueLoading = continueLoading;
panel = widget.Get("INSTALL_FROMCD_PANEL"); panel = widget.Get("INSTALL_FROMCD_PANEL");
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
@@ -74,6 +76,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
InstallTFD(Platform.ResolvePath(path, "data1.hdr")); InstallTFD(Platform.ResolvePath(path, "data1.hdr"));
else else
{ {
var text = "Please insert a {0} install CD and click Retry.".F(ModMetadata.AllMods[modId].Title);
insertDiskContainer.Get<LabelWidget>("INFO2").Text = text;
insertDiskContainer.IsVisible = () => true; insertDiskContainer.IsVisible = () => true;
installingContainer.IsVisible = () => false; installingContainer.IsVisible = () => false;
} }
@@ -103,13 +108,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
var filename = cabExtractor.FileName(index); var filename = cabExtractor.FileName(index);
statusLabel.GetText = () => "Extracting {0}".F(filename); statusLabel.GetText = () => "Extracting {0}".F(filename);
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, filename.ToLowerInvariant()); var dest = Platform.ResolvePath("^", "Content", modId, filename.ToLowerInvariant());
cabExtractor.ExtractFile(index, dest); cabExtractor.ExtractFile(index, dest);
progressBar.Percentage += installPercent; progressBar.Percentage += installPercent;
} }
var ArchivesToExtract = installData.InstallShieldCABFilePackageIds.Select(x => x.Split(':')); var ArchivesToExtract = installData.InstallShieldCABFilePackageIds.Select(x => x.Split(':'));
var destDir = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id); var destDir = Platform.ResolvePath("^", "Content", modId);
var onError = (Action<string>)(s => { }); var onError = (Action<string>)(s => { });
var overwrite = installData.OverwriteFiles; var overwrite = installData.OverwriteFiles;
@@ -124,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
var filename = cabExtractor.FileName(uint.Parse(archive[0])); var filename = cabExtractor.FileName(uint.Parse(archive[0]));
statusLabel.GetText = () => "Extracting {0}".F(filename); statusLabel.GetText = () => "Extracting {0}".F(filename);
var destFile = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, filename.ToLowerInvariant()); var destFile = Platform.ResolvePath("^", "Content", modId, filename.ToLowerInvariant());
cabExtractor.ExtractFile(uint.Parse(archive[0]), destFile); cabExtractor.ExtractFile(uint.Parse(archive[0]), destFile);
var annotation = archive.Length > 1 ? archive[1] : null; var annotation = archive.Length > 1 ? archive[1] : null;
InstallUtils.ExtractFromPackage(source, destFile, annotation, extractFiles, destDir, overwrite, onProgress, onError); InstallUtils.ExtractFromPackage(source, destFile, annotation, extractFiles, destDir, overwrite, onProgress, onError);
@@ -143,7 +148,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
insertDiskContainer.IsVisible = () => false; insertDiskContainer.IsVisible = () => false;
installingContainer.IsVisible = () => true; installingContainer.IsVisible = () => true;
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id); var dest = Platform.ResolvePath("^", "Content", modId);
var copyFiles = installData.CopyFilesFromCD; var copyFiles = installData.CopyFilesFromCD;
var packageToExtract = installData.PackageToExtractFromCD.Split(':'); var packageToExtract = installData.PackageToExtractFromCD.Split(':');

View File

@@ -27,12 +27,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "modId", modId } { "modId", modId }
}; };
var modName = ModMetadata.AllMods[modId].Title; var mod = ModMetadata.AllMods[modId];
var text = panel.Get<LabelWidget>("DESC1").Text; var text = "OpenRA requires the original {0} game content.".F(mod.Title);
panel.Get<LabelWidget>("DESC1").Text = text.F(modName); panel.Get<LabelWidget>("DESC1").Text = text;
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () => var downloadButton = panel.Get<ButtonWidget>("DOWNLOAD_BUTTON");
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs); downloadButton.OnClick = () => Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs);
downloadButton.IsDisabled = () => string.IsNullOrEmpty(mod.Content.PackageMirrorList);
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () => panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_FROMCD_PANEL", widgetArgs); Ui.OpenWindow("INSTALL_FROMCD_PANEL", widgetArgs);

View File

@@ -118,3 +118,80 @@ Container@INSTALL_DOWNLOAD_PANEL:
Font: Bold Font: Bold
Key: escape Key: escape
Container@INSTALL_FROMCD_PANEL:
Logic: InstallFromCDLogic
X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 500
Height: 177
Children:
Background:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Background: panel-bg
Background@RULE:
X: 30
Y: 50
Width: 440
Height:150
Background:panel-rule
Label@TITLE:
X: 0
Y: 12
Width: PARENT_RIGHT
Height: 25
Text: Fetching assets from CD...
Align: Center
Font: MediumBold
Container@INSTALLING:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Visible: false
Children:
ProgressBar@PROGRESS_BAR:
X: 50
Y: 60
Width: PARENT_RIGHT - 100
Height: 16
BarMargin: 0, 0
Label@STATUS_LABEL:
X: 36
Y: 80
Width: PARENT_RIGHT - 100
Height: 25
Align: Left
Container@INSERT_DISK:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Visible: false
Children:
Label@INFO1:
Y: 65
Width: PARENT_RIGHT
Height: 25
Text: Disk not found.
Align: Center
Label@INFO2:
Y: 85
Width: PARENT_RIGHT
Height: 25
Align: Center
Button@RETRY_BUTTON:
X: 20
Y: PARENT_BOTTOM - 52
Background:button-highlighted
Width: 110
Height: 32
Text: Retry
Font: Bold
Key: return
Button@BACK_BUTTON:
X: PARENT_RIGHT - 130
Y: PARENT_BOTTOM - 52
Background:button-highlighted
Width: 110
Height: 32
Text: Back
Font: Bold
Key: escape