ConsoleHelper.cs
1 using Ryujinx.Common.Logging; 2 using System; 3 using System.Runtime.InteropServices; 4 using System.Runtime.Versioning; 5 6 namespace Ryujinx.UI.Common.Helper 7 { 8 public static partial class ConsoleHelper 9 { 10 public static bool SetConsoleWindowStateSupported => OperatingSystem.IsWindows(); 11 12 public static void SetConsoleWindowState(bool show) 13 { 14 if (OperatingSystem.IsWindows()) 15 { 16 SetConsoleWindowStateWindows(show); 17 } 18 else if (show == false) 19 { 20 Logger.Warning?.Print(LogClass.Application, "OS doesn't support hiding console window"); 21 } 22 } 23 24 [SupportedOSPlatform("windows")] 25 private static void SetConsoleWindowStateWindows(bool show) 26 { 27 const int SW_HIDE = 0; 28 const int SW_SHOW = 5; 29 30 IntPtr hWnd = GetConsoleWindow(); 31 32 if (hWnd == IntPtr.Zero) 33 { 34 Logger.Warning?.Print(LogClass.Application, "Attempted to show/hide console window but console window does not exist"); 35 return; 36 } 37 38 ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE); 39 } 40 41 [SupportedOSPlatform("windows")] 42 [LibraryImport("kernel32")] 43 private static partial IntPtr GetConsoleWindow(); 44 45 [SupportedOSPlatform("windows")] 46 [LibraryImport("user32")] 47 [return: MarshalAs(UnmanagedType.Bool)] 48 private static partial bool ShowWindow(IntPtr hWnd, int nCmdShow); 49 } 50 }