Skip to content

Commit

Permalink
make startup more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
bluepilledgreat committed Dec 27, 2024
1 parent 51ededb commit f768f0a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,21 @@ protected override void OnStartup(StartupEventArgs e)
if (installLocation is null)
{
Logger.Initialize(true);
Logger.WriteLine(LOG_IDENT, "Not installed, launching the installer");
LaunchHandler.LaunchInstaller();
}
else
{
Paths.Initialize(installLocation);

Logger.WriteLine(LOG_IDENT, "Entering main logic");

// ensure executable is in the install directory
if (Paths.Process != Paths.Application && !File.Exists(Paths.Application))
{
Logger.WriteLine(LOG_IDENT, "Copying to install directory");
File.Copy(Paths.Process, Paths.Application);
}

Logger.Initialize(LaunchSettings.UninstallFlag.Active);

Expand Down Expand Up @@ -328,6 +334,7 @@ protected override void OnStartup(StartupEventArgs e)
}

// you must *explicitly* call terminate when everything is done, it won't be called implicitly
Logger.WriteLine(LOG_IDENT, "Startup finished");
}
}
}
28 changes: 28 additions & 0 deletions Bloxstrap/LaunchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,68 @@ public static class LaunchHandler
{
public static void ProcessNextAction(NextAction action, bool isUnfinishedInstall = false)
{
const string LOG_IDENT = "LaunchHandler::ProcessNextAction";

switch (action)
{
case NextAction.LaunchSettings:
App.Logger.WriteLine(LOG_IDENT, "Opening settings");
LaunchSettings();
break;

case NextAction.LaunchRoblox:
App.Logger.WriteLine(LOG_IDENT, "Opening Roblox");
LaunchRoblox(LaunchMode.Player);
break;

case NextAction.LaunchRobloxStudio:
App.Logger.WriteLine(LOG_IDENT, "Opening Roblox Studio");
LaunchRoblox(LaunchMode.Studio);
break;

default:
App.Logger.WriteLine(LOG_IDENT, "Closing");
App.Terminate(isUnfinishedInstall ? ErrorCode.ERROR_INSTALL_USEREXIT : ErrorCode.ERROR_SUCCESS);
break;
}
}

public static void ProcessLaunchArgs()
{
const string LOG_IDENT = "LaunchHandler::ProcessLaunchArgs";

// this order is specific

if (App.LaunchSettings.UninstallFlag.Active)
{
App.Logger.WriteLine(LOG_IDENT, "Opening uninstaller");
LaunchUninstaller();
}
else if (App.LaunchSettings.MenuFlag.Active)
{
App.Logger.WriteLine(LOG_IDENT, "Opening settings");
LaunchSettings();
}
else if (App.LaunchSettings.WatcherFlag.Active)
{
App.Logger.WriteLine(LOG_IDENT, "Opening watcher");
LaunchWatcher();
}
else if (App.LaunchSettings.RobloxLaunchMode != LaunchMode.None)
{
App.Logger.WriteLine(LOG_IDENT, $"Opening bootstrapper ({App.LaunchSettings.RobloxLaunchMode})");
LaunchRoblox(App.LaunchSettings.RobloxLaunchMode);
}
else if (!App.LaunchSettings.QuietFlag.Active)
{
App.Logger.WriteLine(LOG_IDENT, "Opening menu");
LaunchMenu();
}
else
{
App.Logger.WriteLine(LOG_IDENT, "Closing - quiet flag active");
App.Terminate();
}
}

public static void LaunchInstaller()
Expand Down Expand Up @@ -235,6 +261,8 @@ public static void LaunchRoblox(LaunchMode launchMode)
});

dialog?.ShowBootstrapper();

App.Logger.WriteLine(LOG_IDENT, "Exiting");
}

public static void LaunchWatcher()
Expand Down
29 changes: 28 additions & 1 deletion Bloxstrap/LaunchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public LaunchSettings(string[] args)
_flagMap.Add(identifier, flag);
}

int startIdx = 0;

// infer roblox launch uris
if (Args.Length >= 1)
{
Expand All @@ -80,23 +82,31 @@ public LaunchSettings(string[] args)
if (arg.StartsWith("roblox:", StringComparison.OrdinalIgnoreCase)
|| arg.StartsWith("roblox-player:", StringComparison.OrdinalIgnoreCase))
{
App.Logger.WriteLine(LOG_IDENT, "Got Roblox player argument");
RobloxLaunchMode = LaunchMode.Player;
RobloxLaunchArgs = arg;
startIdx = 1;
}
}

// parse
for (int i = 0; i < Args.Length; i++)
for (int i = startIdx; i < Args.Length; i++)
{
string arg = Args[i];

if (!arg.StartsWith('-'))
{
App.Logger.WriteLine(LOG_IDENT, $"Invalid argument: {arg}");
continue;
}

string identifier = arg[1..];

if (!_flagMap.TryGetValue(identifier, out LaunchFlag? flag) || flag is null)
{
App.Logger.WriteLine(LOG_IDENT, $"Unknown argument: {identifier}");
continue;
}

flag.Active = true;

Expand All @@ -119,31 +129,48 @@ public LaunchSettings(string[] args)

private void ParsePlayer(string? data)
{
const string LOG_IDENT = "LaunchSettings::ParsePlayer";

RobloxLaunchMode = LaunchMode.Player;

if (!String.IsNullOrEmpty(data))
{
App.Logger.WriteLine(LOG_IDENT, "Got Roblox launch arguments");
RobloxLaunchArgs = data;
}
else
{
App.Logger.WriteLine(LOG_IDENT, "No Roblox launch arguments were provided");
}
}

private void ParseStudio(string? data)
{
const string LOG_IDENT = "LaunchSettings::ParseStudio";

RobloxLaunchMode = LaunchMode.Studio;

if (String.IsNullOrEmpty(data))
{
App.Logger.WriteLine(LOG_IDENT, "No Roblox launch arguments were provided");
return;
}

if (data.StartsWith("roblox-studio:"))
{
App.Logger.WriteLine(LOG_IDENT, "Got Roblox Studio launch arguments");
RobloxLaunchArgs = data;
}
else if (data.StartsWith("roblox-studio-auth:"))
{
App.Logger.WriteLine(LOG_IDENT, "Got Roblox Studio Auth launch arguments");
RobloxLaunchMode = LaunchMode.StudioAuth;
RobloxLaunchArgs = data;
}
else
{
// likely a local path
App.Logger.WriteLine(LOG_IDENT, "Got Roblox Studio local place file");
RobloxLaunchArgs = $"-task EditFile -localPlaceFile \"{data}\"";
}
}
Expand Down

0 comments on commit f768f0a

Please sign in to comment.