Beispiel #1
0
        private static void HashFiles(List <List <FileDetails> > sizeGroups, QueueStatus status, bool showProgress, bool useFastHash)
        {
            IFileHash hash;

            if (useFastHash)
            {
                hash = new xxHash();
            }
            else
            {
                hash = new SHA1Hash();
            }

            //Hash all dupes in each group
            foreach (List <FileDetails> sizeGroup in sizeGroups)
            {
                foreach (FileDetails details in sizeGroup)
                {
                    if (TryReadFile(details, out byte[] data))
Beispiel #2
0
        private static void Main(string[] args)
        {
            //TODO:
            // Filename similarity
            // Partial mode

            ParserResult <Options> parserResult = Parser.Default.ParseArguments <Options>(args);

            if (!(parserResult is Parsed <Options> parsedOptions))
            {
                return;
            }

            Options o = parsedOptions.Value;

            if (o.DryRun)
            {
                Console.WriteLine("Dry-run enabled. Files won't actually be deleted.");
            }

            if (o.ShowProgress)
            {
                Console.WriteLine("Looking for files...");
            }

            Stopwatch sw           = null;
            TimeSpan  filesElapsed = TimeSpan.Zero;

            if (o.ShowTiming)
            {
                sw = Stopwatch.StartNew();
            }

            List <FileDetails> files = GetFiles(o.Directory, o.RecurseSubdirectories, o.EnableTimestamp, new FileFilter(o.MinSize, o.MaxSize, o.SkipHidden)).ToList();

            if (sw != null)
            {
                filesElapsed = sw.Elapsed;
            }

            //Group files by size. This gives us groups with each more than 2 candidates.
            List <List <FileDetails> > sizeGroups = GroupBySize(files).ToList();

            QueueStatus status = new QueueStatus(sizeGroups.Sum(x => x.Count), sizeGroups.Sum(x => x.Sum(y => y.Size)));

            if (o.ShowProgress)
            {
                status.PrintStatus(status);
            }

            sw?.Restart();

            if (!o.DisableHash)
            {
                HashFiles(sizeGroups, status, o.ShowProgress, o.UseFastHash);
            }
            else
            {
                status.BytesProgress = status.BytesTotal;
                status.FilesProgress = status.FilesTotal;
            }

            if (o.ShowProgress)
            {
                status.PrintStatus(status);
            }

            if (sw != null)
            {
                Console.WriteLine($"It took {filesElapsed} to find files. It took {sw.Elapsed} to hash files.");
            }

            List <List <FileDetails> > withCriteria = GroupByCriteria(sizeGroups).ToList();

            if (o.NoAsk)
            {
                DeleteAllButFirst(withCriteria, o.DryRun);
            }
            else
            {
                HandleDupes(withCriteria, o.DryRun);
            }
        }
Beispiel #3
0
 public void PrintStatus(QueueStatus status)
 {
     Console.SetCursorPosition(0, _currentTop);
     Console.Write($"Total progress: {status.FilesProgress}/{status.FilesTotal} - {BytesProgress / 1024 / 1024:N0}/{BytesTotal / 1024 / 1024:N0} MiB - {status.GetTotalProgress() * 100.0f:0.00} %");
     Console.Write(string.Concat(Enumerable.Repeat(" ", Console.WindowWidth - Console.CursorLeft)));
 }