Serialize with a compile-time protobuf model

This commit is contained in:
Pavel Djundik committed 2026-11-02 14:43:03 +02:00
1 parent 49717a7aeb
commit 0fc480e7c4
4 files changed
+32 -10

No files matched your search

+3 -3
View File
@@ -12,7 +12,7 @@ using ProtoBuf;
namespace DepotDownloader
{
[ProtoContract]
class AccountSettingsStore
public class AccountSettingsStore
{
// Member 1 was a Dictionary<string, byte[]> for SentryData.
@@ -55,7 +55,7 @@ namespace DepotDownloader
{
using var fs = IsolatedStorage.OpenFile(filename, FileMode.Open, FileAccess.Read);
using var ds = new DeflateStream(fs, CompressionMode.Decompress);
Instance = Serializer.Deserialize<AccountSettingsStore>(ds);
Instance = ProtobufModel.Instance.Deserialize<AccountSettingsStore>(ds);
}
catch (IOException ex)
{
@@ -80,7 +80,7 @@ namespace DepotDownloader
{
using var fs = IsolatedStorage.OpenFile(Instance.FileName, FileMode.Create, FileAccess.Write);
using var ds = new DeflateStream(fs, CompressionMode.Compress);
Serializer.Serialize(ds, Instance);
ProtobufModel.Instance.Serialize(ds, Instance);
}
catch (IOException ex)
{
+3 -3
View File
@@ -10,7 +10,7 @@ using ProtoBuf;
namespace DepotDownloader
{
[ProtoContract]
class DepotConfigStore
public class DepotConfigStore
{
[ProtoMember(1)]
public Dictionary<uint, ulong> InstalledManifestIDs { get; private set; }
@@ -38,7 +38,7 @@ namespace DepotDownloader
{
using var fs = File.Open(filename, FileMode.Open);
using var ds = new DeflateStream(fs, CompressionMode.Decompress);
Instance = Serializer.Deserialize<DepotConfigStore>(ds);
Instance = ProtobufModel.Instance.Deserialize<DepotConfigStore>(ds);
}
else
{
@@ -55,7 +55,7 @@ namespace DepotDownloader
using var fs = File.Open(Instance.FileName, FileMode.Create);
using var ds = new DeflateStream(fs, CompressionMode.Compress);
Serializer.Serialize(ds, Instance);
ProtobufModel.Instance.Serialize(ds, Instance);
}
}
}
+8 -4
View File
@@ -13,7 +13,7 @@ using SteamKit2;
namespace DepotDownloader
{
[ProtoContract]
class ProtoManifest
public class ProtoManifest
{
// Proto ctor
private ProtoManifest()
@@ -74,9 +74,13 @@ namespace DepotDownloader
public byte[] FileHash { get; private set; }
}
[ProtoContract(SkipConstructor = true)]
[ProtoContract]
public class ChunkData
{
private ChunkData()
{
}
public ChunkData(DepotManifest.ChunkData sourceChunk)
{
ChunkID = sourceChunk.ChunkID;
@@ -142,13 +146,13 @@ namespace DepotDownloader
checksum = SHA1.HashData(ms.ToArray());
ms.Seek(0, SeekOrigin.Begin);
return Serializer.Deserialize<ProtoManifest>(ms);
return ProtobufModel.Instance.Deserialize<ProtoManifest>(ms);
}
public void SaveToFile(string filename, out byte[] checksum)
{
using var ms = new MemoryStream();
Serializer.Serialize(ms, this);
ProtobufModel.Instance.Serialize(ms, this);
checksum = SHA1.HashData(ms.ToArray());
+18
View File
@@ -0,0 +1,18 @@
// This file is subject to the terms and conditions defined
// in file 'LICENSE', which is part of this source code package.
using ProtoBuf;
using ProtoBuf.Meta;
namespace DepotDownloader
{
#pragma warning disable PBN9001
[ProtoModel]
[ProtoSerializable(typeof(AccountSettingsStore))]
[ProtoSerializable(typeof(DepotConfigStore))]
[ProtoSerializable(typeof(ProtoManifest))]
sealed partial class ProtobufModel : TypeModel
{
}
#pragma warning restore PBN9001
}