Esempio n. 1
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);
        }
Esempio n. 2
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);
        }