ソースを参照

Allow Console to fail gracefully if missing extern

This is a bandaid to the problem, Console is only supported under
Windows OS.
notfood 4 年 前
コミット
e7502419a1
1 ファイル変更21 行追加13 行削除
  1. 21 13
      BepInEx/ConsoleUtil/Kon.cs

+ 21 - 13
BepInEx/ConsoleUtil/Kon.cs

@@ -64,20 +64,28 @@ namespace BepInEx.ConsoleUtil
 			succeeded = false;
 			if (!(conOut == INVALID_HANDLE_VALUE))
 			{
-				CONSOLE_SCREEN_BUFFER_INFO console_SCREEN_BUFFER_INFO;
-				if (!GetConsoleScreenBufferInfo(conOut, out console_SCREEN_BUFFER_INFO))
+				try
 				{
-					bool consoleScreenBufferInfo = GetConsoleScreenBufferInfo(GetStdHandle(-12), out console_SCREEN_BUFFER_INFO);
-					if (!consoleScreenBufferInfo)
-						consoleScreenBufferInfo = GetConsoleScreenBufferInfo(GetStdHandle(-10), out console_SCREEN_BUFFER_INFO);
-
-					if (!consoleScreenBufferInfo)
-						if (Marshal.GetLastWin32Error() == 6 && !throwOnNoConsole)
-							return default(CONSOLE_SCREEN_BUFFER_INFO);
+					// FIXME: Windows console shouldn't be used in other OSs in the first place
+					CONSOLE_SCREEN_BUFFER_INFO console_SCREEN_BUFFER_INFO;
+					if (!GetConsoleScreenBufferInfo(conOut, out console_SCREEN_BUFFER_INFO))
+					{
+						bool consoleScreenBufferInfo = GetConsoleScreenBufferInfo(GetStdHandle(-12), out console_SCREEN_BUFFER_INFO);
+						if (!consoleScreenBufferInfo)
+							consoleScreenBufferInfo = GetConsoleScreenBufferInfo(GetStdHandle(-10), out console_SCREEN_BUFFER_INFO);
+						
+						if (!consoleScreenBufferInfo)
+							if (Marshal.GetLastWin32Error() == 6 && !throwOnNoConsole)
+								return default(CONSOLE_SCREEN_BUFFER_INFO);
+							
+							succeeded = true;
+						return console_SCREEN_BUFFER_INFO;
+					}
+				}
+				catch (EntryPointNotFoundException)
+				{
+					// Fails under unsupported OSes
 				}
-
-				succeeded = true;
-				return console_SCREEN_BUFFER_INFO;
 			}
 
 			if (!throwOnNoConsole)
@@ -141,4 +149,4 @@ namespace BepInEx.ConsoleUtil
 
 		#endregion
 	}
-}
+}