Beispiel #1
0
        /// <summary>
        /// Runs the plugin stage with the specififed type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">the script to be processed</param>
        /// <param name="sourceManager"></param>
        /// <param name="defTable">the definitions that are used</param>
        /// <returns>True if the operation completed successfully</returns>
        private bool RunPluginStage(PluginType type, ProcessStage stage, ISourceScript script, ISourceManager sourceManager, IDefinitions defTable)
        {
            List <AbstractPlugin> chain = AbstractPlugin.GetPluginsForStage(_plugins, type, stage);


            bool ret = true;

            if (type == PluginType.FULL_SCRIPT_PLUGIN)
            {
                ret = RunFullScriptStage(chain, stage, script, sourceManager, defTable);
            }
            else if (type == PluginType.LINE_PLUGIN_BEFORE || type == PluginType.LINE_PLUGIN_AFTER)
            {
                string[] src = script.GetSource();
                RunLineStage(chain, stage, src);
                script.SetSource(src);
            }
            if (!ret)
            {
                return(false);
            }


            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Runs the plugin stage with the specififed type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">the script to be processed</param>
        /// <param name="sourceManager"></param>
        /// <param name="defTable">the definitions that are used</param>
        /// <returns>True if the operation completed successfully</returns>
        private bool RunPluginStage(PluginType type, ProcessStage stage, ISourceScript script,
                                    ISourceManager sourceManager, IDefinitions defTable)
        {
            List <AbstractPlugin> chain = AbstractPlugin.GetPluginsForStage(plugins, type, stage);


            bool ret = true;

            if (type == PluginType.FullScriptPlugin)
            {
                ret = RunFullScriptStage(chain, stage, script, sourceManager, defTable);
            }
            else if (type == PluginType.LinePluginBefore || type == PluginType.LinePluginAfter)
            {
                string[] src = script.GetSource();
                RunLineStage(chain, stage, src);
                script.SetSource(src);
            }
            if (!ret)
            {
                return(false);
            }


            return(true);
        }
Beispiel #3
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager sourceManager, IDefinitions defs)
        {
            if (!file.HasValueOfType <string[]>("genParams"))
            {
                return(true); //No error, we just dont have any generic parameters to replace.
            }

            string[] genParams = file.GetValueFromCache <string[]>("genParams");

            Logger.Log(PPLogType.Log, Verbosity.Level5, "Discovering Generic Keywords...");
            if (genParams != null && genParams.Length > 0)
            {
                for (int i = genParams.Length - 1; i >= 0; i--)
                {
                    Logger.Log(PPLogType.Log, Verbosity.Level6, "Replacing Keyword {0}{1} with {2} in file {3}",
                               GenericKeyword, i, genParams[i], file.GetKey());
                    Utils.ReplaceKeyWord(file.GetSource(), genParams[i],
                                         GenericKeyword + i);
                }
            }


            Logger.Log(PPLogType.Log, Verbosity.Level5, "Generic Keyword Replacement Finished");

            return(true);
        }
Beispiel #4
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager sourceManager, IDefinitions defs)
        {
            if (!file.HasValueOfType <string[]>("genParams"))
            {
                return(true); //No error, we just dont have any generic parameters to replace.
            }

            string[] genParams = file.GetValueFromCache <string[]>("genParams");

            Logger.Log(LogType.Log, "Discovering Generic Keywords...", PLUGIN_MIN_SEVERITY);
            if (genParams != null && genParams.Length > 0)
            {
                for (int i = genParams.Length - 1; i >= 0; i--)
                {
                    Logger.Log(LogType.Log,
                               $"Replacing Keyword {GenericKeyword}{i} with {genParams[i]} in file {file.GetKey()}",
                               PLUGIN_MIN_SEVERITY + 1);
                    Utils.ReplaceKeyWord(file.GetSource(), genParams[i],
                                         GenericKeyword + i);
                }
            }


            Logger.Log(LogType.Log, "Generic Keyword Replacement Finished", PLUGIN_MIN_SEVERITY);

            return(true);
        }
