mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Fix NotImplementedException when using shift-jis encoding
This commit is contained in:
1 parent
eebdac95d6
commit
1ab2716993
4 files changed
+19
-12
No files matched your search
@@ -9,6 +9,8 @@ namespace BepInEx
|
||||
{
|
||||
public static class ConsoleManager
|
||||
{
|
||||
private const uint SHIFT_JIS_CP = 932;
|
||||
|
||||
internal static IConsoleDriver Driver { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -79,22 +81,22 @@ namespace BepInEx
|
||||
|
||||
public static void SetConsoleEncoding()
|
||||
{
|
||||
// Apparently Windows code-pages work in Mono.
|
||||
// https://stackoverflow.com/a/33456543
|
||||
// Alternatively we can pass in "shift-jis"
|
||||
var encoding = ConfigConsoleShiftJis.Value ? Encoding.GetEncoding(932): new UTF8Encoding(false);
|
||||
// Apparently some versions of Mono throw a "Encoding name 'xxx' not supported"
|
||||
// if you use Encoding.GetEncoding
|
||||
// That's why we use of codepages directly and handle then in console drivers separately
|
||||
var codepage = ConfigConsoleShiftJis.Value ? SHIFT_JIS_CP: (uint)Encoding.UTF8.CodePage;
|
||||
|
||||
SetConsoleEncoding(encoding);
|
||||
SetConsoleEncoding(codepage);
|
||||
}
|
||||
|
||||
public static void SetConsoleEncoding(Encoding encoding)
|
||||
public static void SetConsoleEncoding(uint codepage)
|
||||
{
|
||||
if (!ConsoleActive)
|
||||
throw new InvalidOperationException("Console is not currently active");
|
||||
|
||||
DriverCheck();
|
||||
|
||||
Driver.SetConsoleEncoding(encoding);
|
||||
Driver.SetConsoleEncoding(codepage);
|
||||
}
|
||||
|
||||
public static void SetConsoleTitle(string title)
|
||||
|
||||
@@ -18,7 +18,10 @@ namespace BepInEx
|
||||
void DetachConsole();
|
||||
|
||||
void SetConsoleColor(ConsoleColor color);
|
||||
void SetConsoleEncoding(Encoding encoding);
|
||||
|
||||
// Apparently Windows code-pages work in Mono.
|
||||
// https://stackoverflow.com/a/33456543
|
||||
void SetConsoleEncoding(uint codepage);
|
||||
void SetConsoleTitle(string title);
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ namespace BepInEx.Unix
|
||||
}
|
||||
}
|
||||
|
||||
public void SetConsoleEncoding(Encoding encoding)
|
||||
public void SetConsoleEncoding(uint codepage)
|
||||
{
|
||||
// We shouldn't be changing this on Unix
|
||||
}
|
||||
|
||||
@@ -62,10 +62,12 @@ namespace BepInEx
|
||||
Kon.ForegroundColor = color;
|
||||
}
|
||||
|
||||
public void SetConsoleEncoding(Encoding encoding)
|
||||
public void SetConsoleEncoding(uint codepage)
|
||||
{
|
||||
ConsoleEncoding.ConsoleCodePage = (uint)encoding.CodePage;
|
||||
Console.OutputEncoding = encoding;
|
||||
// Make sure of ConsoleEncoding helper class because on some Monos
|
||||
// Encoding.GetEncoding throws NotImplementedException on most codepages
|
||||
ConsoleEncoding.ConsoleCodePage = codepage;
|
||||
Console.OutputEncoding = ConsoleEncoding.GetEncoding(codepage);
|
||||
}
|
||||
|
||||
public void SetConsoleTitle(string title)
|
||||
|
||||
Reference in new issue
Block a user