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 Stream s;
|
||||
readonly int bagFilePriority;
|
||||
readonly Dictionary<string, IdxEntry> 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)
|
||||
|
||||
@@ -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<string, Entry> entries = new Dictionary<string, Entry>();
|
||||
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
|
||||
|
||||
@@ -31,13 +31,11 @@ namespace OpenRA.FileSystem
|
||||
readonly Stream s;
|
||||
|
||||
readonly string filename;
|
||||
readonly int priority;
|
||||
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.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();
|
||||
|
||||
@@ -23,52 +23,50 @@ namespace OpenRA.FileSystem
|
||||
readonly Dictionary<IReadOnlyPackage, int> mountedPackages = new Dictionary<IReadOnlyPackage, int>();
|
||||
|
||||
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>());
|
||||
|
||||
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))
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<string, byte[]> contents)
|
||||
public Folder(string path, Dictionary<string, byte[]> 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<string, byte[]> contents)
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace OpenRA.FileSystem
|
||||
Stream GetContent(string filename);
|
||||
bool Exists(string filename);
|
||||
IEnumerable<string> AllFileNames();
|
||||
int Priority { get; }
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
|
||||
@@ -331,19 +331,16 @@ namespace OpenRA.FileSystem
|
||||
readonly Dictionary<uint, FileDescriptor> fileDescriptors = new Dictionary<uint, FileDescriptor>();
|
||||
readonly Dictionary<string, uint> fileLookup = new Dictionary<string, uint>();
|
||||
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<FileGroup>();
|
||||
var fileGroupOffsets = new List<uint>();
|
||||
|
||||
hdrFile = context.Open(hdrFilename);
|
||||
this.priority = priority;
|
||||
this.context = context;
|
||||
|
||||
// Strips archive number AND file extension
|
||||
|
||||
@@ -32,13 +32,11 @@ namespace OpenRA.FileSystem
|
||||
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();
|
||||
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()
|
||||
|
||||
@@ -25,13 +25,11 @@ namespace OpenRA.FileSystem
|
||||
readonly Dictionary<string, PackageEntry> 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();
|
||||
|
||||
@@ -23,14 +23,12 @@ namespace OpenRA.FileSystem
|
||||
public sealed class PakFile : IReadOnlyPackage
|
||||
{
|
||||
readonly string filename;
|
||||
readonly int priority;
|
||||
readonly Dictionary<string, Entry> 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<string, Entry>();
|
||||
|
||||
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()
|
||||
|
||||
@@ -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<string, byte[]> contents)
|
||||
public ZipFile(FileSystem context, string filename, Dictionary<string, byte[]> 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<string, byte[]> contents)
|
||||
|
||||
Reference in New Issue
Block a user