From 3652e7f33b8767f92634ce02e0199b65e620aacf Mon Sep 17 00:00:00 2001 From: database64128 Date: Sun, 19 Apr 2020 15:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Minor=20cleanup=20of=20Shadowsoc?= =?UTF-8?q?ks.Controller.ProtocolHandler.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/System/ProtocolHandler.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/ProtocolHandler.cs b/shadowsocks-csharp/Controller/System/ProtocolHandler.cs index e7cf68da..2a0112cb 100644 --- a/shadowsocks-csharp/Controller/System/ProtocolHandler.cs +++ b/shadowsocks-csharp/Controller/System/ProtocolHandler.cs @@ -12,6 +12,8 @@ namespace Shadowsocks.Controller { static class ProtocolHandler { + const string ssURLRegKey = @"SOFTWARE\Classes\ss"; + private static Logger logger = LogManager.GetCurrentClassLogger(); // Don't use Application.ExecutablePath @@ -22,12 +24,13 @@ namespace Shadowsocks.Controller public static bool Set(bool enabled) { RegistryKey ssURLAssociation = null; + try { - ssURLAssociation = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Classes\ss", RegistryKeyPermissionCheck.ReadWriteSubTree); + ssURLAssociation = Registry.CurrentUser.CreateSubKey(ssURLRegKey, RegistryKeyPermissionCheck.ReadWriteSubTree); if (ssURLAssociation == null) { - logger.Error(@"Failed to create HKCU\SOFTWARE\Classes\ss"); + logger.Error(@"Failed to create HKCU\SOFTWARE\Classes\ss to register ss:// association."); return false; } if (enabled) @@ -40,7 +43,7 @@ namespace Shadowsocks.Controller } else { - Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\Classes\ss"); + Registry.CurrentUser.DeleteSubKeyTree(ssURLRegKey); logger.Info(@"Successfully removed ss:// association."); } return true; @@ -70,7 +73,7 @@ namespace Shadowsocks.Controller RegistryKey ssURLAssociation = null; try { - ssURLAssociation = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Classes\ss", true); + ssURLAssociation = Registry.CurrentUser.OpenSubKey(ssURLRegKey, true); if (ssURLAssociation == null) { //logger.Info(@"ss:// links not associated.");