Move file system mounting into mod code.

This commit is contained in:
Paul Chote
2024-09-28 17:52:04 +01:00
committed by Gustas
parent b60b1e369a
commit 720b925fd5
12 changed files with 178 additions and 131 deletions

View File

@@ -181,12 +181,8 @@ namespace OpenRA.FileSystem
fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>()); fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>());
} }
public void LoadFromManifest(Manifest manifest) public void TrimExcess()
{ {
UnmountAll();
foreach (var kv in manifest.Packages)
Mount(kv.Key, kv.Value);
mountedPackages.TrimExcess(); mountedPackages.TrimExcess();
explicitMounts.TrimExcess(); explicitMounts.TrimExcess();
modPackages.TrimExcess(); modPackages.TrimExcess();

View File

@@ -65,8 +65,8 @@ namespace OpenRA
Weapons, Voices, Notifications, Music, Translations, TileSets, Weapons, Voices, Notifications, Music, Translations, TileSets,
ChromeMetrics, MapCompatibility, Missions, Hotkeys; ChromeMetrics, MapCompatibility, Missions, Hotkeys;
public readonly IReadOnlyDictionary<string, string> Packages;
public readonly IReadOnlyDictionary<string, string> MapFolders; public readonly IReadOnlyDictionary<string, string> MapFolders;
public readonly MiniYaml FileSystem;
public readonly MiniYaml LoadScreen; public readonly MiniYaml LoadScreen;
public readonly string DefaultOrderGenerator; public readonly string DefaultOrderGenerator;
@@ -81,7 +81,7 @@ namespace OpenRA
readonly string[] reservedModuleNames = readonly string[] reservedModuleNames =
{ {
"Include", "Metadata", "Folders", "MapFolders", "Packages", "Rules", "Include", "Metadata", "FileSystem", "MapFolders", "Rules",
"Sequences", "ModelSequences", "Cursors", "Chrome", "Assemblies", "ChromeLayout", "Weapons", "Sequences", "ModelSequences", "Cursors", "Chrome", "Assemblies", "ChromeLayout", "Weapons",
"Voices", "Notifications", "Music", "Translations", "TileSets", "ChromeMetrics", "Missions", "Hotkeys", "Voices", "Notifications", "Music", "Translations", "TileSets", "ChromeMetrics", "Missions", "Hotkeys",
"ServerTraits", "LoadScreen", "DefaultOrderGenerator", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats", "ServerTraits", "LoadScreen", "DefaultOrderGenerator", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats",
@@ -123,8 +123,8 @@ namespace OpenRA
// TODO: Use fieldloader // TODO: Use fieldloader
MapFolders = YamlDictionary(yaml, "MapFolders"); MapFolders = YamlDictionary(yaml, "MapFolders");
if (yaml.TryGetValue("Packages", out var packages)) if (!yaml.TryGetValue("FileSystem", out FileSystem))
Packages = packages.ToDictionary(x => x.Value); throw new InvalidDataException("`FileSystem` section is not defined.");
Rules = YamlList(yaml, "Rules"); Rules = YamlList(yaml, "Rules");
Sequences = YamlList(yaml, "Sequences"); Sequences = YamlList(yaml, "Sequences");

View File

@@ -35,6 +35,8 @@ namespace OpenRA
public readonly ISpriteSequenceLoader SpriteSequenceLoader; public readonly ISpriteSequenceLoader SpriteSequenceLoader;
public readonly IVideoLoader[] VideoLoaders; public readonly IVideoLoader[] VideoLoaders;
public readonly HotkeyManager Hotkeys; public readonly HotkeyManager Hotkeys;
public readonly IFileSystemLoader FileSystemLoader;
public ILoadScreen LoadScreen { get; } public ILoadScreen LoadScreen { get; }
public CursorProvider CursorProvider { get; private set; } public CursorProvider CursorProvider { get; private set; }
public FS ModFiles; public FS ModFiles;
@@ -54,9 +56,13 @@ namespace OpenRA
Manifest = new Manifest(mod.Id, mod.Package); Manifest = new Manifest(mod.Id, mod.Package);
ObjectCreator = new ObjectCreator(Manifest, mods); ObjectCreator = new ObjectCreator(Manifest, mods);
PackageLoaders = ObjectCreator.GetLoaders<IPackageLoader>(Manifest.PackageFormats, "package"); PackageLoaders = ObjectCreator.GetLoaders<IPackageLoader>(Manifest.PackageFormats, "package");
ModFiles = new FS(mod.Id, mods, PackageLoaders); ModFiles = new FS(mod.Id, mods, PackageLoaders);
ModFiles.LoadFromManifest(Manifest);
FileSystemLoader = ObjectCreator.GetLoader<IFileSystemLoader>(Manifest.FileSystem.Value, "filesystem");
FieldLoader.Load(FileSystemLoader, Manifest.FileSystem);
FileSystemLoader.Mount(ModFiles, ObjectCreator);
ModFiles.TrimExcess();
Manifest.LoadCustomData(ObjectCreator); Manifest.LoadCustomData(ObjectCreator);
if (useLoadScreen) if (useLoadScreen)
@@ -190,4 +196,9 @@ namespace OpenRA
/// <summary>Called when the engine expects to connect to a server/replay or load the shellmap.</summary> /// <summary>Called when the engine expects to connect to a server/replay or load the shellmap.</summary>
void StartGame(Arguments args); void StartGame(Arguments args);
} }
public interface IFileSystemLoader
{
void Mount(FS fileSystem, ObjectCreator objectCreator);
}
} }

