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

View File

@ -136,19 +136,13 @@ namespace RedundancyFinderCLI
var json = JsonConvert.SerializeObject(finder.Redundancies, Formatting.Indented); 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); 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) foreach (var redundancy in finder.Redundancies.Values)
{ {
AnsiConsole.WriteLine($"Hash: {redundancy.Hash}"); AnsiConsole.MarkupLine($"Hash: {redundancy.Hash}");
AnsiConsole.WriteLine("Paths:"); AnsiConsole.MarkupLine("Paths:");
foreach (var path in redundancy.Paths) foreach (var path in redundancy.Paths)
{ {
AnsiConsole.WriteLine(path); AnsiConsole.MarkupLine(path);
} }
AnsiConsole.WriteLine(); AnsiConsole.WriteLine();
} }

View File

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