private Setting() { string dic = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), SettingConstants.SettingFolder); FileName = Path.Combine(dic, SettingConstants.SettingFile); if (!Directory.Exists(dic)) { IsFirstInstall = true; Directory.CreateDirectory(dic); } CreateSettings(dic); KeyWords = KeyWordSettings.Instance; if (File.Exists(FileName)) { Doc = XDocument.Load(FileName); //OpenFiles = Doc.Root.Element("OpenFile"); //if (OpenFiles == null) OpenFiles = new XElement("OpenFile"); XMLLuaSettings = Doc.Root.Element(SettingConstants.SettingKeys.LuaSetting); if (XMLLuaSettings == null) { XMLLuaSettings = new XElement(SettingConstants.SettingKeys.LuaSetting); Doc.Root.Add(XMLLuaSettings); } InitLuaSetting(); XMLKeyBinding = Doc.Root.Element(SettingConstants.SettingKeys.KeyBinding); if (XMLKeyBinding == null) { XMLKeyBinding = new XElement(SettingConstants.SettingKeys.KeyBinding); Doc.Root.Add(XMLKeyBinding); } XMLSearchFilters = Doc.Root.Element(SettingConstants.SettingKeys.SearchFilter); if (XMLSearchFilters == null) { XMLSearchFilters = new XElement(SettingConstants.SettingKeys.SearchFilter); Doc.Root.Add(XMLSearchFilters); } XMLUISettings = Doc.Root.Element(SettingConstants.SettingKeys.UISetting); if (XMLUISettings == null) { XMLUISettings = new XElement(SettingConstants.SettingKeys.UISetting); Doc.Root.Add(XMLUISettings); } #region Init Keywords ClassDefinition = "class"; ClassConstructor = "new"; var XMLKeywords = Doc.Root.Element(SettingConstants.SettingKeys.Keywords); if (XMLKeywords == null) { XMLKeywords = new XElement(SettingConstants.SettingKeys.Keywords); XMLKeywords.Add(new XElement(SettingConstants.SettingKeys.ClassDefinition, ClassDefinition)); XMLKeywords.Add(new XElement(SettingConstants.SettingKeys.ClassConstructor, ClassConstructor)); Doc.Root.Add(XMLKeywords); } else { var def = XMLKeywords.Element(SettingConstants.SettingKeys.ClassDefinition); if (def != null) { ClassDefinition = def.Value; } var ctor = XMLKeywords.Element(SettingConstants.SettingKeys.ClassConstructor); if (ctor != null) { ClassConstructor = ctor.Value; } } #endregion #region InitHighlight XElement XMLHighlight = Doc.Root.Element(SettingConstants.SettingKeys.Highlight); if (XMLHighlight == null) { XMLHighlight = new XElement(SettingConstants.SettingKeys.Highlight); XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Function, new XAttribute(SettingConstants.KeywordsKeys.R, SettingConstants.Default.FuncR), new XAttribute(SettingConstants.KeywordsKeys.G, SettingConstants.Default.FuncG), new XAttribute(SettingConstants.KeywordsKeys.B, SettingConstants.Default.FuncB) ) ); KeyWords.Function = Color.FromRgb(SettingConstants.Default.FuncR, SettingConstants.Default.FuncG, SettingConstants.Default.FuncB); XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Table, new XAttribute(SettingConstants.KeywordsKeys.R, SettingConstants.Default.TableR), new XAttribute(SettingConstants.KeywordsKeys.G, SettingConstants.Default.TableG), new XAttribute(SettingConstants.KeywordsKeys.B, SettingConstants.Default.TableB) ) ); KeyWords.Table = Color.FromRgb(SettingConstants.Default.TableR, SettingConstants.Default.TableG, SettingConstants.Default.TableB); Doc.Root.Add(XMLHighlight); } else { var table = XMLHighlight.Element(SettingConstants.SettingKeys.Table); if (table != null) { var color = Color.FromRgb( byte.Parse(table.Attribute(SettingConstants.KeywordsKeys.R).Value), byte.Parse(table.Attribute(SettingConstants.KeywordsKeys.G).Value), byte.Parse(table.Attribute(SettingConstants.KeywordsKeys.B).Value)); if (color.R != 0 || color.B != 0 || color.G != 0) { KeyWords.Table = color; } //为了兼容之前的版本,修改默认值 else { table.ReplaceAttributes( new XAttribute(SettingConstants.KeywordsKeys.R, SettingConstants.Default.TableR), new XAttribute(SettingConstants.KeywordsKeys.G, SettingConstants.Default.TableG), new XAttribute(SettingConstants.KeywordsKeys.B, SettingConstants.Default.TableB) ); KeyWords.Table = Color.FromRgb(SettingConstants.Default.TableR, SettingConstants.Default.TableG, SettingConstants.Default.TableB); } } else { XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Table, new XAttribute(SettingConstants.KeywordsKeys.R, SettingConstants.Default.TableR), new XAttribute(SettingConstants.KeywordsKeys.G, SettingConstants.Default.TableG), new XAttribute(SettingConstants.KeywordsKeys.B, SettingConstants.Default.TableB) ) ); KeyWords.Table = Color.FromRgb(SettingConstants.Default.TableR, SettingConstants.Default.TableG, SettingConstants.Default.TableB); } var function = XMLHighlight.Element(SettingConstants.SettingKeys.Function); if (function != null) { var color = Color.FromRgb( byte.Parse(function.Attribute(SettingConstants.KeywordsKeys.R).Value), byte.Parse(function.Attribute(SettingConstants.KeywordsKeys.G).Value), byte.Parse(function.Attribute(SettingConstants.KeywordsKeys.B).Value)); if (color.R != 0 || color.B != 0 || color.G != 0) { KeyWords.Function = color; } //为了兼容之前的版本,修改默认值 else { function.ReplaceAttributes( new XAttribute(SettingConstants.KeywordsKeys.R, SettingConstants.Default.FuncR), new XAttribute(SettingConstants.KeywordsKeys.G, SettingConstants.Default.FuncG), new XAttribute(SettingConstants.KeywordsKeys.B, SettingConstants.Default.FuncB) ); KeyWords.Function = Color.FromRgb(SettingConstants.Default.FuncR, SettingConstants.Default.FuncG, SettingConstants.Default.FuncB); } } else { XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Function, new XAttribute(SettingConstants.KeywordsKeys.R, SettingConstants.Default.FuncR), new XAttribute(SettingConstants.KeywordsKeys.G, SettingConstants.Default.FuncG), new XAttribute(SettingConstants.KeywordsKeys.B, SettingConstants.Default.FuncB) ) ); KeyWords.Function = Color.FromRgb(SettingConstants.Default.FuncR, SettingConstants.Default.FuncG, SettingConstants.Default.FuncB); } } #endregion Save(); } InitSearchFilterList(); }
private Setting() { string dic = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), SettingConstants.SettingFolder); FileName = Path.Combine(dic, SettingConstants.SettingFile); if (!Directory.Exists(dic)) { IsFirstRun = true; Directory.CreateDirectory(dic); } CreateSettings(dic); KeyWords = KeyWordSettings.Instance; if (File.Exists(FileName)) { Doc = XDocument.Load(FileName); //OpenFiles = Doc.Root.Element("OpenFile"); //if (OpenFiles == null) OpenFiles = new XElement("OpenFile"); XMLLuaSettings = Doc.Root.Element(SettingConstants.SettingKeys.LuaSetting); if (XMLLuaSettings == null) { XMLLuaSettings = new XElement(SettingConstants.SettingKeys.LuaSetting); Doc.Root.Add(XMLLuaSettings); } InitLuaSetting(); XMLKeyBinding = Doc.Root.Element(SettingConstants.SettingKeys.KeyBinding); if (XMLKeyBinding == null) { XMLKeyBinding = new XElement(SettingConstants.SettingKeys.KeyBinding); Doc.Root.Add(XMLKeyBinding); } XMLSearchFilters = Doc.Root.Element(SettingConstants.SettingKeys.SearchFilter); if (XMLSearchFilters == null) { XMLSearchFilters = new XElement(SettingConstants.SettingKeys.SearchFilter); Doc.Root.Add(XMLSearchFilters); } XMLUISettings = Doc.Root.Element(SettingConstants.SettingKeys.UISetting); if (XMLUISettings == null) { XMLUISettings = new XElement(SettingConstants.SettingKeys.UISetting); Doc.Root.Add(XMLUISettings); } #region Init Keywords ClassDefinition = "class"; ClassConstructor = "new"; var XMLKeywords = Doc.Root.Element(SettingConstants.SettingKeys.Keywords); if (XMLKeywords == null) { XMLKeywords = new XElement(SettingConstants.SettingKeys.Keywords); XMLKeywords.Add(new XElement(SettingConstants.SettingKeys.ClassDefinition, ClassDefinition)); XMLKeywords.Add(new XElement(SettingConstants.SettingKeys.ClassConstructor, ClassConstructor)); Doc.Root.Add(XMLKeywords); } else { var def = XMLKeywords.Element(SettingConstants.SettingKeys.ClassDefinition); if (def != null) ClassDefinition = def.Value; var ctor = XMLKeywords.Element(SettingConstants.SettingKeys.ClassConstructor); if (ctor != null) ClassConstructor = ctor.Value; } #endregion #region InitHighlight XElement XMLHighlight = Doc.Root.Element(SettingConstants.SettingKeys.Highlight); if(XMLHighlight == null) { XMLHighlight = new XElement(SettingConstants.SettingKeys.Highlight); XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Function, new XAttribute(SettingConstants.KeywordsKeys.R, 0), new XAttribute(SettingConstants.KeywordsKeys.G, 0), new XAttribute(SettingConstants.KeywordsKeys.B, 0) ) ); XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Table, new XAttribute(SettingConstants.KeywordsKeys.R, 0), new XAttribute(SettingConstants.KeywordsKeys.G, 0), new XAttribute(SettingConstants.KeywordsKeys.B, 0) ) ); Doc.Root.Add(XMLHighlight); } else { var table = XMLHighlight.Element(SettingConstants.SettingKeys.Table); if (table != null) { var color = Color.FromRgb( byte.Parse(table.Attribute(SettingConstants.KeywordsKeys.R).Value), byte.Parse(table.Attribute(SettingConstants.KeywordsKeys.G).Value), byte.Parse(table.Attribute(SettingConstants.KeywordsKeys.B).Value)); if (color.R != 0 || color.B != 0 || color.G != 0) { KeyWords.Table = color; } } else { XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Table, new XAttribute(SettingConstants.KeywordsKeys.R, 0), new XAttribute(SettingConstants.KeywordsKeys.G, 0), new XAttribute(SettingConstants.KeywordsKeys.B, 0) ) ); } var function = XMLHighlight.Element(SettingConstants.SettingKeys.Function); if (function != null) { var color = Color.FromRgb( byte.Parse(function.Attribute(SettingConstants.KeywordsKeys.R).Value), byte.Parse(function.Attribute(SettingConstants.KeywordsKeys.G).Value), byte.Parse(function.Attribute(SettingConstants.KeywordsKeys.B).Value)); if (color.R != 0 || color.B != 0 || color.G != 0) { KeyWords.Function = color; } } else { XMLHighlight.Add ( new XElement ( SettingConstants.SettingKeys.Function, new XAttribute(SettingConstants.KeywordsKeys.R, 0), new XAttribute(SettingConstants.KeywordsKeys.G, 0), new XAttribute(SettingConstants.KeywordsKeys.B, 0) ) ); } } #endregion Save(); } InitSearchFilterList(); }