add nocmd, fix loop

This commit is contained in:
Bitl 2022-09-18 07:59:32 -07:00
parent cfac86bc5d
commit ceea62b2f9
7 changed files with 148 additions and 38 deletions

View File

@ -43,6 +43,7 @@ namespace Novetus.Bootstrapper
this.URIButton = new System.Windows.Forms.Button();
this.VersionLabel = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.LaunchNovetusWithConsoleButton = new System.Windows.Forms.Button();
this.CMDGroup.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
@ -50,10 +51,10 @@ namespace Novetus.Bootstrapper
//
// LaunchNovetusButton
//
this.LaunchNovetusButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 27.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.LaunchNovetusButton.Location = new System.Drawing.Point(12, 132);
this.LaunchNovetusButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.LaunchNovetusButton.Location = new System.Drawing.Point(12, 99);
this.LaunchNovetusButton.Name = "LaunchNovetusButton";
this.LaunchNovetusButton.Size = new System.Drawing.Size(485, 52);
this.LaunchNovetusButton.Size = new System.Drawing.Size(485, 50);
this.LaunchNovetusButton.TabIndex = 0;
this.LaunchNovetusButton.Text = "PLAY NOVETUS";
this.LaunchNovetusButton.UseVisualStyleBackColor = true;
@ -166,9 +167,9 @@ namespace Novetus.Bootstrapper
//
this.VersionLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.VersionLabel.ForeColor = System.Drawing.Color.IndianRed;
this.VersionLabel.Location = new System.Drawing.Point(20, 95);
this.VersionLabel.Location = new System.Drawing.Point(20, 73);
this.VersionLabel.Name = "VersionLabel";
this.VersionLabel.Size = new System.Drawing.Size(470, 34);
this.VersionLabel.Size = new System.Drawing.Size(470, 26);
this.VersionLabel.TabIndex = 8;
this.VersionLabel.Text = "v1.0";
this.VersionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@ -178,19 +179,31 @@ namespace Novetus.Bootstrapper
this.pictureBox1.BackgroundImage = global::Novetus.Bootstrapper.Properties.Resources.NOVETUS_new_final_smol;
this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox1.InitialImage = null;
this.pictureBox1.Location = new System.Drawing.Point(21, 12);
this.pictureBox1.Location = new System.Drawing.Point(70, 2);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(469, 91);
this.pictureBox1.Size = new System.Drawing.Size(371, 80);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// LaunchNovetusWithConsoleButton
//
this.LaunchNovetusWithConsoleButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.LaunchNovetusWithConsoleButton.Location = new System.Drawing.Point(12, 155);
this.LaunchNovetusWithConsoleButton.Name = "LaunchNovetusWithConsoleButton";
this.LaunchNovetusWithConsoleButton.Size = new System.Drawing.Size(485, 30);
this.LaunchNovetusWithConsoleButton.TabIndex = 9;
this.LaunchNovetusWithConsoleButton.Text = "PLAY NOVETUS WITH CONSOLE";
this.LaunchNovetusWithConsoleButton.UseVisualStyleBackColor = true;
this.LaunchNovetusWithConsoleButton.Click += new System.EventHandler(this.LaunchNovetusWithConsoleButton_Click);
//
// NovetusLaunchForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(508, 294);
this.Controls.Add(this.LaunchNovetusWithConsoleButton);
this.Controls.Add(this.VersionLabel);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.CMDGroup);
@ -226,6 +239,7 @@ namespace Novetus.Bootstrapper
private System.Windows.Forms.Button URIButton;
private System.Windows.Forms.Label VersionLabel;
private System.Windows.Forms.CheckBox LauncherBox;
private System.Windows.Forms.Button LaunchNovetusWithConsoleButton;
}
}

View File

