Update alerts file loading

Fix issue with blank lines. Avoid duplicate entries.
Issue fixed with an alerts file provided by TRTrident
This commit is contained in:
ORelio 2014-08-29 12:04:52 +02:00
parent dbefe16831
commit 2a8a6fadd3

View file

@ -18,23 +18,23 @@ namespace MinecraftClient.ChatBots
{ {
if (System.IO.File.Exists(Settings.Alerts_MatchesFile)) if (System.IO.File.Exists(Settings.Alerts_MatchesFile))
{ {
dictionary = System.IO.File.ReadAllLines(Settings.Alerts_MatchesFile); List<string> tmp_dictionary = new List<string>();
string[] file_lines = System.IO.File.ReadAllLines(Settings.Alerts_MatchesFile);
for (int i = 0; i < dictionary.Length; i++) foreach (string line in file_lines)
{ if (line.Trim().Length > 0 && !tmp_dictionary.Contains(line.ToLower()))
dictionary[i] = dictionary[i].ToLower(); tmp_dictionary.Add(line.ToLower());
} dictionary = tmp_dictionary.ToArray();
} }
else LogToConsole("File not found: " + Settings.Alerts_MatchesFile); else LogToConsole("File not found: " + Settings.Alerts_MatchesFile);
if (System.IO.File.Exists(Settings.Alerts_ExcludesFile)) if (System.IO.File.Exists(Settings.Alerts_ExcludesFile))
{ {
excludelist = System.IO.File.ReadAllLines(Settings.Alerts_ExcludesFile); List<string> tmp_excludelist = new List<string>();
string[] file_lines = System.IO.File.ReadAllLines(Settings.Alerts_ExcludesFile);
for (int i = 0; i < excludelist.Length; i++) foreach (string line in file_lines)
{ if (line.Trim().Length > 0 && !tmp_excludelist.Contains(line.Trim().ToLower()))
excludelist[i] = excludelist[i].ToLower(); tmp_excludelist.Add(line.ToLower());
} excludelist = tmp_excludelist.ToArray();
} }
else LogToConsole("File not found : " + Settings.Alerts_ExcludesFile); else LogToConsole("File not found : " + Settings.Alerts_ExcludesFile);
} }