reload implemented
This commit is contained in:
parent
63c1c88393
commit
1bb7d461e0
@ -10,6 +10,8 @@ namespace RedundancyFinder
|
||||
|
||||
string[] extensions;
|
||||
|
||||
List<string> ignorePaths = new List<string>();
|
||||
|
||||
public event EventHandler<DirectoryErrorEventArgs>? DirectoryError;
|
||||
public event EventHandler<FileErrorEventArgs>? FileError;
|
||||
public event EventHandler<FileFoundEventArgs>? FileFound;
|
||||
@ -17,6 +19,7 @@ namespace RedundancyFinder
|
||||
public event EventHandler<ProcessingFileEventArgs>? ProcessingFile;
|
||||
public void FindRedundancies(string[] paths, string[] extensions)
|
||||
{
|
||||
redundancies?.Values.SelectMany(x => x.Paths).ToList().ForEach(x => ignorePaths.Add(x));
|
||||
this.extensions = extensions;
|
||||
foreach (var path in paths)
|
||||
{
|
||||
@ -70,6 +73,11 @@ namespace RedundancyFinder
|
||||
|
||||
private void ProcessFile(string filePath)
|
||||
{
|
||||
if(ignorePaths.Contains(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!extensions.Contains(Path.GetExtension(filePath)))
|
||||
{
|
||||
return;
|
||||
@ -89,11 +97,6 @@ namespace RedundancyFinder
|
||||
long fileSize = new FileInfo(filePath).Length;
|
||||
lock (redundancies)
|
||||
{
|
||||
if (redundancies.ContainsKey(fileHash))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!redundancies.ContainsKey(fileHash))
|
||||
{
|
||||
var redundancy = new Redundancy() { Hash = fileHash, FileSize = fileSize };
|
||||
|
||||
@ -50,6 +50,31 @@ namespace RedundancyFinderCLI
|
||||
SaveRedundancies(finder, settings.OutputPath);
|
||||
};
|
||||
|
||||
// Load existing redundancies if the output file exists
|
||||
if (File.Exists(settings.OutputPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var existingData = File.ReadAllText(settings.OutputPath);
|
||||
var existingRedundancies = JsonConvert.DeserializeObject<Dictionary<string, Redundancy>>(existingData);
|
||||
|
||||
if (existingRedundancies != null)
|
||||
{
|
||||
foreach (var entry in existingRedundancies)
|
||||
{
|
||||
finder.Redundancies[entry.Key] = entry.Value;
|
||||
}
|
||||
|
||||
WriteLine($"[yellow]Resumed from existing output file: [/]'{settings.OutputPath}'");
|
||||
WriteLine($"[yellow]Loaded {finder.Redundancies.Count} redundancies from the file.[/]");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"[red]Failed to load existing output file: {ex.Message}[/]");
|
||||
}
|
||||
}
|
||||
|
||||
finder.FileError += (sender, e) =>
|
||||
{
|
||||
if (e.Exception is UnauthorizedAccessException)
|
||||
@ -168,6 +193,7 @@ namespace RedundancyFinderCLI
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void WriteLine(string v)
|
||||
{
|
||||
string now = Markup.Escape($"[{DateTime.Now.ToString("HH:mm:ss")}]");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user