diff --git a/OpenRA.Game/FileSystem/BagFile.cs b/OpenRA.Game/FileSystem/BagFile.cs index 6fe5287a31..7572007838 100644 --- a/OpenRA.Game/FileSystem/BagFile.cs +++ b/OpenRA.Game/FileSystem/BagFile.cs @@ -23,13 +23,11 @@ namespace OpenRA.FileSystem { readonly string bagFilename; readonly Stream s; - readonly int bagFilePriority; readonly Dictionary index; - public BagFile(FileSystem context, string filename, int priority) + public BagFile(FileSystem context, string filename) { bagFilename = filename; - bagFilePriority = priority; // A bag file is always accompanied with an .idx counterpart // For example: audio.bag requires the audio.idx file @@ -47,7 +45,6 @@ namespace OpenRA.FileSystem s = context.Open(filename); } - public int Priority { get { return 1000 + bagFilePriority; } } public string Name { get { return bagFilename; } } public Stream GetContent(string filename) diff --git a/OpenRA.Game/FileSystem/BigFile.cs b/OpenRA.Game/FileSystem/BigFile.cs index 8bb6b69025..0474e28857 100644 --- a/OpenRA.Game/FileSystem/BigFile.cs +++ b/OpenRA.Game/FileSystem/BigFile.cs @@ -18,14 +18,12 @@ namespace OpenRA.FileSystem public sealed class BigFile : IReadOnlyPackage { public string Name { get; private set; } - public int Priority { get; private set; } readonly Dictionary entries = new Dictionary(); readonly Stream s; - public BigFile(FileSystem context, string filename, int priority) + public BigFile(FileSystem context, string filename) { Name = filename; - Priority = priority; s = context.Open(filename); try diff --git a/OpenRA.Game/FileSystem/D2kSoundResources.cs b/OpenRA.Game/FileSystem/D2kSoundResources.cs index 369b9ddeb4..19d9f6ed02 100644 --- a/OpenRA.Game/FileSystem/D2kSoundResources.cs +++ b/OpenRA.Game/FileSystem/D2kSoundResources.cs @@ -31,13 +31,11 @@ namespace OpenRA.FileSystem readonly Stream s; readonly string filename; - readonly int priority; readonly Dictionary index = new Dictionary(); - public D2kSoundResources(FileSystem context, string filename, int priority) + public D2kSoundResources(FileSystem context, string filename) { this.filename = filename; - this.priority = priority; s = context.Open(filename); try @@ -80,8 +78,6 @@ namespace OpenRA.FileSystem public string Name { get { return filename; } } - public int Priority { get { return 1000 + priority; } } - public void Dispose() { s.Dispose(); diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index 559378362b..069743f7cf 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -23,52 +23,50 @@ namespace OpenRA.FileSystem readonly Dictionary mountedPackages = new Dictionary(); static readonly Dictionary AssemblyCache = new Dictionary(); - - int order; Cache> fileIndex = new Cache>(_ => new List()); - public IReadWritePackage CreatePackage(string filename, int order, Dictionary content) + public IReadWritePackage CreatePackage(string filename, Dictionary content) { if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(this, filename, order, content); + return new ZipFile(this, filename, content); if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(this, filename, order, content); + return new ZipFile(this, filename, content); - return new Folder(filename, order, content); + return new Folder(filename, content); } - public IReadOnlyPackage OpenPackage(string filename, int order) + public IReadOnlyPackage OpenPackage(string filename) { if (filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase)) - return new MixFile(this, filename, order); + return new MixFile(this, filename); if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(this, filename, order); + return new ZipFile(this, filename); if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(this, filename, order); + return new ZipFile(this, filename); if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase)) - return new D2kSoundResources(this, filename, order); + return new D2kSoundResources(this, filename); if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase)) - return new InstallShieldPackage(this, filename, order); + return new InstallShieldPackage(this, filename); if (filename.EndsWith(".PAK", StringComparison.InvariantCultureIgnoreCase)) - return new PakFile(this, filename, order); + return new PakFile(this, filename); if (filename.EndsWith(".big", StringComparison.InvariantCultureIgnoreCase)) - return new BigFile(this, filename, order); + return new BigFile(this, filename); if (filename.EndsWith(".bag", StringComparison.InvariantCultureIgnoreCase)) - return new BagFile(this, filename, order); + return new BagFile(this, filename); if (filename.EndsWith(".hdr", StringComparison.InvariantCultureIgnoreCase)) - return new InstallShieldCABExtractor(this, filename, order); + return new InstallShieldCABExtractor(this, filename); - return new Folder(filename, order); + return new Folder(filename); } - public IReadWritePackage OpenWritablePackage(string filename, int order) + public IReadWritePackage OpenWritablePackage(string filename) { if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(this, filename, order); + return new ZipFile(this, filename); if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase)) - return new ZipFile(this, filename, order); + return new ZipFile(this, filename); - return new Folder(filename, order); + return new Folder(filename); } public void Mount(string name) @@ -79,7 +77,7 @@ namespace OpenRA.FileSystem name = Platform.ResolvePath(name); - Action a = () => Mount(OpenPackage(name, order++)); + Action a = () => Mount(OpenPackage(name)); if (optional) try { a(); } catch { } @@ -149,8 +147,7 @@ namespace OpenRA.FileSystem Stream GetFromCache(string filename) { var package = fileIndex[filename] - .Where(x => x.Exists(filename)) - .MinByOrDefault(x => x.Priority); + .LastOrDefault(x => x.Exists(filename)); if (package != null) return package.GetContent(filename); @@ -193,9 +190,9 @@ namespace OpenRA.FileSystem // Ask each package individually IReadOnlyPackage package; if (explicitPackage && !string.IsNullOrEmpty(packageName)) - package = mountedPackages.Keys.Where(x => x.Name == packageName).MaxByOrDefault(x => x.Priority); + package = mountedPackages.Keys.LastOrDefault(x => x.Name == packageName); else - package = mountedPackages.Keys.Where(x => x.Exists(filename)).MaxByOrDefault(x => x.Priority); + package = mountedPackages.Keys.LastOrDefault(x => x.Exists(filename)); if (package != null) { diff --git a/OpenRA.Game/FileSystem/Folder.cs b/OpenRA.Game/FileSystem/Folder.cs index 1fcef789d9..b8ab6884ed 100644 --- a/OpenRA.Game/FileSystem/Folder.cs +++ b/OpenRA.Game/FileSystem/Folder.cs @@ -16,23 +16,20 @@ namespace OpenRA.FileSystem public sealed class Folder : IReadWritePackage { readonly string path; - readonly int priority; // Create a new folder package - public Folder(string path, int priority, Dictionary contents) + public Folder(string path, Dictionary contents) { this.path = path; - this.priority = priority; if (Directory.Exists(path)) Directory.Delete(path, true); Write(contents); } - public Folder(string path, int priority) + public Folder(string path) { this.path = path; - this.priority = priority; if (!Directory.Exists(path)) Directory.CreateDirectory(path); } @@ -54,7 +51,6 @@ namespace OpenRA.FileSystem return File.Exists(Path.Combine(path, filename)); } - public int Priority { get { return priority; } } public string Name { get { return path; } } public void Write(Dictionary contents) diff --git a/OpenRA.Game/FileSystem/IPackage.cs b/OpenRA.Game/FileSystem/IPackage.cs index cb9c54d1c5..ffa61a1c6f 100644 --- a/OpenRA.Game/FileSystem/IPackage.cs +++ b/OpenRA.Game/FileSystem/IPackage.cs @@ -19,7 +19,6 @@ namespace OpenRA.FileSystem Stream GetContent(string filename); bool Exists(string filename); IEnumerable AllFileNames(); - int Priority { get; } string Name { get; } } diff --git a/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs b/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs index 17756bd979..2b05f5c07f 100644 --- a/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs +++ b/OpenRA.Game/FileSystem/InstallShieldCABExtractor.cs @@ -331,19 +331,16 @@ namespace OpenRA.FileSystem readonly Dictionary fileDescriptors = new Dictionary(); readonly Dictionary fileLookup = new Dictionary(); readonly FileSystem context; - int priority; string commonName; - public int Priority { get { return priority; } } public string Name { get { return commonName; } } - public InstallShieldCABExtractor(FileSystem context, string hdrFilename, int priority = -1) + public InstallShieldCABExtractor(FileSystem context, string hdrFilename) { var fileGroups = new List(); var fileGroupOffsets = new List(); hdrFile = context.Open(hdrFilename); - this.priority = priority; this.context = context; // Strips archive number AND file extension diff --git a/OpenRA.Game/FileSystem/InstallShieldPackage.cs b/OpenRA.Game/FileSystem/InstallShieldPackage.cs index 240cb88475..597f187c09 100644 --- a/OpenRA.Game/FileSystem/InstallShieldPackage.cs +++ b/OpenRA.Game/FileSystem/InstallShieldPackage.cs @@ -32,13 +32,11 @@ namespace OpenRA.FileSystem readonly Dictionary index = new Dictionary(); readonly Stream s; readonly long dataStart = 255; - readonly int priority; readonly string filename; - public InstallShieldPackage(FileSystem context, string filename, int priority) + public InstallShieldPackage(FileSystem context, string filename) { this.filename = filename; - this.priority = priority; s = context.Open(filename); try @@ -128,7 +126,6 @@ namespace OpenRA.FileSystem return index.ContainsKey(filename); } - public int Priority { get { return 2000 + priority; } } public string Name { get { return filename; } } public void Dispose() diff --git a/OpenRA.Game/FileSystem/MixFile.cs b/OpenRA.Game/FileSystem/MixFile.cs index cae11109f8..9171d97f5b 100644 --- a/OpenRA.Game/FileSystem/MixFile.cs +++ b/OpenRA.Game/FileSystem/MixFile.cs @@ -25,13 +25,11 @@ namespace OpenRA.FileSystem readonly Dictionary index; readonly long dataStart; readonly Stream s; - readonly int priority; readonly FileSystem context; - public MixFile(FileSystem context, string filename, int priority) + public MixFile(FileSystem context, string filename) { Name = filename; - this.priority = priority; this.context = context; s = context.Open(filename); @@ -213,8 +211,6 @@ namespace OpenRA.FileSystem return index.ContainsKey(filename); } - public int Priority { get { return 1000 + priority; } } - public void Dispose() { s.Dispose(); diff --git a/OpenRA.Game/FileSystem/Pak.cs b/OpenRA.Game/FileSystem/Pak.cs index 6ac57a7ae4..f14f42d8ff 100644 --- a/OpenRA.Game/FileSystem/Pak.cs +++ b/OpenRA.Game/FileSystem/Pak.cs @@ -23,14 +23,12 @@ namespace OpenRA.FileSystem public sealed class PakFile : IReadOnlyPackage { readonly string filename; - readonly int priority; readonly Dictionary index; readonly Stream stream; - public PakFile(FileSystem context, string filename, int priority) + public PakFile(FileSystem context, string filename) { this.filename = filename; - this.priority = priority; index = new Dictionary(); stream = context.Open(filename); @@ -81,7 +79,6 @@ namespace OpenRA.FileSystem return index.ContainsKey(filename); } - public int Priority { get { return 1000 + priority; } } public string Name { get { return filename; } } public void Dispose() diff --git a/OpenRA.Game/FileSystem/ZipFile.cs b/OpenRA.Game/FileSystem/ZipFile.cs index 03e25ce0f5..b5008c7b7c 100644 --- a/OpenRA.Game/FileSystem/ZipFile.cs +++ b/OpenRA.Game/FileSystem/ZipFile.cs @@ -19,7 +19,6 @@ namespace OpenRA.FileSystem public sealed class ZipFile : IReadWritePackage { readonly string filename; - readonly int priority; SZipFile pkg; static ZipFile() @@ -27,10 +26,9 @@ namespace OpenRA.FileSystem ZipConstants.DefaultCodePage = Encoding.UTF8.CodePage; } - public ZipFile(FileSystem context, string filename, int priority) + public ZipFile(FileSystem context, string filename) { this.filename = filename; - this.priority = priority; try { @@ -44,9 +42,8 @@ namespace OpenRA.FileSystem } // Create a new zip with the specified contents. - public ZipFile(FileSystem context, string filename, int priority, Dictionary contents) + public ZipFile(FileSystem context, string filename, Dictionary contents) { - this.priority = priority; this.filename = filename; if (File.Exists(filename)) @@ -82,7 +79,6 @@ namespace OpenRA.FileSystem return pkg.GetEntry(filename) != null; } - public int Priority { get { return 500 + priority; } } public string Name { get { return filename; } } public void Write(Dictionary contents) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 230c794bf4..4619b2a911 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -316,7 +316,7 @@ namespace OpenRA public Map(string path) { Path = path; - Container = Game.ModData.ModFiles.OpenWritablePackage(path, int.MaxValue); + Container = Game.ModData.ModFiles.OpenWritablePackage(path); AssertExists("map.yaml"); AssertExists("map.bin"); @@ -649,7 +649,7 @@ namespace OpenRA Path = toPath; // Create a new map package - Container = Game.ModData.ModFiles.CreatePackage(Path, int.MaxValue, entries); + Container = Game.ModData.ModFiles.CreatePackage(Path, entries); } // Update existing package diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index fd792d3467..66cb3254fe 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -175,8 +175,8 @@ namespace OpenRA InitializeLoaders(); ModFiles.LoadFromManifest(Manifest); - // Mount map package so custom assets can be used. TODO: check priority. - ModFiles.Mount(ModFiles.OpenPackage(map.Path, int.MaxValue)); + // Mount map package so custom assets can be used. + ModFiles.Mount(ModFiles.OpenPackage(map.Path)); using (new Support.PerfTimer("Map.PreloadRules")) map.PreloadRules();