mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-19 15:51:45 +00:00
ConsoleManager: refactor useWinApiEncoder -> useManagedEncoder
This commit is contained in:
1 parent
57658bdbb7
commit
a1c7f5c4b1
8 files changed
+15
-14
No files matched your search
@@ -94,7 +94,7 @@ public static class ConsoleManager
|
||||
public static TextWriter ConsoleStream => Driver?.ConsoleOut;
|
||||
|
||||
|
||||
public static void Initialize(bool alreadyActive, bool useWinApiEncoder)
|
||||
public static void Initialize(bool alreadyActive, bool useManagedEncoder)
|
||||
{
|
||||
if (PlatformHelper.Is(Platform.Unix))
|
||||
Driver = new LinuxConsoleDriver();
|
||||
@@ -104,7 +104,7 @@ public static class ConsoleManager
|
||||
throw new PlatformNotSupportedException("Was unable to determine console driver for platform " +
|
||||
PlatformHelper.Current);
|
||||
|
||||
Driver.Initialize(alreadyActive, useWinApiEncoder);
|
||||
Driver.Initialize(alreadyActive, useManagedEncoder);
|
||||
}
|
||||
|
||||
private static void DriverCheck()
|
||||
|
||||
@@ -13,7 +13,7 @@ internal interface IConsoleDriver
|
||||
|
||||
void PreventClose();
|
||||
|
||||
void Initialize(bool alreadyActive, bool useWinApiEncoder);
|
||||
void Initialize(bool alreadyActive, bool useManagedEncoder);
|
||||
|
||||
// Apparently Windows code-pages work in Mono.
|
||||
// https://stackoverflow.com/a/33456543
|
||||
|
||||
@@ -46,7 +46,7 @@ internal class LinuxConsoleDriver : IConsoleDriver
|
||||
// Not supported by all distros
|
||||
}
|
||||
|
||||
public void Initialize(bool alreadyActive, bool useWinApiEncoder)
|
||||
public void Initialize(bool alreadyActive, bool useManagedEncoder)
|
||||
{
|
||||
// Console is always considered active on Unix
|
||||
ConsoleActive = true;
|
||||
|
||||
@@ -30,7 +30,7 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
.PropertyGetter(typeof(Console), nameof(Console.WindowWidth))
|
||||
?.CreateDelegate<Func<int>>();
|
||||
|
||||
private bool useWinApiEncoder;
|
||||
private bool useManagedEncoder;
|
||||
|
||||
private int ConsoleWidth
|
||||
{
|
||||
@@ -68,10 +68,10 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
public bool ConsoleActive { get; private set; }
|
||||
public bool ConsoleIsExternal => true;
|
||||
|
||||
public void Initialize(bool alreadyActive, bool useWinApiEncoder)
|
||||
public void Initialize(bool alreadyActive, bool useManagedEncoder)
|
||||
{
|
||||
ConsoleActive = alreadyActive || TryCheckConsoleExists();
|
||||
this.useWinApiEncoder = useWinApiEncoder;
|
||||
this.useManagedEncoder = useManagedEncoder;
|
||||
|
||||
if (ConsoleActive)
|
||||
{
|
||||
@@ -92,7 +92,8 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
// Make sure of ConsoleEncoding helper class because on some Monos
|
||||
// Encoding.GetEncoding throws NotImplementedException on most codepages
|
||||
// NOTE: We don't set Console.OutputEncoding because it resets any existing Console.Out writers
|
||||
ConsoleEncoding.ConsoleCodePage = codepage;
|
||||
if (!useManagedEncoder)
|
||||
ConsoleEncoding.ConsoleCodePage = codepage;
|
||||
|
||||
// If stdout exists, write to it, otherwise make it the same as console out
|
||||
// Not sure if this is needed? Does the original Console.Out still work?
|
||||
@@ -113,7 +114,7 @@ internal class WindowsConsoleDriver : IConsoleDriver
|
||||
var consoleOutStream = OpenFileStream(ConsoleWindow.ConsoleOutHandle);
|
||||
// Can't use Console.OutputEncoding because it can be null (i.e. not preference by user)
|
||||
ConsoleOut = new StreamWriter(consoleOutStream,
|
||||
useWinApiEncoder ? ConsoleEncoding.OutputEncoding : Utility.UTF8NoBom)
|
||||
useManagedEncoder ? Utility.UTF8NoBom : ConsoleEncoding.OutputEncoding)
|
||||
{
|
||||
AutoFlush = true
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ public static class Preloader
|
||||
{
|
||||
HarmonyBackendFix.Initialize();
|
||||
|
||||
ConsoleManager.Initialize(false, false);
|
||||
ConsoleManager.Initialize(false, true);
|
||||
|
||||
PreloaderLog = new PreloaderConsoleListener();
|
||||
Logger.Listeners.Add(PreloaderLog);
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace BepInEx.NetCore
|
||||
{
|
||||
internal static void PreloaderMain()
|
||||
{
|
||||
ConsoleManager.Initialize(false, false);
|
||||
ConsoleManager.Initialize(false, true);
|
||||
|
||||
ConsoleManager.CreateConsole();
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ internal class Program
|
||||
filename = Process.GetCurrentProcess().MainModule.FileName;
|
||||
ResolveDirectories.Add(Path.Combine(Path.GetDirectoryName(filename), "BepInEx", "core"));
|
||||
#endif
|
||||
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += SharedEntrypoint.RemoteResolve(ResolveDirectories);
|
||||
|
||||
NetPreloaderRunner.OuterMain(args, filename);
|
||||
@@ -64,7 +64,7 @@ internal static class NetPreloaderRunner
|
||||
{
|
||||
Logger.Listeners.Add(new ConsoleLogListener());
|
||||
|
||||
ConsoleManager.Initialize(true, false);
|
||||
ConsoleManager.Initialize(true, true);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ internal static class UnityPreloader
|
||||
{
|
||||
HarmonyBackendFix.Initialize();
|
||||
|
||||
ConsoleManager.Initialize(false, true);
|
||||
ConsoleManager.Initialize(false, false);
|
||||
AllocateConsole();
|
||||
|
||||
Utility.TryDo(() =>
|
||||
|
||||
Reference in new issue
Block a user