diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs index 9e2f642f8..a1b0aa728 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/GlobalCache.cs @@ -22,10 +22,12 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Threading.Tasks; using ArchiSteamFarm.Helpers; +using ArchiSteamFarm.Localization; using Newtonsoft.Json; using SteamKit2; @@ -65,27 +67,37 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { internal Dictionary GetDepotKeysForSubmission() => DepotKeys.Where(depotKey => !string.IsNullOrEmpty(depotKey.Value) && (!SubmittedDepots.TryGetValue(depotKey.Key, out string? key) || (depotKey.Value != key))).ToDictionary(depotKey => depotKey.Key, depotKey => depotKey.Value); internal Dictionary GetPackageTokensForSubmission() => PackageTokens.Where(packageToken => (packageToken.Value > 0) && (!SubmittedPackages.TryGetValue(packageToken.Key, out ulong token) || (packageToken.Value != token))).ToDictionary(packageToken => packageToken.Key, packageToken => packageToken.Value); - internal static async Task Load() { + internal static async Task Load() { if (!File.Exists(SharedFilePath)) { - return new GlobalCache(); + GlobalCache result = new(); + + Utilities.InBackground(result.Save); + + return result; } - GlobalCache? globalCache = null; + GlobalCache? globalCache; try { string json = await RuntimeCompatibility.File.ReadAllTextAsync(SharedFilePath).ConfigureAwait(false); - if (!string.IsNullOrEmpty(json)) { - globalCache = JsonConvert.DeserializeObject(json); + if (string.IsNullOrEmpty(json)) { + ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(json))); + + return null; } + + globalCache = JsonConvert.DeserializeObject(json); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); + + return null; } if (globalCache == null) { - ASF.ArchiLogger.LogGenericError($"{nameof(GlobalCache)} could not be loaded, a fresh instance will be initialized."); + ASF.ArchiLogger.LogNullError(nameof(globalCache)); - globalCache = new GlobalCache(); + return null; } return globalCache; @@ -104,8 +116,6 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - ASF.ArchiLogger.LogGenericTrace($"{LastChangeNumber} => {currentChangeNumber}"); - LastChangeNumber = currentChangeNumber; foreach ((uint appID, SteamApps.PICSChangesCallback.PICSChangeData appData) in appChanges) { @@ -114,7 +124,6 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { } AppChangeNumbers.TryRemove(appID, out _); - ASF.ArchiLogger.LogGenericTrace($"App needs refresh: {appID}"); } Utilities.InBackground(Save); @@ -129,8 +138,6 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - ASF.ArchiLogger.LogGenericDebug($"RESET {LastChangeNumber} => {currentChangeNumber}"); - LastChangeNumber = currentChangeNumber; AppChangeNumbers.Clear(); @@ -203,7 +210,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { bool save = false; foreach (SteamApps.DepotKeyCallback depotKeyResult in depotKeyResults) { - if (depotKeyResult?.Result != EResult.OK) { + if (depotKeyResult.Result != EResult.OK) { continue; } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs index d7130b859..d1296a358 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.Designer.cs @@ -60,6 +60,114 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Localization { } } + /// + /// Looks up a localized string similar to Finished retrieving {0} app access tokens.. + /// + internal static string BotFinishedRetrievingAppAccessTokens { + get { + return ResourceManager.GetString("BotFinishedRetrievingAppAccessTokens", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Finished retrieving {0} app infos.. + /// + internal static string BotFinishedRetrievingAppInfos { + get { + return ResourceManager.GetString("BotFinishedRetrievingAppInfos", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Finished retrieving {0} depot keys.. + /// + internal static string BotFinishedRetrievingDepotKeys { + get { + return ResourceManager.GetString("BotFinishedRetrievingDepotKeys", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Finished retrieving a total of {0} app access tokens.. + /// + internal static string BotFinishedRetrievingTotalAppAccessTokens { + get { + return ResourceManager.GetString("BotFinishedRetrievingTotalAppAccessTokens", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Finished retrieving all depot keys for a total of {0} apps.. + /// + internal static string BotFinishedRetrievingTotalDepots { + get { + return ResourceManager.GetString("BotFinishedRetrievingTotalDepots", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There are no apps that require a refresh on this bot instance.. + /// + internal static string BotNoAppsToRefresh { + get { + return ResourceManager.GetString("BotNoAppsToRefresh", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Retrieving {0} app access tokens.... + /// + internal static string BotRetrievingAppAccessTokens { + get { + return ResourceManager.GetString("BotRetrievingAppAccessTokens", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Retrieving {0} app infos.... + /// + internal static string BotRetrievingAppInfos { + get { + return ResourceManager.GetString("BotRetrievingAppInfos", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Retrieving {0} depot keys.... + /// + internal static string BotRetrievingDepotKeys { + get { + return ResourceManager.GetString("BotRetrievingDepotKeys", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Retrieving a total of {0} app access tokens.... + /// + internal static string BotRetrievingTotalAppAccessTokens { + get { + return ResourceManager.GetString("BotRetrievingTotalAppAccessTokens", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Retrieving all depots for a total of {0} apps.... + /// + internal static string BotRetrievingTotalDepots { + get { + return ResourceManager.GetString("BotRetrievingTotalDepots", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} could not be loaded, a fresh instance will be initialized.... + /// + internal static string FileCouldNotBeLoadedFreshInit { + get { + return ResourceManager.GetString("FileCouldNotBeLoadedFreshInit", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} is currently disabled according to your configuration. If you'd like to help SteamDB in data submission, please check out our wiki.. /// @@ -86,5 +194,50 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Localization { return ResourceManager.GetString("PluginInitializedAndEnabled", resourceCulture); } } + + /// + /// Looks up a localized string similar to The submission has failed due to too many requests sent, we'll try again in approximately {0} from now.. + /// + internal static string SubmissionFailedTooManyRequests { + get { + return ResourceManager.GetString("SubmissionFailedTooManyRequests", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Submitting a total of registered apps/subs/depots: {0}/{1}/{2}.... + /// + internal static string SubmissionInProgress { + get { + return ResourceManager.GetString("SubmissionInProgress", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Could not submit the data because there is no valid SteamID set that we could classify as a contributor. Consider setting up {0} property.. + /// + internal static string SubmissionNoContributorSet { + get { + return ResourceManager.GetString("SubmissionNoContributorSet", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There is no new data to submit, everything is up-to-date.. + /// + internal static string SubmissionNoNewData { + get { + return ResourceManager.GetString("SubmissionNoNewData", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The data has been successfully submitted. The server has registered a total of new apps/subs/depots: {0}/{1}/{2}.. + /// + internal static string SubmissionSuccessful { + get { + return ResourceManager.GetString("SubmissionSuccessful", resourceCulture); + } + } } } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx index ec8e39800..16eb5f6b9 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/Localization/Strings.resx @@ -129,4 +129,70 @@ {0} has been initialized successfully, thank you in advance for your help. The first submission will happen in approximately {1} from now. {0} will be replaced by the name of the plugin (e.g. "SteamTokenDumperPlugin"), {1} will be replaced by translated TimeSpan string (such as "53 minutes") + + {0} could not be loaded, a fresh instance will be initialized... + {0} will be replaced by the name of the file (e.g. "GlobalCache") + + + There are no apps that require a refresh on this bot instance. + + + Retrieving a total of {0} app access tokens... + {0} will be replaced by the number (total count) of app access tokens being retrieved + + + Retrieving {0} app access tokens... + {0} will be replaced by the number (count this batch) of app access tokens being retrieved + + + Finished retrieving {0} app access tokens. + {0} will be replaced by the number (count this batch) of app access tokens retrieved + + + Finished retrieving a total of {0} app access tokens. + {0} will be replaced by the number (total count) of app access tokens retrieved + + + Retrieving all depots for a total of {0} apps... + {0} will be replaced by the number (total count) of apps being retrieved + + + Retrieving {0} app infos... + {0} will be replaced by the number (count this batch) of app infos being retrieved + + + Finished retrieving {0} app infos. + {0} will be replaced by the number (count this batch) of app infos retrieved + + + Retrieving {0} depot keys... + {0} will be replaced by the number (count this batch) of depot keys being retrieved + + + Finished retrieving {0} depot keys. + {0} will be replaced by the number (count this batch) of depot keys retrieved + + + Finished retrieving all depot keys for a total of {0} apps. + {0} will be replaced by the number (total count) of apps retrieved + + + There is no new data to submit, everything is up-to-date. + + + Could not submit the data because there is no valid SteamID set that we could classify as a contributor. Consider setting up {0} property. + {0} will be replaced by the name of the config property (e.g. "SteamOwnerID") that the user is expected to set + + + Submitting a total of registered apps/subs/depots: {0}/{1}/{2}... + {0} will be replaced by the number of app access tokens being submitted, {1} will be replaced by the number of package access tokens being submitted, {2} will be replaced by the number of depot keys being submitted + + + The submission has failed due to too many requests sent, we'll try again in approximately {0} from now. + {0} will be replaced by translated TimeSpan string (such as "53 minutes") + + + The data has been successfully submitted. The server has registered a total of new apps/subs/depots: {0}/{1}/{2}. + {0} will be replaced by the number of new app access tokens that the server has registered, {1} will be replaced by the number of new package access tokens that the server has registered, {2} will be replaced by the number of new depot keys that the server has registered + diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs index e41dc8caa..d0ef0765e 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/RequestData.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Globalization; using Newtonsoft.Json; using SteamKit2; @@ -73,9 +74,9 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { SteamID = steamID; - Apps = apps.ToImmutableDictionary(app => app.Key.ToString(), app => app.Value.ToString()); - Subs = accessTokens.ToImmutableDictionary(package => package.Key.ToString(), package => package.Value.ToString()); - Depots = depots.ToImmutableDictionary(depot => depot.Key.ToString(), depot => depot.Value); + Apps = apps.ToImmutableDictionary(app => app.Key.ToString(CultureInfo.InvariantCulture), app => app.Value.ToString(CultureInfo.InvariantCulture)); + Subs = accessTokens.ToImmutableDictionary(package => package.Key.ToString(CultureInfo.InvariantCulture), package => package.Value.ToString(CultureInfo.InvariantCulture)); + Depots = depots.ToImmutableDictionary(depot => depot.Key.ToString(CultureInfo.InvariantCulture), depot => depot.Value); } } } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index 2aad5b5bb..98d96546e 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -89,7 +89,17 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - GlobalCache ??= await GlobalCache.Load().ConfigureAwait(false); + if (GlobalCache == null) { + GlobalCache? globalCache = await GlobalCache.Load().ConfigureAwait(false); + + if (globalCache == null) { + ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.FileCouldNotBeLoadedFreshInit, nameof(GlobalCache))); + + globalCache = new GlobalCache(); + } + + GlobalCache = globalCache; + } TimeSpan startIn = TimeSpan.FromMinutes(Utilities.RandomNext(SharedInfo.MinimumMinutesBeforeFirstUpload, SharedInfo.MaximumMinutesBeforeFirstUpload)); @@ -271,12 +281,12 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { } if (appIDsToRefresh.Count == 0) { - bot.ArchiLogger.LogGenericDebug($"There are no apps to refresh for {bot.BotName}."); + bot.ArchiLogger.LogGenericDebug(Strings.BotNoAppsToRefresh); return; } - bot.ArchiLogger.LogGenericInfo($"Retrieving a total of {appIDsToRefresh.Count} app access tokens..."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotRetrievingTotalAppAccessTokens, appIDsToRefresh.Count)); HashSet appIDsThisRound = new(Math.Min(appIDsToRefresh.Count, SharedInfo.AppInfosPerSingleRequest)); @@ -294,7 +304,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - bot.ArchiLogger.LogGenericInfo($"Retrieving {appIDsThisRound.Count} app access tokens..."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotRetrievingAppAccessTokens, appIDsThisRound.Count)); SteamApps.PICSTokensCallback response; @@ -306,7 +316,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - bot.ArchiLogger.LogGenericInfo($"Finished retrieving {appIDsThisRound.Count} app access tokens."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotFinishedRetrievingAppAccessTokens, appIDsThisRound.Count)); appIDsThisRound.Clear(); @@ -314,10 +324,8 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { } } - bot.ArchiLogger.LogGenericInfo($"Finished retrieving a total of {appIDsToRefresh.Count} app access tokens."); - bot.ArchiLogger.LogGenericInfo($"Retrieving all depots for a total of {appIDsToRefresh.Count} apps..."); - - appIDsThisRound.Clear(); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotFinishedRetrievingTotalAppAccessTokens, appIDsToRefresh.Count)); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotRetrievingTotalDepots, appIDsToRefresh.Count)); using (HashSet.Enumerator enumerator = appIDsToRefresh.GetEnumerator()) { while (true) { @@ -333,7 +341,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - bot.ArchiLogger.LogGenericInfo($"Retrieving {appIDsThisRound.Count} app infos..."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotRetrievingAppInfos, appIDsThisRound.Count)); AsyncJobMultiple.ResultSet response; @@ -351,7 +359,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - bot.ArchiLogger.LogGenericInfo($"Finished retrieving {appIDsThisRound.Count} app infos."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotFinishedRetrievingAppInfos, appIDsThisRound.Count)); appIDsThisRound.Clear(); @@ -376,7 +384,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { GlobalCache.UpdateAppChangeNumbers(appChangeNumbers); if (depotTasks.Count > 0) { - bot.ArchiLogger.LogGenericInfo($"Retrieving {depotTasks.Count} depot keys..."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotRetrievingDepotKeys, depotTasks.Count)); IList results; @@ -388,14 +396,14 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - bot.ArchiLogger.LogGenericInfo($"Finished retrieving {depotTasks.Count} depot keys."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotFinishedRetrievingDepotKeys, depotTasks.Count)); GlobalCache.UpdateDepotKeys(results); } } } - bot.ArchiLogger.LogGenericInfo($"Finished retrieving all depot keys for a total of {appIDsToRefresh.Count} apps."); + bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotFinishedRetrievingTotalDepots, appIDsToRefresh.Count)); } finally { TimeSpan timeSpan = TimeSpan.FromHours(SharedInfo.MaximumHoursBetweenRefresh); @@ -428,8 +436,6 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { } if (!await SubmissionSemaphore.WaitAsync(0).ConfigureAwait(false)) { - ASF.ArchiLogger.LogGenericDebug($"Skipped {nameof(SubmitData)} trigger because there is already one in progress."); - return; } @@ -439,7 +445,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { Dictionary depotKeys = GlobalCache.GetDepotKeysForSubmission(); if ((appTokens.Count == 0) && (packageTokens.Count == 0) && (depotKeys.Count == 0)) { - ASF.ArchiLogger.LogGenericInfo("There is no new data to submit, everything up-to-date."); + ASF.ArchiLogger.LogGenericInfo(Strings.SubmissionNoNewData); return; } @@ -447,14 +453,14 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { ulong contributorSteamID = (ASF.GlobalConfig.SteamOwnerID > 0) && new SteamID(ASF.GlobalConfig.SteamOwnerID).IsIndividualAccount ? ASF.GlobalConfig.SteamOwnerID : Bot.Bots.Values.Where(bot => bot.SteamID > 0).OrderByDescending(bot => bot.OwnedPackageIDsReadOnly.Count).FirstOrDefault()?.SteamID ?? 0; if (contributorSteamID == 0) { - ASF.ArchiLogger.LogGenericError($"Skipped {nameof(SubmitData)} trigger because there is no valid steamID we could classify as a contributor. Consider setting up {nameof(ASF.GlobalConfig.SteamOwnerID)} property."); + ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.SubmissionNoContributorSet, nameof(ASF.GlobalConfig.SteamOwnerID))); return; } RequestData requestData = new(contributorSteamID, appTokens, packageTokens, depotKeys); - ASF.ArchiLogger.LogGenericInfo($"Submitting registered apps/subs/depots: {appTokens.Count}/{packageTokens.Count}/{depotKeys.Count}..."); + ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.SubmissionInProgress, appTokens.Count, packageTokens.Count, depotKeys.Count)); WebBrowser.ObjectResponse? response = await ASF.WebBrowser.UrlPostToJsonObject(request, data: requestData, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors).ConfigureAwait(false); @@ -478,14 +484,14 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { SubmissionTimer.Change(startIn, TimeSpan.FromHours(SharedInfo.MinimumHoursBetweenUploads)); } - ASF.ArchiLogger.LogGenericInfo($"The submission will happen in approximately {startIn.ToHumanReadable()} from now."); + ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.SubmissionFailedTooManyRequests, startIn.ToHumanReadable())); } return; } if (!response.Content.Success) { - ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, ArchiSteamFarm.Localization.Strings.ErrorIsInvalid), nameof(response.Content.Success)); + ASF.ArchiLogger.LogGenericError(ArchiSteamFarm.Localization.Strings.WarningFailed); return; } @@ -496,7 +502,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { return; } - ASF.ArchiLogger.LogGenericInfo($"Data successfully submitted. Newly registered apps/subs/depots: {response.Content.Data.NewAppsCount}/{response.Content.Data.NewSubsCount}/{response.Content.Data.NewDepotsCount}."); + ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.SubmissionSuccessful, response.Content.Data.NewAppsCount, response.Content.Data.NewSubsCount, response.Content.Data.NewDepotsCount)); GlobalCache.UpdateSubmittedData(appTokens, packageTokens, depotKeys); } finally {