mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 19:47:21 +01:00
potential fix for downloads hanging at 0 bytes
This commit is contained in:
parent
9307aaecac
commit
b65ae8fca3
3 changed files with 25 additions and 18 deletions
|
|
@ -112,6 +112,8 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
|||
return;
|
||||
}
|
||||
|
||||
_forceApplyMods |= forceApplyCustomization;
|
||||
|
||||
var charaDataToUpdate = characterData.CheckUpdatedData(applicationBase, _cachedData?.DeepClone() ?? new(), Logger, this, forceApplyCustomization, _forceApplyMods);
|
||||
|
||||
if (_charaHandler != null && _forceApplyMods)
|
||||
|
|
@ -451,8 +453,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
|||
});
|
||||
|
||||
_ipcManager.PenumbraAssignTemporaryCollectionAsync(Logger, _penumbraCollection, _charaHandler.GetGameObject()!.ObjectIndex).GetAwaiter().GetResult();
|
||||
|
||||
_downloadManager.Initialize();
|
||||
}
|
||||
|
||||
private void IpcManagerOnPenumbraRedrawEvent(PenumbraRedrawMessage msg)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using MareSynchronos.PlayerData.Handlers;
|
|||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.WebAPI.Files.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
|
|
@ -16,7 +15,6 @@ namespace MareSynchronos.WebAPI.Files;
|
|||
|
||||
public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
{
|
||||
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
|
||||
private readonly Dictionary<string, FileDownloadStatus> _downloadStatus;
|
||||
private readonly FileCacheManager _fileDbManager;
|
||||
private readonly FileTransferOrchestrator _orchestrator;
|
||||
|
|
@ -60,17 +58,6 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
|||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Mediator.Subscribe<DownloadReadyMessage>(this, (msg) =>
|
||||
{
|
||||
if (_downloadReady.ContainsKey(msg.RequestId))
|
||||
{
|
||||
_downloadReady[msg.RequestId] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
CancelDownload();
|
||||
|
|
@ -232,7 +219,6 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
|||
Logger.LogDebug("Sent request for {n} files on server {uri} with result {result}", fileGroup.Count(), fileGroup.First().DownloadUri, requestIdResponse.Content.ReadAsStringAsync().Result);
|
||||
|
||||
Guid requestId = Guid.Parse(requestIdResponse.Content.ReadAsStringAsync().Result.Trim('"'));
|
||||
_downloadReady[requestId] = false;
|
||||
|
||||
Logger.LogDebug("GUID {requestId} for {n} files on server {uri}", requestId, fileGroup.Count(), fileGroup.First().DownloadUri);
|
||||
|
||||
|
|
@ -367,7 +353,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
|||
localTimeoutCts.CancelAfter(TimeSpan.FromSeconds(5));
|
||||
CancellationTokenSource composite = CancellationTokenSource.CreateLinkedTokenSource(downloadCt, localTimeoutCts.Token);
|
||||
|
||||
while (_downloadReady.TryGetValue(requestId, out bool isReady) && !isReady)
|
||||
while (!_orchestrator.IsDownloadReady(requestId))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -420,7 +406,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
|||
// ignore whatever happens here
|
||||
}
|
||||
}
|
||||
_downloadReady.Remove(requestId, out _);
|
||||
_orchestrator.ClearDownloadRequest(requestId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ using MareSynchronos.Services.Mediator;
|
|||
using MareSynchronos.Services.ServerConfiguration;
|
||||
using MareSynchronos.WebAPI.Files.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection;
|
||||
|
|
@ -17,6 +18,7 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
|||
private readonly ServerConfigurationManager _serverManager;
|
||||
private int _availableDownloadSlots;
|
||||
private SemaphoreSlim _downloadSemaphore;
|
||||
private readonly ConcurrentDictionary<Guid, bool> _downloadReady = new();
|
||||
|
||||
public FileTransferOrchestrator(ILogger<FileTransferOrchestrator> logger, MareConfigService mareConfig, ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
|
||||
{
|
||||
|
|
@ -39,6 +41,10 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
|||
{
|
||||
FilesCdnUri = null;
|
||||
});
|
||||
Mediator.Subscribe<DownloadReadyMessage>(this, (msg) =>
|
||||
{
|
||||
_downloadReady[msg.RequestId] = true;
|
||||
});
|
||||
}
|
||||
|
||||
public Uri? FilesCdnUri { private set; get; }
|
||||
|
|
@ -50,6 +56,21 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
|
|||
_downloadSemaphore.Release();
|
||||
}
|
||||
|
||||
public bool IsDownloadReady(Guid guid)
|
||||
{
|
||||
if (_downloadReady.TryGetValue(guid, out bool isReady) && isReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ClearDownloadRequest(Guid guid)
|
||||
{
|
||||
_downloadReady.Remove(guid, out _);
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri, CancellationToken? ct = null)
|
||||
{
|
||||
using var requestMessage = new HttpRequestMessage(method, uri);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue