Extract content sources and downloads to external files.
This commit is contained in:
@@ -29,6 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
enum Mode { Progress, Message, List }
|
||||
|
||||
readonly ModContent content;
|
||||
readonly Dictionary<string, ModContent.ModSource> sources;
|
||||
|
||||
readonly Widget panel;
|
||||
readonly LabelWidget titleLabel;
|
||||
@@ -54,9 +55,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Mode visible = Mode.Progress;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public InstallFromDiscLogic(Widget widget, ModContent content, Action afterInstall)
|
||||
public InstallFromDiscLogic(Widget widget, ModContent content, Dictionary<string, ModContent.ModSource> sources, Action afterInstall)
|
||||
{
|
||||
this.content = content;
|
||||
this.sources = sources;
|
||||
|
||||
Log.AddChannel("install", "install.log");
|
||||
|
||||
@@ -106,7 +108,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
.Where(v => v.DriveType == DriveType.CDRom && v.IsReady)
|
||||
.Select(v => v.RootDirectory.FullName);
|
||||
|
||||
foreach (var kv in content.Sources)
|
||||
foreach (var kv in sources)
|
||||
{
|
||||
message = "Searching for " + kv.Value.Title;
|
||||
|
||||
@@ -131,12 +133,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
var sources = content.Packages.Values
|
||||
var missingSources = content.Packages.Values
|
||||
.Where(p => !p.IsInstalled())
|
||||
.SelectMany(p => p.Sources)
|
||||
.Select(d => content.Sources[d]);
|
||||
.Select(d => sources[d]);
|
||||
|
||||
var discs = sources
|
||||
var discs = missingSources
|
||||
.Where(s => s.Type == ModContent.SourceType.Disc)
|
||||
.Select(s => s.Title)
|
||||
.Distinct();
|
||||
@@ -148,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
if (Platform.CurrentPlatform == PlatformType.Windows)
|
||||
{
|
||||
var installations = sources
|
||||
var installations = missingSources
|
||||
.Where(s => s.Type == ModContent.SourceType.Install)
|
||||
.Select(s => s.Title)
|
||||
.Distinct();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -20,6 +21,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ModContent content;
|
||||
readonly ScrollPanelWidget scrollPanel;
|
||||
readonly Widget template;
|
||||
|
||||
readonly Dictionary<string, ModContent.ModSource> sources = new Dictionary<string, ModContent.ModSource>();
|
||||
readonly Dictionary<string, ModContent.ModDownload> downloads = new Dictionary<string, ModContent.ModDownload>();
|
||||
|
||||
bool discAvailable;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
@@ -29,6 +34,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var panel = widget.Get("CONTENT_PANEL");
|
||||
|
||||
var modFileSystem = new FileSystem.FileSystem(Game.Mods);
|
||||
modFileSystem.LoadFromManifest(mod);
|
||||
|
||||
var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null);
|
||||
foreach (var s in sourceYaml)
|
||||
sources.Add(s.Key, new ModContent.ModSource(s.Value));
|
||||
|
||||
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
|
||||
foreach (var d in downloadYaml)
|
||||
downloads.Add(d.Key, new ModContent.ModDownload(d.Value));
|
||||
|
||||
modFileSystem.UnmountAll();
|
||||
|
||||
scrollPanel = panel.Get<ScrollPanelWidget>("PACKAGES");
|
||||
template = scrollPanel.Get<ContainerWidget>("PACKAGE_TEMPLATE");
|
||||
|
||||
@@ -56,6 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
discButton.OnClick = () => Ui.OpenWindow("DISC_INSTALL_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "afterInstall", () => { } },
|
||||
{ "sources", sources },
|
||||
{ "content", content }
|
||||
});
|
||||
|
||||
@@ -87,9 +106,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
requiredWidget.IsVisible = () => p.Value.Required;
|
||||
|
||||
var sourceWidget = container.Get<ImageWidget>("DISC");
|
||||
var sources = p.Value.Sources.Select(s => content.Sources[s].Title).Distinct();
|
||||
var sourceList = sources.JoinWith("\n");
|
||||
var isSourceAvailable = sources.Any();
|
||||
var sourceTitles = p.Value.Sources.Select(s => sources[s].Title).Distinct();
|
||||
var sourceList = sourceTitles.JoinWith("\n");
|
||||
var isSourceAvailable = sourceTitles.Any();
|
||||
sourceWidget.GetTooltipText = () => sourceList;
|
||||
sourceWidget.IsVisible = () => isSourceAvailable;
|
||||
|
||||
@@ -100,10 +119,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
if (downloadEnabled)
|
||||
{
|
||||
var download = content.Downloads[p.Value.Download];
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "download", download },
|
||||
{ "download", downloads[p.Value.Download] },
|
||||
{ "onSuccess", () => { } }
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -54,9 +55,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
quickButton.Bounds.Y += headerHeight;
|
||||
quickButton.OnClick = () =>
|
||||
{
|
||||
var modFileSystem = new FileSystem.FileSystem(Game.Mods);
|
||||
modFileSystem.LoadFromManifest(mod);
|
||||
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
|
||||
modFileSystem.UnmountAll();
|
||||
|
||||
var download = downloadYaml.FirstOrDefault(n => n.Key == content.QuickDownload);
|
||||
if (download == null)
|
||||
throw new InvalidOperationException("Mod QuickDownload `{0}` definition not found.".F(content.QuickDownload));
|
||||
|
||||
Ui.OpenWindow("PACKAGE_DOWNLOAD_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "download", content.Downloads[content.QuickDownload] },
|
||||
{ "download", new ModContent.ModDownload(download.Value) },
|
||||
{ "onSuccess", continueLoading }
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user