From 96650a1f6c5e17e1d7914f41f304995ba81c8927 Mon Sep 17 00:00:00 2001 From: ahmadali shafiee Date: Mon, 2 Nov 2020 11:12:13 +0330 Subject: [PATCH] combine foreaches Signed-off-by: ahmadali shafiee --- .../Controller/System/AutoStartup.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 8e89fc8e..557b8a3f 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -71,23 +71,22 @@ namespace Shadowsocks.Controller logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); 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()) { - if (valueName == Key) + if (string.Equals(valueName, Key, StringComparison.InvariantCultureIgnoreCase)) + { + check = true; 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)) { runKey.DeleteValue(valueName); } } - foreach (string item in runKey.GetValueNames()) - { - if (item.Equals(Key, StringComparison.OrdinalIgnoreCase)) - return true; - } - return false; + return check; } catch (Exception e) {