mirror of
https://github.com/SteamRE/DepotDownloader.git
synced 2026-10-19 15:51:50 +00:00
Include and validate checksums with locally cached manifests
This commit is contained in:
1 parent
0b598b43a7
commit
2e30364d8f
2 files changed
+75
-12
No files matched your search
@@ -583,8 +583,30 @@ namespace DepotDownloader
|
||||
if ( lastManifestId != INVALID_MANIFEST_ID )
|
||||
{
|
||||
var oldManifestFileName = Path.Combine( configDir, string.Format( "{0}.bin", lastManifestId ) );
|
||||
if ( File.Exists( oldManifestFileName ) )
|
||||
oldProtoManifest = ProtoManifest.LoadFromFile( oldManifestFileName );
|
||||
|
||||
if (File.Exists(oldManifestFileName))
|
||||
{
|
||||
byte[] expectedChecksum, currentChecksum;
|
||||
|
||||
try
|
||||
{
|
||||
expectedChecksum = File.ReadAllBytes(oldManifestFileName + ".sha");
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
expectedChecksum = null;
|
||||
}
|
||||
|
||||
oldProtoManifest = ProtoManifest.LoadFromFile(oldManifestFileName, out currentChecksum);
|
||||
|
||||
if (expectedChecksum == null || !expectedChecksum.SequenceEqual(currentChecksum))
|
||||
{
|
||||
// We only have to show this warning if the old manifest ID was different
|
||||
if (lastManifestId != depot.manifestId)
|
||||
Console.WriteLine("Manifest {0} on disk did not match the expected checksum.", lastManifestId);
|
||||
oldProtoManifest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( lastManifestId == depot.manifestId && oldProtoManifest != null )
|
||||
@@ -597,7 +619,24 @@ namespace DepotDownloader
|
||||
var newManifestFileName = Path.Combine( configDir, string.Format( "{0}.bin", depot.manifestId ) );
|
||||
if ( newManifestFileName != null )
|
||||
{
|
||||
newProtoManifest = ProtoManifest.LoadFromFile( newManifestFileName );
|
||||
byte[] expectedChecksum, currentChecksum;
|
||||
|
||||
try
|
||||
{
|
||||
expectedChecksum = File.ReadAllBytes(newManifestFileName + ".sha");
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
expectedChecksum = null;
|
||||
}
|
||||
|
||||
newProtoManifest = ProtoManifest.LoadFromFile(newManifestFileName, out currentChecksum);
|
||||
|
||||
if (expectedChecksum == null || !expectedChecksum.SequenceEqual(currentChecksum))
|
||||
{
|
||||
Console.WriteLine("Manifest {0} on disk did not match the expected checksum.", depot.manifestId);
|
||||
newProtoManifest = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( newProtoManifest != null )
|
||||
@@ -656,8 +695,11 @@ namespace DepotDownloader
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] checksum;
|
||||
|
||||
newProtoManifest = new ProtoManifest( depotManifest, depot.manifestId );
|
||||
newProtoManifest.SaveToFile( newManifestFileName );
|
||||
newProtoManifest.SaveToFile( newManifestFileName, out checksum );
|
||||
File.WriteAllBytes( newManifestFileName + ".sha", checksum );
|
||||
|
||||
Console.WriteLine( " Done!" );
|
||||
}
|
||||
|
||||
@@ -117,21 +117,42 @@ namespace DepotDownloader
|
||||
[ProtoMember(2)]
|
||||
public ulong ID { get; private set; }
|
||||
|
||||
public static ProtoManifest LoadFromFile(string filename)
|
||||
public static ProtoManifest LoadFromFile(string filename, out byte[] checksum)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
checksum = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
using (FileStream fs = File.Open(filename, FileMode.Open))
|
||||
using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Decompress))
|
||||
return ProtoBuf.Serializer.Deserialize<ProtoManifest>(ds);
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (FileStream fs = File.Open(filename, FileMode.Open))
|
||||
using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Decompress))
|
||||
ds.CopyTo(ms);
|
||||
|
||||
checksum = Util.SHAHash(ms.ToArray());
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return ProtoBuf.Serializer.Deserialize<ProtoManifest>(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveToFile(string filename)
|
||||
public void SaveToFile(string filename, out byte[] checksum)
|
||||
{
|
||||
using (FileStream fs = File.Open(filename, FileMode.Create))
|
||||
using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Compress))
|
||||
ProtoBuf.Serializer.Serialize<ProtoManifest>(ds, this);
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
ProtoBuf.Serializer.Serialize<ProtoManifest>(ms, this);
|
||||
|
||||
checksum = Util.SHAHash(ms.ToArray());
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
using (FileStream fs = File.Open(filename, FileMode.Create))
|
||||
using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Compress))
|
||||
ms.CopyTo(ds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user