feat: versatile IProtocolHandler
This commit is contained in:
parent
dc0e6a1362
commit
a5971a5412
|
|
@ -1,40 +1,38 @@
|
||||||
using System.Windows;
|
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace Kiseki.Launcher.Windows
|
namespace Kiseki.Launcher.Windows
|
||||||
{
|
{
|
||||||
public class ProtocolHandler : IProtocolHandler
|
public class ProtocolHandler : IProtocolHandler
|
||||||
{
|
{
|
||||||
public void Register(string handler)
|
public void Register(string key, string name, string handler)
|
||||||
{
|
{
|
||||||
string arguments = $"\"{handler}\" \"%1\"";
|
string arguments = $"\"{handler}\" \"%1\"";
|
||||||
|
|
||||||
RegistryKey uri = Registry.CurrentUser.CreateSubKey(@"Software\Classes\kiseki");
|
RegistryKey uriKey = Registry.CurrentUser.CreateSubKey(@$"Software\Classes\{key}");
|
||||||
RegistryKey icon = uri.CreateSubKey("DefaultIcon");
|
RegistryKey uriIconKey = uriKey.CreateSubKey("DefaultIcon");
|
||||||
RegistryKey command = uri.CreateSubKey(@"shell\open\command");
|
RegistryKey uriCommandKey = uriKey.CreateSubKey(@"shell\open\command");
|
||||||
|
|
||||||
if (uri.GetValue("") is null)
|
if (uriKey.GetValue("") is null)
|
||||||
{
|
{
|
||||||
uri.SetValue("", "URL: Kiseki Protocol");
|
uriKey.SetValue("", $"URL: {name} Protocol");
|
||||||
uri.SetValue("URL Protocol", "");
|
uriKey.SetValue("URL Protocol", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((string?)command.GetValue("") != arguments)
|
if ((string?)uriCommandKey.GetValue("") != arguments)
|
||||||
{
|
{
|
||||||
command.SetValue("", arguments);
|
uriCommandKey.SetValue("", arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
uri.Close();
|
uriKey.Close();
|
||||||
icon.Close();
|
uriIconKey.Close();
|
||||||
command.Close();
|
uriCommandKey.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unregister()
|
public void Unregister(string key)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Classes\kiseki");
|
Registry.CurrentUser.DeleteSubKeyTree(@$"Software\Classes\{key}");
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ namespace Kiseki.Launcher
|
||||||
{
|
{
|
||||||
interface IProtocolHandler
|
interface IProtocolHandler
|
||||||
{
|
{
|
||||||
void Register(string handler);
|
void Register(string key, string name, string handler);
|
||||||
void Unregister();
|
void Unregister(string key);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IMainWindow
|
interface IMainWindow
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue