public void ReadFromFile() { // Use default value if key/value does not exist or malformed. SetToDefault(); // compatFile does not exist -> Default compat options if (!File.Exists(_compatFile)) { return; } IniKey[] keys = { new IniKey(SectionName, nameof(AsteriskBugDirCopy)), // Boolean new IniKey(SectionName, nameof(AsteriskBugDirLink)), // Boolean new IniKey(SectionName, nameof(FileRenameCanMoveDir)), // Boolean new IniKey(SectionName, nameof(AllowLetterInLoop)), // Boolean new IniKey(SectionName, nameof(LegacyBranchCondition)), // Boolean new IniKey(SectionName, nameof(LegacyRegWrite)), // Boolean new IniKey(SectionName, nameof(AllowSetModifyInterface)), // Boolean new IniKey(SectionName, nameof(LegacyInterfaceCommand)), // Boolean new IniKey(SectionName, nameof(LegacySectionParamCommand)), // Boolean new IniKey(SectionName, nameof(IgnoreWidthOfWebLabel)), // Boolean new IniKey(SectionName, nameof(OverridableFixedVariables)), // Boolean new IniKey(SectionName, nameof(OverridableLoopCounter)), // Boolean new IniKey(SectionName, nameof(EnableEnvironmentVariables)), // Boolean new IniKey(SectionName, nameof(DisableExtendedSectionParams)), // Boolean }; keys = IniReadWriter.ReadKeys(_compatFile, keys); Dictionary <string, string> keyDict = keys.ToDictionary( x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase); // Asterisk AsteriskBugDirCopy = DictParser.ParseBoolean(keyDict, SectionName, nameof(AsteriskBugDirCopy), AsteriskBugDirCopy); AsteriskBugDirLink = DictParser.ParseBoolean(keyDict, SectionName, nameof(AsteriskBugDirLink), AsteriskBugDirLink); // Command FileRenameCanMoveDir = DictParser.ParseBoolean(keyDict, SectionName, nameof(FileRenameCanMoveDir), FileRenameCanMoveDir); AllowLetterInLoop = DictParser.ParseBoolean(keyDict, SectionName, nameof(AllowLetterInLoop), AllowLetterInLoop); LegacyBranchCondition = DictParser.ParseBoolean(keyDict, SectionName, nameof(LegacyBranchCondition), LegacyBranchCondition); LegacyRegWrite = DictParser.ParseBoolean(keyDict, SectionName, nameof(LegacyRegWrite), LegacyRegWrite); AllowSetModifyInterface = DictParser.ParseBoolean(keyDict, SectionName, nameof(AllowSetModifyInterface), AllowSetModifyInterface); LegacyInterfaceCommand = DictParser.ParseBoolean(keyDict, SectionName, nameof(LegacyInterfaceCommand), LegacyInterfaceCommand); LegacySectionParamCommand = DictParser.ParseBoolean(keyDict, SectionName, nameof(LegacySectionParamCommand), LegacySectionParamCommand); // Script Interface IgnoreWidthOfWebLabel = DictParser.ParseBoolean(keyDict, SectionName, nameof(IgnoreWidthOfWebLabel), IgnoreWidthOfWebLabel); // Variable OverridableFixedVariables = DictParser.ParseBoolean(keyDict, SectionName, nameof(OverridableFixedVariables), OverridableFixedVariables); OverridableLoopCounter = DictParser.ParseBoolean(keyDict, SectionName, nameof(OverridableLoopCounter), OverridableLoopCounter); EnableEnvironmentVariables = DictParser.ParseBoolean(keyDict, SectionName, nameof(EnableEnvironmentVariables), EnableEnvironmentVariables); DisableExtendedSectionParams = DictParser.ParseBoolean(keyDict, SectionName, nameof(DisableExtendedSectionParams), DisableExtendedSectionParams); }
public void ReadFromFile() { // Use default value if key/value does not exist or malformed. SetToDefault(); if (!File.Exists(_settingFile)) { return; } IniKey[] keys = { // Project new IniKey(ProjectSetting.SectionName, nameof(Project.DefaultProject)), // String // General new IniKey(GeneralSetting.SectionName, nameof(General.OptimizeCode)), // Boolean new IniKey(GeneralSetting.SectionName, nameof(General.ShowLogAfterBuild)), // Boolean new IniKey(GeneralSetting.SectionName, nameof(General.StopBuildOnError)), // Boolean new IniKey(GeneralSetting.SectionName, nameof(General.EnableLongFilePath)), // Boolean new IniKey(GeneralSetting.SectionName, nameof(General.UseCustomUserAgent)), // Boolean new IniKey(GeneralSetting.SectionName, nameof(General.CustomUserAgent)), // String // Interface new IniKey(InterfaceSetting.SectionName, nameof(Interface.UseCustomTitle)), // Boolean new IniKey(InterfaceSetting.SectionName, nameof(Interface.CustomTitle)), // String new IniKey(InterfaceSetting.SectionName, nameof(Interface.UseCustomEditor)), // Boolean new IniKey(InterfaceSetting.SectionName, nameof(Interface.CustomEditorPath)), // String new IniKey(InterfaceSetting.SectionName, nameof(Interface.MonospacedFontFamily)), // FontFamily new IniKey(InterfaceSetting.SectionName, nameof(Interface.MonospacedFontWeight)), // FontWeight new IniKey(InterfaceSetting.SectionName, nameof(Interface.MonospacedFontSize)), // FontSize new IniKey(InterfaceSetting.SectionName, nameof(Interface.ScaleFactor)), // Integer (70 - 200) new IniKey(InterfaceSetting.SectionName, nameof(Interface.DisplayShellExecuteConOut)), // Boolean new IniKey(InterfaceSetting.SectionName, nameof(Interface.InterfaceSize)), // Integer (0 - 2) // Theme new IniKey(ThemeSetting.SectionName, nameof(Theme.ThemeType)), // Integer new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomTopPanelBackground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomTopPanelForeground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomTreePanelBackground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomTreePanelForeground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomTreePanelHighlight)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomScriptPanelBackground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomScriptPanelForeground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomStatusBarBackground)), // Color new IniKey(ThemeSetting.SectionName, nameof(Theme.CustomStatusBarForeground)), // Color // Script new IniKey(ScriptSetting.SectionName, nameof(Script.EnableCache)), // Boolean new IniKey(ScriptSetting.SectionName, nameof(Script.AutoSyntaxCheck)), // Boolean // Log new IniKey(LogSetting.SectionName, nameof(Log.DebugLevel)), // Integer (0 - 2) new IniKey(LogSetting.SectionName, nameof(Log.DeferredLogging)), // Boolean new IniKey(LogSetting.SectionName, nameof(Log.MinifyHtmlExport)), // Boolean }; keys = IniReadWriter.ReadKeys(_settingFile, keys); Dictionary <string, Dictionary <string, string> > keyDict = keys .GroupBy(x => x.Section) .ToDictionary( x => x.Key, y => y.ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase); // Project if (keyDict.ContainsKey(ProjectSetting.SectionName)) { Dictionary <string, string> projectDict = keyDict[ProjectSetting.SectionName]; Project.DefaultProject = DictParser.ParseString(projectDict, nameof(Project.DefaultProject), string.Empty); } // General if (keyDict.ContainsKey(GeneralSetting.SectionName)) { Dictionary <string, string> generalDict = keyDict[GeneralSetting.SectionName]; General.OptimizeCode = DictParser.ParseBoolean(generalDict, GeneralSetting.SectionName, nameof(General.OptimizeCode), General.OptimizeCode); General.ShowLogAfterBuild = DictParser.ParseBoolean(generalDict, GeneralSetting.SectionName, nameof(General.ShowLogAfterBuild), General.ShowLogAfterBuild); General.StopBuildOnError = DictParser.ParseBoolean(generalDict, GeneralSetting.SectionName, nameof(General.StopBuildOnError), General.StopBuildOnError); General.EnableLongFilePath = DictParser.ParseBoolean(generalDict, GeneralSetting.SectionName, nameof(General.EnableLongFilePath), General.EnableLongFilePath); General.UseCustomUserAgent = DictParser.ParseBoolean(generalDict, GeneralSetting.SectionName, nameof(General.UseCustomUserAgent), General.UseCustomUserAgent); General.CustomUserAgent = DictParser.ParseString(generalDict, nameof(General.CustomUserAgent), General.CustomUserAgent); } // Interface if (keyDict.ContainsKey(InterfaceSetting.SectionName)) { Dictionary <string, string> ifaceDict = keyDict[InterfaceSetting.SectionName]; // Parse MonospacedFont FontFamily monoFontFamily = Interface.MonospacedFont.FontFamily; FontWeight monoFontWeight = Interface.MonospacedFont.FontWeight; if (ifaceDict[nameof(Interface.MonospacedFontFamily)] != null) { monoFontFamily = new FontFamily(ifaceDict[nameof(Interface.MonospacedFontFamily)]); } if (ifaceDict[nameof(Interface.MonospacedFontWeight)] != null) { monoFontWeight = FontHelper.ParseFontWeight(ifaceDict[nameof(Interface.MonospacedFontWeight)]); } int monoFontSize = DictParser.ParseInteger(ifaceDict, InterfaceSetting.SectionName, nameof(Interface.MonospacedFontSize), Interface.MonospacedFont.PointSize, 1, -1); Interface.MonospacedFont = new FontHelper.FontInfo(monoFontFamily, monoFontWeight, monoFontSize); Interface.UseCustomTitle = DictParser.ParseBoolean(ifaceDict, InterfaceSetting.SectionName, nameof(Interface.UseCustomTitle), Interface.UseCustomTitle); Interface.CustomTitle = DictParser.ParseString(ifaceDict, nameof(Interface.CustomTitle), Interface.CustomTitle); Interface.UseCustomEditor = DictParser.ParseBoolean(ifaceDict, InterfaceSetting.SectionName, nameof(Interface.UseCustomEditor), Interface.UseCustomEditor); Interface.CustomEditorPath = DictParser.ParseString(ifaceDict, nameof(Interface.CustomEditorPath), Interface.CustomEditorPath); Interface.ScaleFactor = DictParser.ParseInteger(ifaceDict, InterfaceSetting.SectionName, nameof(Interface.ScaleFactor), Interface.ScaleFactor, 70, 200); Interface.DisplayShellExecuteConOut = DictParser.ParseBoolean(ifaceDict, InterfaceSetting.SectionName, nameof(Interface.DisplayShellExecuteConOut), Interface.DisplayShellExecuteConOut); Interface.InterfaceSize = (InterfaceSize)DictParser.ParseInteger(ifaceDict, InterfaceSetting.SectionName, nameof(Interface.InterfaceSize), (int)Interface.InterfaceSize, 0, Enum.GetValues(typeof(InterfaceSize)).Length - 1); } // Theme if (keyDict.ContainsKey(ThemeSetting.SectionName)) { Dictionary <string, string> scDict = keyDict[ThemeSetting.SectionName]; Theme.ThemeType = (ThemeType)DictParser.ParseInteger(scDict, ThemeSetting.SectionName, nameof(Theme.ThemeType), (int)Theme.ThemeType, 0, Enum.GetValues(typeof(ThemeType)).Length - 1); Theme.CustomTopPanelBackground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomTopPanelBackground), Theme.CustomTopPanelBackground); Theme.CustomTopPanelForeground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomTopPanelForeground), Theme.CustomTopPanelForeground); Theme.CustomTreePanelBackground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomTreePanelBackground), Theme.CustomTreePanelBackground); Theme.CustomTreePanelForeground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomTreePanelForeground), Theme.CustomTreePanelForeground); Theme.CustomTreePanelHighlight = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomTreePanelHighlight), Theme.CustomTreePanelHighlight); Theme.CustomScriptPanelBackground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomScriptPanelBackground), Theme.CustomScriptPanelBackground); Theme.CustomScriptPanelForeground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomScriptPanelForeground), Theme.CustomScriptPanelForeground); Theme.CustomStatusBarBackground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomStatusBarBackground), Theme.CustomStatusBarBackground); Theme.CustomStatusBarForeground = DictParser.ParseColor(scDict, ThemeSetting.SectionName, nameof(Theme.CustomStatusBarForeground), Theme.CustomStatusBarForeground); } // Script if (keyDict.ContainsKey(ScriptSetting.SectionName)) { Dictionary <string, string> scDict = keyDict[ScriptSetting.SectionName]; Script.EnableCache = DictParser.ParseBoolean(scDict, ScriptSetting.SectionName, nameof(Script.EnableCache), Script.EnableCache); Script.AutoSyntaxCheck = DictParser.ParseBoolean(scDict, ScriptSetting.SectionName, nameof(Script.AutoSyntaxCheck), Script.AutoSyntaxCheck); } // Log if (keyDict.ContainsKey(LogSetting.SectionName)) { Dictionary <string, string> logDict = keyDict[LogSetting.SectionName]; Log.DebugLevel = (LogDebugLevel)DictParser.ParseInteger(logDict, LogSetting.SectionName, nameof(Log.DebugLevel), (int)Log.DebugLevel, 0, Enum.GetValues(typeof(LogDebugLevel)).Length - 1); Log.DeferredLogging = DictParser.ParseBoolean(logDict, LogSetting.SectionName, nameof(Log.DeferredLogging), Log.DeferredLogging); Log.MinifyHtmlExport = DictParser.ParseBoolean(logDict, LogSetting.SectionName, nameof(Log.MinifyHtmlExport), Log.MinifyHtmlExport); } }