bloxstrap/Bloxstrap/Helpers/Protocol.cs
pizzaboxer 92b159d682 Updates and bugfixes for v1.3.0
- Features
    - Added integration with rbxfpsunlocker
    - Added support for user-applicable mods
    - Added ability to disable auto-update checking

 - Misc
    - Removed Bloxstrap branding from Discord Rich Presence
    - Mod presets for old death sound and mouse cursor are now statically stored as base64 strings, eliminating reliance on the website and the old cursors still existing

 - Bugfixes
    - Fixed vista bootstrapper style not hiding properly and improper behavior when closed
    - Fixed forms not being brought to the front when shown

 - Code
    - Reconsolidated Bootstrapper to a single file, using regions instead of partials
2022-08-21 22:41:16 +01:00

83 lines
2.6 KiB
C#

using System.Text;
using System.Web;
using Microsoft.Win32;
namespace Bloxstrap.Helpers
{
public class Protocol
{
// map uri keys to command line args
private static readonly IReadOnlyDictionary<string, string> UriKeyArgMap = new Dictionary<string, string>()
{
// excluding roblox-player, browsertrackerid and channel
{ "launchmode", "--" },
{ "gameinfo", "-t " },
{ "placelauncherurl", "-j "},
// { "launchtime", "--launchtime=" }, we'll set this when launching the game client
{ "robloxLocale", "--rloc " },
{ "gameLocale", "--gloc " },
};
public static string Parse(string protocol)
{
string[] keyvalPair;
string key;
string val;
StringBuilder commandLine = new();
foreach (var parameter in protocol.Split('+'))
{
if (!parameter.Contains(':'))
continue;
keyvalPair = parameter.Split(':');
key = keyvalPair[0];
val = keyvalPair[1];
if (!UriKeyArgMap.ContainsKey(key))
continue;
if (key == "placelauncherurl")
val = HttpUtility.UrlDecode(val).Replace("browserTrackerId", "lol");
commandLine.Append(UriKeyArgMap[key] + val + " ");
}
return commandLine.ToString();
}
public static void Register(string key, string name, string handler)
{
string handlerArgs = $"\"{handler}\" %1";
RegistryKey uriKey = Registry.CurrentUser.CreateSubKey($@"Software\Classes\{key}");
RegistryKey uriIconKey = uriKey.CreateSubKey("DefaultIcon");
RegistryKey uriCommandKey = uriKey.CreateSubKey(@"shell\open\command");
if (uriKey.GetValue("") is null)
{
uriKey.SetValue("", $"URL: {name} Protocol");
uriKey.SetValue("URL Protocol", "");
}
if ((string?)uriCommandKey.GetValue("") != handlerArgs)
{
uriIconKey.SetValue("", handler);
uriCommandKey.SetValue("", handlerArgs);
}
uriKey.Close();
uriIconKey.Close();
uriCommandKey.Close();
}
public static void Unregister(string key)
{
try
{
Registry.CurrentUser.DeleteSubKey($@"Software\Classes\{key}");
}
catch (Exception) { }
}
}
}