Bladeren bron

Allow Console to fail gracefully if missing extern

This is a bandaid to the problem, Console is only supported under
Windows OS.
notfood 4 jaren geleden
bovenliggende
commit
e7502419a1
1 gewijzigde bestanden met toevoegingen van 21 en 13 verwijderingen
  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
 	}
-}
+}