feat: implement IProtocolHandler
This commit is contained in:
parent
03769b50e8
commit
dc0e6a1362
|
|
@ -1,15 +1,48 @@
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace Kiseki.Launcher.Windows
|
namespace Kiseki.Launcher.Windows
|
||||||
{
|
{
|
||||||
public class ProtocolHandler : IProtocolHandler
|
public class ProtocolHandler : IProtocolHandler
|
||||||
{
|
{
|
||||||
public void Register()
|
public void Register(string handler)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
string arguments = $"\"{handler}\" \"%1\"";
|
||||||
|
|
||||||
|
RegistryKey uri = Registry.CurrentUser.CreateSubKey(@"Software\Classes\kiseki");
|
||||||
|
RegistryKey icon = uri.CreateSubKey("DefaultIcon");
|
||||||
|
RegistryKey command = uri.CreateSubKey(@"shell\open\command");
|
||||||
|
|
||||||
|
if (uri.GetValue("") is null)
|
||||||
|
{
|
||||||
|
uri.SetValue("", "URL: Kiseki Protocol");
|
||||||
|
uri.SetValue("URL Protocol", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((string?)command.GetValue("") != arguments)
|
||||||
|
{
|
||||||
|
command.SetValue("", arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
uri.Close();
|
||||||
|
icon.Close();
|
||||||
|
command.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unregister()
|
public void Unregister()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
try
|
||||||
|
{
|
||||||
|
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Classes\kiseki");
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// Key doesn't exist (and why are we here?)
|
||||||
|
#if DEBUG
|
||||||
|
throw;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ namespace Kiseki.Launcher
|
||||||
{
|
{
|
||||||
interface IProtocolHandler
|
interface IProtocolHandler
|
||||||
{
|
{
|
||||||
void Register();
|
void Register(string handler);
|
||||||
void Unregister();
|
void Unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue