Partial roll-up to reduce code divergence

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
Loporrit
2025-02-15 23:07:46 +00:00
parent 324288652d
commit 7a8de7add6
41 changed files with 963 additions and 464 deletions

View File

@@ -74,11 +74,15 @@ public class DrawGroupPair : DrawPairBase
{
_mediator.Publish(new TargetPairMessage(_pair));
}
if (_pair.LastAppliedDataSize >= 0)
if (_pair.LastAppliedDataBytes >= 0)
{
presenceText += UiSharedService.TooltipSeparator;
presenceText += ((!_pair.IsVisible) ? "(Last) " : string.Empty) + "Mods Info" + Environment.NewLine;
presenceText += "Files Size: " + UiSharedService.ByteToString(_pair.LastAppliedDataSize, true);
presenceText += "Files Size: " + UiSharedService.ByteToString(_pair.LastAppliedDataBytes, true);
if (_pair.LastAppliedApproximateVRAMBytes >= 0)
{
presenceText += Environment.NewLine + "Approx. VRAM Usage: " + UiSharedService.ByteToString(_pair.LastAppliedApproximateVRAMBytes, true);
}
if (_pair.LastAppliedDataTris >= 0)
{
presenceText += Environment.NewLine + "Triangle Count (excl. Vanilla): "

View File

@@ -72,16 +72,20 @@ public class DrawUserPair : DrawPairBase
}
ImGui.PopFont();
var visibleTooltip = _pair.UserData.AliasOrUID + " is visible: " + _pair.PlayerName! + Environment.NewLine + "Click to target this player";
if (_pair.LastAppliedDataSize >= 0)
if (_pair.LastAppliedDataBytes >= 0)
{
visibleTooltip += UiSharedService.TooltipSeparator;
visibleTooltip += ((!_pair.IsVisible) ? "(Last) " : string.Empty) + "Mods Info" + Environment.NewLine;
visibleTooltip += "Files Size: " + UiSharedService.ByteToString(_pair.LastAppliedDataSize, true);
visibleTooltip += "Files Size: " + UiSharedService.ByteToString(_pair.LastAppliedDataBytes, true);
if (_pair.LastAppliedApproximateVRAMBytes >= 0)
{
visibleTooltip += Environment.NewLine + "Approx. VRAM Usage: " + UiSharedService.ByteToString(_pair.LastAppliedApproximateVRAMBytes, true);
}
if (_pair.LastAppliedDataTris >= 0)
{
visibleTooltip += Environment.NewLine + "Triangle Count (excl. Vanilla): "
+ (_pair.LastAppliedDataTris > 1000 ? (_pair.LastAppliedDataTris / 1000d).ToString("0.0'k'") : _pair.LastAppliedDataTris);
}
}
}
UiSharedService.AttachToolTip(visibleTooltip);
@@ -273,16 +277,5 @@ public class DrawUserPair : DrawPairBase
_ = _apiController.UserRemovePair(new(entry.UserData));
}
UiSharedService.AttachToolTip("Hold CTRL and click to unpair permanently from " + entryUID);
ImGui.Separator();
if (!entry.IsPaused)
{
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.ExclamationTriangle, "Report Profile"))
{
ImGui.CloseCurrentPopup();
_mediator.Publish(new OpenReportPopupMessage(_pair));
}
UiSharedService.AttachToolTip("Report this users profile to the administrative team");
}
}
}

View File

