Consolidate registry handling

This commit is contained in:
pizzaboxer 2024-09-09 11:41:21 +01:00
parent dd568faf9c
commit 62064117b6
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 78 additions and 57 deletions

View File

@ -193,27 +193,12 @@ namespace Bloxstrap
await ApplyModifications(); await ApplyModifications();
} }
// check if launch uri is set to our bootstrapper // check registry entries for every launch, just in case the stock bootstrapper changes it back
// this doesn't go under register, so we check every launch
// just in case the stock bootstrapper changes it back
if (IsStudioLaunch) if (IsStudioLaunch)
{ WindowsRegistry.RegisterStudio();
#if STUDIO_FEATURES
ProtocolHandler.Register("roblox-studio", "Roblox", Paths.Application);
ProtocolHandler.Register("roblox-studio-auth", "Roblox", Paths.Application);
ProtocolHandler.RegisterRobloxPlace(Paths.Application);
ProtocolHandler.RegisterExtension(".rbxl");
ProtocolHandler.RegisterExtension(".rbxlx");
#endif
}
else else
{ WindowsRegistry.RegisterPlayer();
// TODO: there needs to be better helper functions for these
ProtocolHandler.Register("roblox", "Roblox", Paths.Application, "-player \"%1\"");
ProtocolHandler.Register("roblox-player", "Roblox", Paths.Application, "-player \"%1\"");
}
await mutex.ReleaseAsync(); await mutex.ReleaseAsync();

View File

