From a7a40a77f2c07ea0ea9f6e7bfb57dbe9fce06db7 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 28 Oct 2021 18:06:45 -0300 Subject: [PATCH] Add support for the brazilian portuguese language code (#2792) * Add support for the brazilian portuguese language code * Fix error applet message --- Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs | 12 ++++++------ .../ApplicationProxy/IApplicationFunctions.cs | 4 ++-- Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs | 3 ++- Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs | 3 ++- Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs | 3 ++- Ryujinx/Configuration/System/Language.cs | 3 ++- Ryujinx/Ui/Windows/SettingsWindow.glade | 1 + 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs b/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs index c8bdf3e19..845621769 100644 --- a/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs +++ b/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs @@ -94,13 +94,14 @@ namespace Ryujinx.HLE.HOS.Applets.Error SystemLanguage.LatinAmericanSpanish => "es-419", SystemLanguage.SimplifiedChinese => "zh-Hans", SystemLanguage.TraditionalChinese => "zh-Hant", + SystemLanguage.BrazilianPortuguese => "pt-BR", _ => "en-US" }; } - public string CleanText(string value) + private static string CleanText(string value) { - return Regex.Replace(Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(value)), @"[^\u0009\u000A\u000D\u0020-\u007E]", ""); + return Regex.Replace(value, @"[^\u0000\u0009\u000A\u000D\u0020-\uFFFF]..", "").Replace("\0", ""); } private string GetMessageText(uint module, uint description, string key) @@ -112,13 +113,12 @@ namespace Ryujinx.HLE.HOS.Applets.Error Nca nca = new Nca(_horizon.Device.FileSystem.KeySet, ncaFileStream); IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _horizon.FsIntegrityCheckLevel); string languageCode = SystemLanguageToLanguageKey(_horizon.State.DesiredSystemLanguage); - string filePath = "/" + Path.Combine(module.ToString(), $"{description:0000}", $"{languageCode}_{key}").Replace(@"\", "/"); + string filePath = $"/{module}/{description:0000}/{languageCode}_{key}"; if (romfs.FileExists(filePath)) { romfs.OpenFile(out IFile binaryFile, filePath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); - - StreamReader reader = new StreamReader(binaryFile.AsStream()); + StreamReader reader = new StreamReader(binaryFile.AsStream(), Encoding.Unicode); return CleanText(reader.ReadToEnd()); } @@ -149,7 +149,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error } string message = GetMessageText(module, description, "DlgMsg"); - + if (message == "") { message = "An error has occured.\n\n" diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs b/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs index b358606ca..8c2e92989 100644 --- a/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs +++ b/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/ApplicationProxy/IApplicationFunctions.cs @@ -151,7 +151,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati int supportedLanguages = (int)context.Device.Application.ControlData.Value.SupportedLanguages; int firstSupported = BitOperations.TrailingZeroCount(supportedLanguages); - if (firstSupported > (int)SystemState.TitleLanguage.Chinese) + if (firstSupported > (int)SystemState.TitleLanguage.BrazilianPortuguese) { Logger.Warning?.Print(LogClass.ServiceAm, "Application has zero supported languages"); @@ -578,7 +578,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.Applicati { // NOTE: IStorage are pushed in the channel with IApplicationAccessor PushToFriendInvitationStorageChannel // If _friendInvitationStorageChannelEvent is signaled, the event is cleared. - // If an IStorage is available, returns it with ResultCode.Success. + // If an IStorage is available, returns it with ResultCode.Success. // If not, just returns ResultCode.NotAvailable. Since we don't support friend feature for now, it's fine to do the same. Logger.Stub?.PrintStub(LogClass.ServiceAm); diff --git a/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs b/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs index 2046ed62f..3f755105b 100644 --- a/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs +++ b/Ryujinx.HLE/HOS/SystemState/SystemLanguage.cs @@ -18,6 +18,7 @@ namespace Ryujinx.HLE.HOS.SystemState CanadianFrench, LatinAmericanSpanish, SimplifiedChinese, - TraditionalChinese + TraditionalChinese, + BrazilianPortuguese } } \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs b/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs index 2a6f327b1..8aa0bffff 100644 --- a/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs +++ b/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs @@ -22,7 +22,8 @@ namespace Ryujinx.HLE.HOS.SystemState "fr-CA", "es-419", "zh-Hans", - "zh-Hant" + "zh-Hant", + "pt-BR" }; internal long DesiredKeyboardLayout { get; private set; } diff --git a/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs b/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs index 931463a74..21f063289 100644 --- a/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs +++ b/Ryujinx.HLE/HOS/SystemState/TitleLanguage.cs @@ -16,6 +16,7 @@ Russian, Korean, Taiwanese, - Chinese + Chinese, + BrazilianPortuguese } } diff --git a/Ryujinx/Configuration/System/Language.cs b/Ryujinx/Configuration/System/Language.cs index d3af296ba..d99ae0bc9 100644 --- a/Ryujinx/Configuration/System/Language.cs +++ b/Ryujinx/Configuration/System/Language.cs @@ -18,6 +18,7 @@ CanadianFrench, LatinAmericanSpanish, SimplifiedChinese, - TraditionalChinese + TraditionalChinese, + BrazilianPortuguese } } diff --git a/Ryujinx/Ui/Windows/SettingsWindow.glade b/Ryujinx/Ui/Windows/SettingsWindow.glade index 0d3fdf518..7e2f86cdc 100644 --- a/Ryujinx/Ui/Windows/SettingsWindow.glade +++ b/Ryujinx/Ui/Windows/SettingsWindow.glade @@ -1266,6 +1266,7 @@ Spanish Taiwanese Traditional Chinese + Brazilian Portuguese