You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DepotDownloader/DepotDownloader/DepotConfigStore.cs

59 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using ProtoBuf;
namespace DepotDownloader
{
[ProtoContract]
class DepotConfigStore
{
[ProtoMember(1)]
public Dictionary<uint, ulong> InstalledManifestIDs { get; private set; }
string FileName;
DepotConfigStore()
{
InstalledManifestIDs = [];
}
static bool Loaded
{
get { return Instance != null; }
}
public static DepotConfigStore Instance;
public static void LoadFromFile(string filename)
{
if (Loaded)
throw new Exception("Config already loaded");
if (File.Exists(filename))
{
using var fs = File.Open(filename, FileMode.Open);
using var ds = new DeflateStream(fs, CompressionMode.Decompress);
Instance = Serializer.Deserialize<DepotConfigStore>(ds);
}
else
{
Instance = new DepotConfigStore();
}
Instance.FileName = filename;
}
public static void Save()
{
if (!Loaded)
throw new Exception("Saved config before loading");
using var fs = File.Open(Instance.FileName, FileMode.Create);
using var ds = new DeflateStream(fs, CompressionMode.Compress);
Serializer.Serialize(ds, Instance);
}
}
}