diff --git a/.gitignore b/.gitignore index b9911e9..bbb789e 100644 --- a/.gitignore +++ b/.gitignore @@ -488,3 +488,6 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + +# https://www.paraesthesia.com/archive/2022/09/30/strongly-typed-resources-with-net-core/ +*.Designer.cs diff --git a/FreePackages/Commands.cs b/FreePackages/Commands.cs index 52d32ec..3473aa0 100644 --- a/FreePackages/Commands.cs +++ b/FreePackages/Commands.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Text; using ArchiSteamFarm.Core; -using ArchiSteamFarm.Localization; using ArchiSteamFarm.Steam; namespace FreePackages { @@ -66,7 +65,7 @@ internal static class Commands { } if (!bot.IsConnectedAndLoggedOn) { - return FormatBotResponse(bot, Strings.BotNotConnected); + return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected); } if (!PackageHandler.Handlers.Keys.Contains(bot.BotName)) { @@ -84,7 +83,7 @@ internal static class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(String.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames)) : null; } IEnumerable results = bots.Select(bot => ResponseClearQueue(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID))); @@ -100,7 +99,7 @@ internal static class Commands { } if (!bot.IsConnectedAndLoggedOn) { - return FormatBotResponse(bot, Strings.BotNotConnected); + return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected); } if (!PackageHandler.Handlers.Keys.Contains(bot.BotName)) { @@ -118,7 +117,7 @@ internal static class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(String.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames)) : null; } IEnumerable results = bots.Select(bot => ResponseQueueStatus(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID))); @@ -134,7 +133,7 @@ internal static class Commands { } if (!bot.IsConnectedAndLoggedOn) { - return FormatBotResponse(bot, Strings.BotNotConnected); + return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected); } if (!PackageHandler.Handlers.Keys.Contains(bot.BotName)) { @@ -154,7 +153,7 @@ internal static class Commands { if ((index > 0) && (entry.Length > index + 1)) { if (!uint.TryParse(entry[(index + 1)..], out gameID) || (gameID == 0)) { - response.AppendLine(FormatBotResponse(bot, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(gameID)))); + response.AppendLine(FormatBotResponse(bot, string.Format(CultureInfo.CurrentCulture, ArchiSteamFarm.Localization.Strings.ErrorIsInvalid, nameof(gameID)))); continue; } @@ -163,7 +162,7 @@ internal static class Commands { } else if (uint.TryParse(entry, out gameID) && (gameID > 0)) { type = "SUB"; } else { - response.AppendLine(FormatBotResponse(bot, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(gameID)))); + response.AppendLine(FormatBotResponse(bot, string.Format(CultureInfo.CurrentCulture, ArchiSteamFarm.Localization.Strings.ErrorIsInvalid, nameof(gameID)))); continue; } @@ -190,7 +189,7 @@ internal static class Commands { HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, botNames)) : null; + return access >= EAccess.Owner ? FormatStaticResponse(String.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames)) : null; } IEnumerable results = bots.Select(bot => ResponseQueueLicense(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), licenses, useFilter)); diff --git a/FreePackages/Data/BotCache.cs b/FreePackages/Data/BotCache.cs index 76aab3e..b0e9f58 100644 --- a/FreePackages/Data/BotCache.cs +++ b/FreePackages/Data/BotCache.cs @@ -8,7 +8,6 @@ using ArchiSteamFarm.Core; using ArchiSteamFarm.Helpers; using ArchiSteamFarm.Helpers.Json; -using ArchiSteamFarm.Localization; using SteamKit2; namespace FreePackages { @@ -68,7 +67,7 @@ internal BotCache(string filePath) : this() { string json = await File.ReadAllTextAsync(filePath).ConfigureAwait(false); if (string.IsNullOrEmpty(json)) { - ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(json))); + ASF.ArchiLogger.LogGenericError(string.Format(ArchiSteamFarm.Localization.Strings.ErrorIsEmpty, nameof(json))); return null; } diff --git a/FreePackages/Data/CardApps.cs b/FreePackages/Data/CardApps.cs index f7b201a..9f09b75 100644 --- a/FreePackages/Data/CardApps.cs +++ b/FreePackages/Data/CardApps.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using ArchiSteamFarm.Core; using ArchiSteamFarm.Web.Responses; +using FreePackages.Localization; namespace FreePackages { internal static class CardApps { @@ -26,7 +27,7 @@ private static async Task DoUpdate() { ObjectResponse? response = await ASF.WebBrowser.UrlGetToJsonObject(request).ConfigureAwait(false); if (response == null) { - ASF.ArchiLogger.LogGenericDebug("Failed to fetch badge data for free packages"); + ASF.ArchiLogger.LogGenericDebug(Strings.BadgeDataFetchFailed); UpdateTimer.Change(TimeSpan.FromMinutes(1), UpdateFrequency); return; @@ -38,7 +39,7 @@ private static async Task DoUpdate() { AppIDs = response.Content.Data.Keys.Select(uint.Parse).ToHashSet(); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); - ASF.ArchiLogger.LogGenericError("Failed to parse badge data for free packages"); + ASF.ArchiLogger.LogGenericError(Strings.BadgeDataParsingFailed); return; } diff --git a/FreePackages/Data/GlobalCache.cs b/FreePackages/Data/GlobalCache.cs index 1d744e8..502b3c7 100644 --- a/FreePackages/Data/GlobalCache.cs +++ b/FreePackages/Data/GlobalCache.cs @@ -5,7 +5,6 @@ using ArchiSteamFarm.Core; using ArchiSteamFarm.Helpers; using ArchiSteamFarm.Helpers.Json; -using ArchiSteamFarm.Localization; namespace FreePackages { internal sealed class GlobalCache : SerializableFile { @@ -34,7 +33,7 @@ internal GlobalCache() { string json = await File.ReadAllTextAsync(SharedFilePath).ConfigureAwait(false); if (string.IsNullOrEmpty(json)) { - ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(json))); + ASF.ArchiLogger.LogGenericError(string.Format(ArchiSteamFarm.Localization.Strings.ErrorIsEmpty, nameof(json))); return null; } diff --git a/FreePackages/FreePackages.csproj b/FreePackages/FreePackages.csproj index feed3e6..0bf2d34 100644 --- a/FreePackages/FreePackages.csproj +++ b/FreePackages/FreePackages.csproj @@ -7,6 +7,7 @@ latest net8.0 true + PrepareResources;$(CompileDependsOn) @@ -21,4 +22,16 @@ + + + + MSBuild:Compile + Strings.Designer.cs + $(IntermediateOutputPath)\Strings.Designer.cs + CSharp + FreePackages.Localization + Strings + + + diff --git a/FreePackages/Handlers/PICSHandler.cs b/FreePackages/Handlers/PICSHandler.cs index 3a29c5a..698ae57 100644 --- a/FreePackages/Handlers/PICSHandler.cs +++ b/FreePackages/Handlers/PICSHandler.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using ArchiSteamFarm.Core; using ArchiSteamFarm.Steam; +using FreePackages.Localization; using SteamKit2; namespace FreePackages { @@ -37,7 +38,7 @@ internal async static Task OnPICSRestart(uint currentChangeNumber) { } uint oldChangeNumber = FreePackages.GlobalCache.LastChangeNumber; - ASF.ArchiLogger.LogGenericDebug(String.Format("PICS restarted, skipping from change number {0} to {1}", oldChangeNumber, currentChangeNumber)); + ASF.ArchiLogger.LogGenericDebug(String.Format(Strings.PICSRestart, oldChangeNumber, currentChangeNumber)); // ASF restarts PICS if either apps or packages needs a full update. Check the old change number, as one of them might still be good. SteamApps.PICSChangesCallback? picsChanges = await FetchPICSChanges(oldChangeNumber, sendAppChangeList: false, sendPackageChangeList: true).ConfigureAwait(false); @@ -48,12 +49,12 @@ internal async static Task OnPICSRestart(uint currentChangeNumber) { if (!picsChanges.RequiresFullAppUpdate) { PackageHandler.AddChanges(picsChanges.AppChanges, new Dictionary()); } else { - ASF.ArchiLogger.LogGenericDebug("Possibly missed some free apps due to PICS restart"); + ASF.ArchiLogger.LogGenericDebug(Strings.MissedApps); // Search for the oldest change number which is still valid for apps var appChanges = await FindOldestPICSChanges(oldChangeNumber + 1, picsChanges.CurrentChangeNumber, findApps: true); if (appChanges != null) { - ASF.ArchiLogger.LogGenericDebug(String.Format("Recovered {0} app changes at change number {1}", appChanges.AppChanges.Count, appChanges.LastChangeNumber + 1)); + ASF.ArchiLogger.LogGenericDebug(String.Format(Strings.RecoveredApps, appChanges.AppChanges.Count, appChanges.LastChangeNumber + 1)); PackageHandler.AddChanges(appChanges.AppChanges, new Dictionary()); } @@ -62,12 +63,12 @@ internal async static Task OnPICSRestart(uint currentChangeNumber) { if (!picsChanges.RequiresFullPackageUpdate) { PackageHandler.AddChanges(new Dictionary(), picsChanges.PackageChanges); } else { - ASF.ArchiLogger.LogGenericDebug("Possibly missed some free packages due to PICS restart"); + ASF.ArchiLogger.LogGenericDebug(Strings.MissedPackages); // Search for the oldest change number which is still valid for packages var packageChanges = await FindOldestPICSChanges(oldChangeNumber + 1, picsChanges.CurrentChangeNumber, findApps: false); if (packageChanges != null) { - ASF.ArchiLogger.LogGenericDebug(String.Format("Recovered {0} package changes at change number {1}", packageChanges.PackageChanges.Count, packageChanges.LastChangeNumber + 1)); + ASF.ArchiLogger.LogGenericDebug(String.Format(Strings.RecoveredPackages, packageChanges.PackageChanges.Count, packageChanges.LastChangeNumber + 1)); PackageHandler.AddChanges(new Dictionary(), packageChanges.PackageChanges); } diff --git a/FreePackages/Handlers/PackageHandler.cs b/FreePackages/Handlers/PackageHandler.cs index d20bb84..6e73ae2 100644 --- a/FreePackages/Handlers/PackageHandler.cs +++ b/FreePackages/Handlers/PackageHandler.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using ArchiSteamFarm.Core; -using ArchiSteamFarm.Localization; using ArchiSteamFarm.Steam; +using FreePackages.Localization; using SteamKit2; namespace FreePackages { @@ -47,14 +47,14 @@ internal static async Task AddHandler(Bot bot, List filterConfigs, int numBotsThatIncludePlaytests = Handlers.Values.Where(x => x.PackageFilter.FilterConfigs.Any(filterConfig => filterConfig.PlaytestMode != EPlaytestMode.None)).Count(); if (numBotsThatIncludePlaytests > 0) { filterConfigs.ForEach(filterConfig => filterConfig.PlaytestMode = EPlaytestMode.None); - bot.ArchiLogger.LogGenericInfo("Changed PlaytestMode to 0 (None), only 1 bot is allowed to use this filter"); + bot.ArchiLogger.LogGenericInfo(Strings.PlaytestConfigLimitTriggered); } } string cacheFilePath = Bot.GetFilePath(String.Format("{0}_{1}", bot.BotName, nameof(FreePackages)), Bot.EFileType.Database); BotCache? botCache = await BotCache.CreateOrLoad(cacheFilePath).ConfigureAwait(false); if (botCache == null) { - bot.ArchiLogger.LogGenericError(String.Format(Strings.ErrorDatabaseInvalid, cacheFilePath)); + bot.ArchiLogger.LogGenericError(String.Format(ArchiSteamFarm.Localization.Strings.ErrorDatabaseInvalid, cacheFilePath)); botCache = new(cacheFilePath); } @@ -98,7 +98,7 @@ private async Task FetchUserData() { UserData? userData = await WebRequest.GetUserData(Bot).ConfigureAwait(false); if (userData == null) { UserDataRefreshTimer.Change(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(15)); - Bot.ArchiLogger.LogGenericError(String.Format(Strings.ErrorObjectIsNull, userData)); + Bot.ArchiLogger.LogGenericError(String.Format(ArchiSteamFarm.Localization.Strings.ErrorObjectIsNull, userData)); return; } @@ -425,7 +425,7 @@ internal string ClearQueue() { int numChangedPackages = BotCache.ChangedPackages.Count; if (numPackages == 0 && numChangedApps == 0 && numChangedPackages == 0) { - return "Queue is empty"; + return Strings.QueueEmpty; } BotCache.Clear(); @@ -433,13 +433,13 @@ internal string ClearQueue() { HashSet responses = new HashSet(); if (numPackages > 0) { - responses.Add(String.Format("{0} free packages removed.", numPackages)); + responses.Add(String.Format(Strings.PackagesRemoved, numPackages)); } if (numChangedApps > 0) { - responses.Add(String.Format("{0} discovered apps removed.", numChangedApps)); + responses.Add(String.Format(Strings.DiscoveredAppsRemoved, numChangedApps)); } if (numChangedPackages > 0) { - responses.Add(String.Format("{0} discovered packages removed.", numChangedPackages)); + responses.Add(String.Format(Strings.DiscoveredPackagesRemoved, numChangedPackages)); } return String.Join(" ", responses); @@ -450,20 +450,20 @@ internal string AddPackage(EPackageType type, uint id, bool useFilter) { if (type == EPackageType.App) { BotCache.AddChanges(appIDs: new HashSet {id}); - return String.Format("Added app/{0} to discovered apps queue", id); + return String.Format(Strings.DiscoveredAppsAdded, String.Format("app/{0}", id)); } else { BotCache.AddChanges(packageIDs: new HashSet {id}); - return String.Format("Added sub/{0} to discovered packages queue", id); + return String.Format(Strings.DiscoveredPackagesAdded, String.Format("sub/{0}", id)); } } PackageQueue.AddPackage(new Package(type, id)); if (type == EPackageType.App) { - return String.Format("Added app/{0} to free packages queue", id); + return String.Format(Strings.AppsQueued, String.Format("app/{0}", id)); } else { - return String.Format("Added sub/{0} to free packages queue", id); + return String.Format(Strings.PackagesQueued, String.Format("sub/{0}", id)); } } diff --git a/FreePackages/Handlers/PackageQueue.cs b/FreePackages/Handlers/PackageQueue.cs index 7a74fc6..2f497e7 100644 --- a/FreePackages/Handlers/PackageQueue.cs +++ b/FreePackages/Handlers/PackageQueue.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using ArchiSteamFarm.Core; using ArchiSteamFarm.Steam; +using FreePackages.Localization; using SteamKit2; namespace FreePackages { @@ -67,7 +68,7 @@ private async Task ProcessQueue() { if (BotCache.NumActivationsPastHour() >= ActivationsPerHour) { DateTime resumeTime = BotCache.GetLastActivation()!.Value.AddHours(1).AddMinutes(1); - Bot.ArchiLogger.LogGenericInfo(String.Format("Pausing free package activations until {0:T}", resumeTime)); + Bot.ArchiLogger.LogGenericInfo(String.Format(Strings.ActivationPaused, String.Format("{0:T}", resumeTime))); UpdateTimer(resumeTime); return; @@ -93,8 +94,8 @@ private async Task ProcessQueue() { if (result == EResult.RateLimitExceeded) { BotCache.AddActivation(DateTime.Now, MaxActivationsPerHour); // However many activations we thought were made, we were wrong. Correct for this by adding a bunch of fake times to our cache DateTime resumeTime = DateTime.Now.AddHours(1).AddMinutes(1); - Bot.ArchiLogger.LogGenericInfo("Free Package rate limit exceeded"); - Bot.ArchiLogger.LogGenericInfo(String.Format("Pausing free package activations until {0:T}", resumeTime)); + Bot.ArchiLogger.LogGenericInfo(Strings.RateLimitExceeded); + Bot.ArchiLogger.LogGenericInfo(String.Format(Strings.ActivationPaused, String.Format("{0:T}", resumeTime))); UpdateTimer(resumeTime); return; @@ -150,14 +151,14 @@ private async Task ClaimFreeApp(uint appID) { // The Result returned by RequestFreeLicense is useless and I've only ever seen it return EResult.OK if (response.Result != EResult.OK) { - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: app/{0} | Status: {1}", appID, response.Result)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("app/{0}", appID), response.Result)); return EResult.Fail; } if (response.GrantedApps.Count > 0 || response.GrantedPackages.Count > 0) { // When only GrantedPackages is empty we probably tried to activate an app we already own. I don't think it's possible for only GrantedApps to be empty - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: app/{0} | Status: {1} | Items: {2}", appID, response.Result, String.Join(", ", response.GrantedApps.Select(x => $"app/{x}").Union(response.GrantedPackages.Select(x => $"sub/{x}"))))); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicenseWithItems, String.Format("app/{0}", appID), response.Result, String.Join(", ", response.GrantedApps.Select(x => $"app/{x}").Union(response.GrantedPackages.Select(x => $"sub/{x}"))))); return EResult.OK; } @@ -172,7 +173,7 @@ private async Task ClaimFreeApp(uint appID) { bool isComingSoon = appDetails?.Data?.ReleaseDate?.ComingSoon ?? true; if (!success || !isFree || isComingSoon) { - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: app/{0} | Status: {1}", appID, EResult.Invalid)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("app/{0}", appID), EResult.Invalid)); return EResult.Invalid; } @@ -182,7 +183,7 @@ private async Task ClaimFreeApp(uint appID) { if (hasPackages) { // Replace the app with the appropriate package and when we try to activate that we'll find out for sure if we're rate limited or not // Note: This is mostly wishful thinking. /api/appdetails rarely shows the free packages for free apps (one example where it does: https://steamdb.info/app/2119270/) - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: app/{0} | Status: Replaced with {1}", appID, String.Join(", ", appDetails!.Data!.Packages.Select(x => $"sub/{x}")))); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("app/{0}", appID), String.Format(Strings.ReplacedWith, String.Join(", ", appDetails!.Data!.Packages.Select(x => $"sub/{x}"))))); BotCache.AddChanges(packageIDs: appDetails.Data.Packages); return EResult.OK; @@ -191,7 +192,7 @@ private async Task ClaimFreeApp(uint appID) { // We could be rate limited, but the app could also be invalid beacause it has no available licenses. It's necessary to assume invalid so we don't get into an infinite loop. // Examples: https://steamdb.info/app/2401570/ on Oct 2, 2023, Attempting to download demo through Steam client gives error "no licenses" // Free games that still have store pages but display "At the request of the publisher, ___ is unlisted on the Steam store and will not appear in search.": https://store.steampowered.com/app/376570/WildStar/ - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: app/{0} | Status: Unknown", appID)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("app/{0}", appID), Strings.Unknown)); return EResult.Invalid; } @@ -210,7 +211,7 @@ private async Task ClaimFreeSub(uint subID) { return EResult.Invalid; } - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: sub/{0} | Status: {1}/{2}", subID, result, purchaseResult)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("sub/{0}", subID), String.Format("{0}/{1}", result, purchaseResult))); if (purchaseResult == EPurchaseResultDetail.RateLimited) { return EResult.RateLimitExceeded; @@ -232,21 +233,21 @@ private async Task ClaimPlaytest(uint appID) { if (response == null) { // Playtest does not exist currently - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: playtest/{0} | Status: Invalid", appID)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("playtest/{0}", appID), Strings.Invalid)); return EResult.Invalid; } if (response.Success != 1) { // Not sure if/when this happens - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: playtest/{0} | Status: Failed", appID)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("playtest/{0}", appID), Strings.Failed)); return EResult.Invalid; } if (response.Granted == null) { // Playtest has limited slots, account was added to the waitlist - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: playtest/{0} | Status: Waitlisted", appID)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("playtest/{0}", appID), Strings.Waitlisted)); // This won't show up in our owned apps until we're accepted, save it so we don't retry BotCache.AddWaitlistedPlaytest(appID); @@ -254,7 +255,7 @@ private async Task ClaimPlaytest(uint appID) { } // Access to playtest granted - Bot.ArchiLogger.LogGenericInfo(string.Format("ID: playtest/{0} | Status: {1}", appID, EResult.OK)); + Bot.ArchiLogger.LogGenericInfo(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("playtest/{0}", appID), EResult.OK)); return EResult.OK; } @@ -263,19 +264,19 @@ internal string GetStatus() { HashSet responses = new HashSet(); int activationsPastHour = Math.Min(BotCache.NumActivationsPastHour(), (int) MaxActivationsPerHour); - responses.Add(String.Format("{0} free packages queued. {1}/{2} hourly activations used.", BotCache.Packages.Count, activationsPastHour, ActivationsPerHour)); + responses.Add(String.Format(Strings.QueueStatus, BotCache.Packages.Count, activationsPastHour, ActivationsPerHour)); if (PauseWhilePlaying && !Bot.IsPlayingPossible) { - responses.Add("Activations are now paused as the account is being used to play a game."); + responses.Add(Strings.QueuePausedWhileIngame); } if (activationsPastHour >= ActivationsPerHour) { DateTime resumeTime = BotCache.GetLastActivation()!.Value.AddHours(1).AddMinutes(1); - responses.Add(String.Format("Activations will resume at {0:T}.", resumeTime)); + responses.Add(String.Format(Strings.QueueLimitedUntil, String.Format("{0:T}", resumeTime))); } if (BotCache.ChangedApps.Count > 0 || BotCache.ChangedPackages.Count > 0) { - responses.Add(String.Format("{0} apps and {1} packages discovered but not processed yet.", BotCache.ChangedApps.Count, BotCache.ChangedPackages.Count)); + responses.Add(String.Format(Strings.QueueDiscoveryStatus, BotCache.ChangedApps.Count, BotCache.ChangedPackages.Count)); } return String.Join(" ", responses);; diff --git a/FreePackages/IPC/Api/FreePackagesController.cs b/FreePackages/IPC/Api/FreePackagesController.cs index 00a71c6..97be617 100644 --- a/FreePackages/IPC/Api/FreePackagesController.cs +++ b/FreePackages/IPC/Api/FreePackagesController.cs @@ -7,8 +7,8 @@ using ArchiSteamFarm.Core; using ArchiSteamFarm.IPC.Controllers.Api; using ArchiSteamFarm.IPC.Responses; -using ArchiSteamFarm.Localization; using ArchiSteamFarm.Steam; +using FreePackages.Localization; using Microsoft.AspNetCore.Mvc; using SteamKit2; using Swashbuckle.AspNetCore.Annotations; @@ -27,12 +27,12 @@ public async Task> GetChangesSince(string botNames HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames))); + return BadRequest(new GenericResponse(false, string.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames))); } Bot? bot = bots.FirstOrDefault(static bot => bot.IsConnectedAndLoggedOn); if (bot == null) { - return BadRequest(new GenericResponse(false, Strings.BotNotConnected)); + return BadRequest(new GenericResponse(false, ArchiSteamFarm.Localization.Strings.BotNotConnected)); } SteamApps.PICSChangesCallback picsChanges; @@ -59,12 +59,12 @@ public async Task> GetProductInfo(string botNames, HashSet? bots = Bot.GetBots(botNames); if ((bots == null) || (bots.Count == 0)) { - return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames))); + return BadRequest(new GenericResponse(false, string.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames))); } Bot? bot = bots.FirstOrDefault(static bot => bot.IsConnectedAndLoggedOn); if (bot == null) { - return BadRequest(new GenericResponse(false, Strings.BotNotConnected)); + return BadRequest(new GenericResponse(false, ArchiSteamFarm.Localization.Strings.BotNotConnected)); } IEnumerable productInfos; @@ -114,24 +114,24 @@ public async Task> RequestFreeAppLicense(string bo Bot? bot = Bot.GetBot(botName); if (bot == null) { - return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botName))); + return BadRequest(new GenericResponse(false, string.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botName))); } if (!bot.IsConnectedAndLoggedOn) { - return BadRequest(new GenericResponse(false, Strings.BotNotConnected)); + return BadRequest(new GenericResponse(false, ArchiSteamFarm.Localization.Strings.BotNotConnected)); } HashSet apps = new(); foreach (string appIDString in appIDs.Split(",", StringSplitOptions.RemoveEmptyEntries)) { if (!uint.TryParse(appIDString, out uint appID)) { - return BadRequest(new GenericResponse(false, String.Format(Strings.ErrorParsingObject, nameof(appIDString)))); + return BadRequest(new GenericResponse(false, String.Format(ArchiSteamFarm.Localization.Strings.ErrorParsingObject, nameof(appIDString)))); } apps.Add(appID); } if (apps.Count == 0) { - return BadRequest(new GenericResponse(false, String.Format(Strings.ErrorIsEmpty, nameof(appIDs)))); + return BadRequest(new GenericResponse(false, String.Format(ArchiSteamFarm.Localization.Strings.ErrorIsEmpty, nameof(appIDs)))); } SteamApps.FreeLicenseCallback response; @@ -157,11 +157,11 @@ public async Task> RequestFreeSubLicense(string bo Bot? bot = Bot.GetBot(botName); if (bot == null) { - return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botName))); + return BadRequest(new GenericResponse(false, string.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botName))); } if (!bot.IsConnectedAndLoggedOn) { - return BadRequest(new GenericResponse(false, Strings.BotNotConnected)); + return BadRequest(new GenericResponse(false, ArchiSteamFarm.Localization.Strings.BotNotConnected)); } EResult result; @@ -188,11 +188,11 @@ public ActionResult GetOwnedPackages(string botName) { Bot? bot = Bot.GetBot(botName); if (bot == null) { - return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botName))); + return BadRequest(new GenericResponse(false, string.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botName))); } if (bot.OwnedPackageIDs.Count == 0) { - return BadRequest(new GenericResponse(false, "No packages found")); + return BadRequest(new GenericResponse(false, Strings.NoPackagesFound)); } return Ok(new GenericResponse>(true, bot.OwnedPackageIDs.Keys)); @@ -210,15 +210,15 @@ public async Task> GetOwnedApps(string botName, bo Bot? bot = Bot.GetBot(botName); if (bot == null) { - return BadRequest(new GenericResponse(false, String.Format(Strings.BotNotFound, botName))); + return BadRequest(new GenericResponse(false, String.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botName))); } if (bot.OwnedPackageIDs.Count == 0) { - return BadRequest(new GenericResponse(false, "No apps found")); + return BadRequest(new GenericResponse(false, Strings.NoAppsFound)); } if (ASF.GlobalDatabase == null) { - return BadRequest(new GenericResponse(false, String.Format(Strings.ErrorObjectIsNull, nameof(ASF.GlobalDatabase)))); + return BadRequest(new GenericResponse(false, String.Format(ArchiSteamFarm.Localization.Strings.ErrorObjectIsNull, nameof(ASF.GlobalDatabase)))); } var ownedPackageIDs = bot.OwnedPackageIDs.Keys.ToHashSet(); @@ -230,7 +230,7 @@ public async Task> GetOwnedApps(string botName, bo try { appList = await WebRequest.GetAppList(bot).ConfigureAwait(false); if (appList == null) { - return BadRequest(new GenericResponse(false, "Failed to get app list")); + return BadRequest(new GenericResponse(false, Strings.AppListFetchFailed)); } } catch (Exception e) { return BadRequest(new GenericResponse(false, e.Message)); @@ -254,11 +254,11 @@ public ActionResult QueueLicenses(string botNames, [FromBody] Q HashSet? bots = Bot.GetBots(botNames); if (bots == null || bots.Count == 0) { - return BadRequest(new GenericResponse(false, String.Format(Strings.BotNotFound, botNames))); + return BadRequest(new GenericResponse(false, String.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames))); } if (PackageHandler.Handlers.Keys.Union(bots.Select(x => x.BotName)).Count() == 0) { - return BadRequest(new GenericResponse(false, "Free Packages plugin not enabled")); + return BadRequest(new GenericResponse(false, Strings.PluginNotEnabled)); } foreach (Bot bot in bots) { diff --git a/FreePackages/Localization/Strings.resx b/FreePackages/Localization/Strings.resx new file mode 100644 index 0000000..3f29a03 --- /dev/null +++ b/FreePackages/Localization/Strings.resx @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Failed to fetch badge data for free packages + + + + Failed to parse badge data for free packages + + + + Changed PlaytestMode to 0 (None), only 1 bot is allowed to use this filter + + + + Queue is empty + + + + {0} free packages removed. + {0} will be replaced by a number + + + {0} discovered apps removed. + {0} will be replaced by a number + + + {0} discovered packages removed. + {0} will be replaced by a number + + + Added {0} to discovered apps queue + {0} will be replaced by an appID + + + Added {0} to discovered packages queue + {0} will be replaced by a subID + + + Added {0} to free packages queue + {0} will be replaced by an appID + + + Added {0} to free packages queue + {0} will be replaced by a subID + + + Pausing free package activations until {0} + {0} will be replaced by a time + + + Free Package rate limit exceeded + + + + Replaced with {0} + {0} will be replaced by a number + + + Unknown + + + + Invalid + + + + Failed + + + + Waitlisted + + + + {0} free packages queued. {1}/{2} hourly activations used. + {0} will be replaced by a number, {1} will be replaced by a number, {2} will be replaced by a number + + + Activations are now paused as the account is being used to play a game. + + + + Activations will resume at {0}. + {0} will be replaced by a time + + + {0} apps and {1} packages discovered but not processed yet. + {0} will be replaced by a number, {1} will be replaced by a number + + + PICS restarted, skipping from change number {0} to {1} + {0} will be replaced by a number, {1} will be replaced by a number + + + Possibly missed some free apps due to PICS restart + + + + Recovered {0} app changes at change number {1} + {0} will be replaced by a number, {1} will be replaced by a number + + + Possibly missed some free packages due to PICS restart + + + + Recovered {0} package changes at change number {1} + {0} will be replaced by a number, {1} will be replaced by a number + + + No packages found + + + + No apps found + + + + Failed to get app list + + + + Free Packages plugin not enabled + + + \ No newline at end of file