Remove IReadOnlyPackage.Priority.
Priority is now determined solely by order in mod.yaml (later packages take priority of earlier ones).
This commit is contained in:
@@ -23,13 +23,11 @@ namespace OpenRA.FileSystem
|
|||||||
{
|
{
|
||||||
readonly string bagFilename;
|
readonly string bagFilename;
|
||||||
readonly Stream s;
|
readonly Stream s;
|
||||||
readonly int bagFilePriority;
|
|
||||||
readonly Dictionary<string, IdxEntry> index;
|
readonly Dictionary<string, IdxEntry> index;
|
||||||
|
|
||||||
public BagFile(FileSystem context, string filename, int priority)
|
public BagFile(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
bagFilename = filename;
|
bagFilename = filename;
|
||||||
bagFilePriority = priority;
|
|
||||||
|
|
||||||
// A bag file is always accompanied with an .idx counterpart
|
// A bag file is always accompanied with an .idx counterpart
|
||||||
// For example: audio.bag requires the audio.idx file
|
// For example: audio.bag requires the audio.idx file
|
||||||
@@ -47,7 +45,6 @@ namespace OpenRA.FileSystem
|
|||||||
s = context.Open(filename);
|
s = context.Open(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return 1000 + bagFilePriority; } }
|
|
||||||
public string Name { get { return bagFilename; } }
|
public string Name { get { return bagFilename; } }
|
||||||
|
|
||||||
public Stream GetContent(string filename)
|
public Stream GetContent(string filename)
|
||||||
|
|||||||
@@ -18,14 +18,12 @@ namespace OpenRA.FileSystem
|
|||||||
public sealed class BigFile : IReadOnlyPackage
|
public sealed class BigFile : IReadOnlyPackage
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public int Priority { get; private set; }
|
|
||||||
readonly Dictionary<string, Entry> entries = new Dictionary<string, Entry>();
|
readonly Dictionary<string, Entry> entries = new Dictionary<string, Entry>();
|
||||||
readonly Stream s;
|
readonly Stream s;
|
||||||
|
|
||||||
public BigFile(FileSystem context, string filename, int priority)
|
public BigFile(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
Name = filename;
|
Name = filename;
|
||||||
Priority = priority;
|
|
||||||
|
|
||||||
s = context.Open(filename);
|
s = context.Open(filename);
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -31,13 +31,11 @@ namespace OpenRA.FileSystem
|
|||||||
readonly Stream s;
|
readonly Stream s;
|
||||||
|
|
||||||
readonly string filename;
|
readonly string filename;
|
||||||
readonly int priority;
|
|
||||||
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();
|
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();
|
||||||
|
|
||||||
public D2kSoundResources(FileSystem context, string filename, int priority)
|
public D2kSoundResources(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.priority = priority;
|
|
||||||
|
|
||||||
s = context.Open(filename);
|
s = context.Open(filename);
|
||||||
try
|
try
|
||||||
@@ -80,8 +78,6 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public string Name { get { return filename; } }
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
public int Priority { get { return 1000 + priority; } }
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
|
|||||||
@@ -23,52 +23,50 @@ namespace OpenRA.FileSystem
|
|||||||
readonly Dictionary<IReadOnlyPackage, int> mountedPackages = new Dictionary<IReadOnlyPackage, int>();
|
readonly Dictionary<IReadOnlyPackage, int> mountedPackages = new Dictionary<IReadOnlyPackage, int>();
|
||||||
|
|
||||||
static readonly Dictionary<string, Assembly> AssemblyCache = new Dictionary<string, Assembly>();
|
static readonly Dictionary<string, Assembly> AssemblyCache = new Dictionary<string, Assembly>();
|
||||||
|
|
||||||
int order;
|
|
||||||
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 IReadWritePackage CreatePackage(string filename, int order, Dictionary<string, byte[]> content)
|
public IReadWritePackage CreatePackage(string filename, Dictionary<string, byte[]> content)
|
||||||
{
|
{
|
||||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
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))
|
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))
|
if (filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new MixFile(this, filename, order);
|
return new MixFile(this, filename);
|
||||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(this, filename, order);
|
return new ZipFile(this, filename);
|
||||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(this, filename, order);
|
return new ZipFile(this, filename);
|
||||||
if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new D2kSoundResources(this, filename, order);
|
return new D2kSoundResources(this, filename);
|
||||||
if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new InstallShieldPackage(this, filename, order);
|
return new InstallShieldPackage(this, filename);
|
||||||
if (filename.EndsWith(".PAK", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".PAK", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new PakFile(this, filename, order);
|
return new PakFile(this, filename);
|
||||||
if (filename.EndsWith(".big", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".big", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new BigFile(this, filename, order);
|
return new BigFile(this, filename);
|
||||||
if (filename.EndsWith(".bag", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".bag", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new BagFile(this, filename, order);
|
return new BagFile(this, filename);
|
||||||
if (filename.EndsWith(".hdr", StringComparison.InvariantCultureIgnoreCase))
|
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))
|
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(this, filename, order);
|
return new ZipFile(this, filename);
|
||||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
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)
|
public void Mount(string name)
|
||||||
@@ -79,7 +77,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
name = Platform.ResolvePath(name);
|
name = Platform.ResolvePath(name);
|
||||||
|
|
||||||
Action a = () => Mount(OpenPackage(name, order++));
|
Action a = () => Mount(OpenPackage(name));
|
||||||
if (optional)
|
if (optional)
|
||||||
try { a(); }
|
try { a(); }
|
||||||
catch { }
|
catch { }
|
||||||
@@ -149,8 +147,7 @@ namespace OpenRA.FileSystem
|
|||||||
Stream GetFromCache(string filename)
|
Stream GetFromCache(string filename)
|
||||||
{
|
{
|
||||||
var package = fileIndex[filename]
|
var package = fileIndex[filename]
|
||||||
.Where(x => x.Exists(filename))
|
.LastOrDefault(x => x.Exists(filename));
|
||||||
.MinByOrDefault(x => x.Priority);
|
|
||||||
|
|
||||||
if (package != null)
|
if (package != null)
|
||||||
return package.GetContent(filename);
|
return package.GetContent(filename);
|
||||||
@@ -193,9 +190,9 @@ namespace OpenRA.FileSystem
|
|||||||
// Ask each package individually
|
// Ask each package individually
|
||||||
IReadOnlyPackage package;
|
IReadOnlyPackage package;
|
||||||
if (explicitPackage && !string.IsNullOrEmpty(packageName))
|
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
|
else
|
||||||
package = mountedPackages.Keys.Where(x => x.Exists(filename)).MaxByOrDefault(x => x.Priority);
|
package = mountedPackages.Keys.LastOrDefault(x => x.Exists(filename));
|
||||||
|
|
||||||
if (package != null)
|
if (package != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,23 +16,20 @@ namespace OpenRA.FileSystem
|
|||||||
public sealed class Folder : IReadWritePackage
|
public sealed class Folder : IReadWritePackage
|
||||||
{
|
{
|
||||||
readonly string path;
|
readonly string path;
|
||||||
readonly int priority;
|
|
||||||
|
|
||||||
// Create a new folder package
|
// Create a new folder package
|
||||||
public Folder(string path, int priority, Dictionary<string, byte[]> contents)
|
public Folder(string path, Dictionary<string, byte[]> contents)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.priority = priority;
|
|
||||||
if (Directory.Exists(path))
|
if (Directory.Exists(path))
|
||||||
Directory.Delete(path, true);
|
Directory.Delete(path, true);
|
||||||
|
|
||||||
Write(contents);
|
Write(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Folder(string path, int priority)
|
public Folder(string path)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.priority = priority;
|
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(path);
|
||||||
}
|
}
|
||||||
@@ -54,7 +51,6 @@ namespace OpenRA.FileSystem
|
|||||||
return File.Exists(Path.Combine(path, filename));
|
return File.Exists(Path.Combine(path, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return priority; } }
|
|
||||||
public string Name { get { return path; } }
|
public string Name { get { return path; } }
|
||||||
|
|
||||||
public void Write(Dictionary<string, byte[]> contents)
|
public void Write(Dictionary<string, byte[]> contents)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace OpenRA.FileSystem
|
|||||||
Stream GetContent(string filename);
|
Stream GetContent(string filename);
|
||||||
bool Exists(string filename);
|
bool Exists(string filename);
|
||||||
IEnumerable<string> AllFileNames();
|
IEnumerable<string> AllFileNames();
|
||||||
int Priority { get; }
|
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -331,19 +331,16 @@ namespace OpenRA.FileSystem
|
|||||||
readonly Dictionary<uint, FileDescriptor> fileDescriptors = new Dictionary<uint, FileDescriptor>();
|
readonly Dictionary<uint, FileDescriptor> fileDescriptors = new Dictionary<uint, FileDescriptor>();
|
||||||
readonly Dictionary<string, uint> fileLookup = new Dictionary<string, uint>();
|
readonly Dictionary<string, uint> fileLookup = new Dictionary<string, uint>();
|
||||||
readonly FileSystem context;
|
readonly FileSystem context;
|
||||||
int priority;
|
|
||||||
string commonName;
|
string commonName;
|
||||||
public int Priority { get { return priority; } }
|
|
||||||
|
|
||||||
public string Name { get { return commonName; } }
|
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<FileGroup>();
|
var fileGroups = new List<FileGroup>();
|
||||||
var fileGroupOffsets = new List<uint>();
|
var fileGroupOffsets = new List<uint>();
|
||||||
|
|
||||||
hdrFile = context.Open(hdrFilename);
|
hdrFile = context.Open(hdrFilename);
|
||||||
this.priority = priority;
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
// Strips archive number AND file extension
|
// Strips archive number AND file extension
|
||||||
|
|||||||
@@ -32,13 +32,11 @@ namespace OpenRA.FileSystem
|
|||||||
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();
|
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();
|
||||||
readonly Stream s;
|
readonly Stream s;
|
||||||
readonly long dataStart = 255;
|
readonly long dataStart = 255;
|
||||||
readonly int priority;
|
|
||||||
readonly string filename;
|
readonly string filename;
|
||||||
|
|
||||||
public InstallShieldPackage(FileSystem context, string filename, int priority)
|
public InstallShieldPackage(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.priority = priority;
|
|
||||||
|
|
||||||
s = context.Open(filename);
|
s = context.Open(filename);
|
||||||
try
|
try
|
||||||
@@ -128,7 +126,6 @@ namespace OpenRA.FileSystem
|
|||||||
return index.ContainsKey(filename);
|
return index.ContainsKey(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return 2000 + priority; } }
|
|
||||||
public string Name { get { return filename; } }
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -25,13 +25,11 @@ namespace OpenRA.FileSystem
|
|||||||
readonly Dictionary<string, PackageEntry> index;
|
readonly Dictionary<string, PackageEntry> index;
|
||||||
readonly long dataStart;
|
readonly long dataStart;
|
||||||
readonly Stream s;
|
readonly Stream s;
|
||||||
readonly int priority;
|
|
||||||
readonly FileSystem context;
|
readonly FileSystem context;
|
||||||
|
|
||||||
public MixFile(FileSystem context, string filename, int priority)
|
public MixFile(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
Name = filename;
|
Name = filename;
|
||||||
this.priority = priority;
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
s = context.Open(filename);
|
s = context.Open(filename);
|
||||||
@@ -213,8 +211,6 @@ namespace OpenRA.FileSystem
|
|||||||
return index.ContainsKey(filename);
|
return index.ContainsKey(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return 1000 + priority; } }
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
|
|||||||
@@ -23,14 +23,12 @@ namespace OpenRA.FileSystem
|
|||||||
public sealed class PakFile : IReadOnlyPackage
|
public sealed class PakFile : IReadOnlyPackage
|
||||||
{
|
{
|
||||||
readonly string filename;
|
readonly string filename;
|
||||||
readonly int priority;
|
|
||||||
readonly Dictionary<string, Entry> index;
|
readonly Dictionary<string, Entry> index;
|
||||||
readonly Stream stream;
|
readonly Stream stream;
|
||||||
|
|
||||||
public PakFile(FileSystem context, string filename, int priority)
|
public PakFile(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.priority = priority;
|
|
||||||
index = new Dictionary<string, Entry>();
|
index = new Dictionary<string, Entry>();
|
||||||
|
|
||||||
stream = context.Open(filename);
|
stream = context.Open(filename);
|
||||||
@@ -81,7 +79,6 @@ namespace OpenRA.FileSystem
|
|||||||
return index.ContainsKey(filename);
|
return index.ContainsKey(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return 1000 + priority; } }
|
|
||||||
public string Name { get { return filename; } }
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace OpenRA.FileSystem
|
|||||||
public sealed class ZipFile : IReadWritePackage
|
public sealed class ZipFile : IReadWritePackage
|
||||||
{
|
{
|
||||||
readonly string filename;
|
readonly string filename;
|
||||||
readonly int priority;
|
|
||||||
SZipFile pkg;
|
SZipFile pkg;
|
||||||
|
|
||||||
static ZipFile()
|
static ZipFile()
|
||||||
@@ -27,10 +26,9 @@ namespace OpenRA.FileSystem
|
|||||||
ZipConstants.DefaultCodePage = Encoding.UTF8.CodePage;
|
ZipConstants.DefaultCodePage = Encoding.UTF8.CodePage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipFile(FileSystem context, string filename, int priority)
|
public ZipFile(FileSystem context, string filename)
|
||||||
{
|
{
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.priority = priority;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -44,9 +42,8 @@ namespace OpenRA.FileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new zip with the specified contents.
|
// Create a new zip with the specified contents.
|
||||||
public ZipFile(FileSystem context, string filename, int priority, Dictionary<string, byte[]> contents)
|
public ZipFile(FileSystem context, string filename, Dictionary<string, byte[]> contents)
|
||||||
{
|
{
|
||||||
this.priority = priority;
|
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
|
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
@@ -82,7 +79,6 @@ namespace OpenRA.FileSystem
|
|||||||
return pkg.GetEntry(filename) != null;
|
return pkg.GetEntry(filename) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return 500 + priority; } }
|
|
||||||
public string Name { get { return filename; } }
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
public void Write(Dictionary<string, byte[]> contents)
|
public void Write(Dictionary<string, byte[]> contents)
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ namespace OpenRA
|
|||||||
public Map(string path)
|
public Map(string path)
|
||||||
{
|
{
|
||||||
Path = path;
|
Path = path;
|
||||||
Container = Game.ModData.ModFiles.OpenWritablePackage(path, int.MaxValue);
|
Container = Game.ModData.ModFiles.OpenWritablePackage(path);
|
||||||
|
|
||||||
AssertExists("map.yaml");
|
AssertExists("map.yaml");
|
||||||
AssertExists("map.bin");
|
AssertExists("map.bin");
|
||||||
@@ -649,7 +649,7 @@ namespace OpenRA
|
|||||||
Path = toPath;
|
Path = toPath;
|
||||||
|
|
||||||
// Create a new map package
|
// Create a new map package
|
||||||
Container = Game.ModData.ModFiles.CreatePackage(Path, int.MaxValue, entries);
|
Container = Game.ModData.ModFiles.CreatePackage(Path, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update existing package
|
// Update existing package
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ namespace OpenRA
|
|||||||
InitializeLoaders();
|
InitializeLoaders();
|
||||||
ModFiles.LoadFromManifest(Manifest);
|
ModFiles.LoadFromManifest(Manifest);
|
||||||
|
|
||||||
// Mount map package so custom assets can be used. TODO: check priority.
|
// Mount map package so custom assets can be used.
|
||||||
ModFiles.Mount(ModFiles.OpenPackage(map.Path, int.MaxValue));
|
ModFiles.Mount(ModFiles.OpenPackage(map.Path));
|
||||||
|
|
||||||
using (new Support.PerfTimer("Map.PreloadRules"))
|
using (new Support.PerfTimer("Map.PreloadRules"))
|
||||||
map.PreloadRules();
|
map.PreloadRules();
|
||||||
|
|||||||
Reference in New Issue
Block a user