@@ -31,7 +31,9 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
private ObjectKind _selectedObjectTab;
private bool _showModal = false;
public DataAnalysisUi(ILogger<DataAnalysisUi> logger, MareMediator mediator, CharacterAnalyzer characterAnalyzer, IpcManager ipcManager, PerformanceCollectorService performanceCollectorService)
public DataAnalysisUi(ILogger<DataAnalysisUi> logger, MareMediator mediator,
CharacterAnalyzer characterAnalyzer, IpcManager ipcManager,
PerformanceCollectorService performanceCollectorService)
: base(logger, mediator, "Character Data Analysis", performanceCollectorService)
{
_characterAnalyzer = characterAnalyzer;
@@ -152,10 +154,10 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
+ ", compressed: " + UiSharedService.ByteToString(f.Sum(v => v.CompressedSize))));
ImGui.SetTooltip(text);
}
ImGui.TextUnformatted("Total size (uncompressed):");
ImGui.TextUnformatted("Total size (actual):");
ImGui.SameLine();
ImGui.TextUnformatted(UiSharedService.ByteToString(_cachedAnalysis!.Sum(c => c.Value.Sum(c => c.Value.OriginalSize))));
ImGui.TextUnformatted("Total size (compressed):");
ImGui.TextUnformatted("Total size (compressed for up/download only):");
ImGui.SameLine();
ImGui.TextUnformatted(UiSharedService.ByteToString(_cachedAnalysis!.Sum(c => c.Value.Sum(c => c.Value.CompressedSize))));
ImGui.TextUnformatted($"Total modded model triangles: {_cachedAnalysis.Sum(c => c.Value.Sum(f => f.Value.Triangles))}");
@@ -170,7 +172,8 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
using var tab = ImRaii.TabItem(tabText + "###" + kvp.Key.ToString());
if (tab.Success)
{
var groupedfiles = kvp.Value.Select(v => v.Value).GroupBy(f => f.FileType, StringComparer.Ordinal).OrderBy(k => k.Key, StringComparer.Ordinal).ToList();
var groupedfiles = kvp.Value.Select(v => v.Value).GroupBy(f => f.FileType, StringComparer.Ordinal)
.OrderBy(k => k.Key, StringComparer.Ordinal).ToList();
ImGui.TextUnformatted("Files for " + kvp.Key);
ImGui.SameLine();
@@ -189,12 +192,19 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
+ ", compressed: " + UiSharedService.ByteToString(f.Sum(v => v.CompressedSize))));
ImGui.SetTooltip(text);
}
ImGui.TextUnformatted($"{kvp.Key} size (uncompressed):");
ImGui.TextUnformatted($"{kvp.Key} size (actual):");
ImGui.SameLine();
ImGui.TextUnformatted(UiSharedService.ByteToString(kvp.Value.Sum(c => c.Value.OriginalSize)));
ImGui.TextUnformatted($"{kvp.Key} size (compressed):");
ImGui.TextUnformatted($"{kvp.Key} size (compressed for up/download only):");
ImGui.SameLine();
ImGui.TextUnformatted(UiSharedService.ByteToString(kvp.Value.Sum(c => c.Value.CompressedSize)));
ImGui.TextUnformatted($"{kvp.Key} VRAM usage:");
ImGui.SameLine();
var vramUsage = groupedfiles.SingleOrDefault(v => string.Equals(v.Key, "tex", StringComparison.Ordinal));
if (vramUsage != null)
{
ImGui.TextUnformatted(UiSharedService.ByteToString(vramUsage.Sum(f => f.OriginalSize)));
}
ImGui.TextUnformatted($"{kvp.Key} modded model triangles: {kvp.Value.Sum(f => f.Value.Triangles)}");
ImGui.Separator();
@@ -239,11 +249,11 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
ImGui.SameLine();
ImGui.TextUnformatted(fileGroup.Count().ToString());
ImGui.TextUnformatted($"{fileGroup.Key} files size (uncompressed):");
ImGui.TextUnformatted($"{fileGroup.Key} files size (actual):");
ImGui.SameLine();
ImGui.TextUnformatted(UiSharedService.ByteToString(fileGroup.Sum(c => c.OriginalSize)));
ImGui.TextUnformatted($"{fileGroup.Key} files size (compressed):");
ImGui.TextUnformatted($"{fileGroup.Key} files size (compressed for up/download only):");
ImGui.SameLine();
ImGui.TextUnformatted(UiSharedService.ByteToString(fileGroup.Sum(c => c.CompressedSize)));
@@ -383,10 +393,14 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderBy(k => k.Value.CompressedSize).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
if (idx == 4 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Descending)
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderByDescending(k => k.Value.CompressedSize).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
if (string.Equals(fileGroup.Key, "mdl", StringComparison.Ordinal) && idx == 5 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Ascending)
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderBy(k => k.Value.Triangles).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
if (string.Equals(fileGroup.Key, "mdl", StringComparison.Ordinal) && idx == 5 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Descending)
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderByDescending(k => k.Value.Triangles).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
if (string.Equals(fileGroup.Key, "tex", StringComparison.Ordinal) && idx == 5 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Ascending)
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderBy(k => k.Value.Format).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderBy(k => k.Value.Format.Value, StringComparer.Ordinal).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
if (string.Equals(fileGroup.Key, "tex", StringComparison.Ordinal) && idx == 5 && sortSpecs.Specs.SortDirection == ImGuiSortDirection.Descending)
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderByDescending(k => k.Value.Format).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
_cachedAnalysis![_selectedObjectTab] = _cachedAnalysis[_selectedObjectTab].OrderByDescending(k => k.Value.Format.Value, StringComparer.Ordinal).ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
sortSpecs.SpecsDirty = false;
}

View File

