Allow hashes to be accepted as valid mix filenames.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -138,6 +139,29 @@ namespace OpenRA.FileFormats
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint? FindMatchingHash(string filename)
|
||||||
|
{
|
||||||
|
// Try first as a TD/RA hash
|
||||||
|
var hash = PackageEntry.HashFilename(filename);
|
||||||
|
if (index.ContainsKey(hash))
|
||||||
|
return hash;
|
||||||
|
|
||||||
|
// Fall back to TS/RA2 hash style
|
||||||
|
var crc = PackageEntry.CrcHashFilename(filename);
|
||||||
|
if (index.ContainsKey(crc))
|
||||||
|
return hash;
|
||||||
|
|
||||||
|
// Test for a raw hash before giving up
|
||||||
|
uint raw;
|
||||||
|
if (!uint.TryParse(filename, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out raw))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if ("{0:X}".F(raw) == filename && index.ContainsKey(raw))
|
||||||
|
return raw;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Stream GetContent(uint hash)
|
public Stream GetContent(uint hash)
|
||||||
{
|
{
|
||||||
PackageEntry e;
|
PackageEntry e;
|
||||||
@@ -152,11 +176,8 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
public Stream GetContent(string filename)
|
public Stream GetContent(string filename)
|
||||||
{
|
{
|
||||||
var content = GetContent(PackageEntry.HashFilename(filename)); // RA1 and TD
|
var hash = FindMatchingHash(filename);
|
||||||
if (content != null)
|
return hash.HasValue ? GetContent(hash.Value) : null;
|
||||||
return content;
|
|
||||||
else
|
|
||||||
return GetContent(PackageEntry.CrcHashFilename(filename)); // TS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<uint> AllFileHashes()
|
public IEnumerable<uint> AllFileHashes()
|
||||||
@@ -197,15 +218,14 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return index.Keys.Select(k => lookup.ContainsKey(k) ? lookup[k] : "Unknown File [{0}]".F(k));
|
return index.Keys.Select(k => lookup.ContainsKey(k) ? lookup[k] : "{0:X}".F(k));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Exists(string filename)
|
public bool Exists(string filename)
|
||||||
{
|
{
|
||||||
return (index.ContainsKey(PackageEntry.HashFilename(filename)) || index.ContainsKey(PackageEntry.CrcHashFilename(filename)));
|
return FindMatchingHash(filename).HasValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int Priority
|
public int Priority
|
||||||
{
|
{
|
||||||
get { return 1000 + priority; }
|
get { return 1000 + priority; }
|
||||||
|
|||||||
Reference in New Issue
Block a user