Beispiel #5
0
        public bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            List <string> source = file.GetSource().ToList();

            foreach (var breakpoint in _breakpoints)
            {
                for (lineCount = 0; lineCount < source.Count; lineCount++)
                {
                    if (isBreaking)
                    {
                        do
                        {
                            this.Log(DebugLevel.LOGS, Verbosity.LEVEL1, "Type -dbg-continue to contine processing\nType -dbg-exit to exit the program\nType -dbg-file to list the current file from line you set the breakpoint\n-dbg-file-all to list the whole file\n-dbg-dump <pathtofile> dumps the current file source.\n-dbg-add-bp <breakpointstring>");
                            string getInput = Console.ReadLine();
                            if (getInput == "-dbg-continue")
                            {
                                isBreaking = false;
                                return(true);
                            }
                            else if (getInput == "-dbg-exit")
                            {
                                return(false);
                            }
                            else if (getInput == "-dbg-file")
                            {
                                source.TakeLast(source.Count - lineCount).ToList().ForEach(Console.WriteLine);
                            }
                            else if (getInput == "-dbg-file-all")
                            {
                                source.ForEach(Console.WriteLine);
                            }
                            else if (getInput.StartsWith("-dbg-dump "))
                            {
                                string ff = getInput.Split(" ")[1];
                                if (ff != "")
                                {
                                    File.WriteAllLines(ff, source);
                                }
                            }
                            else if (getInput.StartsWith("-dbg-add-bp "))
                            {
                                Breakpoint[] ff = Breakpoint.Parse(getInput.Split(" "), this);
                                _breakpoints.AddRange(ff);
                            }
                        } while (isBreaking);
                    }
                    if (breakpoint.Break(lineCount, file.GetKey()))
                    {
                        isBreaking = true;
                    }
                }
            }



            return(true);
        }
Beispiel #6
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            List <string> source = file.GetSource().ToList();

            for (int i = source.Count - 1; i >= 0; i--)
            {
                if (i < source.Count - 1 && source[i].TrimEnd().EndsWith(MultiLineKeyword))
                {
                    string newstr = source[i].Substring(0, source[i].Length - MultiLineKeyword.Length) + source[i + 1];
                    source.RemoveAt(i + 1);
                    source[i] = newstr;
                }
            }
            file.SetSource(source.ToArray());
            return(true);
        }
        public bool FullScriptStage(ISourceScript file, ISourceManager sourceManager, IDefinitions defs)
        {
            if (!file.HasValueOfType <string[]>("genParams"))
            {
                return(true);                                             //No error, we just dont have any generic parameters to replace.
            }
            string[] GenParams = file.GetValueFromCache <string[]>("genParams");

            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Discovering Generic Keywords...");
            if (GenParams != null && GenParams.Length > 0)
            {
                for (var i = GenParams.Length - 1; i >= 0; i--)
                {
                    this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Replacing Keyword {0}{1} with {2} in file {3}", GenericKeyword, i, GenParams[i], file.GetKey());
                    Utils.ReplaceKeyWord(file.GetSource(), GenParams[i],
                                         GenericKeyword + i);
                }
            }


            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Generic Keyword Replacement Finished");

            return(true);
        }
Beispiel #8
0
        public override bool FullScriptStage(ISourceScript script, ISourceManager sourceManager, IDefinitions defs)
        {
            Logger.Log(LogType.Log, "Disovering Include Statments...", PLUGIN_MIN_SEVERITY);
            List <string> source      = script.GetSource().ToList();
            string        currentPath = Path.GetDirectoryName(script.GetFileInterface().GetFilePath());
            bool          hasIncludedInline;

            do
            {
                hasIncludedInline = false;
                for (int i = source.Count - 1; i >= 0; i--)
                {
                    if (Utils.IsStatement(source[i], IncludeInlineKeyword))
                    {
                        Logger.Log(LogType.Log, "Found Inline Include Statement...", PLUGIN_MIN_SEVERITY + 1);
                        string[] args = Utils.SplitAndRemoveFirst(source[i], Separator);
                        if (args.Length == 0)
                        {
                            Logger.Log(LogType.Error, "No File Specified", 1);
                            continue;
                        }

                        if (Utils.FileExistsRelativeTo(currentPath, args[0]))
                        {
                            Logger.Log(LogType.Log, "Replacing Inline Keyword with file content",
                                       PLUGIN_MIN_SEVERITY + 2);
                            source.RemoveAt(i);

                            source.InsertRange(i, IOManager.ReadAllLines(Path.Combine(currentPath, args[0])));
                            hasIncludedInline = true;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"File does not exist: {args[0]}", 1);
                        }
                    }
                }

                script.SetSource(source.ToArray());
            } while (hasIncludedInline);


            string[] incs = Utils.FindStatements(source.ToArray(), IncludeKeyword);

            foreach (string includes in incs)
            {
                Logger.Log(LogType.Log, $"Processing Statement: {includes}", PLUGIN_MIN_SEVERITY + 1);
                bool tmp = GetISourceScript(sourceManager, includes, currentPath, out List <ISourceScript> sources);
                if (tmp)
                {
                    foreach (ISourceScript sourceScript in sources)
                    {
                        Logger.Log(LogType.Log,
                                   $"Processing Include: {Path.GetFileName(sourceScript.GetFileInterface().GetKey())}",
                                   PLUGIN_MIN_SEVERITY + 2);

                        if (!sourceManager.IsIncluded(sourceScript))
                        {
                            sourceManager.AddToTodo(sourceScript);
                        }
                        else
                        {
                            sourceManager.FixOrder(sourceScript);
                        }
                    }
                }
                else
                {
                    return
                        (false); //We crash if we didnt find the file. but if the user forgets to specify the path we will just log the error
                }
            }

            Logger.Log(LogType.Log, "Inclusion of Files Finished", PLUGIN_MIN_SEVERITY);
            return(true);
        }