View File

@@ -0,0 +1,27 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Mods.Common.FileSystem
{
public class DefaultFileSystemLoader : IFileSystemLoader
{
public readonly Dictionary<string, string> Packages = null;
public void Mount(OpenRA.FileSystem.FileSystem fileSystem, ObjectCreator objectCreator)
{
if (Packages != null)
foreach (var kv in Packages)
fileSystem.Mount(kv.Key, kv.Value);
}
}
}

View File

@@ -42,7 +42,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var modObjectCreator = new ObjectCreator(mod, Game.Mods); var modObjectCreator = new ObjectCreator(mod, Game.Mods);
var modPackageLoaders = modObjectCreator.GetLoaders<IPackageLoader>(mod.PackageFormats, "package"); var modPackageLoaders = modObjectCreator.GetLoaders<IPackageLoader>(mod.PackageFormats, "package");
var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders); var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders);
modFileSystem.LoadFromManifest(mod);
var modFileSystemLoader = modObjectCreator.GetLoader<IFileSystemLoader>(mod.FileSystem.Value, "filesystem");
FieldLoader.Load(modFileSystemLoader, mod.FileSystem);
modFileSystemLoader.Mount(modFileSystem, modObjectCreator);
modFileSystem.TrimExcess();
var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null); var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null);
foreach (var s in sourceYaml) foreach (var s in sourceYaml)

View File

@@ -78,7 +78,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var modObjectCreator = new ObjectCreator(mod, Game.Mods); var modObjectCreator = new ObjectCreator(mod, Game.Mods);
var modPackageLoaders = modObjectCreator.GetLoaders<IPackageLoader>(mod.PackageFormats, "package"); var modPackageLoaders = modObjectCreator.GetLoaders<IPackageLoader>(mod.PackageFormats, "package");
var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders); var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders);
modFileSystem.LoadFromManifest(mod);
var modFileSystemLoader = modObjectCreator.GetLoader<IFileSystemLoader>(mod.FileSystem.Value, "filesystem");
FieldLoader.Load(modFileSystemLoader, mod.FileSystem);
modFileSystemLoader.Mount(modFileSystem, modObjectCreator);
modFileSystem.TrimExcess();
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null); var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
modFileSystem.UnmountAll(); modFileSystem.UnmountAll();

View File

@@ -3,6 +3,7 @@ Metadata:
Version: {DEV_VERSION} Version: {DEV_VERSION}
Hidden: true Hidden: true
FileSystem: DefaultFileSystem
Packages: Packages:
^EngineDir ^EngineDir

View File

@@ -7,6 +7,7 @@ Metadata:
PackageFormats: Mix PackageFormats: Mix
FileSystem: DefaultFileSystem
Packages: Packages:
~^SupportDir|Content/cnc ~^SupportDir|Content/cnc
~^SupportDir|Content/cnc/movies ~^SupportDir|Content/cnc/movies

View File

@@ -7,6 +7,7 @@ Metadata:
PackageFormats: D2kSoundResources PackageFormats: D2kSoundResources
FileSystem: DefaultFileSystem
Packages: Packages:
~^SupportDir|Content/d2k/v3/ ~^SupportDir|Content/d2k/v3/
~^SupportDir|Content/d2k/v3/GAMESFX ~^SupportDir|Content/d2k/v3/GAMESFX
@@ -15,7 +16,6 @@ Packages:
^EngineDir ^EngineDir
$d2k: d2k $d2k: d2k
^EngineDir|mods/common: common ^EngineDir|mods/common: common
~SOUND.RS ~SOUND.RS
d2k|bits d2k|bits
d2k|scripts d2k|scripts

View File

@@ -3,6 +3,7 @@ Metadata:
Version: {DEV_VERSION} Version: {DEV_VERSION}
Hidden: true Hidden: true
FileSystem: DefaultFileSystem
Packages: Packages:
^EngineDir ^EngineDir
^EngineDir|mods/modcontent: modcontent ^EngineDir|mods/modcontent: modcontent

View File

@@ -7,6 +7,7 @@ Metadata:
PackageFormats: Mix PackageFormats: Mix
FileSystem: DefaultFileSystem
Packages: Packages:
~^SupportDir|Content/ra/v2/ ~^SupportDir|Content/ra/v2/
~^SupportDir|Content/ra/v2/expand ~^SupportDir|Content/ra/v2/expand

View File

@@ -7,6 +7,7 @@ Metadata:
PackageFormats: Mix PackageFormats: Mix
FileSystem: DefaultFileSystem
Packages: Packages:
~^SupportDir|Content/ts ~^SupportDir|Content/ts
~^SupportDir|Content/ts/firestorm ~^SupportDir|Content/ts/firestorm