@ -63,6 +63,12 @@ namespace Novetus.Bootstrapper
}
private void LaunchNovetus()
{
LocalFuncs.LaunchApplication(LocalPaths.LauncherName, "-nocmd");
Close();
}
private void LaunchNovetusWithConsoleButton_Click(object sender, EventArgs e)
{
LocalFuncs.LaunchApplication(LocalPaths.LauncherName);
Close();
@ -76,13 +82,13 @@ namespace Novetus.Bootstrapper
private void CMDButton_Click(object sender, EventArgs e)
{
LocalFuncs.LaunchApplication(LocalPaths.LauncherName, "-cmd -cmdmode " + ArgBox.Text);
LocalFuncs.LaunchApplication(LocalPaths.LauncherName, "-cmdonly -cmdmode " + ArgBox.Text);
Close();
}
private void CMDHelpButton_Click(object sender, EventArgs e)
{
LocalFuncs.LaunchApplication(LocalPaths.LauncherName, "-cmd -help");
LocalFuncs.LaunchApplication(LocalPaths.LauncherName, "-cmdonly -help");
}
private void DependencyInstallerButton_Click(object sender, EventArgs e)

View File

@ -14,6 +14,7 @@ using NLog;
using System.Text.RegularExpressions;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Management;
#if !BASICLAUNCHER
using Mono.Nat;
#endif
@ -21,17 +22,18 @@ using Mono.Nat;
#region Utils
//This code was brought to you by:
//https://stackoverflow.com/questions/1926264/color-different-parts-of-a-richtextbox-string
//https://stackoverflow.com/questions/262280/how-can-i-know-if-a-process-is-running
//https://stackoverflow.com/questions/444798/case-insensitive-containsstring
//https://stackoverflow.com/questions/6084940/how-do-i-search-a-multi-dimensional-array
//https://www.dotnetperls.com/between-before-after
//https://stackoverflow.com/questions/12422619/can-i-disable-the-close-button-of-a-form-using-c
//https://stackoverflow.com/questions/9031537/really-simple-encryption-with-c-sharp-and-symmetricalgorithm
public static class Util
{
#region Extensions
//This code was brought to you by:
//https://stackoverflow.com/questions/1926264/color-different-parts-of-a-richtextbox-string
//https://stackoverflow.com/questions/262280/how-can-i-know-if-a-process-is-running
//https://stackoverflow.com/questions/444798/case-insensitive-containsstring
//https://stackoverflow.com/questions/6084940/how-do-i-search-a-multi-dimensional-array
//https://www.dotnetperls.com/between-before-after
//https://stackoverflow.com/questions/12422619/can-i-disable-the-close-button-of-a-form-using-c
//https://stackoverflow.com/questions/9031537/really-simple-encryption-with-c-sharp-and-symmetricalgorithm
#region Rich Text Box Extensions
public static void AppendText(this RichTextBox box, string text, Color color)
{
@ -237,6 +239,71 @@ public static class Util
}
#endregion
#region Process Extensions
//https://stackoverflow.com/questions/2633628/can-i-get-command-line-arguments-of-other-processes-from-net-c
// Define an extension method for type System.Process that returns the command
// line via WMI.
public static string GetCommandLine(this Process process)
{
string cmdLine = null;
using (var searcher = new ManagementObjectSearcher(
$"SELECT CommandLine FROM Win32_Process WHERE ProcessId = {process.Id}"))
{
// By definition, the query returns at most 1 match, because the process
// is looked up by ID (which is unique by definition).
using (var matchEnum = searcher.Get().GetEnumerator())
{
if (matchEnum.MoveNext()) // Move to the 1st item.
{
cmdLine = matchEnum.Current["CommandLine"]?.ToString();
}
}
}
if (cmdLine == null)
{
// Not having found a command line implies 1 of 2 exceptions, which the
// WMI query masked:
// An "Access denied" exception due to lack of privileges.
// A "Cannot process request because the process (<pid>) has exited."
// exception due to the process having terminated.
// We provoke the same exception again simply by accessing process.MainModule.
var dummy = process.MainModule; // Provoke exception.
}
return cmdLine;
}
// based off the above function
public static string GetFilePath(this Process process)
{
string path = null;
using (var searcher = new ManagementObjectSearcher(
$"SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = {process.Id}"))
{
// By definition, the query returns at most 1 match, because the process
// is looked up by ID (which is unique by definition).
using (var matchEnum = searcher.Get().GetEnumerator())
{
if (matchEnum.MoveNext()) // Move to the 1st item.
{
path = matchEnum.Current["ExecutablePath"]?.ToString();
}
}
}
if (path == null)
{
// Not having found a command line implies 1 of 2 exceptions, which the
// WMI query masked:
// An "Access denied" exception due to lack of privileges.
// A "Cannot process request because the process (<pid>) has exited."
// exception due to the process having terminated.
// We provoke the same exception again simply by accessing process.MainModule.
var dummy = process.MainModule; // Provoke exception.
}
return path;
}
#endregion
#endregion
#region Utility Functions
private static DialogResult ShowOverrideWarning(string dest)
{

View File

@ -3,6 +3,7 @@ using Mono.Nat;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
@ -528,24 +529,21 @@ namespace NovetusLauncher
if (FormStyle != Settings.Style.Extended)
{
GlobalVars.UserConfiguration.LauncherStyle = Settings.Style.Extended;
CloseEventInternal();
System.Diagnostics.Process.Start(Application.ExecutablePath);
RestartApp();
}
break;
case 1:
if (FormStyle != Settings.Style.Compact)
{
GlobalVars.UserConfiguration.LauncherStyle = Settings.Style.Compact;
CloseEventInternal();
System.Diagnostics.Process.Start(Application.ExecutablePath);
RestartApp();
}
break;
case 2:
if (FormStyle != Settings.Style.Stylish)
{
GlobalVars.UserConfiguration.LauncherStyle = Settings.Style.Stylish;
CloseEventInternal();
System.Diagnostics.Process.Start(Application.ExecutablePath);
RestartApp();
}
break;
default:
@ -553,6 +551,13 @@ namespace NovetusLauncher
}
}
public void RestartApp()
{
var process = Process.GetCurrentProcess();
Process.Start(process.GetFilePath(), process.GetCommandLine());
CloseEventInternal();
}
public void ReadConfigValues(bool initial = false)
{
FileManagement.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, false);

View File

@ -488,13 +488,11 @@ namespace NovetusLauncher
{
case 0:
GlobalVars.UserConfiguration.LauncherStyle = Settings.Style.Extended;
launcherForm.CloseEventInternal();
System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath);
launcherForm.RestartApp();
break;
case 1:
GlobalVars.UserConfiguration.LauncherStyle = Settings.Style.Compact;
launcherForm.CloseEventInternal();
System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath);
launcherForm.RestartApp();
break;
default:
break;

