From deb7f67e593d0cc0d1d49a06ba4dcbfe872a7c5d Mon Sep 17 00:00:00 2001 From: cake Date: Sat, 3 Jan 2026 23:12:18 +0100 Subject: [PATCH] Added another try on fetching download status --- LightlessSync/UI/DownloadUi.cs | 53 +++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/LightlessSync/UI/DownloadUi.cs b/LightlessSync/UI/DownloadUi.cs index 2d9cdc1..f898232 100644 --- a/LightlessSync/UI/DownloadUi.cs +++ b/LightlessSync/UI/DownloadUi.cs @@ -1,4 +1,5 @@ using Dalamud.Bindings.ImGui; +using Dalamud.Game.ClientState.Statuses; using Dalamud.Interface.Colors; using LightlessSync.LightlessConfiguration; using LightlessSync.LightlessConfiguration.Models; @@ -167,22 +168,30 @@ public class DownloadUi : WindowMediatorSubscriberBase List>> transfers; try { - transfers = _currentDownloads.ToList(); + transfers = _currentDownloads?.ToList() ?? []; } catch (ArgumentException) { return; } - foreach (var transfer in transfers) { var transferKey = transfer.Key; - - // Skip if no valid game object - if (transferKey.GetGameObject() == null) + if (transferKey is null) continue; + var statusDict = transfer.Value; + if (statusDict is null) + continue; + + var gameObj = transferKey.GetGameObject(); + if (gameObj is null) + { + _smoothed.Remove(transferKey); + continue; + } + var rawPos = _dalamudUtilService.WorldToScreen(transferKey.GetGameObject()); // If RawPos is zero, remove it from smoothed dictionary @@ -207,25 +216,29 @@ public class DownloadUi : WindowMediatorSubscriberBase var dlProg = 0; var dlDecomp = 0; - foreach (var entry in transfer.Value) + try { - var fileStatus = entry.Value; - switch (fileStatus.DownloadStatus) + foreach (var entry in statusDict) { - case DownloadStatus.WaitingForSlot: - dlSlot++; - break; - case DownloadStatus.WaitingForQueue: - dlQueue++; - break; - case DownloadStatus.Downloading: - dlProg++; - break; - case DownloadStatus.Decompressing: - dlDecomp++; - break; + var fileStatus = entry.Value; + if (fileStatus is null) continue; + + totalBytes += fileStatus.TotalBytes; + transferredBytes += fileStatus.TransferredBytes; + + switch (fileStatus.DownloadStatus) + { + case DownloadStatus.WaitingForSlot: dlSlot++; break; + case DownloadStatus.WaitingForQueue: dlQueue++; break; + case DownloadStatus.Downloading: dlProg++; break; + case DownloadStatus.Decompressing: dlDecomp++; break; + } } } + catch (InvalidOperationException) + { + continue; + } string statusText; if (dlProg > 0)