예제 #1
0
        public void WriteToFile()
        {
            string WriteColor(Color c) => $"{c.R}, {c.G}, {c.B}";

            IniKey[] keys =
            {
                // Project
                new IniKey(ProjectSetting.SectionName,   nameof(Project.DefaultProject),              Project.DefaultProject),                // String
                // General
                new IniKey(GeneralSetting.SectionName,   nameof(General.EnableLongFilePath),          General.EnableLongFilePath.ToString()), // Boolean
                new IniKey(GeneralSetting.SectionName,   nameof(General.OptimizeCode),                General.OptimizeCode.ToString()),       // Boolean
                new IniKey(GeneralSetting.SectionName,   nameof(General.ShowLogAfterBuild),           General.ShowLogAfterBuild.ToString()),  // Boolean
                new IniKey(GeneralSetting.SectionName,   nameof(General.StopBuildOnError),            General.StopBuildOnError.ToString()),   // Boolean
                new IniKey(GeneralSetting.SectionName,   nameof(General.UseCustomUserAgent),          General.UseCustomUserAgent.ToString()), // Boolean
                new IniKey(GeneralSetting.SectionName,   nameof(General.CustomUserAgent),             General.CustomUserAgent),               // String
                // Interface
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.UseCustomTitle),            Interface.UseCustomTitle.ToString()),   // Boolean
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.CustomTitle),               Interface.CustomTitle),                 // String
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.UseCustomEditor),           Interface.UseCustomEditor.ToString()),  // Boolean
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.CustomEditorPath),          Interface.CustomEditorPath),            // String
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.MonospacedFontFamily),      Interface.MonospacedFont.FontFamily.Source),
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.MonospacedFontWeight),      Interface.MonospacedFont.FontWeight.ToString()),
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.MonospacedFontSize),        Interface.MonospacedFont.PointSize.ToString()),
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.ScaleFactor),               Interface.ScaleFactor.ToString(CultureInfo.InvariantCulture)), // Integer
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.DisplayShellExecuteConOut), Interface.DisplayShellExecuteConOut.ToString()),               // Boolean
                new IniKey(InterfaceSetting.SectionName, nameof(Interface.InterfaceSize),             ((int)Interface.InterfaceSize).ToString()),                    // Integer
                // Theme
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.ThemeType),                     ((int)Theme.ThemeType).ToString()),                            // Integer
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomTopPanelBackground),      WriteColor(Theme.CustomTopPanelBackground)),                   // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomTopPanelForeground),      WriteColor(Theme.CustomTopPanelForeground)),                   // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomTreePanelBackground),     WriteColor(Theme.CustomTreePanelBackground)),                  // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomTreePanelForeground),     WriteColor(Theme.CustomTreePanelForeground)),                  // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomTreePanelHighlight),      WriteColor(Theme.CustomTreePanelHighlight)),                   // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomScriptPanelBackground),   WriteColor(Theme.CustomScriptPanelBackground)),                // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomScriptPanelForeground),   WriteColor(Theme.CustomScriptPanelForeground)),                // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomStatusBarBackground),     WriteColor(Theme.CustomStatusBarBackground)),                  // Color
                new IniKey(ThemeSetting.SectionName,     nameof(Theme.CustomStatusBarForeground),     WriteColor(Theme.CustomStatusBarForeground)),                  // Color
                // Script
                new IniKey(ScriptSetting.SectionName,    nameof(Script.EnableCache),                  Script.EnableCache.ToString()),                                // Boolean
                new IniKey(ScriptSetting.SectionName,    nameof(Script.AutoSyntaxCheck),              Script.AutoSyntaxCheck.ToString()),                            // Boolean
                // Log
                new IniKey(LogSetting.SectionName,       nameof(Log.DebugLevel),                      ((int)Log.DebugLevel).ToString()),                             // Integer
                new IniKey(LogSetting.SectionName,       nameof(Log.DeferredLogging),                 Log.DeferredLogging.ToString()),                               // Boolean
                new IniKey(LogSetting.SectionName,       nameof(Log.MinifyHtmlExport),                Log.MinifyHtmlExport.ToString()),                              // Boolean
            };
            IniReadWriter.WriteKeys(_settingFile, keys);
        }
