Browse Source

🐛 Fixed the issue where associating ss:// links requires admin privilege.

tags/4.2.0.0
database64128 5 years ago
parent
commit
ee586d8804
3 changed files with 22 additions and 25 deletions
  1. +21
    -23
      shadowsocks-csharp/Controller/System/ProtocolHandler.cs
  2. +0
    -1
      shadowsocks-csharp/Data/i18n.csv
  3. +1
    -1
      shadowsocks-csharp/View/MenuViewController.cs

+ 21
- 23
shadowsocks-csharp/Controller/System/ProtocolHandler.cs View File

@@ -21,29 +21,27 @@ namespace Shadowsocks.Controller
// TODO: Elevate when necessary
public static bool Set(bool enabled)
{
RegistryKey runKey = null;
RegistryKey ssURLAssociation = null;
try
{
RegistryKey hkcr = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);

runKey = hkcr.CreateSubKey("ss",RegistryKeyPermissionCheck.ReadWriteSubTree);
if (runKey == null)
ssURLAssociation = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Classes\ss", RegistryKeyPermissionCheck.ReadWriteSubTree);
if (ssURLAssociation == null)
{
logger.Error(@"Cannot find HKCR\ss");
logger.Error(@"Failed to create HKCU\SOFTWARE\Classes\ss");
return false;
}
if (enabled)
{
runKey.SetValue("", "URL:Shadowsocks");
runKey.SetValue("URL Protocol", "");
var shellOpen = runKey.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command");
ssURLAssociation.SetValue("", "URL:Shadowsocks");
ssURLAssociation.SetValue("URL Protocol", "");
var shellOpen = ssURLAssociation.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command");
shellOpen.SetValue("", $"{ExecutablePath} --open-url %1");
logger.Info(@"Successfully added ss:// association.");
}
else
{
hkcr.DeleteSubKeyTree("ss");
Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\Classes\ss");
logger.Info(@"Successfully removed ss:// association.");
}
return true;
}
@@ -54,12 +52,12 @@ namespace Shadowsocks.Controller
}
finally
{
if (runKey != null)
if (ssURLAssociation != null)
{
try
{
runKey.Close();
runKey.Dispose();
ssURLAssociation.Close();
ssURLAssociation.Dispose();
}
catch (Exception e)
{ logger.LogUsefulException(e); }
@@ -69,17 +67,17 @@ namespace Shadowsocks.Controller

public static bool Check()
{
RegistryKey runKey = null;
RegistryKey ssURLAssociation = null;
try
{
runKey = Utils.OpenRegKey(@"ss", true, RegistryHive.ClassesRoot);
if (runKey == null)
ssURLAssociation = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Classes\ss", true);
if (ssURLAssociation == null)
{
logger.Error(@"Cannot find HKCR\ss");
//logger.Info(@"ss:// links not associated.");
return false;
}

var shellOpen = runKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
var shellOpen = ssURLAssociation.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
return (string)shellOpen.GetValue("") == $"{ExecutablePath} --open-url %1";
}
catch (Exception e)
@@ -89,12 +87,12 @@ namespace Shadowsocks.Controller
}
finally
{
if (runKey != null)
if (ssURLAssociation != null)
{
try
{
runKey.Close();
runKey.Dispose();
ssURLAssociation.Close();
ssURLAssociation.Dispose();
}
catch (Exception e)
{ logger.LogUsefulException(e); }


+ 0
- 1
shadowsocks-csharp/Data/i18n.csv View File

@@ -185,7 +185,6 @@ Find Shadowsocks icon in your notify tray.,Значок Shadowsocks можно
"If you want to start multiple Shadowsocks, make a copy in another directory.","Если вы хотите запустить несколько копий Shadowsocks одновременно, создайте отдельную папку на каждую копию.",如果想同时启动多个,可以另外复制一份到别的目录。,如果想同時啟動多個,可以另外複製一份至別的目錄。,複数起動したい場合は、プログラムファイルを別のフォルダーにコピーしてから、もう一度実行して下さい。,"만약 여러 개의 Shadowsocks를 사용하고 싶으시다면, 파일을 다른 곳에 복사해주세요."
Failed to decode QRCode,Не удалось распознать QRCode,无法解析二维码,QR 碼解碼失敗,QR コードの読み取りに失敗しました。,QR코드를 해석하는데에 실패했습니다.
Failed to update registry,Не удалось обновить запись в реестре,无法修改注册表,無法修改登錄檔,レジストリの更新に失敗しました。,레지스트리를 업데이트하는데에 실패했습니다.
Failed to update registry. Try running as administrator.,Не удалось обновить запись в реестр. Попробуйте запустить от имени администратора.,注册表更新失败,尝试以管理员身份运行。,無法修改登錄檔,嘗試以管理員身份運行。,,
Import from URL: {0} ?,импортировать из адреса: {0} ?,从URL导入: {0} ?,從URL匯入: {0} ?,,
System Proxy On: ,Системный прокси:,系统代理已启用:,系統 Proxy 已啟用:,システム プロキシが有効:,시스템 프록시 활성화됨:
Running: Port {0},Запущен на порту {0},正在运行:端口 {0},正在執行:連接埠號碼 {0},実行中:ポート {0},실행 중: 포트 {0}번


+ 1
- 1
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -855,7 +855,7 @@ namespace Shadowsocks.View
ProtocolHandlerItem.Checked = !ProtocolHandlerItem.Checked;
if (!ProtocolHandler.Set(ProtocolHandlerItem.Checked))
{
MessageBox.Show(I18N.GetString("Failed to update registry. Try running as administrator."));
MessageBox.Show(I18N.GetString("Failed to update registry"));
}
LoadCurrentConfiguration();
}


Loading…
Cancel
Save