mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-22 02:21:27 -07:00
122 lines
4.5 KiB
C#
122 lines
4.5 KiB
C#
using Microsoft.Win32;
|
|
|
|
namespace Bloxstrap.Utility
|
|
{
|
|
static class WindowsRegistry
|
|
{
|
|
private const string RobloxPlaceKey = "Roblox.Place";
|
|
|
|
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");
|
|
|
|
if (uriKey.GetValue("") is null)
|
|
{
|
|
uriKey.SetValue("", $"URL: {name} Protocol");
|
|
uriKey.SetValue("URL Protocol", "");
|
|
}
|
|
|
|
if (uriCommandKey.GetValue("") as string != handlerArgs)
|
|
{
|
|
uriIconKey.SetValue("", handler);
|
|
uriCommandKey.SetValue("", handlerArgs);
|
|
}
|
|
}
|
|
|
|
/// <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}\" {handlerParam}";
|
|
string iconValue = $"{handler},0";
|
|
|
|
using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + RobloxPlaceKey);
|
|
using RegistryKey uriIconKey = uriKey.CreateSubKey("DefaultIcon");
|
|
using RegistryKey uriOpenKey = uriKey.CreateSubKey(@"shell\Open");
|
|
using RegistryKey uriCommandKey = uriOpenKey.CreateSubKey(@"command");
|
|
|
|
if (uriKey.GetValue("") as string != keyValue)
|
|
uriKey.SetValue("", keyValue);
|
|
|
|
if (uriCommandKey.GetValue("") as string != handlerArgs)
|
|
uriCommandKey.SetValue("", handlerArgs);
|
|
|
|
if (uriOpenKey.GetValue("") as string != "Open")
|
|
uriOpenKey.SetValue("", "Open");
|
|
|
|
if (uriIconKey.GetValue("") as string != iconValue)
|
|
uriIconKey.SetValue("", iconValue);
|
|
}
|
|
|
|
public static void RegisterStudioFileType(string key)
|
|
{
|
|
using RegistryKey uriKey = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{key}");
|
|
uriKey.CreateSubKey(RobloxPlaceKey + @"\ShellNew");
|
|
|
|
if (uriKey.GetValue("") as string != RobloxPlaceKey)
|
|
uriKey.SetValue("", RobloxPlaceKey);
|
|
}
|
|
|
|
public static void Unregister(string key)
|
|
{
|
|
try
|
|
{
|
|
Registry.CurrentUser.DeleteSubKeyTree($@"Software\Classes\{key}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
App.Logger.WriteLine("Protocol::Unregister", $"Failed to unregister {key}: {ex}");
|
|
}
|
|
}
|
|
}
|
|
}
|