public static Format ( string path, |
||
path | string | |
options | ||
ct | ||
return | void |
private WorkItem DecompileSourceFile(DecompilerTypeSystem ts, IGrouping <string, TypeDefinitionHandle> src, string projectName, string conditional = null) { return(new WorkItem("Decompiling: " + src.Key, updateStatus => { var path = Path.Combine(srcDir, projectName, src.Key); CreateParentDirectory(path); using (var w = new StringWriter()) { if (conditional != null) { w.WriteLine("#if " + conditional); } CreateDecompiler(ts) .DecompileTypes(src.ToArray()) .AcceptVisitor(new CSharpOutputVisitor(w, projectDecompiler.Settings.CSharpFormattingOptions)); if (conditional != null) { w.WriteLine("#endif"); } string source = w.ToString(); if (formatOutput) { updateStatus("Formatting: " + src.Key); source = FormatTask.Format(source, taskInterface.CancellationToken, true); } File.WriteAllText(path, source); } })); }
public override void Run() { taskInterface.SetStatus("Deleting Old Src"); if (Directory.Exists(FullSrcDir)) { Directory.Delete(FullSrcDir, true); } var baseFiles = Directory.EnumerateFiles(FullBaseDir, "*", SearchOption.AllDirectories); var patchFiles = Directory.EnumerateFiles(FullPatchDir, "*", SearchOption.AllDirectories); var copyItems = new List <WorkItem>(); var patchItems = new List <WorkItem>(); var formatItems = new List <WorkItem>(); foreach (var file in baseFiles) { var relPath = RelPath(FullBaseDir, file); if (DiffTask.excluded.Any(relPath.StartsWith)) { continue; } var srcPath = Path.Combine(FullSrcDir, relPath); copyItems.Add(new WorkItem("Copying: " + relPath, () => Copy(file, srcPath))); if (format != null && file.EndsWith(".cs")) { formatItems.Add(new WorkItem("Formatting: " + relPath, () => FormatTask.Format(srcPath, format, taskInterface.CancellationToken()))); } } foreach (var file in patchFiles) { var relPath = RelPath(FullPatchDir, file); if (relPath.EndsWith(".patch")) { patchItems.Add(new WorkItem("Patching: " + relPath, () => Patch(relPath))); } else { copyItems.Add(new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(FullSrcDir, relPath)))); } } taskInterface.SetMaxProgress(copyItems.Count + formatItems.Count + patchItems.Count); ExecuteParallel(copyItems, false); ExecuteParallel(formatItems, false); try { CreateDirectory(Program.LogDir); logFile = new StreamWriter(Path.Combine(Program.LogDir, "patch.log")); ExecuteParallel(patchItems, false); } finally { if (logFile != null) { logFile.Close(); } } switch (stepNumber) { case 0: DiffTask.MergedDiffCutoff.Set(DateTime.Now); break; case 1: DiffTask.TerrariaDiffCutoff.Set(DateTime.Now); break; case 2: DiffTask.tModLoaderDiffCutoff.Set(DateTime.Now); break; } }
public override void Run() { taskInterface.SetStatus("Deleting Old Src"); if (Directory.Exists(FullSrcDir)) { Directory.Delete(FullSrcDir, true); } var baseFiles = Directory.EnumerateFiles(FullBaseDir, "*", SearchOption.AllDirectories); var patchFiles = Directory.EnumerateFiles(FullPatchDir, "*", SearchOption.AllDirectories); var removedFileList = Path.Combine(FullPatchDir, DiffTask.RemovedFileList); var removedFiles = File.Exists(removedFileList) ? new HashSet <string>(File.ReadAllLines(removedFileList)) : new HashSet <string>(); var copyItems = new List <WorkItem>(); var patchItems = new List <WorkItem>(); var formatItems = new List <WorkItem>(); foreach (var file in baseFiles) { var relPath = RelPath(FullBaseDir, file); if (DiffTask.excluded.Any(relPath.StartsWith) || removedFiles.Contains(relPath)) { continue; } var srcPath = Path.Combine(FullSrcDir, relPath); copyItems.Add(new WorkItem("Copying: " + relPath, () => Copy(file, srcPath))); if (format != null && file.EndsWith(".cs")) { formatItems.Add(new WorkItem("Formatting: " + relPath, () => FormatTask.Format(srcPath, format, taskInterface.CancellationToken()))); } } foreach (var file in patchFiles) { var relPath = RelPath(FullPatchDir, file); if (relPath.EndsWith(".patch")) { patchItems.Add(new WorkItem("Patching: " + relPath, () => Patch(relPath))); } else if (relPath != DiffTask.RemovedFileList) { copyItems.Add(new WorkItem("Copying: " + relPath, () => Copy(file, Path.Combine(FullSrcDir, relPath)))); } } taskInterface.SetMaxProgress(copyItems.Count + formatItems.Count + patchItems.Count); ExecuteParallel(copyItems, false); ExecuteParallel(formatItems, false); try { CreateDirectory(Program.LogDir); logFile = new StreamWriter(Path.Combine(Program.LogDir, "patch.log")); ExecuteParallel(patchItems, false); } finally { logFile?.Close(); } cutoff.Set(DateTime.Now); }