Add IReadOnlyFileSystem.IsExternalModFile.

This commit is contained in:
Paul Chote
2018-04-29 20:23:23 +01:00
committed by reaperrr
parent 0c30a1d670
commit 91295f9c68
6 changed files with 44 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ namespace OpenRA.FileSystem
bool TryGetPackageContaining(string path, out IReadOnlyPackage package, out string filename); bool TryGetPackageContaining(string path, out IReadOnlyPackage package, out string filename);
bool TryOpen(string filename, out Stream s); bool TryOpen(string filename, out Stream s);
bool Exists(string filename); bool Exists(string filename);
bool IsExternalModFile(string filename);
} }
public class FileSystem : IReadOnlyFileSystem public class FileSystem : IReadOnlyFileSystem
@@ -30,6 +31,7 @@ namespace OpenRA.FileSystem
public IEnumerable<IReadOnlyPackage> MountedPackages { get { return mountedPackages.Keys; } } public IEnumerable<IReadOnlyPackage> MountedPackages { get { return mountedPackages.Keys; } }
readonly Dictionary<IReadOnlyPackage, int> mountedPackages = new Dictionary<IReadOnlyPackage, int>(); readonly Dictionary<IReadOnlyPackage, int> mountedPackages = new Dictionary<IReadOnlyPackage, int>();
readonly Dictionary<string, IReadOnlyPackage> explicitMounts = new Dictionary<string, IReadOnlyPackage>(); readonly Dictionary<string, IReadOnlyPackage> explicitMounts = new Dictionary<string, IReadOnlyPackage>();
readonly string modID;
// Mod packages that should not be disposed // Mod packages that should not be disposed
readonly List<IReadOnlyPackage> modPackages = new List<IReadOnlyPackage>(); readonly List<IReadOnlyPackage> modPackages = new List<IReadOnlyPackage>();
@@ -38,8 +40,9 @@ namespace OpenRA.FileSystem
Cache<string, List<IReadOnlyPackage>> fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>()); Cache<string, List<IReadOnlyPackage>> fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>());
public FileSystem(IReadOnlyDictionary<string, Manifest> installedMods, IPackageLoader[] packageLoaders) public FileSystem(string modID, IReadOnlyDictionary<string, Manifest> installedMods, IPackageLoader[] packageLoaders)
{ {
this.modID = modID;
this.installedMods = installedMods; this.installedMods = installedMods;
this.packageLoaders = packageLoaders this.packageLoaders = packageLoaders
.Append(new ZipFileLoader()) .Append(new ZipFileLoader())
@@ -281,6 +284,25 @@ namespace OpenRA.FileSystem
return fileIndex.ContainsKey(filename); return fileIndex.ContainsKey(filename);
} }
/// <summary>
/// Returns true if the given filename references an external mod via an explicit mount
/// </summary>
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);
}
/// <summary> /// <summary>
/// Resolves a filesystem for an assembly, accounting for explicit and mod mounts. /// 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). /// Assemblies must exist in the native OS file system (not inside an OpenRA-defined package).

View File

@@ -1229,5 +1229,14 @@ namespace OpenRA
return modData.DefaultFileSystem.Exists(filename); 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;
}
} }
} }

View File

@@ -568,5 +568,14 @@ namespace OpenRA
return modData.DefaultFileSystem.Exists(filename); 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;
}
} }
} }

View File

@@ -55,7 +55,7 @@ namespace OpenRA
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(mods, PackageLoaders); ModFiles = new FS(mod.Id, mods, PackageLoaders);
ModFiles.LoadFromManifest(Manifest); ModFiles.LoadFromManifest(Manifest);
Manifest.LoadCustomData(ObjectCreator); Manifest.LoadCustomData(ObjectCreator);

View File

@@ -38,7 +38,7 @@ 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(Game.Mods, modPackageLoaders); var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders);
modFileSystem.LoadFromManifest(mod); modFileSystem.LoadFromManifest(mod);
var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null); var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null);

View File

@@ -65,7 +65,7 @@ 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(Game.Mods, modPackageLoaders); var modFileSystem = new FS(mod.Id, Game.Mods, modPackageLoaders);
modFileSystem.LoadFromManifest(mod); modFileSystem.LoadFromManifest(mod);
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null); var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);