瀏覽代碼

Fix console compatibility with unix platforms

Bepis 4 年之前
父節點
當前提交
dbea82eb2a
共有 2 個文件被更改,包括 8 次插入14 次删除
  1. 6 12
      BepInEx.Core/ConsoleManager.cs
  2. 2 2
      BepInEx.Preloader.Core/Logging/PreloaderLogWriter.cs

+ 6 - 12
BepInEx.Core/ConsoleManager.cs

@@ -71,37 +71,31 @@ namespace BepInEx
 
 		public static void SetConsoleTitle(string title)
 		{
-			if (!ConsoleActive)
-				throw new InvalidOperationException("Console is not currently active");
-
 			switch (Environment.OSVersion.Platform)
 			{
 				case PlatformID.Win32NT:
 				{
+					if (!ConsoleActive)
+						return;
+
 					ConsoleWindow.Title = title;
 					break;
 				}
-				default:
-					throw new PlatformNotSupportedException("Spawning a console is not currently supported on this platform");
 			}
 		}
 
 		public static void SetConsoleColor(ConsoleColor color)
 		{
-			if (!ConsoleActive)
-				throw new InvalidOperationException("Console is not currently active");
-
 			switch (Environment.OSVersion.Platform)
 			{
 				case PlatformID.Win32NT:
 				{
+					if (!ConsoleActive)
+						return;
+
 					Kon.ForegroundColor = color;
 					break;
 				}
-				default:
-				{
-					break;
-				}
 			}
 
 			Console.ForegroundColor = color;

+ 2 - 2
BepInEx.Preloader.Core/Logging/PreloaderLogWriter.cs

@@ -37,9 +37,9 @@ namespace BepInEx.Preloader.Core.Logging
 
 			LogBuilder.Append(log);
 
-			Kon.ForegroundColor = eventArgs.Level.GetConsoleColor();
+			ConsoleManager.SetConsoleColor(eventArgs.Level.GetConsoleColor());
 			ConsoleDirectWrite(log);
-			Kon.ForegroundColor = ConsoleColor.Gray;
+			ConsoleManager.SetConsoleColor(ConsoleColor.Gray);
 		}
 
 		public void ConsoleDirectWrite(string value)