private string GenerateReport() { StringBuilder buffer = new StringBuilder(); buffer.AppendLine(String.Format("--- Installer Comparison: {0} --> {1}", FileName1, FileName2)); // Store identical filenames if necessary. if (cbShowIdentical.Checked) { buffer.AppendLine("= Identical files"); foreach (RCH2File file in CompareInstance.IdenticalFiles) { buffer.AppendLine(String.Format("{0,8:x} [{1,8}] {2}", file.CRCSum, file.Size, file.Path)); } buffer.AppendLine(); } // Store different filenames if necessary. if (cbDifferent.Checked) { buffer.AppendLine("= Different files"); foreach (RCH2File file in CompareInstance.File1.DifferentFiles) { RCH2File file2 = FIB.FindFileByPath(CompareInstance.File2.Container, file.Path); buffer.AppendLine(file.Path); buffer.AppendLine(String.Format(" - CRC32: {0,8:x} --> {1,8:x}", file.CRCSum, file2.CRCSum)); buffer.AppendLine(String.Format(" - Size: {0,8} --> {1,8}", file.Size, file2.Size)); } buffer.AppendLine(); } // Store unique filenames if necessary. if (cbUnique.Checked) { buffer.AppendLine("= Unique files"); foreach (RCH2File file in CompareInstance.File1.UniqueFiles) { buffer.AppendLine("- " + file.Path); } foreach (RCH2File file in CompareInstance.File2.UniqueFiles) { buffer.AppendLine("+ " + file.Path); } } return(buffer.ToString()); }
private void bgw_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bw = sender as BackgroundWorker; bool showIdentical = cbShowIdentical.Checked; bool showDifferent = cbDifferent.Checked; bool showUnique = cbUnique.Checked; string targetPath = (string)e.Argument; extractCurrentFile = 0; extractTotalFiles = (showIdentical ? CompareInstance.IdenticalFiles.Count : 0) + (showDifferent ? CompareInstance.File1.DifferentFiles.Count + CompareInstance.File2.DifferentFiles.Count : 0) + (showUnique ? CompareInstance.File1.UniqueFiles.Count + CompareInstance.File2.UniqueFiles.Count : 0); // Create File1 and File2 folders. string file1path = targetPath + Path.DirectorySeparatorChar + FileName1; string file2path = targetPath + Path.DirectorySeparatorChar + FileName2; Directory.CreateDirectory(file1path); Directory.CreateDirectory(file2path); // Extract the files mentioned. if (showIdentical) { foreach (RCH2File file in CompareInstance.IdenticalFiles) { string processedPath = FIB.ProcessPath(file.Path); string file1full = file1path + Path.DirectorySeparatorChar + processedPath; string file2full = file2path + Path.DirectorySeparatorChar + processedPath; Directory.CreateDirectory(Path.GetDirectoryName(file1full)); Directory.CreateDirectory(Path.GetDirectoryName(file2full)); file.Extract(file1full); File.Copy(file1full, file2full, true); extractCurrentFile++; if (bw.CancellationPending) { goto bgwCancel; } } } if (showDifferent) { foreach (RCH2File file in CompareInstance.File1.DifferentFiles) { RCH2File file2 = FIB.FindFileByPath(CompareInstance.File2.Container, file.Path); string processedPath = FIB.ProcessPath(file.Path); string file1full = file1path + Path.DirectorySeparatorChar + processedPath; string file2full = file2path + Path.DirectorySeparatorChar + processedPath; Directory.CreateDirectory(Path.GetDirectoryName(file1full)); Directory.CreateDirectory(Path.GetDirectoryName(file2full)); file.Extract(file1full); file2.Extract(file2full); extractCurrentFile += 2; if (bw.CancellationPending) { goto bgwCancel; } } } if (showUnique) { bool flag = true; foreach (List <RCH2File> list in new List <RCH2File>[] { CompareInstance.File1.UniqueFiles, CompareInstance.File2.UniqueFiles }) { foreach (RCH2File file in list) { string full = (flag ? file1path : file2path) + Path.DirectorySeparatorChar + FIB.ProcessPath(file.Path); Directory.CreateDirectory(Path.GetDirectoryName(full)); file.Extract(full); extractCurrentFile++; if (bw.CancellationPending) { goto bgwCancel; } } flag = false; } } return; bgwCancel: e.Cancel = true; }
private RCH2File FindFileByPath(string filePath) { return(FIB.FindFileByPath(rch2, filePath)); }