public static void PrintDebugBuild() { ConsoleUtilities.HighlightConsole(() => { Console.WriteLine($"This is a debug build of {ApplicationInfo.Name}."); Console.WriteLine(new String('-', 33)); Console.WriteLine(); }); }
/// <summary> /// Prints an exit message and exits. /// </summary> /// <param name="exitCode">The exit code of the administrator process. Leave null if none.</param> private static void Exit(int?exitCode = null) { if (ProcessUtilities.HasOwnWindow()) { ConsoleUtilities.HighlightConsole(() => { Console.WriteLine(); if (exitCode.HasValue) { Console.WriteLine($"The administrator process has exited with exit code {exitCode}."); } Console.WriteLine("Press any key to continue."); }); Console.ReadKey(); } Environment.Exit(0); }
/// <summary> /// Checks if help information should be printed. /// </summary> /// <param name="commandLineArgs"></param> /// <returns></returns> public static bool CheckHelp(string[] commandLineArgs) { if (commandLineArgs.Length >= 2) { if (commandLineArgs[1] == "-h" || commandLineArgs[1] == "--help" || commandLineArgs[1] == "-?") { ConsoleUtilities.HighlightConsole(() => Console.WriteLine($"{ApplicationInfo.Name} version {ApplicationInfo.Version}")); Console.WriteLine(); Console.WriteLine("[su only]"); Console.WriteLine("Use the '-c' option to run the specified commands in a console window and close the console window."); Console.WriteLine("Use the '-C' option to run the specified commands in a console window."); Console.WriteLine(); Console.WriteLine($"The following options can be used in {ApplicationInfo.Name}:"); Console.WriteLine(); Settings.PrintSettings(); return(true); } } return(false); }
/// <summary> /// Executes the progam. /// </summary> /// <param name="args">Command line arguments.</param> public static void Main(string[] args) { Debugging.PrintDebugBuild(); /* In this array, the first item (at 0) will be the path to the current * executable. The second item (at 1) will be the executable to be * invoked. Further arguments are input to the other process. */ string[] commandLineArgs = Environment.GetCommandLineArgs(); if (RuntimeChecks.CheckHelp(commandLineArgs)) { Exit(); } if (RuntimeChecks.CheckAliases(commandLineArgs)) { return; } ProcessStartInfo processStartInfo = CreateProcessStartInfo(commandLineArgs); if (processStartInfo == null) { ConsoleUtilities.HighlightConsole(() => Console.WriteLine("Please specify the command to execute.")); Console.WriteLine(); Console.WriteLine("Usage: sudo <executable> [<executable arguments>]"); Exit(); } if (ProcessUtilities.HasOwnWindow()) { Console.Title = $"{ApplicationInfo.Name} - {processStartInfo.FileName} {processStartInfo.Arguments}"; } int?exitCode = ProcessUtilities.RunSafe(processStartInfo, true); Exit(exitCode); }