private SerializedFileMetaData CalculateFileMetadata(ref WriteResult result) { List <object> contentHashObjects = new List <object>(); List <object> fullHashObjects = new List <object>(); foreach (ResourceFile file in result.resourceFiles) { RawHash fileHash = HashingMethods.CalculateFile(file.fileName); RawHash contentHash = fileHash; fullHashObjects.Add(fileHash); if (file.serializedFile && result.serializedObjects.Count > 0) { using (var stream = new FileStream(file.fileName, FileMode.Open, FileAccess.Read)) { stream.Position = (long)result.serializedObjects[0].header.offset; contentHash = HashingMethods.CalculateStream(stream); } } contentHashObjects.Add(contentHash); } SerializedFileMetaData data = new SerializedFileMetaData(); data.RawFileHash = HashingMethods.Calculate(fullHashObjects).ToHash128(); data.ContentHash = HashingMethods.Calculate(contentHashObjects).ToHash128(); return(data); }
public void CalculateStreamCanUseOffsets() { byte[] bytes = { 0xe1, 0x43, 0x2f, 0x83, 0xdf, 0xeb, 0xa8, 0x86, 0xfb, 0xfe, 0xc9, 0x97, 0x20, 0xfb, 0x53, 0x45, 0x24, 0x5d, 0x92, 0x8b, 0xa2, 0xc4, 0xe1, 0xe2, 0x48, 0x4a, 0xbb, 0x66, 0x43, 0x9a, 0xbc, 0x84 }; using (var stream = new MemoryStream(bytes)) { stream.Position = 16; RawHash hash1 = HashingMethods.CalculateStream(stream); stream.Position = 0; RawHash hash2 = HashingMethods.CalculateStream(stream); Assert.AreNotEqual(hash1.ToString(), hash2.ToString()); } }
static Hash128 CalculateHashVersion(Dictionary <string, ulong> fileOffsets, ResourceFile[] resourceFiles) { List <RawHash> hashes = new List <RawHash>(); foreach (ResourceFile file in resourceFiles) { if (file.serializedFile) { // For serialized files, we ignore the header for the hash value. // This leaves us with a hash value of just the written object data. using (var stream = new FileStream(file.fileName, FileMode.Open, FileAccess.Read)) { stream.Position = (long)fileOffsets[file.fileName]; hashes.Add(HashingMethods.CalculateStream(stream)); } } else { hashes.Add(HashingMethods.CalculateFile(file.fileName)); } } return(HashingMethods.Calculate(hashes).ToHash128()); }
public void OneTimeSetup() { // Spooky hash has a static constructor that must be called on the main thread. m_FixtureTempDir = CreateTempDir("FixtureTemp"); HashingMethods.CalculateStream(new MemoryStream(new byte[] { 1 })); }
public RawHash CalculateStream(Stream stream) => HashingMethods.CalculateStream <T>(stream);
public Hash128 GetHash() { m_Stream.Position = 0; return(HashingMethods.CalculateStream(m_Stream).ToHash128()); }