Compare commits

..

No commits in common. "b66e7dd4ad397101969bb3f173cd3294985df42d" and "b1b24593efae15a6834930b2d7ef981983b8d27f" have entirely different histories.

4 changed files with 19 additions and 27 deletions

BIN
0.2.zip

Binary file not shown.

View File

@ -4,6 +4,8 @@ namespace RedundancyFinder
{
public class Finder
{
List<Task> tasks = new List<Task>();
Dictionary<string, Redundancy> redundancies = new Dictionary<string, Redundancy>();
public Dictionary<string, Redundancy> Redundancies { get => redundancies; }
@ -29,14 +31,15 @@ namespace RedundancyFinder
ProcessFile(path);
}
}
// Wait for all tasks to complete
Task.WaitAll(tasks.ToArray());
}
private void ProcessDirectory(string directoryPath)
{
try
{
// Process files in the current directory
foreach (var file in Directory.GetFiles(directoryPath))
{
@ -46,13 +49,6 @@ namespace RedundancyFinder
// Recursively process subdirectories
foreach (var subDirectory in Directory.GetDirectories(directoryPath))
{
// Check if the directory is hidden and skip it if true
var attributes = File.GetAttributes(subDirectory);
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
continue;
}
try
{
ProcessDirectory(subDirectory);
@ -77,10 +73,9 @@ namespace RedundancyFinder
return;
}
TaskStarted?.Invoke(this, filePath);
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
Task task = new(() =>
{
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
try
{
@ -111,8 +106,11 @@ namespace RedundancyFinder
{
FileError?.Invoke(this, new FileErrorEventArgs() { Exception = ex, Path = filePath });
}
}
});
task.Start();
TaskStarted?.Invoke(this, filePath);
tasks.Add(task);
}
private static string ComputeFileHash(string filePath)
{

View File

@ -136,19 +136,13 @@ namespace RedundancyFinderCLI
var json = JsonConvert.SerializeObject(finder.Redundancies, Formatting.Indented);
var outputPath = settings.OutputPath;
//check if path is relative or absolute
if (!Path.IsPathRooted(settings.OutputPath))
{
outputPath = Path.Combine(Directory.GetCurrentDirectory(), outputPath);
}
File.WriteAllText(outputPath, json);
File.WriteAllText(settings.OutputPath, json);
AnsiConsole.MarkupLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{outputPath}'");
AnsiConsole.MarkupLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{settings.OutputPath}'");
ulong totalSize = finder.Redundancies.Select(x => (ulong)x.Value.FileSize).Aggregate((a, b) => a + b);
@ -159,11 +153,11 @@ namespace RedundancyFinderCLI
{
foreach (var redundancy in finder.Redundancies.Values)
{
AnsiConsole.WriteLine($"Hash: {redundancy.Hash}");
AnsiConsole.WriteLine("Paths:");
AnsiConsole.MarkupLine($"Hash: {redundancy.Hash}");
AnsiConsole.MarkupLine("Paths:");
foreach (var path in redundancy.Paths)
{
AnsiConsole.WriteLine(path);
AnsiConsole.MarkupLine(path);
}
AnsiConsole.WriteLine();
}

View File

@ -2,7 +2,7 @@
"profiles": {
"RedundancyFinderCLI": {
"commandName": "Project",
"commandLineArgs": "C:\\Users\\daskn\\Pictures\\ -v"
"commandLineArgs": "C:\\ -v"
}
}
}