diff --git a/DepotDownloader/DepotDownloader.csproj b/DepotDownloader/DepotDownloader.csproj index 0b060b10..319e2818 100644 --- a/DepotDownloader/DepotDownloader.csproj +++ b/DepotDownloader/DepotDownloader.csproj @@ -19,6 +19,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DepotDownloader/NativeMethods.txt b/DepotDownloader/NativeMethods.txt new file mode 100644 index 00000000..8f2bb821 --- /dev/null +++ b/DepotDownloader/NativeMethods.txt @@ -0,0 +1,2 @@ +GetConsoleProcessList +MessageBox diff --git a/DepotDownloader/PlatformUtilities.cs b/DepotDownloader/PlatformUtilities.cs index c5fd155e..a4f8fd77 100644 --- a/DepotDownloader/PlatformUtilities.cs +++ b/DepotDownloader/PlatformUtilities.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace DepotDownloader { @@ -27,5 +28,25 @@ namespace DepotDownloader : mode & ~ModeExecute); } } + + [SupportedOSPlatform("windows5.0")] + public static void VerifyConsoleLaunch() + { + // Reference: https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922 + var processList = new uint[2]; + var processCount = Windows.Win32.PInvoke.GetConsoleProcessList(processList); + + if (processCount != 1) + { + return; + } + + _ = Windows.Win32.PInvoke.MessageBox( + 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", + Windows.Win32.UI.WindowsAndMessaging.MESSAGEBOX_STYLE.MB_OK | Windows.Win32.UI.WindowsAndMessaging.MESSAGEBOX_STYLE.MB_ICONWARNING + ); + } } } diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 5d62b00c..a71a0fb6 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -21,6 +21,12 @@ namespace DepotDownloader if (args.Length == 0) { PrintUsage(); + + if (OperatingSystem.IsWindows()) + { + PlatformUtilities.VerifyConsoleLaunch(); + } + return 1; }