From 864c76d2582b9b5ac8daf0510da16841c3b8826d Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Sun, 8 Oct 2023 11:57:38 +0200 Subject: [PATCH] fix transfer progress, add glamourer unlock by name, fix dtrbar, add to xlplugins main --- MareSynchronos/Interop/IpcManager.cs | 26 ++++++++++++------- .../PlayerData/Handlers/PairHandler.cs | 12 ++++----- MareSynchronos/Plugin.cs | 1 - MareSynchronos/Services/UiService.cs | 9 +++++++ MareSynchronos/UI/DtrEntry.cs | 10 +++---- .../WebAPI/Files/FileDownloadManager.cs | 5 ++-- .../WebAPI/Files/FileTransferOrchestrator.cs | 12 +++++---- .../WebAPI/SignalR/ApiController.cs | 3 ++- 8 files changed, 48 insertions(+), 30 deletions(-) diff --git a/MareSynchronos/Interop/IpcManager.cs b/MareSynchronos/Interop/IpcManager.cs index 5d534dc..e8aa965 100644 --- a/MareSynchronos/Interop/IpcManager.cs +++ b/MareSynchronos/Interop/IpcManager.cs @@ -30,7 +30,7 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase private readonly ICallGateSubscriber? _glamourerGetAllCustomization; private readonly ICallGateSubscriber _glamourerRevert; private readonly ICallGateSubscriber _glamourerRevertByName; - private readonly ICallGateSubscriber _glamourerUnlock; + private readonly ICallGateSubscriber _glamourerUnlock; private readonly ICallGateSubscriber<(int, int)> _heelsGetApiVersion; private readonly ICallGateSubscriber _heelsGetOffset; private readonly ICallGateSubscriber _heelsOffsetUpdate; @@ -113,7 +113,7 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase _glamourerApplyAll = pi.GetIpcSubscriber("Glamourer.ApplyAllToCharacterLock"); _glamourerRevert = pi.GetIpcSubscriber("Glamourer.RevertCharacterLock"); _glamourerRevertByName = pi.GetIpcSubscriber("Glamourer.RevertLock"); - _glamourerUnlock = pi.GetIpcSubscriber("Glamourer.Unlock"); + _glamourerUnlock = pi.GetIpcSubscriber("Glamourer.UnlockName"); _heelsGetApiVersion = pi.GetIpcSubscriber<(int, int)>("SimpleHeels.ApiVersion"); _heelsGetOffset = pi.GetIpcSubscriber("SimpleHeels.GetLocalPlayer"); @@ -248,8 +248,6 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase { logger.LogDebug("[{appid}] Calling on IPC: GlamourerApplyAll", applicationId); _glamourerApplyAll!.InvokeAction(customization, chara, LockCode); - logger.LogDebug("[{appid}] Calling on IPC: PenumbraRedraw", applicationId); - _penumbraRedrawObject.Invoke(chara, RedrawType.Redraw); } catch (Exception) { @@ -272,11 +270,19 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase await _redrawSemaphore.WaitAsync(token).ConfigureAwait(false); await PenumbraRedrawInternalAsync(logger, handler, applicationId, (chara) => { - logger.LogDebug("[{appid}] Calling On IPC: GlamourerRevert", applicationId); - _glamourerRevert.InvokeAction(chara, LockCode); - logger.LogDebug("[{appid}] Calling On IPC: PenumbraRedraw", applicationId); - _penumbraRedrawObject.Invoke(chara, RedrawType.AfterGPose); - _glamourerUnlock.InvokeFunc(chara, LockCode); + try + { + logger.LogDebug("[{appid}] Calling On IPC: GlamourerUnlockName", applicationId); + _glamourerUnlock.InvokeFunc(handler.Name, LockCode); + logger.LogDebug("[{appid}] Calling On IPC: GlamourerRevert", applicationId); + _glamourerRevert.InvokeAction(chara, LockCode); + logger.LogDebug("[{appid}] Calling On IPC: PenumbraRedraw", applicationId); + _penumbraRedrawObject.Invoke(chara, RedrawType.AfterGPose); + } + catch (Exception ex) + { + logger.LogWarning(ex, "[{appid}] Error during GlamourerRevert", applicationId); + } }).ConfigureAwait(false); } @@ -293,6 +299,8 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase { logger.LogDebug("[{appid}] Calling On IPC: GlamourerRevertByName", applicationId); _glamourerRevertByName.InvokeAction(name, LockCode); + logger.LogDebug("[{appid}] Calling On IPC: GlamourerUnlockName", applicationId); + _glamourerUnlock.InvokeAction(name, LockCode); } catch (Exception ex) { diff --git a/MareSynchronos/PlayerData/Handlers/PairHandler.cs b/MareSynchronos/PlayerData/Handlers/PairHandler.cs index 947cf93..093d738 100644 --- a/MareSynchronos/PlayerData/Handlers/PairHandler.cs +++ b/MareSynchronos/PlayerData/Handlers/PairHandler.cs @@ -218,7 +218,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase Logger.LogDebug("[{applicationId}] Applying Customization Data for {handler}", applicationId, handler); await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, handler, applicationId, 30000, token).ConfigureAwait(false); token.ThrowIfCancellationRequested(); - foreach (var change in changes.Value) + foreach (var change in changes.Value.OrderBy(p => (int)p)) { Logger.LogDebug("[{applicationId}] Processing {change} for {handler}", applicationId, change, handler); switch (change) @@ -249,22 +249,20 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase case PlayerChanges.Glamourer: if (charaData.GlamourerData.TryGetValue(changes.Key, out var glamourerData)) { - alreadyRedrawn = true; await _ipcManager.GlamourerApplyAllAsync(Logger, handler, glamourerData, applicationId, token).ConfigureAwait(false); } break; case PlayerChanges.ModFiles: case PlayerChanges.ModManip: - if (!alreadyRedrawn) - { - alreadyRedrawn = true; - await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false); - } break; } token.ThrowIfCancellationRequested(); } + + if (changes.Value.Contains(PlayerChanges.ModFiles) || changes.Value.Contains(PlayerChanges.ModManip) || changes.Value.Contains(PlayerChanges.Glamourer)) + await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false); + } finally { diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index be5d3b0..797ff15 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -49,7 +49,6 @@ public sealed class Plugin : IDalamudPlugin // add mare related singletons collection.AddSingleton(); collection.AddSingleton(); - collection.AddSingleton(); collection.AddSingleton(); collection.AddSingleton(); collection.AddSingleton(); diff --git a/MareSynchronos/Services/UiService.cs b/MareSynchronos/Services/UiService.cs index 13eb7af..2e21acd 100644 --- a/MareSynchronos/Services/UiService.cs +++ b/MareSynchronos/Services/UiService.cs @@ -33,6 +33,7 @@ public sealed class UiService : DisposableMediatorSubscriberBase _dalamudPluginInterface.UiBuilder.DisableGposeUiHide = true; _dalamudPluginInterface.UiBuilder.Draw += Draw; _dalamudPluginInterface.UiBuilder.OpenConfigUi += ToggleUi; + _dalamudPluginInterface.UiBuilder.OpenMainUi += ToggleMainUi; foreach (var window in windows) { @@ -59,6 +60,14 @@ public sealed class UiService : DisposableMediatorSubscriberBase } public void ToggleUi() + { + if (_mareConfigService.Current.HasValidSetup()) + Mediator.Publish(new UiToggleMessage(typeof(SettingsUi))); + else + Mediator.Publish(new UiToggleMessage(typeof(IntroUi))); + } + + public void ToggleMainUi() { if (_mareConfigService.Current.HasValidSetup()) Mediator.Publish(new UiToggleMessage(typeof(CompactUi))); diff --git a/MareSynchronos/UI/DtrEntry.cs b/MareSynchronos/UI/DtrEntry.cs index 7a219e1..1ee93a1 100644 --- a/MareSynchronos/UI/DtrEntry.cs +++ b/MareSynchronos/UI/DtrEntry.cs @@ -18,7 +18,7 @@ public sealed class DtrEntry : IDisposable, IHostedService private readonly IDtrBar _dtrBar; private readonly ConfigurationServiceBase _configService; private readonly MareMediator _mareMediator; - private Lazy _entry; + private readonly Lazy _entry; private readonly PairManager _pairManager; private Task? _runTask; private string? _text; @@ -40,6 +40,7 @@ public sealed class DtrEntry : IDisposable, IHostedService { _logger.LogDebug("Disposing DtrEntry"); Clear(); + _entry.Value.Dispose(); } } @@ -68,6 +69,7 @@ public sealed class DtrEntry : IDisposable, IHostedService private DtrBarEntry CreateEntry() { + _logger.LogTrace("Creating new DtrBar entry"); var entry = _dtrBar.Get("Mare Synchronos"); entry.OnClick = () => _mareMediator.Publish(new UiToggleMessage(typeof(CompactUi))); @@ -77,13 +79,10 @@ public sealed class DtrEntry : IDisposable, IHostedService private void Clear() { if (!_entry.IsValueCreated) return; - _text = null; _logger.LogInformation("Clearing entry"); + _text = null; _entry.Value.Shown = false; - _entry.Value.Text = null; - _entry.Value.Dispose(); - _entry = new(CreateEntry); } private async Task RunAsync() @@ -138,6 +137,7 @@ public sealed class DtrEntry : IDisposable, IHostedService text = "\uE044 \uE04C"; tooltip = "Mare Synchronos: Not Connected"; } + if (!string.Equals(text, _text, StringComparison.Ordinal)) { _text = text; diff --git a/MareSynchronos/WebAPI/Files/FileDownloadManager.cs b/MareSynchronos/WebAPI/Files/FileDownloadManager.cs index 8daa26b..933c04b 100644 --- a/MareSynchronos/WebAPI/Files/FileDownloadManager.cs +++ b/MareSynchronos/WebAPI/Files/FileDownloadManager.cs @@ -121,7 +121,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase Logger.LogDebug("Downloading {requestUrl} for request {id}", requestUrl, requestId); try { - response = await _orchestrator.SendRequestAsync(HttpMethod.Get, requestUrl, ct).ConfigureAwait(false); + response = await _orchestrator.SendRequestAsync(HttpMethod.Get, requestUrl, ct, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); response.EnsureSuccessStatusCode(); } catch (HttpRequestException ex) @@ -142,7 +142,8 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase var buffer = new byte[bufferSize]; var bytesRead = 0; - while ((bytesRead = await (await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false)).ReadAsync(buffer, ct).ConfigureAwait(false)) > 0) + var stream = await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false); + while ((bytesRead = await stream.ReadAsync(buffer, ct).ConfigureAwait(false)) > 0) { ct.ThrowIfCancellationRequested(); diff --git a/MareSynchronos/WebAPI/Files/FileTransferOrchestrator.cs b/MareSynchronos/WebAPI/Files/FileTransferOrchestrator.cs index 5981623..bab2706 100644 --- a/MareSynchronos/WebAPI/Files/FileTransferOrchestrator.cs +++ b/MareSynchronos/WebAPI/Files/FileTransferOrchestrator.cs @@ -71,10 +71,11 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase _downloadReady.Remove(guid, out _); } - public async Task SendRequestAsync(HttpMethod method, Uri uri, CancellationToken? ct = null) + public async Task SendRequestAsync(HttpMethod method, Uri uri, + CancellationToken? ct = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) { using var requestMessage = new HttpRequestMessage(method, uri); - return await SendRequestInternalAsync(requestMessage, ct).ConfigureAwait(false); + return await SendRequestInternalAsync(requestMessage, ct, httpCompletionOption).ConfigureAwait(false); } public async Task SendRequestAsync(HttpMethod method, Uri uri, T content, CancellationToken ct) where T : class @@ -108,7 +109,8 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase await _downloadSemaphore.WaitAsync(token).ConfigureAwait(false); } - private async Task SendRequestInternalAsync(HttpRequestMessage requestMessage, CancellationToken? ct = null) + private async Task SendRequestInternalAsync(HttpRequestMessage requestMessage, + CancellationToken? ct = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead) { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _serverManager.GetToken()); @@ -125,8 +127,8 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase try { if (ct != null) - return await _httpClient.SendAsync(requestMessage, ct.Value).ConfigureAwait(false); - return await _httpClient.SendAsync(requestMessage).ConfigureAwait(false); + return await _httpClient.SendAsync(requestMessage, httpCompletionOption, ct.Value).ConfigureAwait(false); + return await _httpClient.SendAsync(requestMessage, httpCompletionOption).ConfigureAwait(false); } catch (Exception ex) { diff --git a/MareSynchronos/WebAPI/SignalR/ApiController.cs b/MareSynchronos/WebAPI/SignalR/ApiController.cs index 6ae180d..0f1b80d 100644 --- a/MareSynchronos/WebAPI/SignalR/ApiController.cs +++ b/MareSynchronos/WebAPI/SignalR/ApiController.cs @@ -409,12 +409,13 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM _initialized = false; _healthCheckTokenSource?.Cancel(); Logger.LogInformation("Stopping existing connection"); - await _hubFactory.DisposeHubAsync().ConfigureAwait(false); Mediator.Publish(new DisconnectedMessage()); _mareHub = null; _connectionDto = null; } + await _hubFactory.DisposeHubAsync().ConfigureAwait(false); + ServerState = state; } } \ No newline at end of file