Beispiel #9
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            Logger.Log(LogType.Log,
                       $"Starting Condition Solver passes on file: {Path.GetFileName(file.GetFileInterface().GetKey())}",
                       PLUGIN_MIN_SEVERITY);
            bool          ret             = true;
            int           openIf          = 0;
            bool          foundConditions = false;
            bool          elseIsValid     = false;
            bool          expectEndOrIf   = false;
            List <string> lastPass        = file.GetSource().ToList();
            List <string> solvedFile      = new List <string>();
            int           passCount       = 0;

            do
            {
                passCount++;
                Logger.Log(LogType.Log, $"Starting Condition Solver pass: {passCount}", PLUGIN_MIN_SEVERITY + 1);

                foundConditions = false;
                elseIsValid     = false;
                for (int i = 0; i < lastPass.Count; i++)
                {
                    string line = lastPass[i].TrimStart();
                    if (IsKeyWord(line, StartCondition))
                    {
                        Logger.Log(LogType.Log, $"Found a {StartCondition} Statement", PLUGIN_MIN_SEVERITY + 2);
                        KeyValuePair <bool, int> prep = PrepareForConditionalEvaluation(line, defs,
                                                                                        lastPass, i,
                                                                                        solvedFile);

                        elseIsValid = prep.Key;
                        i          += prep.Value;

                        openIf++;
                        foundConditions = true;
                        expectEndOrIf   = false;
                    }
                    else if (elseIsValid && IsKeyWord(line, ElseIfCondition))
                    {
                        Logger.Log(LogType.Log, $"Found a {ElseIfCondition} Statement", PLUGIN_MIN_SEVERITY + 2);
                        if (!expectEndOrIf && openIf > 0)
                        {
                            KeyValuePair <bool, int> prep = PrepareForConditionalEvaluation(line, defs,
                                                                                            lastPass, i,
                                                                                            solvedFile);

                            elseIsValid     = prep.Key;
                            i              += prep.Value;
                            foundConditions = true;
                        }
                        else if (expectEndOrIf)
                        {
                            Logger.Log(LogType.Error, $"A {ElseCondition} can not be followed by an {ElseIfCondition}",
                                       1);
                            ret = false;
                            break;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"A {ElseIfCondition} should be preceeded by a {StartCondition}",
                                       1);
                            ret = false;
                            break;
                        }
                    }
                    else if (IsKeyWord(line, ElseCondition))
                    {
                        if (openIf > 0)
                        {
                            Logger.Log(LogType.Log, $"Found a {ElseCondition} Statement", PLUGIN_MIN_SEVERITY + 2);
                            int size = GetBlockSize(lastPass, i);
                            if (elseIsValid)
                            {
                                solvedFile.AddRange(lastPass.SubArray(i + 1, size));
                                Logger.Log(LogType.Log, "Adding Branch To Solved File.", PLUGIN_MIN_SEVERITY + 3);
                            }
                            else
                            {
                                Logger.Log(LogType.Log,
                                           "Ignored since a previous condition was true", PLUGIN_MIN_SEVERITY + 3);
                            }

                            i += size;
                            foundConditions = true;
                            expectEndOrIf   = true;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"A {ElseCondition} should be preceeded by a {StartCondition}",
                                       1);
                            ret = false;
                            break;
                        }
                    }
                    else if (IsKeyWord(line, EndCondition))
                    {
                        if (openIf > 0)
                        {
                            expectEndOrIf = false;
                            openIf--;
                        }
                        else
                        {
                            ret = false;

                            Logger.Log(LogType.Error, $"A {EndCondition} should be preceeded by a {StartCondition}", 1);
                            break;
                        }
                    }
                    else if (EnableDefine &&
                             line.StartsWith(DefineKeyword))
                    {
                        Logger.Log(LogType.Log, $"Found a {DefineKeyword} Statement", PLUGIN_MIN_SEVERITY + 2);
                        defs.Set(Utils.SplitAndRemoveFirst(line, Separator));
                        solvedFile.Add(lastPass[i]);
                    }
                    else if (EnableUndefine &&
                             line.StartsWith(UndefineKeyword))
                    {
                        Logger.Log(LogType.Log, $"Found a {UndefineKeyword} Statement", PLUGIN_MIN_SEVERITY + 2);
                        defs.Unset(Utils.SplitAndRemoveFirst(line, Separator));
                        solvedFile.Add(lastPass[i]);
                    }
                    else
                    {
                        solvedFile.Add(lastPass[i]);
                    }
                }

                if (ret)
                {
                    lastPass = solvedFile;
                }
                else
                {
                    break;
                }

                solvedFile = new List <string>();
            } while (foundConditions);

            file.SetSource(lastPass.ToArray());


            Logger.Log(LogType.Log, "Conditional Solver Finished", PLUGIN_MIN_SEVERITY);

            return(ret);
        }
