diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs index 720ffe2ca00d3..57359d34fb586 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs @@ -52,9 +52,6 @@ internal sealed class GlobalCache : SerializableFile { [JsonProperty(Required = Required.DisallowNull)] private readonly ConcurrentDictionary DepotKeys = new(); - [JsonProperty(Required = Required.DisallowNull)] - private readonly ConcurrentDictionary PackageTokens = new(); - [JsonProperty(Required = Required.DisallowNull)] private readonly ConcurrentDictionary SubmittedApps = new(); @@ -81,9 +78,6 @@ internal sealed class GlobalCache : SerializableFile { [UsedImplicitly] public bool ShouldSerializeLastChangeNumber() => LastChangeNumber > 0; - [UsedImplicitly] - public bool ShouldSerializePackageTokens() => !PackageTokens.IsEmpty; - [UsedImplicitly] public bool ShouldSerializeSubmittedApps() => !SubmittedApps.IsEmpty; @@ -97,7 +91,14 @@ internal sealed class GlobalCache : SerializableFile { internal Dictionary GetAppTokensForSubmission() => AppTokens.Where(appToken => (SteamTokenDumperPlugin.Config?.SecretAppIDs.Contains(appToken.Key) == false) && (appToken.Value > 0) && (!SubmittedApps.TryGetValue(appToken.Key, out ulong token) || (appToken.Value != token))).ToDictionary(static appToken => appToken.Key, static appToken => appToken.Value); internal Dictionary GetDepotKeysForSubmission() => DepotKeys.Where(depotKey => (SteamTokenDumperPlugin.Config?.SecretDepotIDs.Contains(depotKey.Key) == false) && !string.IsNullOrEmpty(depotKey.Value) && (!SubmittedDepots.TryGetValue(depotKey.Key, out string? key) || (depotKey.Value != key))).ToDictionary(static depotKey => depotKey.Key, static depotKey => depotKey.Value); - internal Dictionary GetPackageTokensForSubmission() => PackageTokens.Where(packageToken => (SteamTokenDumperPlugin.Config?.SecretPackageIDs.Contains(packageToken.Key) == false) && (packageToken.Value > 0) && (!SubmittedPackages.TryGetValue(packageToken.Key, out ulong token) || (packageToken.Value != token))).ToDictionary(static packageToken => packageToken.Key, static packageToken => packageToken.Value); + + internal Dictionary GetPackageTokensForSubmission() { + if (ASF.GlobalDatabase == null) { + throw new InvalidOperationException(nameof(ASF.GlobalDatabase)); + } + + return ASF.GlobalDatabase.PackageAccessTokensReadOnly.Where(packageToken => (SteamTokenDumperPlugin.Config?.SecretPackageIDs.Contains(packageToken.Key) == false) && (packageToken.Value > 0) && (!SubmittedPackages.TryGetValue(packageToken.Key, out ulong token) || (packageToken.Value != token))).ToDictionary(static packageToken => packageToken.Key, static packageToken => packageToken.Value); + } internal static async Task Load() { if (!File.Exists(SharedFilePath)) { @@ -180,7 +181,6 @@ internal void Reset(bool clear = false) { if (clear) { AppTokens.Clear(); DepotKeys.Clear(); - PackageTokens.Clear(); } Utilities.InBackground(Save); @@ -261,25 +261,6 @@ internal void UpdateDepotKey(SteamApps.DepotKeyCallback depotKeyResult) { Utilities.InBackground(Save); } - internal void UpdatePackageTokens(IReadOnlyCollection> packageTokens) { - ArgumentNullException.ThrowIfNull(packageTokens); - - bool save = false; - - foreach ((uint packageID, ulong packageToken) in packageTokens) { - if (PackageTokens.TryGetValue(packageID, out ulong previousPackageToken) && (previousPackageToken == packageToken)) { - continue; - } - - PackageTokens[packageID] = packageToken; - save = true; - } - - if (save) { - Utilities.InBackground(Save); - } - } - internal void UpdateSubmittedData(IReadOnlyDictionary apps, IReadOnlyDictionary packages, IReadOnlyDictionary depots) { ArgumentNullException.ThrowIfNull(apps); ArgumentNullException.ThrowIfNull(packages); diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index ea912010ab1b6..878dc4f2c7b75 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -304,11 +304,9 @@ private static async void OnLicenseList(Bot bot, SteamApps.LicenseListCallback c throw new InvalidOperationException(nameof(GlobalCache)); } - Dictionary packageTokens = callback.LicenseList.Where(static license => !Config.SecretPackageIDs.Contains(license.PackageID) && ((license.PaymentMethod != EPaymentMethod.AutoGrant) || !Config.SkipAutoGrantPackages)).GroupBy(static license => license.PackageID).ToDictionary(static group => group.Key, static group => group.OrderByDescending(static license => license.TimeCreated).First().AccessToken); + HashSet packageIDs = callback.LicenseList.Where(static license => !Config.SecretPackageIDs.Contains(license.PackageID) && ((license.PaymentMethod != EPaymentMethod.AutoGrant) || !Config.SkipAutoGrantPackages)).Select(static license => license.PackageID).ToHashSet(); - GlobalCache.UpdatePackageTokens(packageTokens); - - await Refresh(bot, packageTokens.Keys).ConfigureAwait(false); + await Refresh(bot, packageIDs).ConfigureAwait(false); } private static async void OnSubmissionTimer(object? state = null) => await SubmitData().ConfigureAwait(false);