コード例 #1
0
        private void FindDuplicatesOf(
            IEnumerable <VideoFile> videoFiles,
            VideoFile refFile,
            CancellationToken cancelToken)
        {
            OnLogged(string.Format(LogCheckingFile,
                                   refFile.FilePath,
                                   refFile.Duration.ToPrettyString()));

            foreach (var file in videoFiles
                     .Where(f => f != refFile)
                     .Where(f => f.IsDurationEqual(refFile, CurrentState.Settings)))
            {
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }

                OnLogged(string.Format(LogCompareFile, file.FilePath));
                try
                {
                    var comparer = new VideoComparer
                    {
                        LeftVideoFile  = file,
                        RightVideoFile = refFile,
                        Settings       = CurrentState.Settings,
                    };
                    if (comparer.Compare(cancelToken)
                        == ComparisonResult.Duplicate)
                    {
                        OnLogged($"Found duplicate of {refFile.FilePath} and" +
                                 $" {file.FilePath}");
                        OnDuplicateFound(refFile, file);
                    }
                }
                catch (AggregateException exc)
                    when(exc.InnerException is MpvLib.MpvException)
                    {
                        OnLogged(exc.InnerException.Message);
                    }
            }
        }
コード例 #2
0
        private void FindDuplicates(EngineState state,
                                    CancellationToken cancelToken)
        {
            operationStartTime = DateTime.Now;
            OnOperationUpdate(
                OperationType.Comparing,
                0,
                state.VideoFiles.Count());

            var timer = Stopwatch.StartNew();

            state.VideoFiles = state.VideoFiles
                               .OrderBy(f => f.Duration)
                               .ToList();

            for (/*We continue at the current index*/;
                 CurrentState.CurrentIndex < state.VideoFiles.Count() - 1;
                 CurrentState.CurrentIndex++)
            {
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }

                var file = state.VideoFiles[CurrentState.CurrentIndex];

                OnLogged(string.Format(LogCheckingFile,
                                       file.FilePath,
                                       file.Duration.ToPrettyString()));
                OnOperationUpdate(OperationType.Comparing,
                                  CurrentState.CurrentIndex + 1,
                                  state.VideoFiles.Count());

                foreach (var other in state.VideoFiles
                         .Skip(CurrentState.CurrentIndex + 1)
                         .TakeWhile(other =>
                                    file.IsDurationEqual(other, state.Settings)))
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        return;
                    }

                    OnLogged(string.Format(LogCompareFile, other.FilePath));
                    try
                    {
                        var comparer = new VideoComparer
                        {
                            LeftVideoFile  = file,
                            RightVideoFile = other,
                            Settings       = state.Settings,
                        };
                        if (comparer.Compare(cancelToken)
                            == ComparisonResult.Duplicate)
                        {
                            OnLogged($"Found duplicate of {file.FilePath} and " +
                                     $"{other.FilePath}");
                            OnDuplicateFound(file, other);
                        }
                    }
                    catch (AggregateException exc)
                        when(exc.InnerException is MpvLib.MpvException)
                        {
                            OnLogged(exc.InnerException.Message);
                        }
                }

                CurrentState.SaveState();
                file.DisposeImages();
            }
            // To make sure we don't do all the work again
            // when we load the state next time.
            // Maybe we should track that separately though.
            CurrentState.CurrentIndex = int.MaxValue;
            CurrentState.SaveState();

            timer.Stop();
            Debug.Print($"Dedup took {timer.ElapsedMilliseconds} ms");

            OnOperationUpdate(OperationType.Comparing,
                              state.VideoFiles.Count(),
                              state.VideoFiles.Count());
        }