Beispiel #10
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            List <string> lines         = file.GetSource().ToList();
            List <int>    removeIndices = new List <int>();

            Logger.Log(LogType.Log, "Discovering Block Keywords.", PLUGIN_MIN_SEVERITY);

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i].TrimStart();

                if (line.StartsWith(BlockEncodeStartKeyword))
                {
                    removeIndices.Add(i);

                    bool encodingOk = TryParseDecodeStatement(
                        lines[i].TrimStart(),
                        out TextEncoding enc,
                        out string[] encParameter
                        );

                    i++; //Move forward.

                    if (!encodingOk)
                    {
                        Logger.Log(LogType.Error, $"Could not load encoder: {lines[i]}", 1);
                    }

                    Logger.Log(LogType.Log, "Found Block Encode Keyword.", PLUGIN_MIN_SEVERITY + 1);

                    for ( ; i < lines.Count; i++)
                    {
                        if (lines[i].TrimStart().StartsWith(BlockEncodeEndKeyword))
                        {
                            removeIndices.Add(i);
                            i++; //Move Forward

                            break;
                        }

                        Logger.Log(LogType.Log, $"Encoding line {i}.", PLUGIN_MIN_SEVERITY + 2);
                        lines[i] = encodingOk ? enc.Encode(lines[i], encParameter) : lines[i];
                    }
                }
                else if (line.StartsWith(BlockDecodeStartKeyword))
                {
                    removeIndices.Add(i);

                    bool decodingOk = TryParseDecodeStatement(
                        lines[i].TrimStart(),
                        out TextEncoding enc,
                        out string[] encParameter
                        );

                    i++; //Move forward.

                    if (!decodingOk)
                    {
                        Logger.Log(LogType.Error, $"Could not load decoder: {lines[i]}", 1);
                    }

                    Logger.Log(LogType.Log, "Found Block Decode Keyword.", PLUGIN_MIN_SEVERITY + 1);

                    for ( ; i < lines.Count; i++)
                    {
                        if (lines[i].TrimStart().StartsWith(BlockDecodeEndKeyword))
                        {
                            removeIndices.Add(i);
                            i++; //Move Forward

                            break;
                        }

                        Logger.Log(LogType.Log, $"Decoding line {i}.", PLUGIN_MIN_SEVERITY + 2);
                        lines[i] = decodingOk ? enc.Decode(lines[i], encParameter) : lines[i];
                    }
                }
            }

            for (int i = removeIndices.Count - 1; i >= 0; i--)
            {
                lines.RemoveAt(removeIndices[i]);
            }

            removeIndices.Clear();

            file.SetSource(lines.ToArray());

            return(true);
        }
        public bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            this.Log(DebugLevel.LOGS, Verbosity.LEVEL4, "Starting Condition Solver passes on file: {0}", Path.GetFileName(file.GetFilePath()));
            bool          ret             = true;
            int           openIf          = 0;
            bool          foundConditions = false;
            bool          elseIsValid     = false;
            bool          expectEndOrIf   = false;
            List <string> lastPass        = file.GetSource().ToList();
            List <string> solvedFile      = new List <string>();
            int           passCount       = 0;

            do
            {
                passCount++;
                this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Starting Condition Solver pass: {0}", passCount);

                foundConditions = false;
                elseIsValid     = false;
                for (int i = 0; i < lastPass.Count; i++)
                {
                    string line = lastPass[i].TrimStart();
                    if (IsKeyWord(line, StartCondition))
                    {
                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Found a {0} Statement", StartCondition);
                        bool r = EvaluateConditional(line, defs);
                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Evaluation: {0}", r);
                        elseIsValid = !r;
                        int size = GetBlockSize(lastPass, i);
                        if (r)
                        {
                            solvedFile.AddRange(lastPass.SubArray(i + 1, size));
                            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Adding Branch To Solved File.");
                        }

                        openIf++;
                        i += size;
                        foundConditions = true;
                        expectEndOrIf   = false;
                    }
                    else if (elseIsValid && IsKeyWord(line, ElseIfCondition))
                    {
                        if (!expectEndOrIf && openIf > 0)
                        {
                            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Found a {0} Statement", ElseIfCondition);
                            bool r = EvaluateConditional(line, defs);
                            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Evaluation: {0}", r);
                            elseIsValid = !r;
                            int size = GetBlockSize(lastPass, i);
                            if (r)
                            {
                                solvedFile.AddRange(lastPass.SubArray(i + 1, size));
                                this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Adding Branch To Solved File.");
                            }

                            i += size;
                            foundConditions = true;
                        }
                        else if (expectEndOrIf)
                        {
                            this.Log(DebugLevel.ERRORS, Verbosity.LEVEL1, "A {0} can not be followed by an {1}", ElseCondition, ElseIfCondition);
                            ret = false;
                            break;
                        }
                        else
                        {
                            this.Log(DebugLevel.ERRORS, Verbosity.LEVEL1, "A {0} should be preceeded by a {1}", ElseIfCondition, StartCondition);
                            ret = false;
                            break;
                        }
                    }
                    else if (IsKeyWord(line, ElseCondition))
                    {
                        if (openIf > 0)
                        {
                            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Found a {0} Statement", ElseCondition);
                            var size = GetBlockSize(lastPass, i);
                            if (elseIsValid)
                            {
                                solvedFile.AddRange(lastPass.SubArray(i + 1, size));
                                this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Adding Branch To Solved File.");
                            }
                            else
                            {
                                this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Ignored since a previous condition was true");
                            }
                            i += size;
                            foundConditions = true;
                            expectEndOrIf   = true;
                        }
                        else
                        {
                            this.Log(DebugLevel.ERRORS, Verbosity.LEVEL1, "A {0} should be preceeded by a {1}", ElseCondition, StartCondition);
                            ret = false;
                            break;
                        }
                    }
                    else if (IsKeyWord(line, EndCondition))
                    {
                        if (openIf > 0)
                        {
                            expectEndOrIf = false;
                            openIf--;
                        }
                        else
                        {
                            ret = false;

                            this.Log(DebugLevel.ERRORS, Verbosity.LEVEL1, "A {0} should be preceeded by a {1}", EndCondition, StartCondition);
                            break;
                        }
                    }
                    else if (EnableDefine &&
                             line.StartsWith(DefineKeyword))
                    {
                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Found a {0} Statement", DefineKeyword);;
                        defs.Set(Utils.SplitAndRemoveFirst(line, Separator));
                        solvedFile.Add(lastPass[i]);
                    }
                    else if (EnableUndefine &&
                             line.StartsWith(UndefineKeyword))
                    {
                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Found a {0} Statement", UndefineKeyword);
                        defs.Unset(Utils.SplitAndRemoveFirst(line, Separator));
                        solvedFile.Add(lastPass[i]);
                    }
                    else
                    {
                        solvedFile.Add(lastPass[i]);
                    }
                }

                if (ret)
                {
                    lastPass = solvedFile;
                }
                else
                {
                    break;
                }
                solvedFile = new List <string>();
            } while (foundConditions);

            file.SetSource(lastPass.ToArray());


            this.Log(DebugLevel.LOGS, Verbosity.LEVEL4, "Conditional Solver Finished");

            return(ret);
        }
