diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs index 7a98ed324..4eec9a089 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs @@ -41,54 +41,51 @@ internal sealed class BotCache : SerializableFile { [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentList LastAnnouncedAssetsForListing { get; private init; } = []; + [JsonInclude] + [JsonPropertyName("BackingLastAnnouncedTradeToken")] internal string? LastAnnouncedTradeToken { - get => BackingLastAnnouncedTradeToken; + get; set { - if (BackingLastAnnouncedTradeToken == value) { + if (field == value) { return; } - BackingLastAnnouncedTradeToken = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName("BackingLastInventoryChecksumBeforeDeduplication")] internal string? LastInventoryChecksumBeforeDeduplication { - get => BackingLastInventoryChecksumBeforeDeduplication; + get; set { - if (BackingLastInventoryChecksumBeforeDeduplication == value) { + if (field == value) { return; } - BackingLastInventoryChecksumBeforeDeduplication = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName("BackingLastRequestAt")] internal DateTime? LastRequestAt { - get => BackingLastRequestAt; + get; set { - if (BackingLastRequestAt == value) { + if (field == value) { return; } - BackingLastRequestAt = value; + field = value; Utilities.InBackground(Save); } } - [JsonInclude] - private string? BackingLastAnnouncedTradeToken { get; set; } - - [JsonInclude] - private string? BackingLastInventoryChecksumBeforeDeduplication { get; set; } - - [JsonInclude] - private DateTime? BackingLastRequestAt { get; set; } - private BotCache(string filePath) : this() { ArgumentException.ThrowIfNullOrEmpty(filePath); @@ -98,18 +95,18 @@ internal sealed class BotCache : SerializableFile { [JsonConstructor] private BotCache() => LastAnnouncedAssetsForListing.OnModified += OnObjectModified; - [UsedImplicitly] - public bool ShouldSerializeBackingLastAnnouncedTradeToken() => !string.IsNullOrEmpty(BackingLastAnnouncedTradeToken); - - [UsedImplicitly] - public bool ShouldSerializeBackingLastInventoryChecksumBeforeDeduplication() => !string.IsNullOrEmpty(BackingLastInventoryChecksumBeforeDeduplication); - - [UsedImplicitly] - public bool ShouldSerializeBackingLastRequestAt() => BackingLastRequestAt.HasValue; - [UsedImplicitly] public bool ShouldSerializeLastAnnouncedAssetsForListing() => LastAnnouncedAssetsForListing.Count > 0; + [UsedImplicitly] + public bool ShouldSerializeLastAnnouncedTradeToken() => !string.IsNullOrEmpty(LastAnnouncedTradeToken); + + [UsedImplicitly] + public bool ShouldSerializeLastInventoryChecksumBeforeDeduplication() => !string.IsNullOrEmpty(LastInventoryChecksumBeforeDeduplication); + + [UsedImplicitly] + public bool ShouldSerializeLastRequestAt() => LastRequestAt.HasValue; + protected override void Dispose(bool disposing) { if (disposing) { // Events we registered diff --git a/ArchiSteamFarm/Helpers/SerializableFile.cs b/ArchiSteamFarm/Helpers/SerializableFile.cs index 85a539129..893eed53d 100644 --- a/ArchiSteamFarm/Helpers/SerializableFile.cs +++ b/ArchiSteamFarm/Helpers/SerializableFile.cs @@ -67,7 +67,7 @@ public abstract class SerializableFile : IDisposable { ArgumentNullException.ThrowIfNull(serializableFile); if (string.IsNullOrEmpty(serializableFile.FilePath)) { - throw new InvalidOperationException(nameof(serializableFile.FilePath)); + return; } if (serializableFile.ReadOnly) { diff --git a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs index 36151ce50..046c374f9 100644 --- a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs +++ b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs @@ -50,30 +50,33 @@ public sealed class BotDatabase : GenericDatabase { internal bool HasGamesToRedeemInBackground => GamesToRedeemInBackgroundCount > 0; - [JsonIgnore] + [JsonInclude] + [JsonPropertyName("BackingTradeRestrictionsAcknowledged")] [PublicAPI] public bool TradeRestrictionsAcknowledged { - get => BackingTradeRestrictionsAcknowledged; + get; internal set { - if (BackingTradeRestrictionsAcknowledged == value) { + if (field == value) { return; } - BackingTradeRestrictionsAcknowledged = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName("BackingAccessToken")] internal string? AccessToken { - get => BackingAccessToken; + get; set { - if (BackingAccessToken == value) { + if (field == value) { return; } - BackingAccessToken = value; + field = value; Utilities.InBackground(Save); } } @@ -83,15 +86,17 @@ public sealed class BotDatabase : GenericDatabase { [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet ExtraStorePackages { get; private init; } = []; + [JsonInclude] + [JsonPropertyName("BackingExtraStorePackagesRefreshedAt")] internal DateTime ExtraStorePackagesRefreshedAt { - get => BackingExtraStorePackagesRefreshedAt; + get => field; set { - if (BackingExtraStorePackagesRefreshedAt == value) { + if (field == value) { return; } - BackingExtraStorePackagesRefreshedAt = value; + field = value; Utilities.InBackground(Save); } } @@ -121,41 +126,47 @@ public sealed class BotDatabase : GenericDatabase { [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet MatchActivelyBlacklistAppIDs { get; private init; } = []; + [JsonInclude] + [JsonPropertyName($"_{nameof(MobileAuthenticator)}")] internal MobileAuthenticator? MobileAuthenticator { - get => BackingMobileAuthenticator; + get; set { - if (BackingMobileAuthenticator == value) { + if (field == value) { return; } - BackingMobileAuthenticator = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName("BackingRefreshToken")] internal string? RefreshToken { - get => BackingRefreshToken; + get; set { - if (BackingRefreshToken == value) { + if (field == value) { return; } - BackingRefreshToken = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName("BackingSteamGuardData")] internal string? SteamGuardData { - get => BackingSteamGuardData; + get; set { - if (BackingSteamGuardData == value) { + if (field == value) { return; } - BackingSteamGuardData = value; + field = value; Utilities.InBackground(Save); } } @@ -165,25 +176,6 @@ public sealed class BotDatabase : GenericDatabase { [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ConcurrentHashSet TradingBlacklistSteamIDs { get; private init; } = []; - [JsonInclude] - private string? BackingAccessToken { get; set; } - - [JsonInclude] - private DateTime BackingExtraStorePackagesRefreshedAt { get; set; } - - [JsonInclude] - [JsonPropertyName($"_{nameof(MobileAuthenticator)}")] - private MobileAuthenticator? BackingMobileAuthenticator { get; set; } - - [JsonInclude] - private string? BackingRefreshToken { get; set; } - - [JsonInclude] - private string? BackingSteamGuardData { get; set; } - - [JsonInclude] - private bool BackingTradeRestrictionsAcknowledged { get; set; } - [JsonDisallowNull] [JsonInclude] private OrderedDictionary GamesToRedeemInBackground { get; init; } = new(); @@ -232,26 +224,14 @@ public sealed class BotDatabase : GenericDatabase { } [UsedImplicitly] - public bool ShouldSerializeBackingAccessToken() => !string.IsNullOrEmpty(BackingAccessToken); - - [UsedImplicitly] - public bool ShouldSerializeBackingExtraStorePackagesRefreshedAt() => BackingExtraStorePackagesRefreshedAt > DateTime.MinValue; - - [UsedImplicitly] - public bool ShouldSerializeBackingMobileAuthenticator() => BackingMobileAuthenticator != null; - - [UsedImplicitly] - public bool ShouldSerializeBackingRefreshToken() => !string.IsNullOrEmpty(BackingRefreshToken); - - [UsedImplicitly] - public bool ShouldSerializeBackingSteamGuardData() => !string.IsNullOrEmpty(BackingSteamGuardData); - - [UsedImplicitly] - public bool ShouldSerializeBackingTradeRestrictionsAcknowledged() => BackingTradeRestrictionsAcknowledged; + public bool ShouldSerializeAccessToken() => !string.IsNullOrEmpty(AccessToken); [UsedImplicitly] public bool ShouldSerializeExtraStorePackages() => ExtraStorePackages.Count > 0; + [UsedImplicitly] + public bool ShouldSerializeExtraStorePackagesRefreshedAt() => ExtraStorePackagesRefreshedAt > DateTime.MinValue; + [UsedImplicitly] public bool ShouldSerializeFarmingBlacklistAppIDs() => FarmingBlacklistAppIDs.Count > 0; @@ -270,6 +250,18 @@ public sealed class BotDatabase : GenericDatabase { [UsedImplicitly] public bool ShouldSerializeMatchActivelyBlacklistAppIDs() => MatchActivelyBlacklistAppIDs.Count > 0; + [UsedImplicitly] + public bool ShouldSerializeMobileAuthenticator() => MobileAuthenticator != null; + + [UsedImplicitly] + public bool ShouldSerializeRefreshToken() => !string.IsNullOrEmpty(RefreshToken); + + [UsedImplicitly] + public bool ShouldSerializeSteamGuardData() => !string.IsNullOrEmpty(SteamGuardData); + + [UsedImplicitly] + public bool ShouldSerializeTradeRestrictionsAcknowledged() => TradeRestrictionsAcknowledged; + [UsedImplicitly] public bool ShouldSerializeTradingBlacklistSteamIDs() => TradingBlacklistSteamIDs.Count > 0; @@ -285,7 +277,7 @@ public sealed class BotDatabase : GenericDatabase { TradingBlacklistSteamIDs.OnModified -= OnObjectModified; // Those are objects that might be null and the check should be in-place - BackingMobileAuthenticator?.Dispose(); + MobileAuthenticator?.Dispose(); } // Base dispose diff --git a/ArchiSteamFarm/Storage/CrashFile.cs b/ArchiSteamFarm/Storage/CrashFile.cs index 0e2fc3155..84cdef13f 100644 --- a/ArchiSteamFarm/Storage/CrashFile.cs +++ b/ArchiSteamFarm/Storage/CrashFile.cs @@ -34,38 +34,36 @@ using JetBrains.Annotations; namespace ArchiSteamFarm.Storage; internal sealed class CrashFile : SerializableFile { + [JsonInclude] + [JsonPropertyName("BackingLastStartup")] internal DateTime LastStartup { - get => BackingLastStartup; + get; set { - if (BackingLastStartup == value) { + if (field == value) { return; } - BackingLastStartup = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName("BackingStartupCount")] internal byte StartupCount { - get => BackingStartupCount; + get; set { - if (BackingStartupCount == value) { + if (field == value) { return; } - BackingStartupCount = value; + field = value; Utilities.InBackground(Save); } } - [JsonInclude] - private DateTime BackingLastStartup { get; set; } - - [JsonInclude] - private byte BackingStartupCount { get; set; } - private CrashFile(string filePath) : this() { ArgumentException.ThrowIfNullOrEmpty(filePath); @@ -76,10 +74,10 @@ internal sealed class CrashFile : SerializableFile { private CrashFile() { } [UsedImplicitly] - public bool ShouldSerializeBackingLastStartup() => BackingLastStartup > DateTime.MinValue; + public bool ShouldSerializeLastStartup() => LastStartup > DateTime.MinValue; [UsedImplicitly] - public bool ShouldSerializeBackingStartupCount() => BackingStartupCount > 0; + public bool ShouldSerializeStartupCount() => StartupCount > 0; protected override Task Save() => Save(this); diff --git a/ArchiSteamFarm/Storage/GlobalDatabase.cs b/ArchiSteamFarm/Storage/GlobalDatabase.cs index 4a7af1c40..8cf9534f8 100644 --- a/ArchiSteamFarm/Storage/GlobalDatabase.cs +++ b/ArchiSteamFarm/Storage/GlobalDatabase.cs @@ -65,28 +65,32 @@ public sealed class GlobalDatabase : GenericDatabase { [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal ObservableConcurrentDictionary CardCountsPerGame { get; private init; } = new(); + [JsonInclude] + [JsonPropertyName($"_{nameof(CellID)}")] internal uint CellID { - get => BackingCellID; + get; set { - if (BackingCellID == value) { + if (field == value) { return; } - BackingCellID = value; + field = value; Utilities.InBackground(Save); } } + [JsonInclude] + [JsonPropertyName($"_{nameof(LastChangeNumber)}")] internal uint LastChangeNumber { - get => BackingLastChangeNumber; + get; set { - if (BackingLastChangeNumber == value) { + if (field == value) { return; } - BackingLastChangeNumber = value; + field = value; Utilities.InBackground(Save); } } @@ -96,14 +100,6 @@ public sealed class GlobalDatabase : GenericDatabase { [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] internal InMemoryServerListProvider ServerListProvider { get; private init; } = new(); - [JsonInclude] - [JsonPropertyName($"_{nameof(CellID)}")] - private uint BackingCellID { get; set; } - - [JsonInclude] - [JsonPropertyName($"_{nameof(LastChangeNumber)}")] - private uint BackingLastChangeNumber { get; set; } - [JsonDisallowNull] [JsonInclude] private ConcurrentDictionary PackagesAccessTokens { get; init; } = new(); @@ -151,18 +147,18 @@ public sealed class GlobalDatabase : GenericDatabase { SaveToJsonStorage(this, key, value); } - [UsedImplicitly] - public bool ShouldSerializeBackingCellID() => BackingCellID != 0; - - [UsedImplicitly] - public bool ShouldSerializeBackingLastChangeNumber() => BackingLastChangeNumber != 0; - [UsedImplicitly] public bool ShouldSerializeCachedBadBots() => CachedBadBots.Count > 0; [UsedImplicitly] public bool ShouldSerializeCardCountsPerGame() => !CardCountsPerGame.IsEmpty; + [UsedImplicitly] + public bool ShouldSerializeCellID() => CellID != 0; + + [UsedImplicitly] + public bool ShouldSerializeLastChangeNumber() => LastChangeNumber != 0; + [UsedImplicitly] public bool ShouldSerializePackagesAccessTokens() => !PackagesAccessTokens.IsEmpty;