Remove inlined adler hash

This commit is contained in:
Pavel Djundik
2024-08-14 10:18:24 +03:00
parent 294dbff40a
commit a3fc9c4c45
2 changed files with 16 additions and 24 deletions

View File

@@ -1059,18 +1059,7 @@ namespace DepotDownloader
{
fsOld.Seek((long)match.OldChunk.Offset, SeekOrigin.Begin);
uint a = 0, b = 0;
for (var i = 0; i < match.OldChunk.UncompressedLength; i++)
{
var c = (uint)fsOld.ReadByte();
// adler hash
a = (a + c) % 65521;
b = (b + a) % 65521;
}
var adler = BitConverter.GetBytes(a | (b << 16));
var adler = Util.AdlerHash(fsOld, (int)match.OldChunk.UncompressedLength);
if (!adler.SequenceEqual(match.OldChunk.Checksum))
{
neededChunks.Add(match.NewChunk);

View File

@@ -83,18 +83,7 @@ namespace DepotDownloader
{
fs.Seek((long)data.Offset, SeekOrigin.Begin);
uint a = 0, b = 0;
for (var i = 0; i < data.UncompressedLength; i++)
{
var c = (uint)fs.ReadByte();
// adler hash
a = (a + c) % 65521;
b = (b + a) % 65521;
}
var adler = BitConverter.GetBytes(a | (b << 16));
var adler = AdlerHash(fs, (int)data.UncompressedLength);
if (!adler.SequenceEqual(data.Checksum))
{
neededChunks.Add(data);
@@ -104,6 +93,20 @@ namespace DepotDownloader
return neededChunks;
}
public static byte[] AdlerHash(Stream stream, int length)
{
uint a = 0, b = 0;
for (var i = 0; i < length; i++)
{
var c = (uint)stream.ReadByte();
a = (a + c) % 65521;
b = (b + a) % 65521;
}
return BitConverter.GetBytes(a | (b << 16));
}
public static byte[] DecodeHexString(string hex)
{
if (hex == null)