diff --git a/Kiseki.Launcher.Windows/ProtocolHandler.cs b/Kiseki.Launcher.Windows/ProtocolHandler.cs index 638f8ab..57f0353 100644 --- a/Kiseki.Launcher.Windows/ProtocolHandler.cs +++ b/Kiseki.Launcher.Windows/ProtocolHandler.cs @@ -1,15 +1,48 @@ +using System.Windows; + +using Microsoft.Win32; + namespace Kiseki.Launcher.Windows { 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() { - 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 + } } } } \ No newline at end of file diff --git a/Kiseki.Launcher/Interfaces.cs b/Kiseki.Launcher/Interfaces.cs index 6ff6695..91af3d8 100644 --- a/Kiseki.Launcher/Interfaces.cs +++ b/Kiseki.Launcher/Interfaces.cs @@ -2,7 +2,7 @@ namespace Kiseki.Launcher { interface IProtocolHandler { - void Register(); + void Register(string handler); void Unregister(); }