View File

@ -77,7 +77,7 @@ namespace NovetusLauncher
ConsoleHelp();
}
if (ConsoleArgs["cmd"] != null && ConsoleArgs["cmdmode"] != null && !helpMode)
if (ConsoleArgs["cmdonly"] != null && ConsoleArgs["cmdmode"] != null && !helpMode)
{
//cmd mode
disableCommands = true;
@ -312,9 +312,10 @@ namespace NovetusLauncher
Util.ConsolePrint("---------", 1, true);
Util.ConsolePrint("GLOBAL - Affects launcher session.", 5, true);
Util.ConsolePrint("---------", 1, true);
Util.ConsolePrint("- sdk | Launches the Novetus SDK Launcher.", 4, true);
Util.ConsolePrint("- cmd | Launches the Novetus Console only.", 4, true);
Util.ConsolePrint("- sdk | Launches the Novetus SDK Launcher", 4, true);
Util.ConsolePrint("- cmdonly | Launches the Novetus Console only.", 4, true);
Util.ConsolePrint("- nofilelist | Disables file list generation", 4, true);
Util.ConsolePrint("- nocmd | Don't launch the Novetus Console", 4, true);
Util.ConsolePrint("---------", 1, true);
Util.ConsolePrint("CONSOLE - Affects console only.", 5, true);
Util.ConsolePrint("---------", 1, true);

View File

@ -15,6 +15,13 @@ namespace NovetusLauncher
#region Novetus Launcher Main Class
internal sealed class NovetusLauncherEntryPoint
{
enum CMDState
{
CMDOpen,
CMDOnly,
CMDNone
}
static bool formsOpen = false;
/// <summary>
@ -41,6 +48,7 @@ namespace NovetusLauncher
GlobalVars.ColorsLoaded = FileManagement.InitColors();
bool isSDK = false;
CMDState state = CMDState.CMDOpen;
if (args.Length > 0)
{
@ -51,21 +59,27 @@ namespace NovetusLauncher
isSDK = true;
}
if (CommandLine["cmd"] != null)
if (CommandLine["cmdonly"] != null)
{
state = CMDState.CMDOnly;
GlobalVars.isConsoleOnly = true;
}
if (CommandLine["nocmd"] != null)
{
state = CMDState.CMDNone;
}
if (CommandLine["nofilelist"] != null)
{
GlobalVars.NoFileList = true;
}
}
Run(args, isSDK, GlobalVars.isConsoleOnly);
Run(args, isSDK, state);
}
static void Run(string[] args, bool sdk = false, bool cmdonly = false)
static void Run(string[] args, bool sdk = false, CMDState state = CMDState.CMDOpen)
{
try
{
@ -75,11 +89,14 @@ namespace NovetusLauncher
if (!formsOpen)
{
NovetusConsole console = new NovetusConsole(args);
GlobalVars.consoleForm = console;
console.Show();
if (state != CMDState.CMDNone)
{
NovetusConsole console = new NovetusConsole(args);
GlobalVars.consoleForm = console;
console.Show();
}
if (!cmdonly)
if (state != CMDState.CMDOnly)
{
if (!sdk)
{
@ -109,6 +126,8 @@ namespace NovetusLauncher
formsOpen = true;
}
Thread.Sleep(100);
}
System.Windows.Forms.Application.Exit();