diff --git a/RedundancyFinder/Finder.cs b/RedundancyFinder/Finder.cs index f8e3ed0..2519620 100644 --- a/RedundancyFinder/Finder.cs +++ b/RedundancyFinder/Finder.cs @@ -35,8 +35,6 @@ namespace RedundancyFinder { try { - - // Process files in the current directory foreach (var file in Directory.GetFiles(directoryPath)) { @@ -77,8 +75,6 @@ namespace RedundancyFinder return; } - - TaskStarted?.Invoke(this, filePath); ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath }); diff --git a/RedundancyFinderCLI/FinderCommand.cs b/RedundancyFinderCLI/FinderCommand.cs index 8a3c8f0..a2a68f6 100644 --- a/RedundancyFinderCLI/FinderCommand.cs +++ b/RedundancyFinderCLI/FinderCommand.cs @@ -46,26 +46,20 @@ namespace RedundancyFinderCLI int hashingTasks = 0; int hashingTasksFinished = 0; - - - - - - finder.FileError += (sender, e) => { if (e.Exception is UnauthorizedAccessException) { if (settings.Verbose) { - AnsiConsole.MarkupLine($"[red]Access denied to file: [/]{e.Path}. Skipping. Error: [red]{e.Exception.Message}[/]"); + WriteLine($"[red]Access denied to file: [/]{e.Path}. Skipping. Error: [red]{e.Exception.Message}[/]"); } } else { if (settings.Verbose) { - AnsiConsole.MarkupLine($"[red] Error processing file:\n[/]Path:{e.Path}\n[red]{e.Exception.Message}[/]"); + WriteLine($"[red] Error processing file:\n[/]Path:{e.Path}\n[red]{e.Exception.Message}[/]"); } } }; @@ -76,14 +70,14 @@ namespace RedundancyFinderCLI { if (settings.Verbose) { - AnsiConsole.MarkupLine($"[red]Access denied to directory: [/]{e.Path}. Skipping. Error: [red]{e.Exception.Message}[/]"); + WriteLine($"[red]Access denied to directory: [/]{e.Path}. Skipping. Error: [red]{e.Exception.Message}[/]"); } } else { if (settings.Verbose) { - AnsiConsole.MarkupLine($"[red] Error processing directory:\n[/]Path:{e.Path}\n[red]{e.Exception.Message}[/]"); + WriteLine($"[red] Error processing directory:\n[/]Path:{e.Path}\n[red]{e.Exception.Message}[/]"); } } }; @@ -92,11 +86,10 @@ namespace RedundancyFinderCLI { if (settings.Verbose) { - AnsiConsole.MarkupLine($"[green]Processing file: [/]{e.Path}"); + WriteLine($"[green]Processing file: [/]{e.Path}"); } }; - try { var p = AnsiConsole.Progress(); @@ -111,7 +104,7 @@ namespace RedundancyFinderCLI hashingTasks++; if (settings.Verbose) { - AnsiConsole.MarkupLine($"[green]Task started: [/]{e}"); + WriteLine($"[green]Task started: [/]{e}"); } //hashing.MaxValue = hashingTasks; }; @@ -120,7 +113,7 @@ namespace RedundancyFinderCLI { if (settings.Verbose) { - AnsiConsole.MarkupLine($"[green]File found: [/]{e.FilePath} {GetSizeFormat((ulong)e.Size)} "); + WriteLine($"[green]File found: [/]{e.FilePath} {GetSizeFormat((ulong)e.Size)} "); } hashingTasksFinished++; //hashing.Value = hashingTasksFinished; @@ -128,10 +121,6 @@ namespace RedundancyFinderCLI //hashing.Value = hashing.MaxValue; finder.FindRedundancies(settings.SearchPaths, extensions); //hashing.StopTask(); - - - - }); var json = JsonConvert.SerializeObject(finder.Redundancies, Formatting.Indented); @@ -143,17 +132,13 @@ namespace RedundancyFinderCLI outputPath = Path.Combine(Directory.GetCurrentDirectory(), outputPath); } - File.WriteAllText(outputPath, json); - - - AnsiConsole.MarkupLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{outputPath}'"); - + WriteLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{outputPath}'"); ulong totalSize = finder.Redundancies.Select(x => (ulong)x.Value.FileSize).Aggregate((a, b) => a + b); string sizeFormat = GetSizeFormat(totalSize); - AnsiConsole.MarkupLine($"Total Size: [green]{sizeFormat}[/]"); + WriteLine($"Total Size: [green]{sizeFormat}[/]"); if (settings.Verbose) { @@ -172,12 +157,18 @@ namespace RedundancyFinderCLI } catch (Exception e) { - AnsiConsole.MarkupLine($"[red] Error:\n[/]{e.Message}"); + WriteLine($"[red] Error:\n[/]{e.Message}"); } return 0; } + private void WriteLine(string v) + { + string now = Markup.Escape($"[{DateTime.Now.ToString("HH:mm:ss")}]"); + AnsiConsole.MarkupLine($"[gray]{now}[/] {v}"); + } + private static string GetSizeFormat(ulong totalSize) { string sizeUnit = "B";