Clean up console listener logic

This commit is contained in:
ghorsington committed 2021-11-02 20:16:50 +02:00
1 parent dbe443d4fb
commit 8ff2c1088b
4 files changed
+33 -36

No files matched your search

+1 -1
View File
@@ -151,7 +151,7 @@ namespace BepInEx.Bootstrap
protected virtual void InitializeLoggers()
{
if (ConsoleManager.ConfigConsoleEnabled.Value && !ConsoleManager.ConsoleActive)
if (ConsoleManager.ConsoleEnabled && !ConsoleManager.ConsoleActive)
ConsoleManager.CreateConsole();
if (ConsoleManager.ConsoleActive)
+21 -22
View File
@@ -24,7 +24,7 @@ namespace BepInEx
private const uint SHIFT_JIS_CP = 932;
public static bool ConsoleEnabled => EnableConsoleArgOverride ?? ConfigConsoleEnabled.Value;
private const string ENABLE_CONSOLE_ARG = "--enable-console";
public static readonly ConfigEntry<bool> ConfigConsoleEnabled = ConfigFile.CoreConfig.Bind(
"Logging.Console", "Enabled",
@@ -53,27 +53,8 @@ namespace BepInEx
.ToString()
);
internal static IConsoleDriver Driver { get; set; }
/// <summary>
/// True if an external console has been started, false otherwise.
/// </summary>
public static bool ConsoleActive => Driver?.ConsoleActive ?? false;
/// <summary>
/// The stream that writes to the standard out stream of the process. Should never be null.
/// </summary>
public static TextWriter StandardOutStream => Driver?.StandardOut;
/// <summary>
/// The stream that writes to an external console. Null if no such console exists
/// </summary>
public static TextWriter ConsoleStream => Driver?.ConsoleOut;
private static readonly bool? EnableConsoleArgOverride;
private const string ENABLE_CONSOLE_ARG = "--enable-console";
static ConsoleManager()
{
// Ensure GetCommandLineArgs failing (e.g. on unix) does not kill bepin
@@ -93,6 +74,25 @@ namespace BepInEx
}
}
public static bool ConsoleEnabled => EnableConsoleArgOverride ?? ConfigConsoleEnabled.Value;
internal static IConsoleDriver Driver { get; set; }
/// <summary>
/// True if an external console has been started, false otherwise.
/// </summary>
public static bool ConsoleActive => Driver?.ConsoleActive ?? false;
/// <summary>
/// The stream that writes to the standard out stream of the process. Should never be null.
/// </summary>
public static TextWriter StandardOutStream => Driver?.StandardOut;
/// <summary>
/// The stream that writes to an external console. Null if no such console exists
/// </summary>
public static TextWriter ConsoleStream => Driver?.ConsoleOut;
public static void Initialize(bool alreadyActive)
{
@@ -123,10 +123,9 @@ namespace BepInEx
// 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;
var codepage = ConfigConsoleShiftJis.Value ? SHIFT_JIS_CP : (uint)Encoding.UTF8.CodePage;
Driver.CreateConsole(codepage);
// Console.SetOut(ConsoleStream);
if (ConfigPreventClose.Value)
Driver.PreventClose();
+10 -12
View File
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Preloader.Core;
@@ -14,6 +13,15 @@ namespace BepInEx.IL2CPP
{
public static class Preloader
{
#region Config
private static readonly ConfigEntry<string> ConfigUnityVersion = ConfigFile.CoreConfig.Bind(
"IL2CPP", "UnityVersion",
string.Empty,
"Unity version to report to Il2CppUnhollower. If empty, version is automatically determined from the game process.");
#endregion
public static string IL2CPPUnhollowedPath { get; internal set; }
private static PreloaderConsoleListener PreloaderLog { get; set; }
@@ -35,8 +43,7 @@ namespace BepInEx.IL2CPP
PreloaderLog = new PreloaderConsoleListener();
Logger.Listeners.Add(PreloaderLog);
if (ConsoleManager.ConfigConsoleEnabled.Value)
if (ConsoleManager.ConsoleEnabled)
{
ConsoleManager.CreateConsole();
Logger.Listeners.Add(new ConsoleLogListener());
@@ -135,14 +142,5 @@ namespace BepInEx.IL2CPP
return false;
}
}
#region Config
private static readonly ConfigEntry<string> ConfigUnityVersion = ConfigFile.CoreConfig.Bind(
"IL2CPP", "UnityVersion",
string.Empty,
"Unity version to report to Il2CppUnhollower. If empty, version is automatically determined from the game process.");
#endregion
}
}
+1 -1
View File
@@ -47,7 +47,6 @@ namespace BepInEx.Preloader.Unity
Logger.Sources.Add(new HarmonyLogSource());
Logger.Sources.Add(TraceLogSource.CreateSource());
Logger.Listeners.Add(new ConsoleLogListener());
PreloaderLog = new PreloaderConsoleListener();
Logger.Listeners.Add(PreloaderLog);
@@ -136,6 +135,7 @@ namespace BepInEx.Preloader.Unity
try
{
ConsoleManager.CreateConsole();
Logger.Listeners.Add(new ConsoleLogListener());
}
catch (Exception ex)
{