From e0f261067e2cc66dbfd7b8273f6d51711a711065 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 10 Oct 2023 23:00:34 +0100 Subject: [PATCH] Use enum value for determining launch mode might change how this looks, such as getting rid of StudioAuth as its own thing --- Bloxstrap/App.xaml.cs | 17 +++++++------- Bloxstrap/Bootstrapper.cs | 44 +++++++++++++++++------------------ Bloxstrap/Enums/LaunchMode.cs | 9 +++++++ 3 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 Bloxstrap/Enums/LaunchMode.cs diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index fddcc1a..c6886c9 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -197,8 +197,7 @@ namespace Bloxstrap #endif string commandLine = ""; - bool isStudioLaunch = false; - bool isStudioAuth = false; + LaunchMode launchMode = LaunchMode.Player; if (IsMenuLaunch) { @@ -240,19 +239,21 @@ namespace Bloxstrap else if (LaunchArgs[0].StartsWith("roblox-studio:")) { commandLine = ProtocolHandler.ParseUri(LaunchArgs[0]); + if (!commandLine.Contains("-startEvent")) commandLine += " -startEvent www.roblox.com/robloxQTStudioStartedEvent"; - isStudioLaunch = true; + + launchMode = LaunchMode.Studio; } else if (LaunchArgs[0].StartsWith("roblox-studio-auth:")) { commandLine = HttpUtility.UrlDecode(LaunchArgs[0]); - isStudioLaunch = true; - isStudioAuth = true; + launchMode = LaunchMode.StudioAuth; } else if (LaunchArgs[0] == "-ide") { - isStudioLaunch = true; + launchMode = LaunchMode.Studio; + if (LaunchArgs.Length >= 2) commandLine = $"-task EditFile -localPlaceFile \"{LaunchArgs[1]}\""; } @@ -273,7 +274,7 @@ namespace Bloxstrap // start bootstrapper and show the bootstrapper modal if we're not running silently Logger.WriteLine(LOG_IDENT, "Initializing bootstrapper"); - Bootstrapper bootstrapper = new(commandLine, isStudioLaunch, isStudioAuth); + Bootstrapper bootstrapper = new(commandLine, launchMode); IBootstrapperDialog? dialog = null; if (!IsQuiet) @@ -290,7 +291,7 @@ namespace Bloxstrap Mutex? singletonMutex = null; - if (Settings.Prop.MultiInstanceLaunching && !isStudioLaunch) + if (Settings.Prop.MultiInstanceLaunching && launchMode == LaunchMode.Player) { Logger.WriteLine(LOG_IDENT, "Creating singleton mutex"); diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index dfeb1b8..c4205f7 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -23,27 +23,26 @@ namespace Bloxstrap private bool FreshInstall => String.IsNullOrEmpty(_versionGuid); - private string _playerFileName => _studioLaunch ? "RobloxStudioBeta.exe" : "RobloxPlayerBeta.exe"; + private string _playerFileName => _launchMode == LaunchMode.Player ? "RobloxPlayerBeta.exe" : "RobloxStudioBeta.exe"; // TODO: change name private string _playerLocation => Path.Combine(_versionFolder, _playerFileName); private string _launchCommandLine; - private bool _studioLaunch; - private bool _studioAuth; + private LaunchMode _launchMode; private string _versionGuid { get { - return _studioLaunch ? App.State.Prop.StudioVersionGuid : App.State.Prop.PlayerVersionGuid; + return _launchMode == LaunchMode.Player ? App.State.Prop.PlayerVersionGuid : App.State.Prop.StudioVersionGuid; } set { - if (_studioLaunch) - App.State.Prop.StudioVersionGuid = value; - else + if (_launchMode == LaunchMode.Player) App.State.Prop.PlayerVersionGuid = value; + else + App.State.Prop.StudioVersionGuid = value; } } @@ -51,15 +50,15 @@ namespace Bloxstrap { get { - return _studioLaunch ? App.State.Prop.StudioSize : App.State.Prop.PlayerSize; + return _launchMode == LaunchMode.Player ? App.State.Prop.PlayerSize : App.State.Prop.StudioSize; } set { - if (_studioLaunch) - App.State.Prop.StudioSize = value; - else + if (_launchMode == LaunchMode.Player) App.State.Prop.PlayerSize = value; + else + App.State.Prop.StudioSize = value; } } @@ -76,17 +75,17 @@ namespace Bloxstrap private IReadOnlyDictionary _packageDirectories; public IBootstrapperDialog? Dialog = null; - public bool IsStudioLaunch => _studioLaunch; + + public bool IsStudioLaunch => _launchMode != LaunchMode.Player; #endregion #region Core - public Bootstrapper(string launchCommandLine, bool studioLaunch, bool studioAuth) + public Bootstrapper(string launchCommandLine, LaunchMode launchMode) { _launchCommandLine = launchCommandLine; - _studioLaunch = studioLaunch; - _studioAuth = studioAuth; + _launchMode = launchMode; - _packageDirectories = _studioLaunch ? PackageMap.Studio : PackageMap.Player; + _packageDirectories = _launchMode == LaunchMode.Player ? PackageMap.Player : PackageMap.Studio; } private void SetStatus(string message) @@ -94,7 +93,8 @@ namespace Bloxstrap App.Logger.WriteLine("Bootstrapper::SetStatus", message); string productName = "Roblox"; - if (_studioLaunch) + + if (_launchMode != LaunchMode.Player) productName += " Studio"; message = message.Replace("{product}", productName); @@ -242,7 +242,7 @@ namespace Bloxstrap ClientVersion clientVersion; - string binaryType = _studioLaunch ? "WindowsStudio64" : "WindowsPlayer"; + string binaryType = _launchMode == LaunchMode.Player ? "WindowsPlayer" : "WindowsStudio64"; try { @@ -314,7 +314,7 @@ namespace Bloxstrap return; } - if (!_studioAuth) + if (_launchMode != LaunchMode.StudioAuth) { _launchCommandLine = _launchCommandLine.Replace("LAUNCHTIMEPLACEHOLDER", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString()); @@ -336,7 +336,7 @@ namespace Bloxstrap WorkingDirectory = _versionFolder }; - if (_studioAuth) + if (_launchMode == LaunchMode.StudioAuth) { Process.Start(startInfo); Dialog?.CloseBootstrapper(); @@ -356,7 +356,7 @@ namespace Bloxstrap App.Logger.WriteLine(LOG_IDENT, $"Started Roblox (PID {gameClientPid})"); - string eventName = _studioLaunch ? "www.roblox.com/robloxQTStudioStartedEvent" : "www.roblox.com/robloxStartedEvent"; + string eventName = _launchMode == LaunchMode.Player ? "www.roblox.com/robloxStartedEvent" : "www.roblox.com/robloxQTStudioStartedEvent"; using (SystemEvent startEvent = new(eventName)) { bool startEventFired = await startEvent.WaitForEvent(); @@ -367,7 +367,7 @@ namespace Bloxstrap return; } - if (App.Settings.Prop.EnableActivityTracking && !_studioLaunch) + if (App.Settings.Prop.EnableActivityTracking && _launchMode == LaunchMode.Player) App.NotifyIcon?.SetProcessId(gameClientPid); if (App.Settings.Prop.EnableActivityTracking) diff --git a/Bloxstrap/Enums/LaunchMode.cs b/Bloxstrap/Enums/LaunchMode.cs new file mode 100644 index 0000000..d1a34e9 --- /dev/null +++ b/Bloxstrap/Enums/LaunchMode.cs @@ -0,0 +1,9 @@ +namespace Bloxstrap.Enums +{ + public enum LaunchMode + { + Player, + Studio, + StudioAuth + } +}