Added Multi Threading for downloads and Auto Scroll to view current downloads

This commit is contained in:
SirBiggin
2026-06-16 10:23:32 -06:00
committed by Allamagoosa
parent bb0ece9ee4
commit d93d325913
6 changed files with 303 additions and 136 deletions

View File

@@ -38,23 +38,21 @@ internal partial class ProcessQueueControl : UserControl
ViewModel.PropertyChanged += ProcessQueue_PropertyChanged;
ViewModel.LogEntries.CollectionChanged += LogEntries_CollectionChanged;
ViewModel.ProcessStart += Book_ProcessStart;
autoScrollChk.CheckedChanged += (s, e) => ViewModel.AutoScrollQueue = autoScrollChk.Checked;
multiThreadChk.CheckedChanged += (s, e) => ViewModel.MultiThreadEnabled = multiThreadChk.Checked;
ProcessQueue_PropertyChanged(this, new PropertyChangedEventArgs(null));
}
private void Book_ProcessStart(object? sender, ProcessBookViewModel e)
{
if (!ViewModel.AutoScrollQueue) return;
Invoke(() =>
{
if (ViewModel.Queue?.IndexOf(e) is int newtBookIndex && newtBookIndex > 0 && itemIsVisible(newtBookIndex - 1))
{
// Only scroll the new item into view if the previous item is visible.
// This allows users to scroll through the queue without being interrupted.
virtualFlowControl2.ScrollIntoView(newtBookIndex);
}
// Pin the first active download to the top so all parallel in-progress items are visible.
int firstActiveIndex = ViewModel.Queue.Completed.Count;
if (firstActiveIndex < ViewModel.Queue.Count)
virtualFlowControl2.ScrollToTop(firstActiveIndex);
});
bool itemIsVisible(int newtBookIndex)
=> virtualFlowControl2.FirstRealizedIndex <= newtBookIndex && virtualFlowControl2.LastRealizedIndex >= newtBookIndex;
}
private void LogEntries_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
@@ -131,6 +129,10 @@ internal partial class ProcessQueueControl : UserControl
numericUpDown1.Increment = ViewModel.SpeedLimitIncrement;
numericUpDown1.DecimalPlaces = ViewModel.SpeedLimit >= 10 ? 0 : ViewModel.SpeedLimit >= 1 ? 1 : 2;
}
if (e.PropertyName is null or nameof(ViewModel.AutoScrollQueue))
autoScrollChk.Checked = ViewModel.AutoScrollQueue;
if (e.PropertyName is null or nameof(ViewModel.MultiThreadEnabled))
multiThreadChk.Checked = ViewModel.MultiThreadEnabled;
}
/// <summary>