private bool GetISourceScript(ISourceManager manager, string statement, string currentPath, out List <ISourceScript> scripts) { string[] vars = Utils.SplitAndRemoveFirst(statement, Separator); scripts = new List <ISourceScript>(); if (vars.Length != 0) { ImportResult importInfo = manager.GetComputingScheme()(vars, currentPath); if (!importInfo) { Logger.Log(LogType.Error, "Invalid Include Statement", 1); return(false); } string filepath = importInfo.GetString("filename"); importInfo.RemoveEntry("filename"); string key = importInfo.GetString("key"); importInfo.RemoveEntry("key"); string originalDefinedName = importInfo.GetString("definedname"); importInfo.RemoveEntry("definedname"); IFileContent cont = new FilePathContent(filepath, originalDefinedName); cont.SetKey(key); if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo)) { scripts.Add(iss); } for (int index = scripts.Count - 1; index >= 0; index--) { ISourceScript sourceScript = scripts[index]; if (sourceScript.GetFileInterface().HasValidFilepath&& !Utils.FileExistsRelativeTo(currentPath, sourceScript.GetFileInterface())) { Logger.Log(LogType.Error, $"Could not find File: {sourceScript.GetFileInterface()}", 1); scripts.RemoveAt(index); } } return(true); } return(false); }
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); }
private bool GetISourceScript(ISourceManager manager, string statement, string currentPath, out List <ISourceScript> scripts) { string[] vars = Utils.SplitAndRemoveFirst(statement, Separator); scripts = new List <ISourceScript>(); if (vars.Length != 0) { ImportResult importInfo = manager.GetComputingScheme()(vars, currentPath); if (!importInfo) { Logger.Log(PPLogType.Error, Verbosity.Level1, "Invalid Include Statement"); return(false); } string filepath = importInfo.GetString("filename"); importInfo.RemoveEntry("filename"); string key = importInfo.GetString("key"); importInfo.RemoveEntry("key"); if (filepath.EndsWith("\\*") || filepath.EndsWith("/*")) { string[] files = IOManager.GetFiles(filepath.Substring(0, filepath.Length - 2)); foreach (string file in files) { IFileContent cont = new FilePathContent(file); cont.SetKey(key); if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo)) { scripts.Add(iss); } } } else { IFileContent cont = new FilePathContent(filepath); cont.SetKey(key); if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo)) { scripts.Add(iss); } } for (int index = scripts.Count - 1; index >= 0; index--) { ISourceScript sourceScript = scripts[index]; if (sourceScript.GetFileInterface().HasValidFilepath&& !Utils.FileExistsRelativeTo(currentPath, sourceScript.GetFileInterface())) { Logger.Log(PPLogType.Error, Verbosity.Level1, "Could not find File: {0}", sourceScript.GetFileInterface()); scripts.RemoveAt(index); } } return(true); } return(false); }