Preserve CachedCardCountsForGame across ASF runs

This commit is contained in:
Archi
2022-02-11 00:05:43 +01:00
parent 8e47a5906f
commit fec57e0fff
3 changed files with 135 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Collections;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers;
using ArchiSteamFarm.Localization;
@@ -48,6 +49,9 @@ public sealed class GlobalDatabase : SerializableFile {
[PublicAPI]
public IReadOnlyDictionary<uint, (uint ChangeNumber, ImmutableHashSet<uint>? AppIDs)> PackagesDataReadOnly => PackagesData;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly ObservableConcurrentDictionary<uint, byte> CardCountsPerGame = new();
[JsonProperty(Required = Required.DisallowNull)]
internal readonly InMemoryServerListProvider ServerListProvider = new();
@@ -107,7 +111,10 @@ public sealed class GlobalDatabase : SerializableFile {
}
[JsonConstructor]
private GlobalDatabase() => ServerListProvider.ServerListUpdated += OnObjectModified;
private GlobalDatabase() {
CardCountsPerGame.OnModified += OnObjectModified;
ServerListProvider.ServerListUpdated += OnObjectModified;
}
[PublicAPI]
public void DeleteFromJsonStorage(string key) {
@@ -159,6 +166,9 @@ public sealed class GlobalDatabase : SerializableFile {
[UsedImplicitly]
public bool ShouldSerializeBackingLastChangeNumber() => LastChangeNumber != 0;
[UsedImplicitly]
public bool ShouldSerializeCardCountsPerGame() => !CardCountsPerGame.IsEmpty;
[UsedImplicitly]
public bool ShouldSerializeKeyValueJsonStorage() => !KeyValueJsonStorage.IsEmpty;
@@ -174,6 +184,7 @@ public sealed class GlobalDatabase : SerializableFile {
protected override void Dispose(bool disposing) {
if (disposing) {
// Events we registered
CardCountsPerGame.OnModified -= OnObjectModified;
ServerListProvider.ServerListUpdated -= OnObjectModified;
// Those are objects that are always being created if constructor doesn't throw exception