@ -63,10 +63,7 @@ namespace Bloxstrap
// only register player, for the scenario where the user installs bloxstrap, closes it, // only register player, for the scenario where the user installs bloxstrap, closes it,
// and then launches from the website expecting it to work // and then launches from the website expecting it to work
// studio can be implicitly registered when it's first launched manually // studio can be implicitly registered when it's first launched manually
ProtocolHandler.Register("roblox", "Roblox", Paths.Application, "-player \"%1\""); WindowsRegistry.RegisterPlayer();
ProtocolHandler.Register("roblox-player", "Roblox", Paths.Application, "-player \"%1\"");
// TODO: implicit installation needs to reregister studio
if (CreateDesktopShortcuts) if (CreateDesktopShortcuts)
Shortcut.Create(Paths.Application, "", DesktopShortcut); Shortcut.Create(Paths.Application, "", DesktopShortcut);
@ -79,6 +76,9 @@ namespace Bloxstrap
App.State.Load(false); App.State.Load(false);
App.FastFlags.Load(false); App.FastFlags.Load(false);
if (!String.IsNullOrEmpty(App.State.Prop.Studio.VersionGuid))
WindowsRegistry.RegisterStudio();
App.Logger.WriteLine(LOG_IDENT, "Installation finished"); App.Logger.WriteLine(LOG_IDENT, "Installation finished");
} }
@ -207,44 +207,38 @@ namespace Bloxstrap
{ {
playerStillInstalled = false; playerStillInstalled = false;
ProtocolHandler.Unregister("roblox"); WindowsRegistry.Unregister("roblox");
ProtocolHandler.Unregister("roblox-player"); WindowsRegistry.Unregister("roblox-player");
} }
else else
{ {
// revert launch uri handler to stock bootstrapper
string playerPath = Path.Combine((string)playerFolder, "RobloxPlayerBeta.exe"); string playerPath = Path.Combine((string)playerFolder, "RobloxPlayerBeta.exe");
ProtocolHandler.Register("roblox", "Roblox", playerPath); WindowsRegistry.RegisterPlayer(playerPath, "%1");
ProtocolHandler.Register("roblox-player", "Roblox", playerPath);
} }
using RegistryKey? studioBootstrapperKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\roblox-studio"); using var studioKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\roblox-studio");
if (studioBootstrapperKey is null) var studioFolder = studioKey?.GetValue("InstallLocation");
if (studioKey is null || studioFolder is not string)
{ {
studioStillInstalled = false; studioStillInstalled = false;
#if STUDIO_FEATURES WindowsRegistry.Unregister("roblox-studio");
ProtocolHandler.Unregister("roblox-studio"); WindowsRegistry.Unregister("roblox-studio-auth");
ProtocolHandler.Unregister("roblox-studio-auth");
ProtocolHandler.Unregister("Roblox.Place"); WindowsRegistry.Unregister("Roblox.Place");
ProtocolHandler.Unregister(".rbxl"); WindowsRegistry.Unregister(".rbxl");
ProtocolHandler.Unregister(".rbxlx"); WindowsRegistry.Unregister(".rbxlx");
#endif
} }
#if STUDIO_FEATURES
else else
{ {
string studioLocation = (string?)studioBootstrapperKey.GetValue("InstallLocation") + "RobloxStudioBeta.exe"; // points to studio exe instead of bootstrapper string studioPath = Path.Combine((string)studioFolder, "RobloxStudioBeta.exe");
ProtocolHandler.Register("roblox-studio", "Roblox", studioLocation); string studioLauncherPath = Path.Combine((string)studioFolder, "RobloxStudioLauncherBeta.exe");
ProtocolHandler.Register("roblox-studio-auth", "Roblox", studioLocation);
ProtocolHandler.RegisterRobloxPlace(studioLocation); WindowsRegistry.RegisterStudioProtocol(studioPath, "%1");
WindowsRegistry.RegisterStudioFileClass(studioPath, "-ide \"%1\"");
} }
#endif
var cleanupSequence = new List<Action> var cleanupSequence = new List<Action>
{ {
@ -512,8 +506,7 @@ namespace Bloxstrap
Registry.CurrentUser.DeleteSubKeyTree("Software\\Bloxstrap", false); Registry.CurrentUser.DeleteSubKeyTree("Software\\Bloxstrap", false);
ProtocolHandler.Register("roblox", "Roblox", Paths.Application, "-player \"%1\""); WindowsRegistry.RegisterPlayer();
ProtocolHandler.Register("roblox-player", "Roblox", Paths.Application, "-player \"%1\"");
string? oldV2Val = App.FastFlags.GetValue("FFlagDisableNewIGMinDUA"); string? oldV2Val = App.FastFlags.GetValue("FFlagDisableNewIGMinDUA");

View File

@ -1,15 +1,12 @@
using System.Web; using Microsoft.Win32;
using System.Windows;
using Microsoft.Win32; namespace Bloxstrap.Utility
namespace Bloxstrap
{ {
static class ProtocolHandler static class WindowsRegistry
{ {
private const string RobloxPlaceKey = "Roblox.Place"; private const string RobloxPlaceKey = "Roblox.Place";
public static void Register(string key, string name, string handler, string handlerParam = "%1") public static void RegisterProtocol(string key, string name, string handler, string handlerParam = "%1")
{ {
string handlerArgs = $"\"{handler}\" {handlerParam}"; string handlerArgs = $"\"{handler}\" {handlerParam}";
@ -30,10 +27,56 @@ namespace Bloxstrap
} }
} }
public static void RegisterRobloxPlace(string handler) /// <summary>
/// Registers Roblox Player protocols for Bloxstrap
/// </summary>
public static void RegisterPlayer() => RegisterPlayer(Paths.Application, "-player \"%1\"");
public static void RegisterPlayer(string handler, string handlerParam)
{
RegisterProtocol("roblox", "Roblox", handler, handlerParam);
RegisterProtocol("roblox-player", "Roblox", handler, handlerParam);
}
/// <summary>
/// Registers all Roblox Studio classes for Bloxstrap
/// </summary>
public static void RegisterStudio()
{
RegisterStudioProtocol(Paths.Application, "-studio \"%1\"");
RegisterStudioFileClass(Paths.Application, "-studio \"%1\"");
RegisterStudioFileTypes();
}
/// <summary>
/// Registers roblox-studio and roblox-studio-auth protocols
/// </summary>
/// <param name="handler"></param>
/// <param name="handlerParam"></param>
public static void RegisterStudioProtocol(string handler, string handlerParam)
{
RegisterProtocol("roblox-studio", "Roblox", handler, handlerParam);
RegisterProtocol("roblox-studio-auth", "Roblox", handler, handlerParam);
}
/// <summary>
/// Registers file associations for Roblox.Place class
/// </summary>
public static void RegisterStudioFileTypes()
{
RegisterStudioFileType(".rbxl");
RegisterStudioFileType(".rbxlx");
}
/// <summary>
/// Registers Roblox.Place class
/// </summary>
/// <param name="handler"></param>
/// <param name="handlerParam"></param>
public static void RegisterStudioFileClass(string handler, string handlerParam)
{ {
const string keyValue = "Roblox Place"; const string keyValue = "Roblox Place";
string handlerArgs = $"\"{handler}\" -ide \"%1\""; string handlerArgs = $"\"{handler}\" {handlerParam}";
string iconValue = $"{handler},0"; string iconValue = $"{handler},0";
using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + RobloxPlaceKey); using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + RobloxPlaceKey);
@ -54,7 +97,7 @@ namespace Bloxstrap
uriIconKey.SetValue("", iconValue); uriIconKey.SetValue("", iconValue);
} }
public static void RegisterExtension(string key) public static void RegisterStudioFileType(string key)
{ {
using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{key}"); using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{key}");
uriKey.CreateSubKey(RobloxPlaceKey + @"\ShellNew"); uriKey.CreateSubKey(RobloxPlaceKey + @"\ShellNew");