Skip to content

Commit

Permalink
Improved updating window title and handling "laargs.txt"
Browse files Browse the repository at this point in the history
  • Loading branch information
zabszk committed Dec 5, 2023
1 parent abb724f commit 0fef669
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
40 changes: 27 additions & 13 deletions Core/LocalAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public sealed class LocalAdmin : IDisposable
private static bool _noTrueColor;
private static bool _stdPrint;
private static bool _ignoreNextRestart;
private static bool _noTerminalTitle;
private static int _restarts = -1, _restartsLimit = 4, _restartsTimeWindow = 480; //480 seconds = 8 minutes

private readonly CommandService _commandService = new();
private readonly string _scpslExecutable;
private volatile bool _processClosing;
private bool _idleMode;
private uint _heartbeatSpanMaxThreshold;
private uint _heartbeatRestartInSeconds;
private Process? _gameProcess;
Expand All @@ -60,11 +62,12 @@ public sealed class LocalAdmin : IDisposable
internal static ulong LogLengthLimit = 25000000000, LogEntriesLimit = 10000000000;
internal static Config? Configuration;
internal static DataJson? DataJson;
internal static string BaseWindowTitle =>
private string BaseWindowTitle =>
(_idleMode ? "[IDLE] " : string.Empty) +
$"LocalAdmin v. {VersionString}" +
(GamePort != 0 ? $" | Port: {GamePort}" : string.Empty) +
(_processId.HasValue ? $" | PID: {_processId}" : string.Empty);
internal static bool NoSetCursor, PrintControlMessages, AutoFlush = true, EnableLogging = true, NoPadding, DismissPluginsSecurityWarning, NoTerminalTitle;
internal static bool NoSetCursor, PrintControlMessages, AutoFlush = true, EnableLogging = true, NoPadding, DismissPluginsSecurityWarning;

internal ShutdownAction ExitAction = ShutdownAction.Crash;
internal bool DisableExitActionSignals;
Expand Down Expand Up @@ -120,6 +123,10 @@ internal LocalAdmin()
internal async Task Start(string[] args)
{
Singleton = this;

if (args.Length == 0)
SetTerminalTitle();

HeartbeatStopwatch.Reset();

if (!PathManager.CorrectPathFound && !args.Contains("--skipHomeCheck", StringComparer.Ordinal))
Expand Down Expand Up @@ -290,7 +297,7 @@ internal async Task Start(string[] args)
NoPadding = true;
break;
case 't':
NoTerminalTitle = true;
_noTerminalTitle = true;
break;
}
}
Expand Down Expand Up @@ -368,7 +375,7 @@ internal async Task Start(string[] args)
break;

case "--noTerminalTitle":
NoTerminalTitle = true;
_noTerminalTitle = true;
break;

case "--":
Expand Down Expand Up @@ -479,7 +486,7 @@ internal async Task Start(string[] args)
}
}

SetTerminalTitle(BaseWindowTitle);
SetTerminalTitle();

if (reconfigure)
ConfigWizard.RunConfigWizard(useDefault);
Expand Down Expand Up @@ -571,7 +578,7 @@ private void StartSession()
TerminateGame();

Menu();
SetTerminalTitle(BaseWindowTitle);
SetTerminalTitle();
Logger.Initialize();

ConsoleUtil.WriteLine($"Started new session on port {GamePort}.", ConsoleColor.DarkGreen);
Expand Down Expand Up @@ -792,7 +799,7 @@ private void RunScpsl()
_gameProcess = Process.Start(startInfo);

_processId = _gameProcess!.Id;
SetTerminalTitle(BaseWindowTitle);
SetTerminalTitle();

ConsoleUtil.WriteLine("Game process started with PID: " + _processId, ConsoleColor.DarkGreen);

Expand Down Expand Up @@ -1147,13 +1154,20 @@ async void HeartbeatMonitoringMethod()
}

/// <summary>
/// Sets the terminal title if not disabled in the config or by command line arguments
/// Sets the terminal title if not disabled in the config or by command line arguments
/// </summary>
public static void SetTerminalTitle(string terminalTitle)
private void SetTerminalTitle()
{
if (!NoTerminalTitle && (Configuration?.SetTerminalTitle ?? false))
{
Console.Title = terminalTitle;
}
if (!_noTerminalTitle && (Configuration?.SetTerminalTitle ?? false))
Console.Title = BaseWindowTitle;
}

internal static void SetIdleModeState(bool state)
{
if (Singleton == null)
return;

Singleton._idleMode = state;
Singleton.SetTerminalTitle();
}
}
27 changes: 12 additions & 15 deletions Core/StartupArgManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,32 @@ public static class StartupArgManager
private const string StartupArgsPath = "laargs.txt";

/// <summary>
/// Merges Command-line arguments and arguments in <paramref name="StartupArgsPath"/>
/// Merges Command-line arguments and arguments in <paramref name="cmdArgs"/>
/// </summary>
/// <param name="CMDArgs">Runtime Command-Line Arguments</param>
/// <param name="cmdArgs">Runtime Command-Line Arguments</param>
/// <returns>Merged Arguments</returns>
public static string[] MergeStartupArgs(IEnumerable<string> CMDArgs)
public static string[] MergeStartupArgs(IEnumerable<string> cmdArgs)
{
List<string> startupArgs = new List<string>();
startupArgs.AddRange(cmdArgs);

try
{
List<string> StartupArgs = new List<string>();
StartupArgs.AddRange(CMDArgs);

if (!File.Exists(StartupArgsPath))
{
File.WriteAllText(StartupArgsPath, string.Empty);
return CMDArgs.ToArray();
}
return startupArgs.ToArray();

foreach (string farg in File.ReadAllLines(StartupArgsPath))
foreach (string arg in File.ReadAllLines(StartupArgsPath))
{
if (!farg.StartsWith("#", StringComparison.Ordinal))
StartupArgs.Add(farg);
if (!arg.StartsWith("#", StringComparison.Ordinal))
startupArgs.Add(arg);
}

return StartupArgs.ToArray();
return startupArgs.ToArray();
}
catch (Exception ex)
{
ConsoleUtil.WriteLine($"An error occured while trying to merge arguments: {ex}", ConsoleColor.Red);
return CMDArgs.ToArray();
return startupArgs.ToArray();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Core/TcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public void Start()
break;

case OutputCodes.IdleEnter:
LocalAdmin.SetTerminalTitle("[IDLE] " + LocalAdmin.BaseWindowTitle);
LocalAdmin.SetIdleModeState(true);
break;

case OutputCodes.IdleExit:
LocalAdmin.SetTerminalTitle(LocalAdmin.BaseWindowTitle);
LocalAdmin.SetIdleModeState(false);
break;

case OutputCodes.ExitActionReset:
Expand Down
4 changes: 3 additions & 1 deletion LocalAdmin V2.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jurczyk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=localadmin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Northwood/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Publishment/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SCPSL/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=zabszk/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=zabszk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0141ukasz/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 0fef669

Please sign in to comment.