diff --git a/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs b/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs index d428846733..8cd69d1cd6 100644 --- a/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs +++ b/OpenRA.Mods.Common/FileSystem/DefaultFileSystemLoader.cs @@ -10,10 +10,19 @@ #endregion using System.Collections.Generic; +using System.IO; +using System.Linq; +using OpenRA.Traits; namespace OpenRA.Mods.Common.FileSystem { - public class DefaultFileSystemLoader : IFileSystemLoader + [RequireExplicitImplementation] + public interface IFileSystemExternalContent + { + public bool InstallContentIfRequired(ModData modData); + } + + public class DefaultFileSystemLoader : IFileSystemLoader, IFileSystemExternalContent { public readonly Dictionary Packages = null; @@ -23,5 +32,24 @@ namespace OpenRA.Mods.Common.FileSystem foreach (var kv in Packages) fileSystem.Mount(kv.Key, kv.Value); } + + bool IFileSystemExternalContent.InstallContentIfRequired(ModData modData) + { + // If a ModContent section is defined then we need to make sure that the + // required content is installed or switch to the defined content installer. + if (!modData.Manifest.Contains()) + return false; + + var content = modData.Manifest.Get(); + var contentInstalled = content.Packages + .Where(p => p.Value.Required) + .All(p => p.Value.TestFiles.All(f => File.Exists(Platform.ResolvePath(f)))); + + if (contentInstalled) + return false; + + Game.InitializeMod(content.ContentInstallerMod, new Arguments("Content.Mod=" + modData.Manifest.Id)); + return true; + } } } diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index 9727bdba28..b76a7dc842 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -12,8 +12,8 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using OpenRA.FileFormats; +using OpenRA.Mods.Common.FileSystem; using OpenRA.Mods.Common.Widgets.Logic; using OpenRA.Widgets; @@ -126,21 +126,10 @@ namespace OpenRA.Mods.Common.LoadScreens if (graphicSettings.GLProfile != GLProfile.Automatic && graphicSettings.GLProfile != Game.Renderer.GLProfile) graphicSettings.GLProfile = GLProfile.Automatic; - // If a ModContent section is defined then we need to make sure that the - // required content is installed or switch to the defined content installer. - if (!ModData.Manifest.Contains()) + if (ModData.FileSystemLoader is not IFileSystemExternalContent content) return true; - var content = ModData.Manifest.Get(); - var contentInstalled = content.Packages - .Where(p => p.Value.Required) - .All(p => p.Value.TestFiles.All(f => File.Exists(Platform.ResolvePath(f)))); - - if (contentInstalled) - return true; - - Game.InitializeMod(content.ContentInstallerMod, new Arguments(new[] { "Content.Mod=" + ModData.Manifest.Id })); - return false; + return !content.InstallContentIfRequired(ModData); } } }