Skip to content

Commit

Permalink
Fixed exception if MSH has same key many times, first key is used. Yl…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylianst committed Jan 24, 2022
1 parent 220ada6 commit b79f408
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions MeshCentralAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> msh = new Dictionary<string, string>();
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); }
Expand Down Expand Up @@ -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<string, string> msh = new Dictionary<string, string>();
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;
Expand Down

0 comments on commit b79f408

Please sign in to comment.