From 08fb3ccb76d2fb8b5bda6a408a0975040d663ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Sat, 28 Jun 2025 13:10:13 +0200 Subject: [PATCH] Fix serializable files not always getting written on change In some cases, STJ might decide to replace the object rather than populating it. This will work for majority of properties and use cases, however, we actually set up events on some properties to notify us back if they change during runtime. That event registration did not work properly, as the object was replaced with the new, that did not have appropriate listeners set up. Populate rather than replacing those selected properties, which fixes the problem. --- ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs | 1 + ArchiSteamFarm/Steam/Storage/BotDatabase.cs | 7 +++++++ ArchiSteamFarm/Storage/GlobalDatabase.cs | 3 +++ 3 files changed, 11 insertions(+) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs index ec63a1566..7a98ed324 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs @@ -38,6 +38,7 @@ namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher; internal sealed class BotCache : SerializableFile { [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentList LastAnnouncedAssetsForListing { get; private init; } = []; internal string? LastAnnouncedTradeToken { diff --git a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs index 899351ce6..fd7cfbcf8 100644 --- a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs +++ b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs @@ -65,6 +65,7 @@ public sealed class BotDatabase : GenericDatabase { [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet ExtraStorePackages { get; private init; } = []; internal DateTime ExtraStorePackagesRefreshedAt { @@ -82,22 +83,27 @@ public sealed class BotDatabase : GenericDatabase { [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet FarmingBlacklistAppIDs { get; private init; } = []; [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet FarmingPriorityQueueAppIDs { get; private init; } = []; [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ObservableConcurrentDictionary FarmingRiskyIgnoredAppIDs { get; private init; } = new(); [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet FarmingRiskyPrioritizedAppIDs { get; private init; } = []; [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet MatchActivelyBlacklistAppIDs { get; private init; } = []; internal MobileAuthenticator? MobileAuthenticator { @@ -141,6 +147,7 @@ public sealed class BotDatabase : GenericDatabase { [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet TradingBlacklistSteamIDs { get; private init; } = []; [JsonInclude] diff --git a/ArchiSteamFarm/Storage/GlobalDatabase.cs b/ArchiSteamFarm/Storage/GlobalDatabase.cs index c9a3d34bf..4a7af1c40 100644 --- a/ArchiSteamFarm/Storage/GlobalDatabase.cs +++ b/ArchiSteamFarm/Storage/GlobalDatabase.cs @@ -57,10 +57,12 @@ public sealed class GlobalDatabase : GenericDatabase { [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet CachedBadBots { get; private init; } = []; [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ObservableConcurrentDictionary CardCountsPerGame { get; private init; } = new(); internal uint CellID { @@ -91,6 +93,7 @@ public sealed class GlobalDatabase : GenericDatabase { [JsonDisallowNull] [JsonInclude] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal InMemoryServerListProvider ServerListProvider { get; private init; } = new(); [JsonInclude]