merge .FileFormats and .DataStructures

This commit is contained in:
Chris Forbes
2010-01-15 17:08:44 +13:00
parent 685056a3ca
commit a7c368f246
18 changed files with 17 additions and 155 deletions

View File

@@ -0,0 +1,33 @@
using System.IO;
using System.Linq;
using System.Security.Cryptography;
namespace OpenRa.FileFormats
{
public class AssetInfo
{
public readonly string Filename;
public readonly string Hash;
public AssetInfo(string filename, string hash)
{
Filename = filename;
Hash = hash;
}
static string GetHash(string filename)
{
using (var csp = SHA1.Create())
return new string(csp.ComputeHash(File.ReadAllBytes(filename))
.SelectMany(a => a.ToString("x2")).ToArray());
}
public static AssetInfo FromLocalFile(string filename)
{
return new AssetInfo(filename, GetHash(filename));
}
/* todo: perf: cache this */
public bool IsPresent() { return File.Exists(Filename) && (Hash == GetHash(Filename)); }
}
}