private static void CopyBinaries() { WriteHeader("Copying binaries"); var mainProject = GetMainProject(_currentRelease.Projects); outputDir = new DirectoryInfo(_currentRelease.Output) .Combine(mainProject.GetVersion().ToString()); if (outputDir.Exists) { Cli.WriteLine("Deleting ~Yellow~{0}~R~", outputDir.FullName); outputDir.Delete(true); } Cli.WriteLine(); WriteProgressHeader("Copying"); var progress = new CliProgressBar(_currentRelease.Projects.Length); progress.Write(); _currentRelease.Projects .Iter(x => { new DirectoryInfo(x.OutputPath).CopyTo(outputDir.FullName, true); progress.Value++; progress.Write(); }); Cli.WriteLine(); Cli.WriteLine(); }
private static void Cleanup() { WriteHeader("Cleaning up"); Cli.WriteLine("Searching..."); var fsos = new List <FileSystemInfo>(); if (_currentRelease.Cleanup.FilePatterns != null && _currentRelease.Cleanup.FilePatterns.Any()) { fsos.AddRange( outputDir .GetFiles("*", SearchOption.AllDirectories) .Where(x => _currentRelease.Cleanup.FilePatterns.Any(y => Regex.IsMatch(x.FullName, y)))); } if (_currentRelease.Cleanup.Files != null && _currentRelease.Cleanup.Files.Any()) { fsos.AddRange(_currentRelease.Cleanup.Files.Select(x => new FileInfo(Path.Combine(outputDir.FullName, x)))); } if (_currentRelease.Cleanup.Directories != null && _currentRelease.Cleanup.Directories.Any()) { fsos.AddRange(_currentRelease.Cleanup.Directories.Select(x => outputDir.Combine(x))); } Cli.WriteLine("~Cyan~{0}~R~ files and directories found", fsos.Count); Cli.WriteLine(); WriteProgressHeader("Deleting"); var progress = new CliProgressBar(fsos.Count); progress.Write(); fsos.Iter(x => { if (!x.Exists) { progress.Value++; progress.Write(); return; } var dir = x as DirectoryInfo; if (dir != null) { dir.Delete(true); } else { x.Delete(); } progress.Value++; progress.Write(); }); Cli.WriteLine(); Cli.WriteLine(); }
public void Unset(DirectoryInfo Directory) { var files = Directory .GetFiles("*", SearchOption.AllDirectories) .Where(x => x.Extension == ".php" || x.Extension == ".inc"); var progressBar = new CliProgressBar(files.Count()); progressBar.Write(); foreach (FileInfo f in files) { //try //{ IOHelper.TryAction(() => { var backupFile = new FileInfo(f.FullName + ".phpvhbackup"); if (backupFile.Exists) { backupFile.CopyTo(f.FullName, true); backupFile.Delete(); } }, 512, 0); progressBar.Value++; progressBar.Write(); //} //catch (System.Exception ex) //{ // ScannerCli.DisplayError(string.Format("\r\nError unhooking {0}:\r\n{1}\r\n\r\n", f.FullName, ex.Message)); //} } Cli.WriteLine(); //foreach (DirectoryInfo d in Directory.GetDirectories()) // Unset(d); }
static void Main(string[] args) { WriteHeader("Loading release settings"); var script = "PhpVH.alx"; Cli.WriteLine("Executing ~Cyan~{0}~R~", script); var interpreter = new AphidInterpreter(); interpreter.InterpretFile(script); _currentRelease = interpreter.GetReturnValue().ConvertTo <Release>(); var projects = _currentRelease.Projects; Cli.WriteLine(); WriteHeader("Copying binaries"); var outputDir = new DirectoryInfo(_currentRelease.Output) .Combine(GetReleaseVersion(projects).ToString()); if (outputDir.Exists) { Cli.WriteLine("Deleting ~Yellow~{0}~R~", outputDir.FullName); outputDir.Delete(true); } Cli.WriteLine(); WriteProgressHeader("Copying"); var progress = new CliProgressBar(projects.Length); progress.Write(); projects .Iter(x => { new DirectoryInfo(x.OutputPath).CopyTo(outputDir.FullName, true); progress.Value++; progress.Write(); }); Cli.WriteLine(); Cli.WriteLine(); WriteHeader("Cleaning up"); Cli.WriteLine("Searching..."); var fsos = new List <FileSystemInfo>(); if (_currentRelease.Cleanup.FilePatterns != null && _currentRelease.Cleanup.FilePatterns.Any()) { fsos.AddRange( outputDir .GetFiles("*", SearchOption.AllDirectories) .Where(x => _currentRelease.Cleanup.FilePatterns.Any(y => Regex.IsMatch(x.FullName, y)))); } if (_currentRelease.Cleanup.Files != null && _currentRelease.Cleanup.Files.Any()) { fsos.AddRange(_currentRelease.Cleanup.Files.Select(x => new FileInfo(Path.Combine(outputDir.FullName, x)))); } if (_currentRelease.Cleanup.Directories != null && _currentRelease.Cleanup.Directories.Any()) { fsos.AddRange(_currentRelease.Cleanup.Directories.Select(x => outputDir.Combine(x))); } Cli.WriteLine("~Cyan~{0}~R~ files and directories found", fsos.Count); Cli.WriteLine(); WriteProgressHeader("Deleting"); progress = new CliProgressBar(fsos.Count); progress.Write(); fsos.Iter(x => { var dir = x as DirectoryInfo; if (dir != null) { dir.Delete(true); } else { x.Delete(); } progress.Value++; progress.Write(); }); }
public void Set(DirectoryInfo Directory) { IEnumerable <FileInfo> files = null; try { files = Directory .GetFiles("*", SearchOption.AllDirectories) .Where(x => x.Extension.ToLower() == ".php" || x.Extension.ToLower() == ".inc"); } catch (UnauthorizedAccessException) { var error = string.Format("\r\nError enumerating files in {0}", Directory.FullName); ScannerCli.DisplayError(error); return; } var progressBar = new CliProgressBar(files.Count()); progressBar.Write(); files.AsyncIter(f => { if (!CreateBackup(f)) { return; } string php = File.ReadAllText(f.FullName); PhpToken[] tokens = null; Action getTokens = () => tokens = PhpParser.StripWhitespaceAndComments(new PhpLexer(php) .GetTokens() .ToArray()); getTokens(); lock (Program.PageFieldTable) { if (!Program.PageFieldTable.ContainsKey(f.FullName)) { Program.PageFieldTable.Add(f.FullName, new Dictionary <string, List <string> >()); } var superglobals = StaticAnalyzer.FindSuperglobalFields(tokens); foreach (var superglobal in superglobals) { if (!Program.PageFieldTable[f.FullName].ContainsKey(superglobal.Key)) { Program.PageFieldTable[f.FullName].Add(superglobal.Key, new List <string>()); } var newValues = superglobal.Value .Where(x => !Program.PageFieldTable[f.FullName][superglobal.Key].Contains(x)); Program.PageFieldTable[f.FullName][superglobal.Key].AddRange(newValues); } } lock (Program.FileIncludeTable) Program.FileIncludeTable.Add(f.FullName, PhpParser.GetIncludedFiles(tokens)); var functions = PhpParser.GetGlobalFunctionCalls(tokens); if (Program.Config.CodeCoverageReport > 0) { php = ScanMetrics.Default.Annotator.AnnotateCode(f.FullName, php, tokens); } if (!Program.Config.HookSuperglobals) { php = PreloadHelper.Patch(php); } foreach (Hook h in this) { h.Set(ref php); } getTokens(); string include = "require_once('" + Program.Config.WebRoot.Replace('\\', '/') + "/" + Hook.HookFileName + "');"; if (tokens.Length >= 2 && tokens[1].TokenType == PhpTokenType.namespaceKeyword) { var eos = tokens.FirstOrDefault(x => x.TokenType == PhpTokenType.EndOfStatement); php = php.Insert(eos.Index + 1, "\r\n" + include + "\r\n"); } else { php = "<?php " + include + " ?>" + php; } try { File.WriteAllText(f.FullName, php); } catch (UnauthorizedAccessException ex) { ScannerCli.DisplayError(string.Format("\r\n\r\nError hooking file\r\n{0}\r\n", ex.Message)); return; } progressBar.Value++; progressBar.Write(); }); }