Compare commits

..

5 Commits

Author SHA1 Message Date
b66e7dd4ad Released 0.2 2025-05-10 17:08:36 +02:00
a84450cd5e always get absolute outputpath 2025-05-10 15:44:12 +02:00
e6e259ed47 remove tasks
fixed ignoring hidden folders
2025-05-10 14:04:08 +02:00
775e915cfa ignoring hidden directories 2025-05-10 13:48:12 +02:00
95e53b00ec changed some Markups to Writelines 2025-05-10 13:47:43 +02:00
4 changed files with 27 additions and 19 deletions

BIN
0.2.zip Normal file

Binary file not shown.

View File

@ -4,8 +4,6 @@ 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; }
@ -31,15 +29,14 @@ 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))
{
@ -49,6 +46,13 @@ 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);
@ -73,9 +77,10 @@ namespace RedundancyFinder
return;
}
Task task = new(() =>
{
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
TaskStarted?.Invoke(this, filePath);
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
try
{
@ -106,11 +111,8 @@ 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,13 +136,19 @@ 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(settings.OutputPath, json);
File.WriteAllText(outputPath, json);
AnsiConsole.MarkupLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{settings.OutputPath}'");
AnsiConsole.MarkupLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{outputPath}'");
ulong totalSize = finder.Redundancies.Select(x => (ulong)x.Value.FileSize).Aggregate((a, b) => a + b);
@ -153,11 +159,11 @@ namespace RedundancyFinderCLI
{
foreach (var redundancy in finder.Redundancies.Values)
{
AnsiConsole.MarkupLine($"Hash: {redundancy.Hash}");
AnsiConsole.MarkupLine("Paths:");
AnsiConsole.WriteLine($"Hash: {redundancy.Hash}");
AnsiConsole.WriteLine("Paths:");
foreach (var path in redundancy.Paths)
{
AnsiConsole.MarkupLine(path);
AnsiConsole.WriteLine(path);
}
AnsiConsole.WriteLine();
}

View File

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