@@ -21,7 +21,6 @@ public class EditProfileUi : WindowMediatorSubscriberBase
private readonly ApiController _apiController;
private readonly FileDialogManager _fileDialogManager;
private readonly MareProfileManager _mareProfileManager;
private readonly IUiBuilder _uiBuilder;
private readonly UiSharedService _uiSharedService;
private readonly ServerConfigurationManager _serverConfigurationManager;
private bool _adjustedForScollBarsLocalProfile = false;
@@ -34,8 +33,8 @@ public class EditProfileUi : WindowMediatorSubscriberBase
private bool _wasOpen;
public EditProfileUi(ILogger<EditProfileUi> logger, MareMediator mediator,
ApiController apiController, IUiBuilder uiBuilder, UiSharedService uiSharedService,
FileDialogManager fileDialogManager, ServerConfigurationManager serverConfigurationManager,
ApiController apiController, UiSharedService uiSharedService, FileDialogManager fileDialogManager,
ServerConfigurationManager serverConfigurationManager,
MareProfileManager mareProfileManager, PerformanceCollectorService performanceCollectorService)
: base(logger, mediator, "Loporrit Edit Profile###LoporritSyncEditProfileUI", performanceCollectorService)
{
@@ -46,7 +45,6 @@ public class EditProfileUi : WindowMediatorSubscriberBase
MaximumSize = new(768, 2000)
};
_apiController = apiController;
_uiBuilder = uiBuilder;
_uiSharedService = uiSharedService;
_fileDialogManager = fileDialogManager;
_serverConfigurationManager = serverConfigurationManager;

View File

@@ -18,10 +18,11 @@ using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Numerics;
using System.Reflection;
using System.Text.RegularExpressions;
namespace MareSynchronos.UI;
public class IntroUi : WindowMediatorSubscriberBase
public partial class IntroUi : WindowMediatorSubscriberBase
{
private readonly ApiController _apiController;
private readonly MareConfigService _configService;
@@ -42,13 +43,12 @@ public class IntroUi : WindowMediatorSubscriberBase
private string? _registrationMessage;
private RegisterReplyDto? _registrationReply;
public IntroUi(ILogger<IntroUi> logger, UiSharedService uiShared, MareConfigService configService, ApiController apiController,
public IntroUi(ILogger<IntroUi> logger, UiSharedService uiShared, MareConfigService configService,
CacheMonitor fileCacheManager, ServerConfigurationManager serverConfigurationManager, MareMediator mareMediator,
PerformanceCollectorService performanceCollectorService, DalamudUtilService dalamudUtilService) : base(logger, mareMediator, "Loporrit Setup", performanceCollectorService)
{
_uiShared = uiShared;
_configService = configService;
_apiController = apiController;
_cacheMonitor = fileCacheManager;
_serverConfigurationManager = serverConfigurationManager;
_dalamudUtilService = dalamudUtilService;
@@ -87,11 +87,12 @@ public class IntroUi : WindowMediatorSubscriberBase
UiSharedService.ColorTextWrapped("Note: Any modifications you have applied through anything but Penumbra cannot be shared and your character state on other clients " +
"might look broken because of this or others players mods might not apply on your end altogether. " +
"If you want to use this plugin you will have to move your mods to Penumbra.", ImGuiColors.DalamudYellow);
if (!_uiShared.DrawOtherPluginState(true)) return;
if (!_uiShared.DrawOtherPluginState(intro: true)) return;
ImGui.Separator();
if (ImGui.Button("Next##toAgreement"))
{
_readFirstPage = true;
#if !DEBUG
_timeoutTask = Task.Run(async () =>
{
for (int i = 10; i > 0; i--)
@@ -100,6 +101,9 @@ public class IntroUi : WindowMediatorSubscriberBase
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
}
});
#else
_timeoutTask = Task.CompletedTask;
#endif
}
}
else if (!_configService.Current.AcceptedAgreement && _readFirstPage)
@@ -229,7 +233,11 @@ public class IntroUi : WindowMediatorSubscriberBase
ImGui.InputText("", ref _secretKey, 64);
if (_secretKey.Length > 0 && _secretKey.Length != 64)
{
UiSharedService.ColorTextWrapped("Your secret key must be exactly 64 characters long. Don't enter your Lodestone auth here.", ImGuiColors.DalamudRed);
UiSharedService.ColorTextWrapped("Your secret key must be exactly 64 characters long.", ImGuiColors.DalamudRed);
}
else if (_secretKey.Length == 64 && !HexRegex().IsMatch(_secretKey))
{
UiSharedService.ColorTextWrapped("Your secret key can only contain ABCDEF and the numbers 0-9.", ImGuiColors.DalamudRed);
}
else if (_secretKey.Length == 64)
{
@@ -238,7 +246,7 @@ public class IntroUi : WindowMediatorSubscriberBase
{
string keyName;
if (_serverConfigurationManager.CurrentServer == null) _serverConfigurationManager.SelectServer(0);
if (_registrationReply != null && _secretKey == _registrationReply.SecretKey)
if (_registrationReply != null && _secretKey.Equals(_registrationReply.SecretKey, StringComparison.Ordinal))
keyName = _registrationReply.UID + $" (registered {DateTime.Now:yyyy-MM-dd})";
else
keyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})";
@@ -247,13 +255,13 @@ public class IntroUi : WindowMediatorSubscriberBase
FriendlyName = keyName,
Key = _secretKey,
});
_serverConfigurationManager.AddCurrentCharacterToServer(addLastSecretKey: true);
_serverConfigurationManager.AddCurrentCharacterToServer();
_secretKey = string.Empty;
_ = Task.Run(() => _uiShared.ApiController.CreateConnections());
}
}
if (_serverConfigurationManager.CurrentApiUrl == ApiController.LoporritServiceUri)
if (_serverConfigurationManager.CurrentApiUrl.Equals(ApiController.LoporritServiceUri, StringComparison.Ordinal))
{
ImGui.BeginDisabled(_registrationInProgress || _registrationSuccess || _secretKey.Length > 0);
ImGui.Separator();
@@ -270,13 +278,13 @@ public class IntroUi : WindowMediatorSubscriberBase
var postUri = MareAuth.AuthRegisterFullPath(new Uri(_serverConfigurationManager.CurrentApiUrl
.Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase)
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)));
_logger.LogInformation("Registering new account: " + postUri.ToString());
_logger.LogInformation("Registering new account: {uri}", postUri.ToString());
var result = await httpClient.PostAsync(postUri, null).ConfigureAwait(false);
result.EnsureSuccessStatusCode();
var reply = await result.Content.ReadFromJsonAsync<RegisterReplyDto>().ConfigureAwait(false) ?? new();
if (!reply.Success)
{
_logger.LogWarning("Registration failed: " + reply.ErrorMessage);
_logger.LogWarning("Registration failed: {err}", reply.ErrorMessage);
_registrationMessage = reply.ErrorMessage;
if (_registrationMessage.IsNullOrEmpty())
_registrationMessage = "An unknown error occured. Please try again later.";
@@ -331,4 +339,7 @@ public class IntroUi : WindowMediatorSubscriberBase
_tosParagraphs = [Strings.ToS.Paragraph1, Strings.ToS.Paragraph2, Strings.ToS.Paragraph3, Strings.ToS.Paragraph4, Strings.ToS.Paragraph5, Strings.ToS.Paragraph6];
}
[GeneratedRegex("^([A-F0-9]{2})+")]
private static partial Regex HexRegex();
}

