From 91295f9c68b51a3b779c3a02fee905176b69a06f Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 Apr 2018 20:23:23 +0100 Subject: [PATCH] Add IReadOnlyFileSystem.IsExternalModFile. --- OpenRA.Game/FileSystem/FileSystem.cs | 24 ++++++++++++++++++- OpenRA.Game/Map/Map.cs | 9 +++++++ OpenRA.Game/Map/MapPreview.cs | 9 +++++++ OpenRA.Game/ModData.cs | 2 +- .../Logic/Installation/ModContentLogic.cs | 2 +- .../Installation/ModContentPromptLogic.cs | 2 +- 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index ece8a62b44..4618d13da6 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -23,6 +23,7 @@ namespace OpenRA.FileSystem bool TryGetPackageContaining(string path, out IReadOnlyPackage package, out string filename); bool TryOpen(string filename, out Stream s); bool Exists(string filename); + bool IsExternalModFile(string filename); } public class FileSystem : IReadOnlyFileSystem @@ -30,6 +31,7 @@ namespace OpenRA.FileSystem public IEnumerable MountedPackages { get { return mountedPackages.Keys; } } readonly Dictionary mountedPackages = new Dictionary(); readonly Dictionary explicitMounts = new Dictionary(); + readonly string modID; // Mod packages that should not be disposed readonly List modPackages = new List(); @@ -38,8 +40,9 @@ namespace OpenRA.FileSystem Cache> fileIndex = new Cache>(_ => new List()); - public FileSystem(IReadOnlyDictionary installedMods, IPackageLoader[] packageLoaders) + public FileSystem(string modID, IReadOnlyDictionary installedMods, IPackageLoader[] packageLoaders) { + this.modID = modID; this.installedMods = installedMods; this.packageLoaders = packageLoaders .Append(new ZipFileLoader()) @@ -281,6 +284,25 @@ namespace OpenRA.FileSystem return fileIndex.ContainsKey(filename); } + /// + /// Returns true if the given filename references an external mod via an explicit mount + /// + public bool IsExternalModFile(string filename) + { + var explicitSplit = filename.IndexOf('|'); + if (explicitSplit < 0) + return false; + + IReadOnlyPackage explicitPackage; + if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage)) + return false; + + if (installedMods[modID].Package == explicitPackage) + return false; + + return modPackages.Contains(explicitPackage); + } + /// /// Resolves a filesystem for an assembly, accounting for explicit and mod mounts. /// Assemblies must exist in the native OS file system (not inside an OpenRA-defined package). diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 8d8813448e..0bec97beb8 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -1229,5 +1229,14 @@ namespace OpenRA return modData.DefaultFileSystem.Exists(filename); } + + public bool IsExternalModFile(string filename) + { + // Explicit package paths never refer to a map + if (filename.Contains("|")) + return modData.DefaultFileSystem.IsExternalModFile(filename); + + return false; + } } } diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index 16f7a1d3a8..98d4d80bb5 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -568,5 +568,14 @@ namespace OpenRA return modData.DefaultFileSystem.Exists(filename); } + + bool IReadOnlyFileSystem.IsExternalModFile(string filename) + { + // Explicit package paths never refer to a map + if (filename.Contains("|")) + return modData.DefaultFileSystem.IsExternalModFile(filename); + + return false; + } } } diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 8f4ac7ef48..fe4a7c5139 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -55,7 +55,7 @@ namespace OpenRA ObjectCreator = new ObjectCreator(Manifest, mods); PackageLoaders = ObjectCreator.GetLoaders(Manifest.PackageFormats, "package"); - ModFiles = new FS(mods, PackageLoaders); + ModFiles = new FS(mod.Id, mods, PackageLoaders); ModFiles.LoadFromManifest(Manifest); Manifest.LoadCustomData(ObjectCreator); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs index b78162c5eb..6953b23e96 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var modObjectCreator = new ObjectCreator(mod, Game.Mods); var modPackageLoaders = modObjectCreator.GetLoaders(mod.PackageFormats, "package"); - var modFileSystem = new FS(Game.Mods, modPackageLoaders); + var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders); modFileSystem.LoadFromManifest(mod); var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs index adc5dc0463..c29c256b4d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var modObjectCreator = new ObjectCreator(mod, Game.Mods); var modPackageLoaders = modObjectCreator.GetLoaders(mod.PackageFormats, "package"); - var modFileSystem = new FS(Game.Mods, modPackageLoaders); + var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders); modFileSystem.LoadFromManifest(mod); var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);