Crunchy-Downloader/CRD/Utils/QueueManagement/DownloadItemModelCollection.cs
Elwador 245cf787ea - Added setting to **disable partial history tracking**
- Changed **playback error reason parsing and display**
- Changed **queue refreshing and saving** to improve performance
- Fixed **Fast History Refresh** not working correctly
- Fixed **calendar not loading**
- Fixed **partial history tracking** being overwritten on each download
2026-06-10 22:01:01 +02:00

52 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using CRD.Utils.Structs;
using CRD.ViewModels;
namespace CRD.Utils.QueueManagement;
public sealed class DownloadItemModelCollection{
private readonly ObservableCollection<DownloadItemModel> items = new();
private readonly Dictionary<CrunchyEpMeta, DownloadItemModel> models = new();
public ObservableCollection<DownloadItemModel> Items => items;
public DownloadItemModel? Find(CrunchyEpMeta item){
return models.TryGetValue(item, out var model)
? model
: null;
}
public void Remove(CrunchyEpMeta item){
if (models.Remove(item, out var model)){
items.Remove(model);
} else{
Console.Error.WriteLine("Failed to remove episode from list");
}
}
public void Clear(){
models.Clear();
items.Clear();
}
public void AddOrRefresh(CrunchyEpMeta queueItem){
if (models.TryGetValue(queueItem, out var existingModel)){
existingModel.Refresh();
return;
}
var newModel = new DownloadItemModel(queueItem);
models.Add(queueItem, newModel);
items.Add(newModel);
_ = newModel.LoadImage();
}
public void SyncFromQueue(IEnumerable<CrunchyEpMeta> queueItems){
foreach (var queueItem in queueItems){
AddOrRefresh(queueItem);
}
}
}