merge .FileFormats and .DataStructures
This commit is contained in:
33
OpenRa.FileFormats/AssetInfo.cs
Normal file
33
OpenRa.FileFormats/AssetInfo.cs
Normal 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)); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user