From e86d7584a2d06158c47bc70678616832852b123d Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Tue, 19 Dec 2023 21:22:22 -0800 Subject: [PATCH 1/3] Check locale with grep -i utf --- .../Components/MainPage/MainPage.cs | 6 +++--- .../Tabs/SettingsTabTroubleshooting.cs | 6 ++++-- src/XIVLauncher.Core/CoreEnvironmentSettings.cs | 15 +++++++++++++++ src/XIVLauncher.Core/Program.cs | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs index 21837fc1..46ae722f 100644 --- a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs +++ b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs @@ -686,10 +686,10 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b IGameRunner runner; // Hack: Force C.utf8 to fix incorrect unicode paths - if (App.Settings.FixLocale.Value && !System.OperatingSystem.IsWindows()) + if (App.Settings.FixLocale.Value && !string.IsNullOrEmpty(Program.Locale) && !System.OperatingSystem.IsWindows()) { - System.Environment.SetEnvironmentVariable("LC_ALL", "C.utf8"); - System.Environment.SetEnvironmentVariable("LC_CTYPE", "C.utf8"); + System.Environment.SetEnvironmentVariable("LC_ALL", Program.Locale); + System.Environment.SetEnvironmentVariable("LC_CTYPE", Program.Locale); } // Hack: Strip out gameoverlayrenderer.so entries from LD_PRELOAD diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs index 8cd3df57..3605d538 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs @@ -9,12 +9,14 @@ namespace XIVLauncher.Core.Components.SettingsPage.Tabs; public class SettingsTabTroubleshooting : SettingsTab -{ +{ public override SettingsEntry[] Entries { get; } = { new SettingsEntry("Hack: Disable gameoverlayrenderer.so", "Fixes some stuttering issues after 40+ minutes, but may affect steam overlay and input.", () => Program.Config.FixLDP ?? false, x => Program.Config.FixLDP = x), new SettingsEntry("Hack: XMODIFIERS=\"@im=null\"", "Fixes some mouse-related issues, some stuttering issues", () => Program.Config.FixIM ?? false, x => Program.Config.FixIM = x), - new SettingsEntry("Hack: Force locale to C.utf8", "Sets LC_ALL and LC_CTYPE to C.utf8. This can fix some issues with non-Latin unicode characters in file paths.", () => Program.Config.FixLocale ?? false, b => Program.Config.FixLocale = b), + new SettingsEntry($"Hack: Force locale to {(!string.IsNullOrEmpty(Program.Locale) ? Program.Locale : "C.UTF-8 (exact value depends on distro)")}", + !string.IsNullOrEmpty(Program.Locale) ? $"Sets LC_ALL and LC_CTYPE to \"{Program.Locale}\". This can fix some issues with non-Latin unicode characters in file paths." : "Hack Disabled. Could not find a UTF-8 C locale. You may have to set LC_ALL manually if LANG is not a UTF-8 type.", + () => Program.Config.FixLocale ?? false, b => Program.Config.FixLocale = b), }; public override string Title => "Troubleshooting"; diff --git a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs index 2a78b2b3..69ab301f 100644 --- a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs +++ b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.Globalization; namespace XIVLauncher.Core; @@ -37,4 +39,17 @@ public static string GetCleanEnvironmentVariable(string envvar, string badstring if (badstring.Equals("")) return dirty; return string.Join(separator, Array.FindAll(dirty.Split(separator, StringSplitOptions.RemoveEmptyEntries), s => !s.Contains(badstring))); } + + public static string GetLocale() + { + var psi = new ProcessStartInfo("sh"); + psi.Arguments = "-c \"locale -a 2>/dev/null | grep -i utf\""; + psi.RedirectStandardOutput = true; + + var proc = new Process(); + proc.StartInfo = psi; + proc.Start(); + var output = proc.StandardOutput.ReadToEnd().Split('\n', StringSplitOptions.RemoveEmptyEntries); + return Array.Find(output, s => s.ToUpper().StartsWith("C.")); + } } \ No newline at end of file diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index 79801736..7e198c87 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -66,6 +66,8 @@ class Program private const string FRONTIER_FALLBACK = "https://launcher.finalfantasyxiv.com/v650/index.html?rc_lang={0}&time={1}"; + public static string Locale = CoreEnvironmentSettings.GetLocale(); + public static void Invalidate(uint frames = 100) { invalidationFrames = frames; From d20b1808b27cf1bfdb5b18276e2fc6cb8fa3481d Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Tue, 19 Dec 2023 21:32:55 -0800 Subject: [PATCH 2/3] Don't try to check locale on Windows --- src/XIVLauncher.Core/Components/MainPage/MainPage.cs | 6 +++--- .../SettingsPage/Tabs/SettingsTabTroubleshooting.cs | 4 ++-- src/XIVLauncher.Core/CoreEnvironmentSettings.cs | 4 +++- src/XIVLauncher.Core/Program.cs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs index 46ae722f..12098118 100644 --- a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs +++ b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs @@ -686,10 +686,10 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b IGameRunner runner; // Hack: Force C.utf8 to fix incorrect unicode paths - if (App.Settings.FixLocale.Value && !string.IsNullOrEmpty(Program.Locale) && !System.OperatingSystem.IsWindows()) + if (App.Settings.FixLocale.Value && !string.IsNullOrEmpty(Program.CType) && !System.OperatingSystem.IsWindows()) { - System.Environment.SetEnvironmentVariable("LC_ALL", Program.Locale); - System.Environment.SetEnvironmentVariable("LC_CTYPE", Program.Locale); + System.Environment.SetEnvironmentVariable("LC_ALL", Program.CType); + System.Environment.SetEnvironmentVariable("LC_CTYPE", Program.CType); } // Hack: Strip out gameoverlayrenderer.so entries from LD_PRELOAD diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs index 3605d538..77e4ecfd 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs @@ -14,8 +14,8 @@ public class SettingsTabTroubleshooting : SettingsTab { new SettingsEntry("Hack: Disable gameoverlayrenderer.so", "Fixes some stuttering issues after 40+ minutes, but may affect steam overlay and input.", () => Program.Config.FixLDP ?? false, x => Program.Config.FixLDP = x), new SettingsEntry("Hack: XMODIFIERS=\"@im=null\"", "Fixes some mouse-related issues, some stuttering issues", () => Program.Config.FixIM ?? false, x => Program.Config.FixIM = x), - new SettingsEntry($"Hack: Force locale to {(!string.IsNullOrEmpty(Program.Locale) ? Program.Locale : "C.UTF-8 (exact value depends on distro)")}", - !string.IsNullOrEmpty(Program.Locale) ? $"Sets LC_ALL and LC_CTYPE to \"{Program.Locale}\". This can fix some issues with non-Latin unicode characters in file paths." : "Hack Disabled. Could not find a UTF-8 C locale. You may have to set LC_ALL manually if LANG is not a UTF-8 type.", + new SettingsEntry($"Hack: Force locale to {(!string.IsNullOrEmpty(Program.CType) ? Program.CType : "C.UTF-8 (exact value depends on distro)")}", + !string.IsNullOrEmpty(Program.CType) ? $"Sets LC_ALL and LC_CTYPE to \"{Program.CType}\". This can fix some issues with non-Latin unicode characters in file paths." : "Hack Disabled. Could not find a UTF-8 C locale. You may have to set LC_ALL manually if LANG is not a UTF-8 type.", () => Program.Config.FixLocale ?? false, b => Program.Config.FixLocale = b), }; public override string Title => "Troubleshooting"; diff --git a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs index 69ab301f..cfe022b9 100644 --- a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs +++ b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs @@ -40,8 +40,10 @@ public static string GetCleanEnvironmentVariable(string envvar, string badstring return string.Join(separator, Array.FindAll(dirty.Split(separator, StringSplitOptions.RemoveEmptyEntries), s => !s.Contains(badstring))); } - public static string GetLocale() + public static string GetCType() { + if (System.OperatingSystem.IsWindows()) + return ""; var psi = new ProcessStartInfo("sh"); psi.Arguments = "-c \"locale -a 2>/dev/null | grep -i utf\""; psi.RedirectStandardOutput = true; diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index 7e198c87..f6c457be 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -66,7 +66,7 @@ class Program private const string FRONTIER_FALLBACK = "https://launcher.finalfantasyxiv.com/v650/index.html?rc_lang={0}&time={1}"; - public static string Locale = CoreEnvironmentSettings.GetLocale(); + public static string CType = CoreEnvironmentSettings.GetCType(); public static void Invalidate(uint frames = 100) { From 41110bab812c562e75670816ba34ca0ea74dab69 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Tue, 19 Dec 2023 22:08:05 -0800 Subject: [PATCH 3/3] Warn user if they already have a utf-8 type and enable hack --- .../Components/MainPage/MainPage.cs | 2 +- .../SettingsPage/Tabs/SettingsTabTroubleshooting.cs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs index 12098118..c4062a3f 100644 --- a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs +++ b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs @@ -686,7 +686,7 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b IGameRunner runner; // Hack: Force C.utf8 to fix incorrect unicode paths - if (App.Settings.FixLocale.Value && !string.IsNullOrEmpty(Program.CType) && !System.OperatingSystem.IsWindows()) + if (App.Settings.FixLocale.Value && !string.IsNullOrEmpty(Program.CType)) { System.Environment.SetEnvironmentVariable("LC_ALL", Program.CType); System.Environment.SetEnvironmentVariable("LC_CTYPE", Program.CType); diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs index 77e4ecfd..3046be27 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabTroubleshooting.cs @@ -15,8 +15,17 @@ public class SettingsTabTroubleshooting : SettingsTab new SettingsEntry("Hack: Disable gameoverlayrenderer.so", "Fixes some stuttering issues after 40+ minutes, but may affect steam overlay and input.", () => Program.Config.FixLDP ?? false, x => Program.Config.FixLDP = x), new SettingsEntry("Hack: XMODIFIERS=\"@im=null\"", "Fixes some mouse-related issues, some stuttering issues", () => Program.Config.FixIM ?? false, x => Program.Config.FixIM = x), new SettingsEntry($"Hack: Force locale to {(!string.IsNullOrEmpty(Program.CType) ? Program.CType : "C.UTF-8 (exact value depends on distro)")}", - !string.IsNullOrEmpty(Program.CType) ? $"Sets LC_ALL and LC_CTYPE to \"{Program.CType}\". This can fix some issues with non-Latin unicode characters in file paths." : "Hack Disabled. Could not find a UTF-8 C locale. You may have to set LC_ALL manually if LANG is not a UTF-8 type.", - () => Program.Config.FixLocale ?? false, b => Program.Config.FixLocale = b), + !string.IsNullOrEmpty(Program.CType) ? $"Sets LC_ALL and LC_CTYPE to \"{Program.CType}\". This can fix some issues with non-Latin unicode characters in file paths if LANG is not a UTF-8 type" : "Hack Disabled. Could not find a UTF-8 C locale. You may have to set LC_ALL manually if LANG is not a UTF-8 type.", + () => Program.Config.FixLocale ?? false, b => Program.Config.FixLocale = b) + { + CheckWarning = b => + { + var lang = CoreEnvironmentSettings.GetCleanEnvironmentVariable("LANG"); + if (lang.ToUpper().Contains("UTF") && b) + return $"Your locale is \"{lang}\". You probably don't need this hack."; + return null; + } + }, }; public override string Title => "Troubleshooting";