Skip to content

Commit

Permalink
Consolidate registry handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 9, 2024
1 parent dd568fa commit 6206411
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 57 deletions.
21 changes: 3 additions & 18 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,12 @@ public async Task Run()
await ApplyModifications();
}

// check if launch uri is set to our bootstrapper
// this doesn't go under register, so we check every launch
// just in case the stock bootstrapper changes it back
// check registry entries for every launch, just in case the stock bootstrapper changes it back

if (IsStudioLaunch)
{
#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
}
WindowsRegistry.RegisterStudio();
else
{
// 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\"");
}
WindowsRegistry.RegisterPlayer();

await mutex.ReleaseAsync();

Expand Down
49 changes: 21 additions & 28 deletions Bloxstrap/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public void DoInstall()
// only register player, for the scenario where the user installs bloxstrap, closes it,
// and then launches from the website expecting it to work
// studio can be implicitly registered when it's first launched manually
ProtocolHandler.Register("roblox", "Roblox", Paths.Application, "-player \"%1\"");
ProtocolHandler.Register("roblox-player", "Roblox", Paths.Application, "-player \"%1\"");

// TODO: implicit installation needs to reregister studio
WindowsRegistry.RegisterPlayer();

if (CreateDesktopShortcuts)
Shortcut.Create(Paths.Application, "", DesktopShortcut);
Expand All @@ -79,6 +76,9 @@ public void DoInstall()
App.State.Load(false);
App.FastFlags.Load(false);

if (!String.IsNullOrEmpty(App.State.Prop.Studio.VersionGuid))
WindowsRegistry.RegisterStudio();

App.Logger.WriteLine(LOG_IDENT, "Installation finished");
}

Expand Down Expand Up @@ -207,44 +207,38 @@ public static void DoUninstall(bool keepData)
{
playerStillInstalled = false;

ProtocolHandler.Unregister("roblox");
ProtocolHandler.Unregister("roblox-player");
WindowsRegistry.Unregister("roblox");
WindowsRegistry.Unregister("roblox-player");
}
else
{
// revert launch uri handler to stock bootstrapper
string playerPath = Path.Combine((string)playerFolder, "RobloxPlayerBeta.exe");

ProtocolHandler.Register("roblox", "Roblox", playerPath);
ProtocolHandler.Register("roblox-player", "Roblox", playerPath);
WindowsRegistry.RegisterPlayer(playerPath, "%1");
}

using RegistryKey? studioBootstrapperKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\roblox-studio");
if (studioBootstrapperKey is null)
using var studioKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\roblox-studio");
var studioFolder = studioKey?.GetValue("InstallLocation");

if (studioKey is null || studioFolder is not string)
{
studioStillInstalled = false;

#if STUDIO_FEATURES
ProtocolHandler.Unregister("roblox-studio");
ProtocolHandler.Unregister("roblox-studio-auth");
WindowsRegistry.Unregister("roblox-studio");
WindowsRegistry.Unregister("roblox-studio-auth");

ProtocolHandler.Unregister("Roblox.Place");
ProtocolHandler.Unregister(".rbxl");
ProtocolHandler.Unregister(".rbxlx");
#endif
WindowsRegistry.Unregister("Roblox.Place");
WindowsRegistry.Unregister(".rbxl");
WindowsRegistry.Unregister(".rbxlx");
}
#if STUDIO_FEATURES
else
{
string studioLocation = (string?)studioBootstrapperKey.GetValue("InstallLocation") + "RobloxStudioBeta.exe"; // points to studio exe instead of bootstrapper
ProtocolHandler.Register("roblox-studio", "Roblox", studioLocation);
ProtocolHandler.Register("roblox-studio-auth", "Roblox", studioLocation);
string studioPath = Path.Combine((string)studioFolder, "RobloxStudioBeta.exe");
string studioLauncherPath = Path.Combine((string)studioFolder, "RobloxStudioLauncherBeta.exe");

ProtocolHandler.RegisterRobloxPlace(studioLocation);
WindowsRegistry.RegisterStudioProtocol(studioPath, "%1");
WindowsRegistry.RegisterStudioFileClass(studioPath, "-ide \"%1\"");
}
#endif



var cleanupSequence = new List<Action>
{
Expand Down Expand Up @@ -512,8 +506,7 @@ public static void HandleUpgrade()

Registry.CurrentUser.DeleteSubKeyTree("Software\\Bloxstrap", false);

ProtocolHandler.Register("roblox", "Roblox", Paths.Application, "-player \"%1\"");
ProtocolHandler.Register("roblox-player", "Roblox", Paths.Application, "-player \"%1\"");
WindowsRegistry.RegisterPlayer();

string? oldV2Val = App.FastFlags.GetValue("FFlagDisableNewIGMinDUA");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.Web;
using System.Windows;
using Microsoft.Win32;

using Microsoft.Win32;

namespace Bloxstrap
namespace Bloxstrap.Utility
{
static class ProtocolHandler
static class WindowsRegistry
{
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}";

using var uriKey = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{key}");
using var uriIconKey = uriKey.CreateSubKey("DefaultIcon");
using var uriCommandKey = uriKey.CreateSubKey(@"shell\open\command");
Expand All @@ -30,10 +27,56 @@ public static void Register(string key, string name, string handler, string hand
}
}

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";
string handlerArgs = $"\"{handler}\" -ide \"%1\"";
string handlerArgs = $"\"{handler}\" {handlerParam}";
string iconValue = $"{handler},0";

using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + RobloxPlaceKey);
Expand All @@ -54,7 +97,7 @@ public static void RegisterRobloxPlace(string handler)
uriIconKey.SetValue("", iconValue);
}

public static void RegisterExtension(string key)
public static void RegisterStudioFileType(string key)
{
using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{key}");
uriKey.CreateSubKey(RobloxPlaceKey + @"\ShellNew");
Expand Down

0 comments on commit 6206411

Please sign in to comment.