Refactor and optimize audiobook download and decrypt process

- Add more null safety
- Fix possible FilePathCache race condition
- Add MoveFilesToBooksDir progress reporting
- All metadata is now downloaded in parallel with other post-success tasks.
- Improve download resuming and file cleanup reliability
- The downloader creates temp files with a UUID filename and does not insert them into the FilePathCache. Created files only receive their final file names when they are moved into the Books folder. This is to prepare for a future plan re naming templates
This commit is contained in:
Michael Bucari-Tovo
2025-07-22 19:44:56 -06:00
parent 1f473039e1
commit 2f082a9656
12 changed files with 562 additions and 481 deletions

View File

@@ -46,7 +46,9 @@ namespace LibationFileManager
public static List<(FileType fileType, LongPath path)> GetFiles(string id)
{
var matchingFiles = Cache.GetIdEntries(id);
List<CacheEntry> matchingFiles;
lock(locker)
matchingFiles = Cache.GetIdEntries(id);
bool cacheChanged = false;
@@ -68,7 +70,9 @@ namespace LibationFileManager
public static LongPath? GetFirstPath(string id, FileType type)
{
var matchingFiles = Cache.GetIdEntries(id).Where(e => e.FileType == type).ToList();
List<CacheEntry> matchingFiles;
lock (locker)
matchingFiles = Cache.GetIdEntries(id).Where(e => e.FileType == type).ToList();
bool cacheChanged = false;
try
@@ -96,7 +100,10 @@ namespace LibationFileManager
private static bool Remove(CacheEntry entry)
{
if (Cache.Remove(entry.Id, entry))
bool removed;
lock (locker)
removed = Cache.Remove(entry.Id, entry);
if (removed)
{
Removed?.Invoke(null, entry);
return true;
@@ -112,7 +119,8 @@ namespace LibationFileManager
public static void Insert(CacheEntry entry)
{
Cache.Add(entry.Id, entry);
lock(locker)
Cache.Add(entry.Id, entry);
Inserted?.Invoke(null, entry);
save();
}