Compare commits
5 Commits
b1b24593ef
...
b66e7dd4ad
| Author | SHA1 | Date | |
|---|---|---|---|
| b66e7dd4ad | |||
| a84450cd5e | |||
| e6e259ed47 | |||
| 775e915cfa | |||
| 95e53b00ec |
@ -4,8 +4,6 @@ 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; }
|
||||||
@ -31,15 +29,14 @@ 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))
|
||||||
{
|
{
|
||||||
@ -49,6 +46,13 @@ 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);
|
||||||
@ -73,9 +77,10 @@ namespace RedundancyFinder
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task task = new(() =>
|
|
||||||
{
|
|
||||||
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
|
TaskStarted?.Invoke(this, filePath);
|
||||||
|
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -106,11 +111,8 @@ 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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -136,13 +136,19 @@ 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(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);
|
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)
|
foreach (var redundancy in finder.Redundancies.Values)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine($"Hash: {redundancy.Hash}");
|
AnsiConsole.WriteLine($"Hash: {redundancy.Hash}");
|
||||||
AnsiConsole.MarkupLine("Paths:");
|
AnsiConsole.WriteLine("Paths:");
|
||||||
foreach (var path in redundancy.Paths)
|
foreach (var path in redundancy.Paths)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine(path);
|
AnsiConsole.WriteLine(path);
|
||||||
}
|
}
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"RedundancyFinderCLI": {
|
"RedundancyFinderCLI": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "C:\\ -v"
|
"commandLineArgs": "C:\\Users\\daskn\\Pictures\\ -v"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user