From ccd056ba30e361ca9132b0867535edee9ec1b51d Mon Sep 17 00:00:00 2001 From: Citrinate Date: Fri, 22 Mar 2024 15:43:45 -0400 Subject: [PATCH] Move translatable strings into a resource file --- CS2Interface/CS/Client.cs | 75 ++--- CS2Interface/CS/GameData.cs | 5 +- CS2Interface/CS2Interface.csproj | 13 + CS2Interface/Commands.cs | 13 +- CS2Interface/Data/GameDataItems.cs | 5 +- CS2Interface/Data/ItemData.cs | 3 +- CS2Interface/Handlers/ClientHandler.cs | 49 +-- .../IPC/Api/CS2InterfaceController.cs | 17 +- CS2Interface/Localization/Strings.resx | 300 ++++++++++++++++++ 9 files changed, 398 insertions(+), 82 deletions(-) create mode 100644 CS2Interface/Localization/Strings.resx diff --git a/CS2Interface/CS/Client.cs b/CS2Interface/CS/Client.cs index 7dc14d1..16e610c 100644 --- a/CS2Interface/CS/Client.cs +++ b/CS2Interface/CS/Client.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using ArchiSteamFarm.Steam; +using CS2Interface.Localization; using ProtoBuf; using SteamKit2; using SteamKit2.GC; @@ -38,17 +39,17 @@ internal async Task Run() { } if (ConnectionSemaphore.CurrentCount != 1) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Client is already attempting to run, please wait"); + throw new ClientException(EClientExceptionType.Failed, Strings.ClientAlreadyStarting); } if (FatalError) { - throw new ClientException(EClientExceptionType.FatalError, "CS2 Client experienced a fatal error"); + throw new ClientException(EClientExceptionType.FatalError, Strings.ClientFatalError); } await ConnectionSemaphore.WaitAsync().ConfigureAwait(false); try { if (!await GameData.IsLoaded(0).ConfigureAwait(false)) { - throw new ClientException(EClientExceptionType.Failed, "Failed to load Game Data"); + throw new ClientException(EClientExceptionType.Failed, Strings.GameDataLoadingFailed); } // TODO: Verify that this account owns CS2 @@ -69,10 +70,10 @@ internal async Task Run() { }}; var fetcher = new GCFetcher((uint) EGCBaseClientMsg.k_EMsgGCClientWelcome); - Bot.ArchiLogger.LogGenericDebug("Sending hello message"); + Bot.ArchiLogger.LogGenericDebug(Strings.SendingHello); if (fetcher.Fetch(this, msg, resendMsg: true) == null) { - throw new ClientException(EClientExceptionType.Timeout, "CS2 Client wasn't able to connect to GC"); + throw new ClientException(EClientExceptionType.Timeout, Strings.GCConnectionFailed); } HasGCSession = true; @@ -110,7 +111,7 @@ internal async Task VerifyConnection() { return false; } - Bot.ArchiLogger.LogGenericDebug("Verifying CS2 Client's connection to GC"); + Bot.ArchiLogger.LogGenericDebug(Strings.VerifyingGCConnection); try { await RequestPlayerProfile(Bot.SteamID).ConfigureAwait(false); } catch { @@ -126,7 +127,7 @@ private void OnGCMessage(SteamGameCoordinator.MessageCallback callback) { } #if DEBUG - Bot.ArchiLogger.LogGenericDebug(String.Format("Message Received: {0}", callback.EMsg)); + Bot.ArchiLogger.LogGenericDebug(String.Format("{0}: {1}", Strings.MessageRecieved, callback.EMsg)); #endif OnGCMessageRecieved?.Invoke(callback); @@ -167,7 +168,7 @@ private void OnClientWelcome(IPacketGCMsg packetMsg) { } })); - Bot.ArchiLogger.LogGenericDebug("CS2 inventory loaded"); + Bot.ArchiLogger.LogGenericDebug(Strings.InventoryLoaded); return; } @@ -177,7 +178,7 @@ private void OnClientWelcome(IPacketGCMsg packetMsg) { private void OnFatalLogonError(IPacketGCMsg packetMsg) { var msg = new ClientGCMsgProtobuf(packetMsg); - Bot.ArchiLogger.LogGenericError(String.Format("Fatal CS2 logon error {0}: {1}", msg.Body.errorcode, msg.Body.message)); + Bot.ArchiLogger.LogGenericError(String.Format("{0}: {1}", String.Format(Strings.FatalLogonError, msg.Body.errorcode), msg.Body.message)); FatalError = true; } @@ -253,7 +254,7 @@ private void OnMultiItemUpdated(IPacketGCMsg packetMsg) { internal async Task InspectItem(ulong param_s, ulong param_a, ulong param_d, ulong param_m) { if (!HasGCSession) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Client is not connected to GC"); + throw new ClientException(EClientExceptionType.Failed, Strings.ClientNotConnectedToGC); } await GCSemaphore.WaitAsync().ConfigureAwait(false); @@ -271,11 +272,11 @@ internal async Task In VerifyFunc = response => response.Body.iteminfo.itemid == param_a }; - Bot.ArchiLogger.LogGenericDebug(String.Format("Inspecting item: s {0} a {1} d {2} m {3}", param_s, param_a, param_d, param_m)); + Bot.ArchiLogger.LogGenericDebug(String.Format("{0}: s {1} a {2} d {3} m {4}", Strings.InspectingItem, param_s, param_a, param_d, param_m)); var response = fetcher.Fetch(this, msg); if (response == null) { - throw new ClientException(EClientExceptionType.Timeout, "Request timed out"); + throw new ClientException(EClientExceptionType.Timeout, Strings.RequestTimeout); } return response.Body; @@ -286,12 +287,12 @@ internal async Task In internal async Task RequestPlayerProfile(ulong steam_id) { //uint account_id) { if (!HasGCSession) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Client is not connected"); + throw new ClientException(EClientExceptionType.Failed, Strings.ClientNotConnectedToGC); } SteamID SteamID = new(steam_id); if (!SteamID.IsValid || SteamID.AccountUniverse != EUniverse.Public || SteamID.AccountType != EAccountType.Individual || SteamID.AccountInstance != SteamID.DesktopInstance) { - throw new ClientException(EClientExceptionType.BadRequest, "Invalid Steam ID"); + throw new ClientException(EClientExceptionType.BadRequest, Strings.InvalidSteamID); } await GCSemaphore.WaitAsync().ConfigureAwait(false); @@ -308,11 +309,11 @@ internal async Task RequestPlayerProfile(ulon VerifyFunc = response => response.Body.account_profiles.FirstOrDefault()?.account_id == account_id }; - Bot.ArchiLogger.LogGenericDebug(String.Format("Getting CS2 player profile: {0}", steam_id)); + Bot.ArchiLogger.LogGenericDebug(String.Format("{0}: {1}", Strings.InspectingPlayer, steam_id)); var response = fetcher.Fetch(this, msg); if (response == null) { - throw new ClientException(EClientExceptionType.Timeout, "Request timed out"); + throw new ClientException(EClientExceptionType.Timeout, Strings.RequestTimeout); } return response.Body; @@ -323,21 +324,21 @@ internal async Task RequestPlayerProfile(ulon internal async Task> GetCasketContents(ulong casket_id) { if (!HasGCSession) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Client is not connected to GC"); + throw new ClientException(EClientExceptionType.Failed, Strings.ClientNotConnectedToGC); } if (Inventory == null) { - throw new ClientException(EClientExceptionType.Failed, "Inventory not loaded yet"); + throw new ClientException(EClientExceptionType.Failed, Strings.InventoryNotLoaded); } InventoryItem? casket = Inventory.Values.FirstOrDefault(x => x.ItemInfo.id == casket_id); if (casket == null) { - throw new ClientException(EClientExceptionType.BadRequest, "Storage unit not found in inventory"); + throw new ClientException(EClientExceptionType.BadRequest, Strings.CasketNotFound); } uint? items_count = casket.GetAttribute("items count")?.ToUInt32(); if (items_count == null) { - throw new ClientException(EClientExceptionType.Failed, "Could not determine storage unit item count"); + throw new ClientException(EClientExceptionType.Failed, Strings.CasketContentsUndefined); } if (items_count == 0) { @@ -362,21 +363,21 @@ internal async Task> GetCasketContents(ulong casket_id) { VerifyFunc = response => response.Body.item_id.FirstOrDefault() == casket_id && response.Body.request == (uint) EGCItemCustomizationNotification.k_EGCItemCustomizationNotification_CasketContents }; - Bot.ArchiLogger.LogGenericDebug(String.Format("Opening casket {0}", casket_id)); + Bot.ArchiLogger.LogGenericDebug(String.Format(Strings.OpeningCasket, casket_id)); if (fetcher.Fetch(this, msg) == null) { - throw new ClientException(EClientExceptionType.Timeout, "Request timed out"); + throw new ClientException(EClientExceptionType.Timeout, Strings.RequestTimeout); } // Casket contents can sometimes continue to come in after we've recieved the k_EMsgGCItemCustomizationNotification response DateTime waitTime = DateTime.Now.AddSeconds(30); while (Inventory.Values.Where(x => x.CasketID == casket_id).Count() != items_count && DateTime.Now < waitTime) { - Bot.ArchiLogger.LogGenericDebug(String.Format("Waiting for casket {0} items", casket_id)); + Bot.ArchiLogger.LogGenericDebug(String.Format(Strings.CasketContentsLoading, casket_id)); await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); } if (Inventory.Values.Where(x => x.CasketID == casket_id).Count() != items_count) { - throw new ClientException(EClientExceptionType.Failed, String.Format("Casket item count mismatch, casket should have {0} items but only found {1}", items_count, Inventory.Values.Where(x => x.CasketID == casket_id).Count())); + throw new ClientException(EClientExceptionType.Failed, String.Format(Strings.CasketItemCountMismatch, items_count, Inventory.Values.Where(x => x.CasketID == casket_id).Count())); } return Inventory.Values.Where(x => x.CasketID == casket_id).ToList(); @@ -387,27 +388,27 @@ internal async Task> GetCasketContents(ulong casket_id) { internal async Task AddItemToCasket(ulong casket_id, ulong item_id) { if (!HasGCSession) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Client is not connected to GC"); + throw new ClientException(EClientExceptionType.Failed, Strings.ClientNotConnectedToGC); } if (Inventory == null) { - throw new ClientException(EClientExceptionType.Failed, "Inventory not loaded yet"); + throw new ClientException(EClientExceptionType.Failed, Strings.InventoryNotLoaded); } if (Inventory.Values.FirstOrDefault(x => x.ItemInfo.id == item_id) == null) { - throw new ClientException(EClientExceptionType.BadRequest, "Item not found in inventory"); + throw new ClientException(EClientExceptionType.BadRequest, Strings.InventoryItemNotFound); } InventoryItem? casket = Inventory.Values.FirstOrDefault(x => x.ItemInfo.id == casket_id); if (casket == null) { - throw new ClientException(EClientExceptionType.BadRequest, "Storage unit not found in inventory"); + throw new ClientException(EClientExceptionType.BadRequest, Strings.CasketNotFound); } uint? items_count = casket.GetAttribute("items count")?.ToUInt32(); if (items_count == null) { - throw new ClientException(EClientExceptionType.Failed, "Could not determine storage unit item count"); + throw new ClientException(EClientExceptionType.Failed, Strings.CasketContentsUndefined); } else if (items_count == 1000) { - throw new ClientException(EClientExceptionType.BadRequest, "Storage unit is full"); + throw new ClientException(EClientExceptionType.BadRequest, Strings.CasketFull); } await GCSemaphore.WaitAsync().ConfigureAwait(false); @@ -437,10 +438,10 @@ internal async Task AddItemToCasket(ulong casket_id, ulong item_id) { } }; - Bot.ArchiLogger.LogGenericDebug(String.Format("Adding item {0} to casket {1}", item_id, casket_id)); + Bot.ArchiLogger.LogGenericDebug(String.Format(Strings.AddingItemToCasket, item_id, casket_id)); if (fetcher.Fetch(this, msg) == null) { - throw new ClientException(EClientExceptionType.Timeout, "Request timed out"); + throw new ClientException(EClientExceptionType.Timeout, Strings.RequestTimeout); } return true; @@ -451,16 +452,16 @@ internal async Task AddItemToCasket(ulong casket_id, ulong item_id) { internal async Task RemoveItemFromCasket(ulong casket_id, ulong item_id) { if (!HasGCSession) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Client is not connected to GC"); + throw new ClientException(EClientExceptionType.Failed, Strings.ClientNotConnectedToGC); } if (Inventory == null) { - throw new ClientException(EClientExceptionType.Failed, "Inventory not loaded yet"); + throw new ClientException(EClientExceptionType.Failed, Strings.InventoryNotLoaded); } InventoryItem? casket = Inventory.Values.FirstOrDefault(x => x.ItemInfo.id == casket_id); if (casket == null) { - throw new ClientException(EClientExceptionType.BadRequest, "Storage unit not found in inventory"); + throw new ClientException(EClientExceptionType.BadRequest, Strings.CasketNotFound); } // Does not verify that the item is actually in the crate, to do that we would need to request the crate contents first @@ -492,10 +493,10 @@ internal async Task RemoveItemFromCasket(ulong casket_id, ulong item_id) { } }; - Bot.ArchiLogger.LogGenericDebug(String.Format("Removing item {0} from casket {1}", item_id, casket_id)); + Bot.ArchiLogger.LogGenericDebug(String.Format(Strings.RemovingItemFromCasket, item_id, casket_id)); if (fetcher.Fetch(this, msg) == null) { - throw new ClientException(EClientExceptionType.Timeout, "Request timed out"); + throw new ClientException(EClientExceptionType.Timeout, Strings.RequestTimeout); } return true; diff --git a/CS2Interface/CS/GameData.cs b/CS2Interface/CS/GameData.cs index da55cfd..2e844d7 100644 --- a/CS2Interface/CS/GameData.cs +++ b/CS2Interface/CS/GameData.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Threading.Tasks; using ArchiSteamFarm.Core; +using CS2Interface.Localization; namespace CS2Interface { internal static class GameData { @@ -21,7 +22,7 @@ internal static void Update(bool forceUpdate = false) { ItemsGameCdn.Updated = false; CsgoEnglish.Updated = false; DoNotUpdateUntil = DateTime.Now.AddMinutes(15); - ASF.ArchiLogger.LogGenericInfo("Refreshing CS2 game data"); + ASF.ArchiLogger.LogGenericInfo(Strings.GameDataRefreshing); } if (!ItemsGame.Updated || !ItemsGameCdn.Updated || !CsgoEnglish.Updated) { @@ -72,7 +73,7 @@ private static async Task DoUpdate() { if (ItemsGame.Updated && ItemsGameCdn.Updated && CsgoEnglish.Updated) { UpdateTimer.Change(Timeout.Infinite, Timeout.Infinite); IsUpdating = false; - ASF.ArchiLogger.LogGenericInfo("CS2 game data loaded"); + ASF.ArchiLogger.LogGenericInfo(Strings.GameDataLoadingSuccess); } } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); diff --git a/CS2Interface/CS2Interface.csproj b/CS2Interface/CS2Interface.csproj index 94b0e8d..04a11e7 100644 --- a/CS2Interface/CS2Interface.csproj +++ b/CS2Interface/CS2Interface.csproj @@ -7,6 +7,7 @@ latest net8.0 true + PrepareResources;$(CompileDependsOn) @@ -17,4 +18,16 @@ + + + + MSBuild:Compile + Strings.Designer.cs + $(IntermediateOutputPath)\Strings.Designer.cs + CSharp + CS2Interface.Localization + Strings + + + diff --git a/CS2Interface/Commands.cs b/CS2Interface/Commands.cs index dff0efc..46e7ec0 100644 --- a/CS2Interface/Commands.cs +++ b/CS2Interface/Commands.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using ArchiSteamFarm.Core; using System.Collections.Generic; -using ArchiSteamFarm.Localization; using System.Linq; namespace CS2Interface { @@ -61,7 +60,7 @@ internal static class Commands { } if (!bot.IsConnectedAndLoggedOn) { - return FormatBotResponse(bot, Strings.BotNotConnected); + return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected); } (_, string message) = await ClientHandler.ClientHandlers[bot.BotName].Run().ConfigureAwait(false); @@ -77,7 +76,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; } IList results = await Utilities.InParallel(bots.Select(bot => ResponseRun(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); @@ -93,7 +92,7 @@ internal static class Commands { } if (!bot.IsConnectedAndLoggedOn) { - return FormatBotResponse(bot, Strings.BotNotConnected); + return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected); } string message = ClientHandler.ClientHandlers[bot.BotName].Stop(); @@ -109,7 +108,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 => ResponseStop(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID))); @@ -125,7 +124,7 @@ internal static class Commands { } if (!bot.IsConnectedAndLoggedOn) { - return FormatBotResponse(bot, Strings.BotNotConnected); + return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected); } (_, string message) = ClientHandler.ClientHandlers[bot.BotName].Status(); @@ -141,7 +140,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 => ResponseStatus(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID))); diff --git a/CS2Interface/Data/GameDataItems.cs b/CS2Interface/Data/GameDataItems.cs index a8f5211..cc2fbee 100644 --- a/CS2Interface/Data/GameDataItems.cs +++ b/CS2Interface/Data/GameDataItems.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using ArchiSteamFarm.Core; +using CS2Interface.Localization; using SteamKit2; namespace CS2Interface { @@ -14,7 +15,7 @@ internal GameDataItems(string url) : base(url) {} internal async Task Update() { KeyValue? data = await FetchKVResource().ConfigureAwait(false); if (data == null) { - ASF.ArchiLogger.LogGenericError(String.Format("Couldn't load game data from: {0}", Url)); + ASF.ArchiLogger.LogGenericError(String.Format(Strings.GameDataSourceFailed, Url)); return false; } @@ -44,7 +45,7 @@ internal List? this[string? key] { if (def == null) { if (!suppressErrorLogs) { - ASF.ArchiLogger.LogGenericError(String.Format("Couldn't find definition: {0}[{1}]", value, index)); + ASF.ArchiLogger.LogGenericError(String.Format("{0}: {1}[{2}]", Strings.GameDataDefinitionUndefined, value, index)); } return null; diff --git a/CS2Interface/Data/ItemData.cs b/CS2Interface/Data/ItemData.cs index 9dfa04a..0e1de19 100644 --- a/CS2Interface/Data/ItemData.cs +++ b/CS2Interface/Data/ItemData.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json.Serialization; using ArchiSteamFarm.Core; +using CS2Interface.Localization; using SteamKit2; namespace CS2Interface { @@ -73,7 +74,7 @@ private bool MergePrefab(ItemDef itemDef, string? prefab) { } if (!foundValid) { - ASF.ArchiLogger.LogGenericError(String.Format("Couldn't find definition: prefabs[{0}]", prefab)); + ASF.ArchiLogger.LogGenericError(String.Format("{0}: prefabs[{1}]", Strings.GameDataDefinitionUndefined, prefab)); } return foundValid; diff --git a/CS2Interface/Handlers/ClientHandler.cs b/CS2Interface/Handlers/ClientHandler.cs index f67bfe2..bd80f41 100644 --- a/CS2Interface/Handlers/ClientHandler.cs +++ b/CS2Interface/Handlers/ClientHandler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using ArchiSteamFarm.Steam; +using CS2Interface.Localization; using SteamKit2; namespace CS2Interface { @@ -26,7 +27,7 @@ internal static void AddHandler(Bot bot, CallbackManager callbackManager) { internal async Task<(bool Success, string Message)> Run(int numAttempts = 3) { if (!Bot.IsConnectedAndLoggedOn) { - return (false, "Bot is not connected"); + return (false, ArchiSteamFarm.Localization.Strings.BotNotConnected); } (_, _, EClientStatus status) = await VerifyConnection().ConfigureAwait(false); @@ -34,55 +35,55 @@ internal static void AddHandler(Bot bot, CallbackManager callbackManager) { bool ready = ((status & EClientStatus.Ready) == EClientStatus.Ready); if (connected) { - return (true, "CS2 Interface is already running"); + return (true, Strings.InterfaceAlreadyRunning); } if (!connected && !ready) { - return (false, "CS2 Interface is already attempting to run"); + return (false, Strings.InterfaceAlreadyStarting); } try { await Client.Run().ConfigureAwait(false); if (!await Client.VerifyConnection().ConfigureAwait(false)) { - throw new ClientException(EClientExceptionType.Failed, "CS2 Interface seemed to start, but then didn't"); + throw new ClientException(EClientExceptionType.Failed, Strings.InterfaceStartFailedUnexpectedly); } } catch (ClientException e) { Bot.ArchiLogger.LogGenericError(e.Message); if (numAttempts > 0 && e.Type != EClientExceptionType.FatalError) { await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false); - Bot.ArchiLogger.LogGenericError("CS2 Interface failed to start, retrying"); + Bot.ArchiLogger.LogGenericError(Strings.InterfaceStartFailedRetry); return await Run(numAttempts - 1).ConfigureAwait(false); } ForceStop(); Bot.Actions.Resume(); - Bot.ArchiLogger.LogGenericError("CS2 Interface failed to start"); + Bot.ArchiLogger.LogGenericError(Strings.InterfaceStartFailed); - return (false, String.Format("CS2 Interface failed to start: {0}", e.Message)); + return (false, String.Format("{0}: {1}", Strings.InterfaceStartFailed, e.Message)); } - Bot.ArchiLogger.LogGenericInfo("CS2 Interface started"); + Bot.ArchiLogger.LogGenericInfo(Strings.InterfaceStarted); - return (true, "CS2 Interface started"); + return (true, Strings.InterfaceStarted); } internal string Stop() { if (!Bot.IsConnectedAndLoggedOn) { - return "Bot is not connected"; + return ArchiSteamFarm.Localization.Strings.BotNotConnected; } EClientStatus status = Client.Status(); bool connected = ((status & EClientStatus.Connected) == EClientStatus.Connected); if (!connected) { - return "CS2 Interface was not running"; + return Strings.IntefaceNotRunning; } Client.Stop(); Bot.Actions.Resume(); - Bot.ArchiLogger.LogGenericInfo("CS2 Interface stopped"); + Bot.ArchiLogger.LogGenericInfo(Strings.InterfaceStopped); - return "CS2 Interface successfully stopped"; + return Strings.InterfaceStoppedSuccessfully; } internal void ForceStop() { @@ -91,13 +92,13 @@ internal void ForceStop() { if (connected) { Client.Stop(); // Stop even if bot is logged out, to update the client state Bot.Actions.Resume(); - Bot.ArchiLogger.LogGenericInfo("CS2 Interface was forcibly stopped"); + Bot.ArchiLogger.LogGenericInfo(Strings.InterfaceForciblyStopped); } } internal (EClientStatus ClientStatus, string Message) Status() { if (!Bot.IsConnectedAndLoggedOn) { - return (EClientStatus.None, "Bot is not connected"); + return (EClientStatus.None, ArchiSteamFarm.Localization.Strings.BotNotConnected); } EClientStatus status = Client.Status(); @@ -106,17 +107,17 @@ internal void ForceStop() { if (!connected) { if (!ready) { - return (status, "CS2 Interface is connecting"); + return (status, Strings.InterfaceConnecting); } - return (status, "CS2 Interface is not connected"); + return (status, Strings.InterfaceNotConnected); } if (!ready) { - return (status, "CS2 Interface is busy"); + return (status, Strings.InterfaceBusy); } - return (status, "Ready"); + return (status, Strings.Ready); } internal async Task<(bool Connected, string Message, EClientStatus ClientStatus)> VerifyConnection() { @@ -124,18 +125,18 @@ internal void ForceStop() { bool connected = ((status & EClientStatus.Connected) == EClientStatus.Connected); if (!connected) { - return (false, "CS2 Interface is not connected", status); + return (false, Strings.InterfaceNotConnected, status); } connected = await Client.VerifyConnection().ConfigureAwait(false); if (!connected) { ForceStop(); - Bot.ArchiLogger.LogGenericError("CS2 Interface stopped unexpectedly"); + Bot.ArchiLogger.LogGenericError(Strings.InterfaceStoppedUnexpectedly); - return (false, "CS2 Interface stopped unexpectedly", Client.Status()); + return (false, Strings.InterfaceStoppedUnexpectedly, Client.Status()); } - return (true, "CS2 Interface is connected", Client.Status()); + return (true, Strings.InterfaceConnected, Client.Status()); } internal static (Bot?, Client?, string) GetAvailableClient(HashSet bots) { @@ -146,7 +147,7 @@ internal static (Bot?, Client?, string) GetAvailableClient(HashSet bots) { } } - return (null, null, "No bots are available"); + return (null, null, Strings.NoBotsAvailable); } internal (Client?, string) GetClient(EClientStatus desiredStatus = EClientStatus.Connected | EClientStatus.Ready) { diff --git a/CS2Interface/IPC/Api/CS2InterfaceController.cs b/CS2Interface/IPC/Api/CS2InterfaceController.cs index b1e3d47..da0a799 100644 --- a/CS2Interface/IPC/Api/CS2InterfaceController.cs +++ b/CS2Interface/IPC/Api/CS2InterfaceController.cs @@ -7,7 +7,6 @@ using ArchiSteamFarm.Core; using ArchiSteamFarm.IPC.Controllers.Api; using ArchiSteamFarm.IPC.Responses; -using ArchiSteamFarm.Localization; using ArchiSteamFarm.Steam; using Microsoft.AspNetCore.Mvc; using SteamKit2.GC.CSGO.Internal; @@ -28,7 +27,7 @@ public async Task> Start([FromRoute] string botNam 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))); } IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(static bot => ClientHandler.ClientHandlers[bot.BotName].Run())).ConfigureAwait(false); @@ -48,7 +47,7 @@ public ActionResult Stop([FromRoute] 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))); } IEnumerable results = bots.Select(static bot => ClientHandler.ClientHandlers[bot.BotName].Stop()); @@ -92,7 +91,7 @@ public async Task> InspectItem( 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, Client? client, string status) = ClientHandler.GetAvailableClient(bots); @@ -148,7 +147,7 @@ public async Task> PlayerProfile([FromRoute] strin 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))); } (Client? client, string client_status) = ClientHandler.ClientHandlers[bot.BotName].GetClient(); @@ -186,7 +185,7 @@ public ActionResult Inventory( 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))); } (Client? client, string status) = ClientHandler.ClientHandlers[bot.BotName].GetClient(EClientStatus.Connected); @@ -227,7 +226,7 @@ public async Task> GetCrateContents( 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))); } (Client? client, string client_status) = ClientHandler.ClientHandlers[bot.BotName].GetClient(); @@ -259,7 +258,7 @@ public async Task> StoreItem([FromRoute] 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))); } (Client? client, string client_status) = ClientHandler.ClientHandlers[bot.BotName].GetClient(); @@ -288,7 +287,7 @@ public async Task> RetrieveItem([FromRoute] string 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))); } (Client? client, string client_status) = ClientHandler.ClientHandlers[bot.BotName].GetClient(); diff --git a/CS2Interface/Localization/Strings.resx b/CS2Interface/Localization/Strings.resx new file mode 100644 index 0000000..3f26e89 --- /dev/null +++ b/CS2Interface/Localization/Strings.resx @@ -0,0 +1,300 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + CS2 Client is already attempting to run, please wait + + + + CS2 Client experienced a fatal error + + + + Failed to load Game Data + + + + Sending hello message + + + + CS2 Client wasn't able to connect to GC + + + + Verifying CS2 Client's connection to GC + + + + Message Received + + + + CS2 inventory loaded + + + + Fatal CS2 logon error {0} + {0} will be replaced by a number + + + CS2 Client is not connected to GC + + + + Inspecting item + + + + Request timed out + + + + Invalid Steam ID + + + + Getting CS2 player profile + + + + Inventory not loaded yet + + + + Storage unit not found in inventory + + + + Could not determine storage unit item count + + + + Opening storage unit {0} + {0} will be replaced by a number + + + Waiting for storage unit {0} items + {0} will be replaced by a number + + + Storage unit item count mismatch, storage unit should have {0} items but only found {1} + {0} will be replaced by a number, {1} will be replaced by a number + + + Item not found in inventory + + + + Storage unit is full + + + + Adding item {0} to storage unit {1} + {0} will be replaced by a number, {1} will be replaced by a number + + + Removing item {0} from storage unit {1} + {0} will be replaced by a number, {1} will be replaced by a number + + + CS2 game data loaded + + + + Refreshing CS2 game data + + + + Couldn't load game data from: {0} + {0} will be replaced by a url + + + Couldn't find definition + + + + CS2 Interface is already running + + + + CS2 Interface is already attempting to run + + + + CS2 Interface seemed to start, but then didn't + + + + CS2 Interface failed to start, retrying + + + + CS2 Interface failed to start + + + + CS2 Interface started + + + + CS2 Interface was not running + + + + CS2 Interface stopped + + + + CS2 Interface successfully stopped + + + + CS2 Interface was forcibly stopped + + + + CS2 Interface is connecting + + + + CS2 Interface is not connected + + + + CS2 Interface is busy + + + + Ready + + + + CS2 Interface stopped unexpectedly + + + + CS2 Interface is connected + + + + No bots are available + + + \ No newline at end of file