void ScanFile(string aFile, string[] aTerms, PluginLib.ISearchPublisher publishTo) { System.IO.StreamReader file = new System.IO.StreamReader(aFile); string line; int lineNumber = 1; while ((line = file.ReadLine()) != null) { foreach (string term in aTerms) { string lCaseLine = line.ToLowerInvariant(); if (lCaseLine.Contains(term.ToLowerInvariant())) { SearchResult result = new SearchResult { Column = line.IndexOf(term), Line = lineNumber, File = aFile, Text = line.Trim().MakeBold(term) }; publishTo.PublishSearchResult(result); } } ++lineNumber; } }
public void Search(string projectPath, string[] searchTerms, PluginLib.ISearchPublisher publishTo) { Thread thread = new Thread(delegate() { ScanFolder(projectPath, searchTerms, true, publishTo); }); thread.Start(); }
public static bool ProcessLine(string str, PluginLib.ICompileHelper compileErrorPublisher, PluginLib.IErrorPublisher errorPublisher) { if (str == null) return false; compileErrorPublisher.PushOutput(str + "\r\n"); bool isError = false; bool isWarning = false; if (str.Contains("ERROR: ")) { str = str.Replace("ERROR: ", ""); isError = true; } if (str.Contains("WARNING: ")) { str = str.Replace("WARNING: ", ""); isWarning = true; } if (isError || isWarning) { int sPos = str.IndexOf(": "); int driveIndex = str.IndexOf(':', sPos + 1); int colonIndex = str.IndexOf(':', driveIndex + 1); if (colonIndex == -1) return false; //don't count this as an error string fileName = str.Substring(sPos+1, colonIndex); string part = ""; int line = -1; int column = -1; //move to first number ++colonIndex; for (; colonIndex < str.Length; ++colonIndex) { if (str[colonIndex] == ',') { if (line == -1) line = int.Parse(part); else column = int.Parse(part); } if (str[colonIndex] == ' ') break; part += str[colonIndex]; } string msg = str.Substring(colonIndex+1); PluginLib.CompileError error = new PluginLib.CompileError { File = fileName, Line = line, Message = msg, IsError = isError }; compileErrorPublisher.PublishError(error); return isError; } return false; }
void ScanFolder(string aPath, string[] aTerms, bool aScanSubdirs, PluginLib.ISearchPublisher publishTo) { DirectoryInfo info = new DirectoryInfo(aPath); if (info.Exists) { foreach (FileInfo file in info.GetFiles()) { if (file.Length > 128 * 1024) // limit searching to files less than 128kb continue; string lCaseExt = file.Extension.ToLowerInvariant(); ScanFile(file.FullName, aTerms, publishTo); } if (aScanSubdirs) { foreach (DirectoryInfo dir in info.GetDirectories()) { ScanFolder(dir.FullName, aTerms, aScanSubdirs, publishTo); } } } }
public void PublishSearchResult(PluginLib.SearchResult result) { Dispatcher.Invoke(delegate() { searchResults_.Add(result); }); }
public void CompileFile(string file, PluginLib.ICompileHelper compileErrorPublisher, PluginLib.IErrorPublisher errorPublisher) { pushedError = false; this.compileErrorPublisher = compileErrorPublisher; this.errorPublisher = errorPublisher; try { string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); path = Path.Combine(path, "bin"); path = Path.Combine(path, "ScriptCompiler.exe"); // Check for spaces in paths and quote any paths that need to be quoted if (file.Contains(' ')) file = String.Format("\"{0}\"", file); foreach (string s in compileErrorPublisher.GetIncludeDirs()) file = String.Format(file + " {1}{0}{1}", s, s.Contains(' ') ? "\"" : ""); Process pi = new Process(); pi.StartInfo.FileName = path; pi.StartInfo.Arguments = file; pi.EnableRaisingEvents = true; pi.StartInfo.WorkingDirectory = compileErrorPublisher.GetProjectDirectory(); pi.StartInfo.UseShellExecute = false; pi.StartInfo.CreateNoWindow = true; pi.ErrorDataReceived += pi_ErrorDataReceived; pi.OutputDataReceived += pi_OutputDataReceived; pi.StartInfo.RedirectStandardError = true; pi.StartInfo.RedirectStandardOutput = true; pi.Start(); pi.BeginOutputReadLine(); pi.BeginErrorReadLine(); pi.WaitForExit(); if (pushedError) compileErrorPublisher.PushOutput(String.Format("Compiling {0} Failed\r\n", file)); else { compileErrorPublisher.PushOutput(String.Format("Compiling {0} Complete\r\n", file)); UrhoDumpAPI.CreateDumps(compileErrorPublisher.GetProjectDirectory(),compileErrorPublisher.GetProjectSourceTree()); } } catch (Exception ex) { errorPublisher.PublishError(ex); } }
public void PostCompile(string file, string sourceTree, PluginLib.IErrorPublisher errorPublisher) { try { string path = System.Reflection.Assembly.GetEntryAssembly().Location; path = Path.Combine(path, "bin"); path = Path.Combine(path, "ScriptCompiler.exe"); } catch (Exception ex) { errorPublisher.PublishError(ex); } }