added AssetInfo; this is the start of syncing files over netplay

This commit is contained in:
Chris Forbes
2009-12-20 15:30:38 +13:00
parent 301873f88e
commit 32196fa223
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using System.IO;
using System.Linq;
using System.Security.Cryptography;
namespace OpenRa
{
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)); }
}
}