Skip to content

Commit

Permalink
Merge pull request goatcorp#101 from rankynbass/fix-locale-hack-2
Browse files Browse the repository at this point in the history
Fix locale hack 2: Now detects correct C.utf format
  • Loading branch information
reiichi001 authored Dec 20, 2023
2 parents 0941eb4 + 41110ba commit 9438460
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/XIVLauncher.Core/Components/MainPage/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,10 @@ public async Task<Process> 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.CType))
{
System.Environment.SetEnvironmentVariable("LC_ALL", "C.utf8");
System.Environment.SetEnvironmentVariable("LC_CTYPE", "C.utf8");
System.Environment.SetEnvironmentVariable("LC_ALL", Program.CType);
System.Environment.SetEnvironmentVariable("LC_CTYPE", Program.CType);
}

// Hack: Strip out gameoverlayrenderer.so entries from LD_PRELOAD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
namespace XIVLauncher.Core.Components.SettingsPage.Tabs;

public class SettingsTabTroubleshooting : SettingsTab
{
{
public override SettingsEntry[] Entries { get; } =
{
new SettingsEntry<bool>("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<bool>("Hack: XMODIFIERS=\"@im=null\"", "Fixes some mouse-related issues, some stuttering issues", () => Program.Config.FixIM ?? false, x => Program.Config.FixIM = x),
new SettingsEntry<bool>("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<bool>($"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 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";

Expand Down
17 changes: 17 additions & 0 deletions src/XIVLauncher.Core/CoreEnvironmentSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;

namespace XIVLauncher.Core;

Expand Down Expand Up @@ -37,4 +39,19 @@ public static string GetCleanEnvironmentVariable(string envvar, string badstring
if (badstring.Equals("")) return dirty;
return string.Join(separator, Array.FindAll<string>(dirty.Split(separator, StringSplitOptions.RemoveEmptyEntries), s => !s.Contains(badstring)));
}

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;

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."));
}
}
2 changes: 2 additions & 0 deletions src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 CType = CoreEnvironmentSettings.GetCType();

public static void Invalidate(uint frames = 100)
{
invalidationFrames = frames;
Expand Down

0 comments on commit 9438460

Please sign in to comment.