Browse Source

combine foreaches

Signed-off-by: ahmadali shafiee <mail@ahmadalli.net>
tags/4.3.2.0
ahmadali shafiee 4 years ago
parent
commit
96650a1f6c
1 changed files with 7 additions and 8 deletions
  1. +7
    -8
      shadowsocks-csharp/Controller/System/AutoStartup.cs

+ 7
- 8
shadowsocks-csharp/Controller/System/AutoStartup.cs View File

@@ -71,23 +71,22 @@ namespace Shadowsocks.Controller
logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run");
return false; return false;
} }
// Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions
var check = false;
foreach (var valueName in runKey.GetValueNames()) foreach (var valueName in runKey.GetValueNames())
{ {
if (valueName == Key)
if (string.Equals(valueName, Key, StringComparison.InvariantCultureIgnoreCase))
{
check = true;
continue; continue;
}
// Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions
if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase))
{ {
runKey.DeleteValue(valueName); runKey.DeleteValue(valueName);
} }
} }
foreach (string item in runKey.GetValueNames())
{
if (item.Equals(Key, StringComparison.OrdinalIgnoreCase))
return true;
}
return false;
return check;
} }
catch (Exception e) catch (Exception e)
{ {


Loading…
Cancel
Save