Esempio n. 1
0
        public static List<LogInfo> AddVariables(EngineState s, CodeCommand cmd)
        {
            CodeInfo_AddVariables info = cmd.Info.Cast<CodeInfo_AddVariables>();

            string scriptFile = StringEscaper.Preprocess(s, info.ScriptFile);
            string sectionName = StringEscaper.Preprocess(s, info.SectionName);

            Script sc = Engine.GetScriptInstance(s, s.CurrentScript.RealPath, scriptFile, out _);

            // Does section exist?
            if (!sc.Sections.ContainsKey(sectionName))
                return new List<LogInfo>
                    {new LogInfo(LogState.Error, $"Script [{scriptFile}] does not have section [{sectionName}]")};

            // Directly read from file
            List<string> lines = IniReadWriter.ParseRawSection(sc.RealPath, sectionName);
            if (lines == null)
                return new List<LogInfo>
                    {new LogInfo(LogState.Error, $"Script [{scriptFile}] does not have section [{sectionName}]")};

            // Add Variables
            Dictionary<string, string> varDict = IniReadWriter.ParseIniLinesVarStyle(lines);
            List<LogInfo> varLogs = s.Variables.AddVariables(info.Global ? VarsType.Global : VarsType.Local, varDict);

            // Add Macros
            ScriptSection localSection = sc.Sections[sectionName];
            List<LogInfo> macroLogs = s.Macro.LoadMacroDict(info.Global ? MacroType.Global : MacroType.Local, localSection, lines, true);
            varLogs.AddRange(macroLogs);

            if (varLogs.Count == 0) // No variables
                varLogs.Add(new LogInfo(LogState.Info,
                    $"Script [{scriptFile}]'s section [{sectionName}] does not have any variables"));

            return varLogs;
        }
Esempio n. 2
0
        /// <summary>
        /// If _lines is not loaded from file, load it to memory.
        /// </summary>
        /// <returns>
        /// true if _lines is valid
        /// </returns>
        public bool LoadLines()
        {
            if (_lines != null)
            {
                return(true);
            }

            List <string> lineList = IniReadWriter.ParseRawSection(Script.RealPath, Name);

            if (lineList == null)
            {
                return(false);
            }
            _lines = lineList.ToArray();
            return(true);
        }