public static List<LoadedTools> ReadToolsSettings() { var tools = new List<LoadedTools>(); string toolJsonFile = Path.Combine(Directory.GetCurrentDirectory(), TOOLS_FILE_NAME); if (!File.Exists(toolJsonFile)) { tools = GetGenericTools(); WriteToolsSettings(tools); } else { try { using (StreamReader file = File.OpenText(toolJsonFile)) using (JsonTextReader reader = new JsonTextReader(file)) { var tool = new LoadedTools(); reader.SupportMultipleContent = true; while (reader.Read()) { JObject o3 = (JObject) JToken.ReadFrom(reader); foreach (var child in o3.Children()) { AddPropertyToTool(tool, child.Path, child.First.ToString()); } tools.Add(tool); tool = new LoadedTools(); } } } catch (Exception ex) { MessageBox.Show($"{Constants.ToolMessages.ErrorWritingFile}{ex}", Constants.ToolMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } return tools; }
private static LoadedTools AddPropertyToTool(LoadedTools loadedTool, string propertyName, string propertyValue) { switch (propertyName) { case FileConstants.Tools.ID: loadedTool.ID = Guid.Parse(propertyValue); break; case FileConstants.Tools.NAME: loadedTool.Name = propertyValue; break; case FileConstants.Tools.FILE_LOCATION: loadedTool.FileLocation = propertyValue; break; case FileConstants.Tools.HOTKEY: loadedTool.HotKey = propertyValue; break; } return loadedTool; }