예제 #2
0
 public void WriteToFile()
 {
     IniKey[] keys =
     {
         new IniKey(SectionName, nameof(AsteriskBugDirCopy), AsteriskBugDirCopy.ToString()),                     // Boolean
         new IniKey(SectionName, nameof(AsteriskBugDirLink), AsteriskBugDirLink.ToString()),                     // Boolean
         new IniKey(SectionName, nameof(FileRenameCanMoveDir), FileRenameCanMoveDir.ToString()),                 // Boolean
         new IniKey(SectionName, nameof(AllowLetterInLoop), AllowLetterInLoop.ToString()),                       // Boolean
         new IniKey(SectionName, nameof(LegacyBranchCondition), LegacyBranchCondition.ToString()),               // Boolean
         new IniKey(SectionName, nameof(LegacyRegWrite), LegacyRegWrite.ToString()),                             // Boolean
         new IniKey(SectionName, nameof(AllowSetModifyInterface), AllowSetModifyInterface.ToString()),           // Boolean
         new IniKey(SectionName, nameof(LegacyInterfaceCommand), LegacyInterfaceCommand.ToString()),             // Boolean
         new IniKey(SectionName, nameof(LegacySectionParamCommand), LegacySectionParamCommand.ToString()),       // Boolean
         new IniKey(SectionName, nameof(IgnoreWidthOfWebLabel), IgnoreWidthOfWebLabel.ToString()),               // Boolean
         new IniKey(SectionName, nameof(OverridableFixedVariables), OverridableFixedVariables.ToString()),       // Boolean
         new IniKey(SectionName, nameof(OverridableLoopCounter), OverridableLoopCounter.ToString()),             // Boolean
         new IniKey(SectionName, nameof(EnableEnvironmentVariables), EnableEnvironmentVariables.ToString()),     // Boolean
         new IniKey(SectionName, nameof(DisableExtendedSectionParams), DisableExtendedSectionParams.ToString()), // Boolean
     };
     IniReadWriter.WriteKeys(_compatFile, keys);
 }
예제 #3
0
        public static bool Update(IReadOnlyList <UIControl> uiCtrls)
        {
            if (uiCtrls.Count == 0)
            {
                return(true);
            }

            string        fullPath = uiCtrls[0].Section.Script.RealPath;
            List <IniKey> keys     = new List <IniKey>(uiCtrls.Count);

            foreach (UIControl uiCtrl in uiCtrls)
            {
                Debug.Assert(fullPath.Equals(uiCtrl.Section.Script.RealPath, StringComparison.OrdinalIgnoreCase));

                // Update ScriptSection.Lines
                uiCtrl.Section.UpdateIniKey(uiCtrl.Key, uiCtrl.ForgeRawLine(false));

                // Prepare updating actual file
                keys.Add(new IniKey(uiCtrl.Section.Name, uiCtrl.Key, uiCtrl.ForgeRawLine(false)));
            }

            // Update actual file
            return(IniReadWriter.WriteKeys(fullPath, keys));
        }
예제 #4
0
        public static List <LogInfo> IniWriteOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniWriteOp infoOp = cmd.Info.Cast <CodeInfo_IniWriteOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            if (!StringEscaper.PathSecurityCheck(fileName, out string errorMsg))
            {
                return(LogInfo.LogErrorMessage(logs, errorMsg));
            }

            IniKey[] keys = new IniKey[infoOp.Cmds.Count];
            for (int i = 0; i < keys.Length; i++)
            {
                CodeInfo_IniWrite info = infoOp.Infos[i];

                string sectionName = StringEscaper.Preprocess(s, info.Section);
                string key         = StringEscaper.Preprocess(s, info.Key);
                string value       = StringEscaper.Preprocess(s, info.Value);

                if (sectionName.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Section name cannot be empty"));
                }
                if (key.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Key name cannot be empty"));
                }

                keys[i] = new IniKey(sectionName, key, value);
            }

            string dirPath = Path.GetDirectoryName(fileName);

            if (dirPath == null)
            {
                throw new InternalException("Internal Logic Error at IniWriteOp");
            }
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            // If a dest file does not exist, create an empty file to force ANSI encoding as default in IniReadWriter.
            if (!File.Exists(fileName))
            {
                File.Create(fileName).Dispose();
            }

            bool result;

            if (s.CompatAutoCompactIniWriteCommand)
            {
                result = IniReadWriter.WriteCompactKeys(fileName, keys);
            }
            else
            {
                result = IniReadWriter.WriteKeys(fileName, keys);
            }

            if (result)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    IniKey kv = keys[i];
                    logs.Add(new LogInfo(LogState.Success, $"Key [{kv.Key}] and it's value [{kv.Value}] written", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Success, $"Wrote [{keys.Length}] values to [{fileName}]", cmd));
            }
            else
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    IniKey kv = keys[i];
                    logs.Add(new LogInfo(LogState.Error, $"Could not write key [{kv.Key}] and it's value [{kv.Value}]", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Error, $"Could not write [{keys.Length}] values to [{fileName}]", cmd));
            }

            return(logs);
        }