Added Timestamp
This commit is contained in:
parent
b66e7dd4ad
commit
5800f2229f
@ -35,8 +35,6 @@ namespace RedundancyFinder
|
|||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
@ -77,8 +75,6 @@ namespace RedundancyFinder
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TaskStarted?.Invoke(this, filePath);
|
TaskStarted?.Invoke(this, filePath);
|
||||||
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
|
ProcessingFile?.Invoke(this, new ProcessingFileEventArgs() { Path = filePath });
|
||||||
|
|
||||||
|
|||||||
@ -46,26 +46,20 @@ namespace RedundancyFinderCLI
|
|||||||
int hashingTasks = 0;
|
int hashingTasks = 0;
|
||||||
int hashingTasksFinished = 0;
|
int hashingTasksFinished = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
finder.FileError += (sender, e) =>
|
finder.FileError += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (e.Exception is UnauthorizedAccessException)
|
if (e.Exception is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
if (settings.Verbose)
|
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
|
else
|
||||||
{
|
{
|
||||||
if (settings.Verbose)
|
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
if (settings.Verbose)
|
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)
|
if (settings.Verbose)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine($"[green]Processing file: [/]{e.Path}");
|
WriteLine($"[green]Processing file: [/]{e.Path}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var p = AnsiConsole.Progress();
|
var p = AnsiConsole.Progress();
|
||||||
@ -111,7 +104,7 @@ namespace RedundancyFinderCLI
|
|||||||
hashingTasks++;
|
hashingTasks++;
|
||||||
if (settings.Verbose)
|
if (settings.Verbose)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine($"[green]Task started: [/]{e}");
|
WriteLine($"[green]Task started: [/]{e}");
|
||||||
}
|
}
|
||||||
//hashing.MaxValue = hashingTasks;
|
//hashing.MaxValue = hashingTasks;
|
||||||
};
|
};
|
||||||
@ -120,7 +113,7 @@ namespace RedundancyFinderCLI
|
|||||||
{
|
{
|
||||||
if (settings.Verbose)
|
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++;
|
hashingTasksFinished++;
|
||||||
//hashing.Value = hashingTasksFinished;
|
//hashing.Value = hashingTasksFinished;
|
||||||
@ -128,10 +121,6 @@ namespace RedundancyFinderCLI
|
|||||||
//hashing.Value = hashing.MaxValue;
|
//hashing.Value = hashing.MaxValue;
|
||||||
finder.FindRedundancies(settings.SearchPaths, extensions);
|
finder.FindRedundancies(settings.SearchPaths, extensions);
|
||||||
//hashing.StopTask();
|
//hashing.StopTask();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var json = JsonConvert.SerializeObject(finder.Redundancies, Formatting.Indented);
|
var json = JsonConvert.SerializeObject(finder.Redundancies, Formatting.Indented);
|
||||||
@ -143,17 +132,13 @@ namespace RedundancyFinderCLI
|
|||||||
outputPath = Path.Combine(Directory.GetCurrentDirectory(), outputPath);
|
outputPath = Path.Combine(Directory.GetCurrentDirectory(), outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
File.WriteAllText(outputPath, json);
|
File.WriteAllText(outputPath, json);
|
||||||
|
|
||||||
|
WriteLine($"[yellow]Wrote [/]{finder.Redundancies.Count}[yellow] redundancies to [/]'{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);
|
||||||
string sizeFormat = GetSizeFormat(totalSize);
|
string sizeFormat = GetSizeFormat(totalSize);
|
||||||
AnsiConsole.MarkupLine($"Total Size: [green]{sizeFormat}[/]");
|
WriteLine($"Total Size: [green]{sizeFormat}[/]");
|
||||||
|
|
||||||
if (settings.Verbose)
|
if (settings.Verbose)
|
||||||
{
|
{
|
||||||
@ -172,12 +157,18 @@ namespace RedundancyFinderCLI
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine($"[red] Error:\n[/]{e.Message}");
|
WriteLine($"[red] Error:\n[/]{e.Message}");
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
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)
|
private static string GetSizeFormat(ulong totalSize)
|
||||||
{
|
{
|
||||||
string sizeUnit = "B";
|
string sizeUnit = "B";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user