Esempio n. 1
0
        public static List <LogInfo> IniDeleteSection(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniDeleteSection info = cmd.Info.Cast <CodeInfo_IniDeleteSection>();

            string fileName = StringEscaper.Preprocess(s, info.FileName);
            string section  = StringEscaper.Preprocess(s, info.Section);

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

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

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

            bool result = IniReadWriter.DeleteSection(fileName, section);

            if (result)
            {
                logs.Add(new LogInfo(LogState.Success, $"Section [{section}] deleted from [{fileName}]", cmd));
            }
            else
            {
                logs.Add(new LogInfo(LogState.Error, $"Could not delete section [{section}] from [{fileName}]", cmd));
            }
            return(logs);
        }