From 13c2021d960e105475118127be5555e33b8862fa Mon Sep 17 00:00:00 2001 From: David DarkVamprism Date: Thu, 20 Aug 2020 15:03:22 +0800 Subject: [PATCH] Fixed error with using args array when no args were sent. Added console process when ran in silent mode(I guess its more automatic mode rather than silent) --- BandagedBD/Program.cs | 77 ++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/BandagedBD/Program.cs b/BandagedBD/Program.cs index 2a62d00..65e5b97 100644 --- a/BandagedBD/Program.cs +++ b/BandagedBD/Program.cs @@ -1,5 +1,6 @@ using BandagedBD.Silent; using System; +using System.Runtime.InteropServices; using System.Windows.Forms; namespace BandagedBD { @@ -9,44 +10,51 @@ namespace BandagedBD { /// [STAThread] + [DllImport("kernel32.dll")] + static extern bool AttachConsole(int dwProcessId); + private const int ATTACH_PARENT_PROCESS = -1; + static void Main(string[] args) { LaunchMode launchMode = LaunchMode.GUI; // check first argument to check if it is a silent install switch - switch (args[0].ToLower()) { - // Silent Install switches - case "-install": - case "-i": - launchMode = LaunchMode.Install; - break; - case "-repair": - case "-r": - launchMode = LaunchMode.Repair; - break; - case "-uninstall": - case "-u": - launchMode = LaunchMode.Uninstall; - break; - case "-help": - case "-h": - launchMode = LaunchMode.None; - Console.WriteLine("-install, -i Install BBD\n" + - "-uninstall, -u Uninstall BBD\n" + - " Optional switches for uninstall\n" + - " -deleteuserdata deletes all user settings of betterdiscord\n" + - "-repair, -r Repair BBD\n" + - " Optional switches for repair, for the following issues\n" + - " -repairupdateloop Discord update loop\n" + - " -repairnotlaunching BandagedBD not launching with Discord\n" + - " -repairloadingindefinitely BandagedBD loading indefinitely\n" + - " -repairjavascripterror Fatal JavaScript error on launch\n" + - "\nall require using one or more of the following\n" + - " -stable [path], -canary [path], -ptb [path]\n" + - "\n-norestart By default discord will be restarted, this disables restarting of processes" + - ""); - break; - default: - break; + if (args.Length > 0) { + switch (args[0].ToLower()) { + // Silent Install switches + case "-install": + case "-i": + launchMode = LaunchMode.Install; + break; + case "-repair": + case "-r": + launchMode = LaunchMode.Repair; + break; + case "-uninstall": + case "-u": + launchMode = LaunchMode.Uninstall; + break; + case "-help": + case "-h": + launchMode = LaunchMode.None; + AttachConsole(ATTACH_PARENT_PROCESS); + Console.WriteLine("-install, -i Install BBD\n" + + "-uninstall, -u Uninstall BBD\n" + + " Optional switches for uninstall\n" + + " -deleteuserdata deletes all user settings of betterdiscord\n" + + "-repair, -r Repair BBD\n" + + " Optional switches for repair, for the following issues\n" + + " -repairupdateloop Discord update loop\n" + + " -repairnotlaunching BandagedBD not launching with Discord\n" + + " -repairloadingindefinitely BandagedBD loading indefinitely\n" + + " -repairjavascripterror Fatal JavaScript error on launch\n" + + "\nall require using one or more of the following\n" + + " -stable [path], -canary [path], -ptb [path]\n" + + "\n-norestart By default discord will be restarted, this disables restarting of processes" + + ""); + break; + default: + break; + } } switch (launchMode) { @@ -58,6 +66,7 @@ namespace BandagedBD { case LaunchMode.None: break; default: + AttachConsole(ATTACH_PARENT_PROCESS); new SilentOnlyUtilities(launchMode, args); break; }