Merged Cake and Abel branched into 2.0.3 (#131)
Co-authored-by: azyges <aaaaaa@aaa.aaa> Co-authored-by: cake <admin@cakeandbanana.nl> Co-authored-by: defnotken <itsdefnotken@gmail.com> Reviewed-on: #131
This commit was merged in pull request #131.
This commit is contained in:
@@ -17,7 +17,7 @@ namespace LightlessSync.UI;
|
||||
public class DownloadUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly ConcurrentDictionary<GameObjectHandler, Dictionary<string, FileDownloadStatus>> _currentDownloads = new();
|
||||
private readonly ConcurrentDictionary<GameObjectHandler, IReadOnlyDictionary<string, FileDownloadStatus>> _currentDownloads = new();
|
||||
private readonly DalamudUtilService _dalamudUtilService;
|
||||
private readonly FileUploadManager _fileTransferManager;
|
||||
private readonly UiSharedService _uiShared;
|
||||
@@ -25,6 +25,8 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
private readonly ConcurrentDictionary<GameObjectHandler, bool> _uploadingPlayers = new();
|
||||
private readonly Dictionary<GameObjectHandler, Vector2> _smoothed = [];
|
||||
private readonly Dictionary<GameObjectHandler, DownloadSpeedTracker> _downloadSpeeds = [];
|
||||
private readonly Dictionary<GameObjectHandler, (int TotalFiles, long TotalBytes)> _downloadInitialTotals = [];
|
||||
|
||||
|
||||
private byte _transferBoxTransparency = 100;
|
||||
private bool _notificationDismissed = true;
|
||||
@@ -66,6 +68,10 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
Mediator.Subscribe<DownloadStartedMessage>(this, (msg) =>
|
||||
{
|
||||
_currentDownloads[msg.DownloadId] = msg.DownloadStatus;
|
||||
// Capture initial totals when download starts
|
||||
var totalFiles = msg.DownloadStatus.Values.Sum(s => s.TotalFiles);
|
||||
var totalBytes = msg.DownloadStatus.Values.Sum(s => s.TotalBytes);
|
||||
_downloadInitialTotals[msg.DownloadId] = (totalFiles, totalBytes);
|
||||
_notificationDismissed = false;
|
||||
});
|
||||
Mediator.Subscribe<DownloadFinishedMessage>(this, (msg) =>
|
||||
@@ -164,10 +170,10 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
const float rounding = 6f;
|
||||
var shadowOffset = new Vector2(2, 2);
|
||||
|
||||
List<KeyValuePair<GameObjectHandler, Dictionary<string, FileDownloadStatus>>> transfers;
|
||||
List<KeyValuePair<GameObjectHandler, IReadOnlyDictionary<string, FileDownloadStatus>>> transfers;
|
||||
try
|
||||
{
|
||||
transfers = _currentDownloads.ToList();
|
||||
transfers = [.. _currentDownloads];
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
@@ -206,12 +212,16 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var dlQueue = 0;
|
||||
var dlProg = 0;
|
||||
var dlDecomp = 0;
|
||||
var dlComplete = 0;
|
||||
|
||||
foreach (var entry in transfer.Value)
|
||||
{
|
||||
var fileStatus = entry.Value;
|
||||
switch (fileStatus.DownloadStatus)
|
||||
{
|
||||
case DownloadStatus.Initializing:
|
||||
dlQueue++;
|
||||
break;
|
||||
case DownloadStatus.WaitingForSlot:
|
||||
dlSlot++;
|
||||
break;
|
||||
@@ -224,15 +234,20 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
case DownloadStatus.Decompressing:
|
||||
dlDecomp++;
|
||||
break;
|
||||
case DownloadStatus.Completed:
|
||||
dlComplete++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var isAllComplete = dlComplete > 0 && dlProg == 0 && dlDecomp == 0 && dlQueue == 0 && dlSlot == 0;
|
||||
|
||||
string statusText;
|
||||
if (dlProg > 0)
|
||||
{
|
||||
statusText = "Downloading";
|
||||
}
|
||||
else if (dlDecomp > 0 || (totalBytes > 0 && transferredBytes >= totalBytes))
|
||||
else if (dlDecomp > 0)
|
||||
{
|
||||
statusText = "Decompressing";
|
||||
}
|
||||
@@ -244,6 +259,10 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
statusText = "Waiting for slot";
|
||||
}
|
||||
else if (isAllComplete)
|
||||
{
|
||||
statusText = "Completed";
|
||||
}
|
||||
else
|
||||
{
|
||||
statusText = "Waiting";
|
||||
@@ -309,7 +328,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
fillPercent = transferredBytes / (double)totalBytes;
|
||||
showFill = true;
|
||||
}
|
||||
else if (dlDecomp > 0 || transferredBytes >= totalBytes)
|
||||
else if (dlDecomp > 0 || dlComplete > 0 || transferredBytes >= totalBytes)
|
||||
{
|
||||
fillPercent = 1.0;
|
||||
showFill = true;
|
||||
@@ -341,10 +360,14 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
downloadText =
|
||||
$"{statusText} {UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
|
||||
}
|
||||
else if ((dlDecomp > 0 || transferredBytes >= totalBytes) && hasValidSize)
|
||||
else if (dlDecomp > 0)
|
||||
{
|
||||
downloadText = "Decompressing";
|
||||
}
|
||||
else if (isAllComplete)
|
||||
{
|
||||
downloadText = "Completed";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Waiting states
|
||||
@@ -417,6 +440,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var totalDlQueue = 0;
|
||||
var totalDlProg = 0;
|
||||
var totalDlDecomp = 0;
|
||||
var totalDlComplete = 0;
|
||||
|
||||
var perPlayer = new List<(
|
||||
string Name,
|
||||
@@ -428,16 +452,21 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
int DlSlot,
|
||||
int DlQueue,
|
||||
int DlProg,
|
||||
int DlDecomp)>();
|
||||
int DlDecomp,
|
||||
int DlComplete)>();
|
||||
|
||||
foreach (var transfer in _currentDownloads)
|
||||
{
|
||||
var handler = transfer.Key;
|
||||
var statuses = transfer.Value.Values;
|
||||
|
||||
var playerTotalFiles = statuses.Sum(s => s.TotalFiles);
|
||||
var playerTransferredFiles = statuses.Sum(s => s.TransferredFiles);
|
||||
var playerTotalBytes = statuses.Sum(s => s.TotalBytes);
|
||||
var (playerTotalFiles, playerTotalBytes) = _downloadInitialTotals.TryGetValue(handler, out var totals)
|
||||
? totals
|
||||
: (statuses.Sum(s => s.TotalFiles), statuses.Sum(s => s.TotalBytes));
|
||||
|
||||
var playerTransferredFiles = statuses.Count(s =>
|
||||
s.DownloadStatus == DownloadStatus.Decompressing ||
|
||||
s.TransferredBytes >= s.TotalBytes);
|
||||
var playerTransferredBytes = statuses.Sum(s => s.TransferredBytes);
|
||||
|
||||
totalFiles += playerTotalFiles;
|
||||
@@ -450,12 +479,17 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var playerDlQueue = 0;
|
||||
var playerDlProg = 0;
|
||||
var playerDlDecomp = 0;
|
||||
var playerDlComplete = 0;
|
||||
|
||||
foreach (var entry in transfer.Value)
|
||||
{
|
||||
var fileStatus = entry.Value;
|
||||
switch (fileStatus.DownloadStatus)
|
||||
{
|
||||
case DownloadStatus.Initializing:
|
||||
playerDlQueue++;
|
||||
totalDlQueue++;
|
||||
break;
|
||||
case DownloadStatus.WaitingForSlot:
|
||||
playerDlSlot++;
|
||||
totalDlSlot++;
|
||||
@@ -472,6 +506,10 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
playerDlDecomp++;
|
||||
totalDlDecomp++;
|
||||
break;
|
||||
case DownloadStatus.Completed:
|
||||
playerDlComplete++;
|
||||
totalDlComplete++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +535,8 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
playerDlSlot,
|
||||
playerDlQueue,
|
||||
playerDlProg,
|
||||
playerDlDecomp
|
||||
playerDlDecomp,
|
||||
playerDlComplete
|
||||
));
|
||||
}
|
||||
|
||||
@@ -521,7 +560,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
|
||||
// Overall texts
|
||||
var headerText =
|
||||
$"Downloading {transferredFiles}/{totalFiles} files [W:{totalDlSlot}/Q:{totalDlQueue}/P:{totalDlProg}/D:{totalDlDecomp}]";
|
||||
$"Downloading {transferredFiles}/{totalFiles} files [W:{totalDlSlot}/Q:{totalDlQueue}/P:{totalDlProg}/D:{totalDlDecomp}/C:{totalDlComplete}]";
|
||||
|
||||
var bytesText =
|
||||
$"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
|
||||
@@ -544,7 +583,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
foreach (var p in perPlayer)
|
||||
{
|
||||
var line =
|
||||
$"{p.Name} [W:{p.DlSlot}/Q:{p.DlQueue}/P:{p.DlProg}/D:{p.DlDecomp}] {p.TransferredFiles}/{p.TotalFiles}";
|
||||
$"{p.Name} [W:{p.DlSlot}/Q:{p.DlQueue}/P:{p.DlProg}/D:{p.DlDecomp}/C:{p.DlComplete}] {p.TransferredFiles}/{p.TotalFiles}";
|
||||
|
||||
var lineSize = ImGui.CalcTextSize(line);
|
||||
if (lineSize.X > contentWidth)
|
||||
@@ -662,7 +701,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
&& p.TransferredBytes > 0;
|
||||
|
||||
var labelLine =
|
||||
$"{p.Name} [W:{p.DlSlot}/Q:{p.DlQueue}/P:{p.DlProg}/D:{p.DlDecomp}] {p.TransferredFiles}/{p.TotalFiles}";
|
||||
$"{p.Name} [W:{p.DlSlot}/Q:{p.DlQueue}/P:{p.DlProg}/D:{p.DlDecomp}/C:{p.DlComplete}] {p.TransferredFiles}/{p.TotalFiles}";
|
||||
|
||||
if (!showBar)
|
||||
{
|
||||
@@ -721,13 +760,18 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
// Text inside bar: downloading vs decompressing
|
||||
string barText;
|
||||
|
||||
var isDecompressing = p.DlDecomp > 0 && p.TransferredBytes >= p.TotalBytes && p.TotalBytes > 0;
|
||||
var isDecompressing = p.DlDecomp > 0;
|
||||
var isAllComplete = p.DlComplete > 0 && p.DlProg == 0 && p.DlDecomp == 0 && p.DlQueue == 0 && p.DlSlot == 0;
|
||||
|
||||
if (isDecompressing)
|
||||
{
|
||||
// Keep bar full, static text showing decompressing
|
||||
barText = "Decompressing...";
|
||||
}
|
||||
else if (isAllComplete)
|
||||
{
|
||||
barText = "Completed";
|
||||
}
|
||||
else
|
||||
{
|
||||
var bytesInside =
|
||||
@@ -808,6 +852,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var dlQueue = 0;
|
||||
var dlProg = 0;
|
||||
var dlDecomp = 0;
|
||||
var dlComplete = 0;
|
||||
long totalBytes = 0;
|
||||
long transferredBytes = 0;
|
||||
|
||||
@@ -817,22 +862,29 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var fileStatus = entry.Value;
|
||||
switch (fileStatus.DownloadStatus)
|
||||
{
|
||||
case DownloadStatus.Initializing: dlQueue++; break;
|
||||
case DownloadStatus.WaitingForSlot: dlSlot++; break;
|
||||
case DownloadStatus.WaitingForQueue: dlQueue++; break;
|
||||
case DownloadStatus.Downloading: dlProg++; break;
|
||||
case DownloadStatus.Decompressing: dlDecomp++; break;
|
||||
case DownloadStatus.Completed: dlComplete++; break;
|
||||
}
|
||||
totalBytes += fileStatus.TotalBytes;
|
||||
transferredBytes += fileStatus.TransferredBytes;
|
||||
}
|
||||
|
||||
var progress = totalBytes > 0 ? (float)transferredBytes / totalBytes : 0f;
|
||||
if (dlComplete > 0 && dlProg == 0 && dlDecomp == 0 && dlQueue == 0 && dlSlot == 0)
|
||||
{
|
||||
progress = 1f;
|
||||
}
|
||||
|
||||
string status;
|
||||
if (dlDecomp > 0) status = "decompressing";
|
||||
else if (dlProg > 0) status = "downloading";
|
||||
else if (dlQueue > 0) status = "queued";
|
||||
else if (dlSlot > 0) status = "waiting";
|
||||
else if (dlComplete > 0) status = "completed";
|
||||
else status = "completed";
|
||||
|
||||
downloadStatus.Add((item.Key.Name, progress, status));
|
||||
|
||||
Reference in New Issue
Block a user