View File

@@ -77,12 +77,12 @@ public class SettingsUi : WindowMediatorSubscriberBase
MareCharaFileManager mareCharaFileManager, PairManager pairManager, ChatService chatService, GuiHookService guiHookService,
ServerConfigurationManager serverConfigurationManager,
MareMediator mediator, PerformanceCollectorService performanceCollector,
DalamudUtilService dalamudUtilService,
FileUploadManager fileTransferManager,
FileTransferOrchestrator fileTransferOrchestrator,
FileCacheManager fileCacheManager,
FileCompactor fileCompactor, ApiController apiController,
IpcManager ipcManager, CacheMonitor cacheMonitor) : base(logger, mediator, "Loporrit Settings", performanceCollector)
IpcManager ipcManager, CacheMonitor cacheMonitor,
DalamudUtilService dalamudUtilService) : base(logger, mediator, "Loporrit Settings", performanceCollector)
{
_configService = configService;
_mareCharaFileManager = mareCharaFileManager;
@@ -91,7 +91,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
_guiHookService = guiHookService;
_serverConfigurationManager = serverConfigurationManager;
_performanceCollector = performanceCollector;
_dalamudUtilService = dalamudUtilService;
_fileTransferManager = fileTransferManager;
_fileTransferOrchestrator = fileTransferOrchestrator;
_fileCacheManager = fileCacheManager;
@@ -133,6 +132,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
public override void OnClose()
{
_uiShared.EditTrackerPosition = false;
base.OnClose();
}
@@ -191,7 +191,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
}
ImGui.SameLine();
ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale);
_uiShared.DrawCombo("###speed", new[] { DownloadSpeeds.Bps, DownloadSpeeds.KBps, DownloadSpeeds.MBps },
_uiShared.DrawCombo("###speed", [DownloadSpeeds.Bps, DownloadSpeeds.KBps, DownloadSpeeds.MBps],
(s) => s switch
{
DownloadSpeeds.Bps => "Byte/s",

View File

@@ -82,7 +82,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public UiSharedService(ILogger<UiSharedService> logger, IpcManager ipcManager, ApiController apiController,
CacheMonitor cacheMonitor, FileDialogManager fileDialogManager,
MareConfigService configService, DalamudUtilService dalamudUtil, IDalamudPluginInterface pluginInterface,
ITextureProvider textureProvider, Dalamud.Localization localization,
ITextureProvider textureProvider,
Dalamud.Localization localization,
ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
{
_ipcManager = ipcManager;