mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-07 23:40:52 +02:00
Add directory watcher functionality
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using HyperbolicDownloaderApi.Managment;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace HyperbolicDownloaderApi.FileProcessing;
|
||||
@@ -31,10 +32,16 @@ public class FilesManager
|
||||
if (Contains(hash))
|
||||
{
|
||||
fileInfo = null;
|
||||
Debug.WriteLine(filePath + "-.-" + hash);
|
||||
errorMessage = "File already tracked!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (files.Exists(f => f.FilePath == fullPath))
|
||||
{
|
||||
_ = files.RemoveAll(f => f.FilePath == fullPath);
|
||||
}
|
||||
|
||||
fileInfo = new PrivateHyperFileInfo(hash, fullPath);
|
||||
|
||||
files.Add(fileInfo);
|
||||
@@ -91,6 +98,20 @@ public class FilesManager
|
||||
return files.ToList();
|
||||
}
|
||||
|
||||
internal void RemoveFilesThatDontExist()
|
||||
{
|
||||
List<PrivateHyperFileInfo> filesToRemove = files
|
||||
.Where(f => !File.Exists(f.FilePath))
|
||||
.ToList();
|
||||
|
||||
foreach (PrivateHyperFileInfo fileToRemove in filesToRemove)
|
||||
{
|
||||
_ = files.Remove(fileToRemove);
|
||||
}
|
||||
|
||||
SaveFiles();
|
||||
}
|
||||
|
||||
private void SaveFiles()
|
||||
{
|
||||
File.WriteAllText(ApiConfiguration.FilesInfoPath, JsonSerializer.Serialize(files));
|
||||
|
||||
Reference in New Issue
Block a user