Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        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));
        }