private void __bwDest_DoWork(Object sender, DoWorkEventArgs e) { DirectoryInfo origRoot = new DirectoryInfo(Path.GetDirectoryName(__fileName.Text)); DirectoryInfo destRoot = new DirectoryInfo(__destPath.Text); __bwDest.ReportProgress(0, "Copying Files"); origRoot.CopyTo(destRoot.FullName); /////////////////////////// // Load the copied package String packageXmlFileName = Path.Combine(__destPath.Text, Path.GetFileName(__fileName.Text)); __bwDest.ReportProgress(30, "Identifying Duplicate Files"); PackageOptimizer opt = new PackageOptimizer(packageXmlFileName); List <String> messages = opt.LoadAndValidate(); if (messages.Count > 0) { e.Result = messages; return; } DuplicateFinder finder = opt.GetDuplicateFilesFinder(); finder.StatusUpdated += new EventHandler(finderDest_StatusUpdated); finder.Search(); DirectoryInfo moveDupesTo = destRoot.GetDirectory("_duplicates"); if (!moveDupesTo.Exists) { moveDupesTo.Create(); } __bwDest.ReportProgress(60, "Process and Saving Package.xml"); finder.ProcessPackage(opt.Document); ///////////////////////// // Save the updated package xml XmlWriterSettings settings = new XmlWriterSettings(); settings.NewLineChars = "\r\n"; settings.IndentChars = "\t"; XmlWriter wtr = XmlWriter.Create(packageXmlFileName, settings); opt.Document.Save(wtr); __bwDest.ReportProgress(60, "Moving Duplicate Files"); finder.SeparateOutDuplicateFiles(moveDupesTo); __bwDest.ReportProgress(100, "Complete"); }
private Triple <String[], String[], String[]> LoadOptimizer(String fileName) { __bwLoad.ReportProgress(-1, "Loading"); _opt = new PackageOptimizer(__fileName.Text); List <String> messages = _opt.LoadAndValidate(); String[] missing = new String[0], unreferenced = new String[0]; __bwLoad.ReportProgress(-1, "Loading Missing and Unreferenced Files"); if (messages.Count > 0) { return(new Triple <String[], String[], String[]>(messages.ToArray(), missing, unreferenced)); } ///////////////////////// // Missing and Unreferenced Files _opt.GetFiles(out missing, out unreferenced); ///////////////////////// // Duplicate Files __bwLoad.ReportProgress(-1, "Loading Duplicate Files"); DuplicateFinder finder = _opt.GetDuplicateFilesFinder(); finder.StatusUpdated += new EventHandler(finder_StatusUpdated); finder.Search(); return(new Triple <String[], String[], String[]>(messages.ToArray(), missing, unreferenced)); }
private void __bwLoad_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) { Triple <String[], String[], String[]> ret = e.Result as Triple <String[], String[], String[]>; String[] messages = ret.X; String[] missing = ret.Y; String[] unreferenced = ret.Z; ///////////////////// // Messages __messages.Items.Clear(); __messages.Items.AddRange(messages); ///////////////////// // Missing and Unreferenced Files __missingFiles.Items.Clear(); __missingFiles.Items.AddRange(missing); __unreferencedFiles.Items.Clear(); __unreferencedFiles.Items.AddRange(unreferenced); ///////////////////// // Composited Images List <CompositedImage> images = _opt.CompositedImages; __compImages.Items.AddRange(images.ToArray()); ///////////////////// // Duplicate Files DuplicateFinder finder = _opt.GetDuplicateFilesFinder(); String rootDirectory = Path.GetDirectoryName(__fileName.Text); __duplicateFiles.BeginUpdate(); foreach (DuplicateFile set in finder.DuplicateFiles) { ListViewGroup group = new ListViewGroup(set.Hash); __duplicateFiles.Groups.Add(group); foreach (FileInfo file in set.Matches) { String relativeName = file.FullName.Substring(rootDirectory.Length); ListViewItem item = __duplicateFiles.Items.Add(relativeName); item.Group = group; } } __duplicateFiles.EndUpdate(); _prog.Visible = false; this.BringToForeground(); }