Beispiel #12
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            List <string> lines         = file.GetSource().ToList();
            List <int>    removeIndices = new List <int>();

            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Discovering Block Keywords.");
            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i].TrimStart();
                if (line.StartsWith(BlockEncodeStartKeyword))
                {
                    removeIndices.Add(i);

                    bool encodingOk = TryParseDecodeStatement(lines[i].TrimStart(), out TextEncoding enc,
                                                              out string[] encParameter);

                    i++;//Move forward.
                    if (!encodingOk)
                    {
                        this.Error("Could not load encoder: {0}", lines[i]);
                    }


                    this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Found Block Encode Keyword.");
                    for (; i < lines.Count; i++)
                    {
                        if (lines[i].TrimStart().StartsWith(BlockEncodeEndKeyword))
                        {
                            removeIndices.Add(i);
                            i++;//Move Forward
                            break;
                        }

                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL7, "Encoding line {0}.", i);
                        lines[i] = encodingOk ? enc.Encode(lines[i], encParameter) : lines[i];
                    }
                }
                else if (line.StartsWith(BlockDecodeStartKeyword))
                {
                    removeIndices.Add(i);

                    bool decodingOk = TryParseDecodeStatement(lines[i].TrimStart(), out TextEncoding enc,
                                                              out string[] encParameter);
                    i++;//Move forward.

                    if (!decodingOk)
                    {
                        this.Error("Could not load decoder: {0}", lines[i]);
                    }

                    this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Found Block Decode Keyword.");
                    for (; i < lines.Count; i++)
                    {
                        if (lines[i].TrimStart().StartsWith(BlockDecodeEndKeyword))
                        {
                            removeIndices.Add(i);
                            i++;//Move Forward
                            break;
                        }

                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL7, "Decoding line {0}.", i);
                        lines[i] = decodingOk ? enc.Decode(lines[i], encParameter) : lines[i];
                    }
                }
            }

            for (int i = removeIndices.Count - 1; i >= 0; i--)
            {
                lines.RemoveAt(removeIndices[i]);
            }
            removeIndices.Clear();


            file.SetSource(lines.ToArray());


            return(true);
        }
