From 3e02f223b9583a0df290925bde1b0148c9eff7d0 Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 24 Jan 2024 17:54:49 -0500 Subject: [PATCH] Add ProgressStateChanging event --- .../Services/TrackedDownloadService.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/StabilityMatrix.Core/Services/TrackedDownloadService.cs b/StabilityMatrix.Core/Services/TrackedDownloadService.cs index 9a985a21..0006f922 100644 --- a/StabilityMatrix.Core/Services/TrackedDownloadService.cs +++ b/StabilityMatrix.Core/Services/TrackedDownloadService.cs @@ -15,10 +15,8 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable private readonly ISettingsManager settingsManager; private readonly IModelIndexService modelIndexService; - private readonly ConcurrentDictionary< - Guid, - (TrackedDownload Download, FileStream Stream) - > downloads = new(); + private readonly ConcurrentDictionary downloads = + new(); public IEnumerable Downloads => downloads.Values.Select(x => x.Download); @@ -51,6 +49,7 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable private void OnDownloadAdded(TrackedDownload download) { + logger.LogInformation("Download added: ({Download}, {State})", download.Id, download.ProgressState); DownloadAdded?.Invoke(this, download); } @@ -67,11 +66,7 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable var downloadsDir = new DirectoryPath(settingsManager.DownloadsDirectory); downloadsDir.Create(); var jsonFile = downloadsDir.JoinFile($"{download.Id}.json"); - var jsonFileStream = jsonFile.Info.Open( - FileMode.CreateNew, - FileAccess.ReadWrite, - FileShare.Read - ); + var jsonFileStream = jsonFile.Info.Open(FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read); // Serialize to json var json = JsonSerializer.Serialize(download); @@ -81,11 +76,10 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable // Add to dictionary downloads.TryAdd(download.Id, (download, jsonFileStream)); + OnDownloadAdded(download); + // Connect to state changed event to update json file AttachHandlers(download); - - logger.LogDebug("Added download {Download}", download.FileName); - OnDownloadAdded(download); } ///