feat: versatile IProtocolHandler

This commit is contained in:
rjindael 2023-07-28 06:28:51 -07:00
parent dc0e6a1362
commit a5971a5412
No known key found for this signature in database
GPG Key ID: D069369C906CCF31
2 changed files with 16 additions and 18 deletions

View File

@ -1,40 +1,38 @@
using System.Windows;
using Microsoft.Win32;
namespace Kiseki.Launcher.Windows
{
public class ProtocolHandler : IProtocolHandler
{
public void Register(string handler)
public void Register(string key, string name, string handler)
{
string arguments = $"\"{handler}\" \"%1\"";
RegistryKey uri = Registry.CurrentUser.CreateSubKey(@"Software\Classes\kiseki");
RegistryKey icon = uri.CreateSubKey("DefaultIcon");
RegistryKey command = uri.CreateSubKey(@"shell\open\command");
RegistryKey uriKey = Registry.CurrentUser.CreateSubKey(@$"Software\Classes\{key}");
RegistryKey uriIconKey = uriKey.CreateSubKey("DefaultIcon");
RegistryKey uriCommandKey = uriKey.CreateSubKey(@"shell\open\command");
if (uri.GetValue("") is null)
if (uriKey.GetValue("") is null)
{
uri.SetValue("", "URL: Kiseki Protocol");
uri.SetValue("URL Protocol", "");
uriKey.SetValue("", $"URL: {name} Protocol");
uriKey.SetValue("URL Protocol", "");
}
if ((string?)command.GetValue("") != arguments)
if ((string?)uriCommandKey.GetValue("") != arguments)
{
command.SetValue("", arguments);
uriCommandKey.SetValue("", arguments);
}
uri.Close();
icon.Close();
command.Close();
uriKey.Close();
uriIconKey.Close();
uriCommandKey.Close();
}
public void Unregister()
public void Unregister(string key)
{
try
{
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Classes\kiseki");
Registry.CurrentUser.DeleteSubKeyTree(@$"Software\Classes\{key}");
}
catch (Exception)
{

View File

@ -2,8 +2,8 @@ namespace Kiseki.Launcher
{
interface IProtocolHandler
{
void Register(string handler);
void Unregister();
void Register(string key, string name, string handler);
void Unregister(string key);
}
interface IMainWindow