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; 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)
{ {

View File

@ -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