2023-12-04 13:17:13 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2022-03-15 01:35:41 +00:00
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
2024-02-11 02:09:18 +00:00
|
|
|
namespace Ryujinx.UI.Common.Helper
|
2022-03-15 01:35:41 +00:00
|
|
|
{
|
2022-12-15 17:07:31 +00:00
|
|
|
public static partial class ConsoleHelper
|
2022-03-15 01:35:41 +00:00
|
|
|
{
|
|
|
|
public static bool SetConsoleWindowStateSupported => OperatingSystem.IsWindows();
|
|
|
|
|
|
|
|
public static void SetConsoleWindowState(bool show)
|
|
|
|
{
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
{
|
|
|
|
SetConsoleWindowStateWindows(show);
|
|
|
|
}
|
|
|
|
else if (show == false)
|
|
|
|
{
|
|
|
|
Logger.Warning?.Print(LogClass.Application, "OS doesn't support hiding console window");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
private static void SetConsoleWindowStateWindows(bool show)
|
|
|
|
{
|
|
|
|
const int SW_HIDE = 0;
|
|
|
|
const int SW_SHOW = 5;
|
|
|
|
|
2024-10-26 13:46:41 +00:00
|
|
|
nint hWnd = GetConsoleWindow();
|
2022-03-15 01:35:41 +00:00
|
|
|
|
2024-10-26 13:46:41 +00:00
|
|
|
if (hWnd == nint.Zero)
|
2022-03-15 01:35:41 +00:00
|
|
|
{
|
|
|
|
Logger.Warning?.Print(LogClass.Application, "Attempted to show/hide console window but console window does not exist");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
2022-12-15 17:07:31 +00:00
|
|
|
[LibraryImport("kernel32")]
|
2024-10-26 13:46:41 +00:00
|
|
|
private static partial nint GetConsoleWindow();
|
2022-03-15 01:35:41 +00:00
|
|
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
2022-12-15 17:07:31 +00:00
|
|
|
[LibraryImport("user32")]
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
2024-10-26 13:46:41 +00:00
|
|
|
private static partial bool ShowWindow(nint hWnd, int nCmdShow);
|
2022-03-15 01:35:41 +00:00
|
|
|
}
|
2023-06-29 00:39:22 +00:00
|
|
|
}
|