Browse Source

🔀 Merge pull request #3012 from ahmadalli/master

remove duplicate startup entries
tags/4.3.2.0
database64128 GitHub 3 years ago
parent
commit
fdb7a5e620
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 14 deletions
  1. +15
    -14
      shadowsocks-csharp/Controller/System/AutoStartup.cs

+ 15
- 14
shadowsocks-csharp/Controller/System/AutoStartup.cs View File

@@ -14,7 +14,7 @@ namespace Shadowsocks.Controller
// Don't use Application.ExecutablePath
// see https://stackoverflow.com/questions/12945805/odd-c-sharp-path-issue
private static string Key = "Shadowsocks_" + Program.ExecutablePath.GetHashCode();
public static bool Set(bool enabled)
@@ -71,23 +71,24 @@ namespace Shadowsocks.Controller
logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run");
return false;
}
string[] runList = runKey.GetValueNames();
foreach (string item in runList)
var check = false;
foreach (var valueName in runKey.GetValueNames())
{
if (item.Equals(Key, StringComparison.OrdinalIgnoreCase))
return true;
else if (item.Equals("Shadowsocks", StringComparison.OrdinalIgnoreCase)) // Compatibility with older versions
if (valueName.Equals(Key, StringComparison.InvariantCultureIgnoreCase))
{
string value = Convert.ToString(runKey.GetValue(item));
if (Program.ExecutablePath.Equals(value, StringComparison.OrdinalIgnoreCase))
{
runKey.DeleteValue(item);
runKey.SetValue(Key, Program.ExecutablePath);
return true;
}
check = true;
continue;
}
// Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions
if (Program.ExecutablePath.Equals(runKey.GetValue(valueName).ToString(), StringComparison.InvariantCultureIgnoreCase))
{
runKey.DeleteValue(valueName);
runKey.SetValue(Key, Program.ExecutablePath);
check = true;
}
}
return false;
return check;
}
catch (Exception e)
{


Loading…
Cancel
Save