Add support for hashing partial IDFiles.
This commit is contained in:
@@ -48,13 +48,18 @@ namespace OpenRA
|
|||||||
public readonly string RegistryValue;
|
public readonly string RegistryValue;
|
||||||
|
|
||||||
public readonly string Title;
|
public readonly string Title;
|
||||||
public readonly Dictionary<string, string> IDFiles;
|
|
||||||
|
|
||||||
|
[FieldLoader.Ignore] public readonly MiniYaml IDFiles;
|
||||||
[FieldLoader.Ignore] public readonly List<MiniYamlNode> Install;
|
[FieldLoader.Ignore] public readonly List<MiniYamlNode> Install;
|
||||||
|
|
||||||
public ModSource(MiniYaml yaml)
|
public ModSource(MiniYaml yaml)
|
||||||
{
|
{
|
||||||
Title = yaml.Value;
|
Title = yaml.Value;
|
||||||
|
|
||||||
|
var idFiles = yaml.Nodes.FirstOrDefault(n => n.Key == "IDFiles");
|
||||||
|
if (idFiles != null)
|
||||||
|
IDFiles = idFiles.Value;
|
||||||
|
|
||||||
var installNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Install");
|
var installNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Install");
|
||||||
if (installNode != null)
|
if (installNode != null)
|
||||||
Install = installNode.Value.Nodes;
|
Install = installNode.Value.Nodes;
|
||||||
|
|||||||
@@ -505,15 +505,34 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var kv in source.IDFiles)
|
foreach (var kv in source.IDFiles.Nodes)
|
||||||
{
|
{
|
||||||
var filePath = Path.Combine(path, kv.Key);
|
var filePath = Path.Combine(path, kv.Key);
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
using (var fileStream = File.OpenRead(filePath))
|
using (var fileStream = File.OpenRead(filePath))
|
||||||
if (CryptoUtil.SHA1Hash(fileStream) != kv.Value)
|
{
|
||||||
return false;
|
var offsetNode = kv.Value.Nodes.FirstOrDefault(n => n.Key == "Offset");
|
||||||
|
var lengthNode = kv.Value.Nodes.FirstOrDefault(n => n.Key == "Length");
|
||||||
|
if (offsetNode != null || lengthNode != null)
|
||||||
|
{
|
||||||
|
var offset = 0L;
|
||||||
|
if (offsetNode != null)
|
||||||
|
offset = FieldLoader.GetValue<long>("Offset", offsetNode.Value.Value);
|
||||||
|
|
||||||
|
var length = fileStream.Length - offset;
|
||||||
|
if (lengthNode != null)
|
||||||
|
length = FieldLoader.GetValue<long>("Length", lengthNode.Value.Value);
|
||||||
|
|
||||||
|
fileStream.Position = offset;
|
||||||
|
var data = fileStream.ReadBytes((int)length);
|
||||||
|
if (CryptoUtil.SHA1Hash(data) != kv.Value.Value)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (CryptoUtil.SHA1Hash(fileStream) != kv.Value.Value)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
Reference in New Issue
Block a user