Beispiel #13
0
        public bool FullScriptStage(ISourceScript script, ISourceManager sourceManager, IDefinitions defs)
        {
            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Disovering Include Statments...");
            List <string> source      = script.GetSource().ToList();
            string        currentPath = Path.GetDirectoryName(Path.GetFullPath(script.GetFilePath()));

            for (int i = source.Count - 1; i >= 0; i--)
            {
                if (Utils.IsStatement(source[i], IncludeInlineKeyword))
                {
                    this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Found Inline Include Statement...");
                    string[] args = Utils.SplitAndRemoveFirst(source[i], Separator);
                    if (args.Length == 0)
                    {
                        this.Log(DebugLevel.WARNINGS, Verbosity.LEVEL1, "No File Specified");
                        continue;
                    }

                    if (Utils.FileExistsRelativeTo(currentPath, args[0]))
                    {
                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Replacing Inline Keyword with file content");
                        source.RemoveAt(i);

                        source.InsertRange(i, File.ReadAllLines(args[0]));
                    }
                    else
                    {
                        this.Log(DebugLevel.WARNINGS, Verbosity.LEVEL1, "File does not exist: {0}", args[0]);
                    }
                }
            }
            script.SetSource(source.ToArray());


            string[] incs = Utils.FindStatements(source.ToArray(), IncludeKeyword);


            foreach (var includes in incs)
            {
                this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Processing Statement: {0}", includes);
                bool tmp = GetISourceScript(sourceManager, includes, currentPath, out List <ISourceScript> sources);
                if (tmp)
                {
                    foreach (var sourceScript in sources)
                    {
                        this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Processing Include: {0}", Path.GetFileName(sourceScript.GetFilePath()));

                        if (!sourceManager.IsIncluded(sourceScript))
                        {
                            sourceManager.AddToTodo(sourceScript);
                        }
                        else
                        {
                            sourceManager.FixOrder(sourceScript);
                        }
                    }
                }
                else
                {
                    /*if (path != "")*/
                    return(false); //We crash if we didnt find the file. but if the user forgets to specify the path we will just log the error
                }
            }

            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Inclusion of Files Finished");
            return(true);
        }