Use CsWin32

pull/526/head
Pavel Djundik 1 year ago
parent 1620090c19
commit 0ce116fdce

@ -19,6 +19,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="protobuf-net" Version="3.2.30" /> <PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="QRCoder" Version="1.6.0" /> <PackageReference Include="QRCoder" Version="1.6.0" />
<PackageReference Include="SteamKit2" Version="3.0.0-Beta.2" /> <PackageReference Include="SteamKit2" Version="3.0.0-Beta.2" />

@ -0,0 +1,2 @@
GetConsoleProcessList
MessageBox

@ -3,6 +3,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace DepotDownloader namespace DepotDownloader
{ {
@ -146,36 +147,24 @@ namespace DepotDownloader
} }
} }
#region WIN32_CONSOLE_STUFF [SupportedOSPlatform("windows5.0")]
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern uint GetConsoleProcessList(uint[] processList, uint processCount);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern int MessageBoxW(IntPtr hWnd, string text, string caption, uint type);
const uint MB_OK = 0x0;
const uint MB_ICONWARNING = 0x30;
public static void VerifyConsoleLaunch() public static void VerifyConsoleLaunch()
{ {
// Reference: https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922 // Reference: https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922
var processList = new uint[2]; var processList = new uint[2];
var processCount = GetConsoleProcessList(processList, (uint)processList.Length); var processCount = Windows.Win32.PInvoke.GetConsoleProcessList(processList);
if (processCount != 1) if (processCount != 1)
{ {
return; return;
} }
_ = MessageBoxW( _ = Windows.Win32.PInvoke.MessageBox(
IntPtr.Zero, Windows.Win32.Foundation.HWND.Null,
"Depot Downloader is a console application; there is no GUI.\n\nIf you do not pass any command line parameters, it prints usage info and exits.\n\nYou must use this from a terminal/console.", "Depot Downloader is a console application; there is no GUI.\n\nIf you do not pass any command line parameters, it prints usage info and exits.\n\nYou must use this from a terminal/console.",
"DepotDownloader", "Depot Downloader",
MB_OK | MB_ICONWARNING Windows.Win32.UI.WindowsAndMessaging.MESSAGEBOX_STYLE.MB_OK | Windows.Win32.UI.WindowsAndMessaging.MESSAGEBOX_STYLE.MB_ICONWARNING
); );
} }
#endregion
} }
} }

Loading…
Cancel
Save