From b79f408cd57a8ef17f1d84a942951e331be24d21 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 23 Jan 2022 17:41:58 -0800 Subject: [PATCH] Fixed exception if MSH has same key many times, first key is used. #19 --- MeshCentralAgent.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/MeshCentralAgent.cs b/MeshCentralAgent.cs index f67a6a1..7fb36e4 100644 --- a/MeshCentralAgent.cs +++ b/MeshCentralAgent.cs @@ -170,7 +170,15 @@ public MeshCentralAgent(MainForm parent, string mshstr, string softwareName, str // Load the MSH file string[] lines = mshstr.Replace("\r\n", "\r").Split('\r'); Dictionary msh = new Dictionary(); - foreach (string line in lines) { int i = line.IndexOf('='); if (i > 0) { msh.Add(line.Substring(0, i), line.Substring(i + 1)); } } + foreach (string line in lines) { + int i = line.IndexOf('='); + if (i > 0) + { + string key = line.Substring(0, i); + string val = line.Substring(i + 1); + if (msh.ContainsKey(key) == false) { msh.Add(key, val); } + } + } // Get the MeshId, ServerId, and ServerUrl if (msh.ContainsKey("MeshID")) { string m = msh["MeshID"]; if (m.StartsWith("0x")) { m = m.Substring(2); } MeshId = StringToByteArray(m); } @@ -268,7 +276,16 @@ public static bool checkMshStr(string mshstr) if (mshstr == null) return false; string[] lines = mshstr.Replace("\r\n", "\r").Split('\r'); Dictionary msh = new Dictionary(); - foreach (string line in lines) { int i = line.IndexOf('='); if (i > 0) { msh.Add(line.Substring(0, i), line.Substring(i + 1)); } } + foreach (string line in lines) + { + int i = line.IndexOf('='); + if (i > 0) + { + string key = line.Substring(0, i); + string val = line.Substring(i + 1); + if (msh.ContainsKey(key) == false) { msh.Add(key, val); } + } + } if (!msh.ContainsKey("MeshID")) return false; if (!msh.ContainsKey("ServerID")) return false; if (!msh.ContainsKey("MeshServer")) return false;