/// <summary> /// Compile the file provided and its dependencies. Dependencies may be compiled /// conditionally if out of date or unconditionally. /// </summary> /// <param name="srcInfo">The source file info.</param> /// <param name="srcText">The source file text.</param> /// <param name="compileAll">Compile dependencies unconditionally if true.</param> /// <returns>True if the action completed successfully.</returns> public bool Compile(FileInfo srcInfo, string srcText, bool compileAll) { if (_output == null) { return(false); } _output.ClearOutputViews(); _mainForm.SetStatusBarMessage(Resources.BuildStarted); _mainForm.StatusBar.Refresh(); if (srcInfo == null || String.IsNullOrEmpty(srcText)) { _output.AddLineToOutputView(String.Format( "------ {0}: {1}", Resources.BuildErrors, Resources.ErrorSourceInvalid)); _output.AdjustOutputWidth(); _mainForm.SetStatusBarMessage(Resources.BuildErrors); return(false); } if (!CompileDependencies(srcText, compileAll)) { return(false); } BuildCommand compileCommand = GetBuildCommand(srcInfo, Constants.ACTION_COMPILE); return(CompileFile(compileCommand)); }
public void Find(string findText, string replaceText, string filePattern, bool searchSubFolders, bool useRegex, bool matchCase, bool findOnly) { /* * Prepare the output view. */ _outputForm.ClearOutputViews(); _outputForm.Text = String.Format(findOnly ? Resources.OutputTitleFind : Resources.OutputTitleReplace, filePattern); /* * Find all the matching files. */ string[] files = Directory.GetFiles( ".", filePattern, searchSubFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); if (files.Length == 0) { _outputForm.AddLineToOutputView( Resources.FindMessageNoMatchingFiles); _outputForm.AdjustOutputWidth(); return; } /* * Prepare the regular expression if required. */ Regex regex = null; if (useRegex) { try { regex = new Regex(findText); } catch (ArgumentException ex) { _outputForm.AddLineToOutputView( String.Format(Resources.FindError, ex.Message), System.Drawing.Color.Red); _outputForm.AdjustOutputWidth(); return; } } /* * Search. File is ".\filename.ext" so we use Substring(2) for the name. */ if (findOnly) { int lineCount = 0; foreach (string file in files) { if (useRegex) { lineCount += FindInFileRE(file.Substring(2), regex); } else { lineCount += FindInFile(file.Substring(2), findText, matchCase); } } _outputForm.AddLineToOutputView( String.Format(lineCount == 1 ? Resources.FindMessageMatchCountSingle : Resources.FindMessageMatchCountMulti, lineCount)); } else { int fileCount = 0; foreach (string file in files) { bool updated = false; if (useRegex) { updated = ReplaceInFileRE(file.Substring(2), replaceText, regex); } else { updated = ReplaceInFile(file.Substring(2), findText, replaceText); } if (updated) { fileCount++; } } _outputForm.AddLineToOutputView( String.Format(fileCount == 1 ? Resources.FindMessageReplaceCountSingle : Resources.FindMessageReplaceCountMulti, fileCount)); } _outputForm.AdjustOutputWidth(); }