Beispiel #1
0
        public void SearchForDuplicates(string rootFolder, CriteriaSettings pCriteria)
        {
            DuplicateCollector collector = new DuplicateCollector(rootFolder, pCriteria);

            collector.FileAdded += x =>
            {
                SendMessage(Messages.FileAdded, new NotificationEventArgs(x));
            };
            collector.DuplicateFileFound += x =>
            {
                if (FoundDuplicate != null)
                {
                    FoundDuplicate(x);
                }
            };

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Starting count of files..."));
            var count = collector.CountAllFiles();

            SendMessage(Messages.FilesCount, new NotificationEventArgs(count.ToString()));
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Total of: " + count.ToString() + " files found."));

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Starting MD5 Calculation..."));
            AllFiles = collector.ScanFileInfo();
            SendMessage(Messages.NotifyString, new NotificationEventArgs("MD5 Calculation Completed."));
            SendMessage(Messages.NotifyString, new NotificationEventArgs(String.Format(@"Saving results to ""{0}""", DataFile)));

            if (File.Exists(DataFile))
            {
                File.Delete(DataFile);
            }
            var SerializationObject = new SavedSession()
            {
                Duplicates = AllFiles, SelectedPath = rootFolder, Settings = pCriteria
            };

            BinarySerializationAssistor.Serialize(SerializationObject, DataFile);
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Saved."));

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Looking for duplicates..."));
            collector.CalculateDuplicate();
            AllDuplicates = collector.AllDuplicated;
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Done."));
            SendMessage(Messages.NotifyString, new NotificationEventArgs(String.Format("Found {0} duplicated files.", collector.AllDuplicated.Count)));
            SendMessage(Messages.WorkingChanged, new NotificationEventArgs("false"));
            SendMessage(Messages.FilesCompleted, new NotificationEventArgs());
        }
Beispiel #2
0
        public void LoadFromFile(string fileName)
        {
            var collector = new DuplicateCollector();
            var newPath   = collector.LoadFromFile(fileName);

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Loaded."));
            SendMessage(Messages.UserSelectedFolderFromTree, new NotificationEventArgs(newPath));
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Looking for duplicates..."));
            if (collector.AllFiles == null)
            {
                SendMessage(Messages.NotifyString, new NotificationEventArgs("Saved file contain no files."));
                return;
            }
            collector.CalculateDuplicate();
            AllDuplicates = collector.AllDuplicated;
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Done."));

            SendMessage(Messages.NotifyString, new NotificationEventArgs(String.Format("Found {0} duplicated files.", collector.AllDuplicated.Count)));
            //SendMessage(Messages.WorkingChanged, new NotificationEventArgs("false"));
            SendMessage(Messages.FilesCompleted, new NotificationEventArgs());
        }