Mare 0.9 (#65)
* add jwt expiry * start of 0.9 api impl * some stuff idk * some more impl * some cleanup * remove grouppair, add configuration, rework some pair drawing stuff * do some stuff * rework some ui * I don't even know anymore * add cancellationtoken * token bla * ui fixes etc * probably individual adding/removing now working fully as expected * add working report popup * I guess it's more syncshell shit or so * popup shit idk * work out most of the syncshell bullshit I guess * delete some old crap * are we actually getting closer to the end * update pair info stuff * more fixes/adjustments, idk * refactor some things * some rework * some more cleanup * cleanup * make menu buttons w i d e * better icon text buttons * add all syncshell folder and ordering fixes --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
using MareSynchronos.API.Data;
|
||||
using Lumina.Data.Files;
|
||||
using MareSynchronos.API.Data;
|
||||
using MareSynchronos.API.Data.Enum;
|
||||
using MareSynchronos.FileCache;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.UI;
|
||||
using MareSynchronos.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Lumina.Data.Files;
|
||||
|
||||
namespace MareSynchronos.Services;
|
||||
|
||||
@@ -14,7 +14,6 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
private readonly FileCacheManager _fileCacheManager;
|
||||
private CancellationTokenSource? _analysisCts;
|
||||
private string _lastDataHash = string.Empty;
|
||||
internal Dictionary<ObjectKind, Dictionary<string, FileDataEntry>> LastAnalysis { get; } = new();
|
||||
|
||||
public CharacterAnalyzer(ILogger<CharacterAnalyzer> logger, MareMediator mediator, FileCacheManager fileCacheManager) : base(logger, mediator)
|
||||
{
|
||||
@@ -25,10 +24,10 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
_fileCacheManager = fileCacheManager;
|
||||
}
|
||||
|
||||
public bool IsAnalysisRunning => _analysisCts != null;
|
||||
|
||||
public int CurrentFile { get; internal set; }
|
||||
public bool IsAnalysisRunning => _analysisCts != null;
|
||||
public int TotalFiles { get; internal set; }
|
||||
internal Dictionary<ObjectKind, Dictionary<string, FileDataEntry>> LastAnalysis { get; } = [];
|
||||
|
||||
public void CancelAnalyze()
|
||||
{
|
||||
@@ -74,6 +73,11 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
if (print) PrintAnalysis();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_analysisCts.CancelDispose();
|
||||
}
|
||||
|
||||
private void BaseAnalysis(CharacterData charaData)
|
||||
{
|
||||
if (string.Equals(charaData.DataHash.Value, _lastDataHash, StringComparison.Ordinal)) return;
|
||||
@@ -103,7 +107,7 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
foreach (var entry in fileCacheEntries)
|
||||
{
|
||||
data[fileEntry.Hash] = new FileDataEntry(fileEntry.Hash, ext,
|
||||
fileEntry.GamePaths.ToList(),
|
||||
[.. fileEntry.GamePaths],
|
||||
fileCacheEntries.Select(c => c.ResolvedFilepath).Distinct().ToList(),
|
||||
entry.Size > 0 ? entry.Size.Value : 0, entry.CompressedSize > 0 ? entry.CompressedSize.Value : 0);
|
||||
}
|
||||
@@ -133,7 +137,7 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
{
|
||||
Logger.LogInformation(" Game Path: {path}", path);
|
||||
}
|
||||
if (entry.Value.FilePaths.Count > 1) Logger.LogInformation(" Multiple fitting files detected", entry.Key);
|
||||
if (entry.Value.FilePaths.Count > 1) Logger.LogInformation(" Multiple fitting files detected for {key}", entry.Key);
|
||||
foreach (var filePath in entry.Value.FilePaths)
|
||||
{
|
||||
Logger.LogInformation(" File Path: {path}", filePath);
|
||||
@@ -163,11 +167,6 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
Logger.LogInformation("IMPORTANT NOTES:\n\r- For Mare up- and downloads only the compressed size is relevant.\n\r- An unusually high total files count beyond 200 and up will also increase your download time to others significantly.");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_analysisCts.CancelDispose();
|
||||
}
|
||||
|
||||
internal sealed record FileDataEntry(string Hash, string FileType, List<string> GamePaths, List<string> FilePaths, long OriginalSize, long CompressedSize)
|
||||
{
|
||||
public bool IsComputed => OriginalSize > 0 && CompressedSize > 0;
|
||||
@@ -205,11 +204,10 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
}
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.Services.ServerConfiguration;
|
||||
using MareSynchronos.UI;
|
||||
using MareSynchronos.WebAPI;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MareSynchronos.Services;
|
||||
|
||||
@@ -18,15 +19,13 @@ public sealed class CommandManagerService : IDisposable
|
||||
private readonly PerformanceCollectorService _performanceCollectorService;
|
||||
private readonly PeriodicFileScanner _periodicFileScanner;
|
||||
private readonly ServerConfigurationManager _serverConfigurationManager;
|
||||
private readonly UiService _uiService;
|
||||
|
||||
public CommandManagerService(ICommandManager commandManager, PerformanceCollectorService performanceCollectorService,
|
||||
UiService uiService, ServerConfigurationManager serverConfigurationManager, PeriodicFileScanner periodicFileScanner,
|
||||
ServerConfigurationManager serverConfigurationManager, PeriodicFileScanner periodicFileScanner,
|
||||
ApiController apiController, MareMediator mediator)
|
||||
{
|
||||
_commandManager = commandManager;
|
||||
_performanceCollectorService = performanceCollectorService;
|
||||
_uiService = uiService;
|
||||
_serverConfigurationManager = serverConfigurationManager;
|
||||
_periodicFileScanner = periodicFileScanner;
|
||||
_apiController = apiController;
|
||||
@@ -49,7 +48,7 @@ public sealed class CommandManagerService : IDisposable
|
||||
if (splitArgs == null || splitArgs.Length == 0)
|
||||
{
|
||||
// Interpret this as toggling the UI
|
||||
_uiService.ToggleMainUi();
|
||||
_mediator.Publish(new UiToggleMessage(typeof(CompactUi)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ public sealed class CommandManagerService : IDisposable
|
||||
}
|
||||
else if (string.Equals(splitArgs[0], "perf", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (splitArgs.Length > 1 && int.TryParse(splitArgs[1], out var limitBySeconds))
|
||||
if (splitArgs.Length > 1 && int.TryParse(splitArgs[1], CultureInfo.InvariantCulture, out var limitBySeconds))
|
||||
{
|
||||
_performanceCollectorService.PrintPerformanceStats(limitBySeconds);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace MareSynchronos.Services;
|
||||
|
||||
public class DalamudUtilService : IHostedService
|
||||
{
|
||||
private readonly List<uint> _classJobIdsIgnoredForPets = new() { 30 };
|
||||
private readonly List<uint> _classJobIdsIgnoredForPets = [30];
|
||||
private readonly IClientState _clientState;
|
||||
private readonly ICondition _condition;
|
||||
private readonly IFramework _framework;
|
||||
@@ -59,6 +59,7 @@ public class DalamudUtilService : IHostedService
|
||||
public bool IsInCutscene { get; private set; } = false;
|
||||
public bool IsInGpose { get; private set; } = false;
|
||||
public bool IsLoggedIn { get; private set; }
|
||||
public bool IsOnFrameworkThread => _framework.IsInFrameworkUpdateThread;
|
||||
public bool IsZoning => _condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51];
|
||||
|
||||
public Lazy<Dictionary<ushort, string>> WorldData { get; private set; }
|
||||
@@ -74,8 +75,6 @@ public class DalamudUtilService : IHostedService
|
||||
return await RunOnFrameworkThread(() => _objectTable.CreateObjectReference(reference)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public bool IsOnFrameworkThread => _framework.IsInFrameworkUpdateThread;
|
||||
|
||||
public void EnsureIsOnFramework()
|
||||
{
|
||||
if (!_framework.IsInFrameworkUpdateThread) throw new InvalidOperationException("Can only be run on Framework");
|
||||
@@ -89,13 +88,6 @@ public class DalamudUtilService : IHostedService
|
||||
return (Dalamud.Game.ClientState.Objects.Types.Character)objTableObj;
|
||||
}
|
||||
|
||||
public Dalamud.Game.ClientState.Objects.Types.Character? GetGposeCharacterFromObjectTableByName(string name, bool onlyGposeCharacters = false)
|
||||
{
|
||||
EnsureIsOnFramework();
|
||||
return (Dalamud.Game.ClientState.Objects.Types.Character?)_objectTable.Where(i => !onlyGposeCharacters || i.ObjectIndex >= 200)
|
||||
.FirstOrDefault(f => f.Name.ToString() == name);
|
||||
}
|
||||
|
||||
public unsafe IntPtr GetCompanion(IntPtr? playerPointer = null)
|
||||
{
|
||||
EnsureIsOnFramework();
|
||||
@@ -110,6 +102,13 @@ public class DalamudUtilService : IHostedService
|
||||
return await RunOnFrameworkThread(() => GetCompanion(playerPointer)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Dalamud.Game.ClientState.Objects.Types.Character? GetGposeCharacterFromObjectTableByName(string name, bool onlyGposeCharacters = false)
|
||||
{
|
||||
EnsureIsOnFramework();
|
||||
return (Dalamud.Game.ClientState.Objects.Types.Character?)_objectTable
|
||||
.FirstOrDefault(i => (!onlyGposeCharacters || i.ObjectIndex >= 200) && string.Equals(i.Name.ToString(), name, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
public bool GetIsPlayerPresent()
|
||||
{
|
||||
EnsureIsOnFramework();
|
||||
@@ -351,19 +350,18 @@ public class DalamudUtilService : IHostedService
|
||||
if (!isDrawing)
|
||||
{
|
||||
isDrawing = ((CharacterBase*)drawObj)->HasModelFilesInSlotLoaded != 0;
|
||||
if (isDrawing)
|
||||
if (isDrawing && !string.Equals(_lastGlobalBlockPlayer, playerName, StringComparison.Ordinal)
|
||||
&& !string.Equals(_lastGlobalBlockReason, "HasModelFilesInSlotLoaded", StringComparison.Ordinal))
|
||||
{
|
||||
if (!string.Equals(_lastGlobalBlockPlayer, playerName, StringComparison.Ordinal) && !string.Equals(_lastGlobalBlockReason, "HasModelFilesInSlotLoaded"))
|
||||
{
|
||||
_lastGlobalBlockPlayer = playerName;
|
||||
_lastGlobalBlockReason = "HasModelFilesInSlotLoaded";
|
||||
isDrawingChanged = true;
|
||||
}
|
||||
_lastGlobalBlockPlayer = playerName;
|
||||
_lastGlobalBlockReason = "HasModelFilesInSlotLoaded";
|
||||
isDrawingChanged = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.Equals(_lastGlobalBlockPlayer, playerName, StringComparison.Ordinal) && !string.Equals(_lastGlobalBlockReason, "HasModelInSlotLoaded"))
|
||||
if (!string.Equals(_lastGlobalBlockPlayer, playerName, StringComparison.Ordinal)
|
||||
&& !string.Equals(_lastGlobalBlockReason, "HasModelInSlotLoaded", StringComparison.Ordinal))
|
||||
{
|
||||
_lastGlobalBlockPlayer = playerName;
|
||||
_lastGlobalBlockReason = "HasModelInSlotLoaded";
|
||||
@@ -373,7 +371,8 @@ public class DalamudUtilService : IHostedService
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.Equals(_lastGlobalBlockPlayer, playerName, StringComparison.Ordinal) && !string.Equals(_lastGlobalBlockReason, "RenderFlags"))
|
||||
if (!string.Equals(_lastGlobalBlockPlayer, playerName, StringComparison.Ordinal)
|
||||
&& !string.Equals(_lastGlobalBlockReason, "RenderFlags", StringComparison.Ordinal))
|
||||
{
|
||||
_lastGlobalBlockPlayer = playerName;
|
||||
_lastGlobalBlockReason = "RenderFlags";
|
||||
|
||||
7
MareSynchronos/Services/MareProfileData.cs
Normal file
7
MareSynchronos/Services/MareProfileData.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace MareSynchronos.Services;
|
||||
|
||||
public record MareProfileData(bool IsFlagged, bool IsNSFW, string Base64ProfilePicture, string Base64SupporterPicture, string Description)
|
||||
{
|
||||
public Lazy<byte[]> ImageData { get; } = new Lazy<byte[]>(Convert.FromBase64String(Base64ProfilePicture));
|
||||
public Lazy<byte[]> SupporterImageData { get; } = new Lazy<byte[]>(string.IsNullOrEmpty(Base64SupporterPicture) ? [] : Convert.FromBase64String(Base64SupporterPicture));
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -10,7 +10,7 @@ public abstract class DisposableMediatorSubscriberBase : MediatorSubscriberBase,
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace MareSynchronos.Services.Mediator;
|
||||
public sealed class MareMediator : IHostedService
|
||||
{
|
||||
private readonly object _addRemoveLock = new();
|
||||
private readonly Dictionary<object, DateTime> _lastErrorTime = new();
|
||||
private readonly Dictionary<object, DateTime> _lastErrorTime = [];
|
||||
private readonly ILogger<MareMediator> _logger;
|
||||
private readonly CancellationTokenSource _loopCts = new();
|
||||
private readonly ConcurrentQueue<MessageBase> _messageQueue = new();
|
||||
private readonly PerformanceCollectorService _performanceCollector;
|
||||
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = new();
|
||||
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = [];
|
||||
|
||||
public MareMediator(ILogger<MareMediator> logger, PerformanceCollectorService performanceCollector)
|
||||
{
|
||||
@@ -23,13 +23,13 @@ public sealed class MareMediator : IHostedService
|
||||
|
||||
public void PrintSubscriberInfo()
|
||||
{
|
||||
foreach (var kvp in _subscriberDict.SelectMany(c => c.Value.Select(v => v))
|
||||
.DistinctBy(p => p.Subscriber).OrderBy(p => p.Subscriber.GetType().FullName, StringComparer.Ordinal).ToList())
|
||||
foreach (var subscriber in _subscriberDict.SelectMany(c => c.Value.Select(v => v.Subscriber))
|
||||
.DistinctBy(p => p).OrderBy(p => p.GetType().FullName, StringComparer.Ordinal).ToList())
|
||||
{
|
||||
_logger.LogInformation("Subscriber {type}: {sub}", kvp.Subscriber.GetType().Name, kvp.Subscriber.ToString());
|
||||
_logger.LogInformation("Subscriber {type}: {sub}", subscriber.GetType().Name, subscriber.ToString());
|
||||
StringBuilder sb = new();
|
||||
sb.Append("=> ");
|
||||
foreach (var item in _subscriberDict.Where(item => item.Value.Any(v => v.Subscriber == kvp.Subscriber)).ToList())
|
||||
foreach (var item in _subscriberDict.Where(item => item.Value.Any(v => v.Subscriber == subscriber)).ToList())
|
||||
{
|
||||
sb.Append(item.Key.Name).Append(", ");
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public sealed class MareMediator : IHostedService
|
||||
{
|
||||
await Task.Delay(100, _loopCts.Token).ConfigureAwait(false);
|
||||
|
||||
HashSet<MessageBase> processedMessages = new();
|
||||
HashSet<MessageBase> processedMessages = [];
|
||||
while (_messageQueue.TryDequeue(out var message))
|
||||
{
|
||||
if (processedMessages.Contains(message)) { continue; }
|
||||
@@ -89,7 +89,7 @@ public sealed class MareMediator : IHostedService
|
||||
{
|
||||
lock (_addRemoveLock)
|
||||
{
|
||||
_subscriberDict.TryAdd(typeof(T), new HashSet<SubscriberAction>());
|
||||
_subscriberDict.TryAdd(typeof(T), []);
|
||||
|
||||
if (!_subscriberDict[typeof(T)].Add(new(subscriber, action)))
|
||||
{
|
||||
@@ -130,20 +130,22 @@ public sealed class MareMediator : IHostedService
|
||||
{
|
||||
if (!_subscriberDict.TryGetValue(message.GetType(), out HashSet<SubscriberAction>? subscribers) || subscribers == null || !subscribers.Any()) return;
|
||||
|
||||
HashSet<SubscriberAction> subscribersCopy = new HashSet<SubscriberAction>();
|
||||
HashSet<SubscriberAction> subscribersCopy = [];
|
||||
lock (_addRemoveLock)
|
||||
{
|
||||
subscribersCopy = subscribers?.Where(s => s.Subscriber != null).ToHashSet() ?? new HashSet<SubscriberAction>();
|
||||
subscribersCopy = subscribers?.Where(s => s.Subscriber != null).ToHashSet() ?? [];
|
||||
}
|
||||
|
||||
foreach (SubscriberAction subscriber in subscribersCopy)
|
||||
{
|
||||
try
|
||||
{
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
typeof(MareMediator)
|
||||
.GetMethod(nameof(ExecuteSubscriber), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?
|
||||
.MakeGenericMethod(message.GetType())
|
||||
.Invoke(this, new object[] { subscriber, message });
|
||||
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace MareSynchronos.Services.Mediator;
|
||||
|
||||
#pragma warning disable MA0048
|
||||
public abstract record MessageBase
|
||||
{
|
||||
public virtual bool KeepThreadContext => false;
|
||||
@@ -8,4 +9,5 @@ public abstract record MessageBase
|
||||
public record SameThreadMessage : MessageBase
|
||||
{
|
||||
public override bool KeepThreadContext => true;
|
||||
}
|
||||
}
|
||||
#pragma warning restore MA0048
|
||||
@@ -2,6 +2,7 @@
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using MareSynchronos.API.Data;
|
||||
using MareSynchronos.API.Dto;
|
||||
using MareSynchronos.API.Dto.Group;
|
||||
using MareSynchronos.PlayerData.Handlers;
|
||||
using MareSynchronos.PlayerData.Pairs;
|
||||
using MareSynchronos.WebAPI.Files.Models;
|
||||
@@ -10,6 +11,7 @@ using System.Numerics;
|
||||
namespace MareSynchronos.Services.Mediator;
|
||||
|
||||
#pragma warning disable MA0048 // File name must match type name
|
||||
#pragma warning disable S2094
|
||||
public record SwitchToIntroUiMessage : MessageBase;
|
||||
public record SwitchToMainUiMessage : MessageBase;
|
||||
public record OpenSettingsUiMessage : MessageBase;
|
||||
@@ -68,5 +70,12 @@ public record CompactUiChange(Vector2 Size, Vector2 Position) : MessageBase;
|
||||
public record ProfileOpenStandaloneMessage(Pair Pair) : MessageBase;
|
||||
public record RemoveWindowMessage(WindowMediatorSubscriberBase Window) : MessageBase;
|
||||
public record PairHandlerVisibleMessage(PairHandler Player) : MessageBase;
|
||||
public record RefreshUiMessage : MessageBase;
|
||||
public record OpenReportPopupMessage(Pair PairToReport) : MessageBase;
|
||||
public record OpenBanUserPopupMessage(Pair PairToBan, GroupFullInfoDto GroupFullInfoDto) : MessageBase;
|
||||
public record JoinSyncshellPopupMessage() : MessageBase;
|
||||
public record OpenCreateSyncshellPopupMessage() : MessageBase;
|
||||
public record OpenSyncshellAdminPanelPopupMessage(GroupFullInfoDto GroupInfo) : MessageBase;
|
||||
|
||||
#pragma warning restore S2094
|
||||
#pragma warning restore MA0048 // File name must match type name
|
||||
@@ -27,7 +27,7 @@ public abstract class WindowMediatorSubscriberBase : Window, IMediatorSubscriber
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ public sealed class PerformanceCollectorService : IHostedService
|
||||
DrawSeparator(sb, longestCounterName);
|
||||
}
|
||||
|
||||
var pastEntries = limitBySeconds > 0 ? entry.Value.Where(e => e.Item1.AddMinutes(limitBySeconds / 60.0d) >= TimeOnly.FromDateTime(DateTime.Now)).ToList() : entry.Value.ToList();
|
||||
var pastEntries = limitBySeconds > 0 ? entry.Value.Where(e => e.Item1.AddMinutes(limitBySeconds / 60.0d) >= TimeOnly.FromDateTime(DateTime.Now)).ToList() : [.. entry.Value];
|
||||
|
||||
if (pastEntries.Any())
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PluginWarningNotificationService
|
||||
};
|
||||
}
|
||||
|
||||
List<string> missingPluginsForData = new();
|
||||
List<string> missingPluginsForData = [];
|
||||
if (changes.Contains(PlayerChanges.Heels) && !warning.ShownHeelsWarning && !_ipcManager.CheckHeelsApi())
|
||||
{
|
||||
missingPluginsForData.Add("SimpleHeels");
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace MareSynchronos.Services.ServerConfiguration;
|
||||
|
||||
public record JwtCache(string ApiUrl, string PlayerName, uint WorldId, string SecretKey);
|
||||
@@ -1,5 +1,6 @@
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.WebAPI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Diagnostics;
|
||||
@@ -11,18 +12,20 @@ public class ServerConfigurationManager
|
||||
private readonly ServerConfigService _configService;
|
||||
private readonly DalamudUtilService _dalamudUtil;
|
||||
private readonly ILogger<ServerConfigurationManager> _logger;
|
||||
private readonly MareMediator _mareMediator;
|
||||
private readonly NotesConfigService _notesConfig;
|
||||
private readonly ServerTagConfigService _serverTagConfig;
|
||||
private readonly Dictionary<JwtCache, string> _tokenDictionary = new();
|
||||
|
||||
public ServerConfigurationManager(ILogger<ServerConfigurationManager> logger, ServerConfigService configService,
|
||||
ServerTagConfigService serverTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil)
|
||||
ServerTagConfigService serverTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil,
|
||||
MareMediator mareMediator)
|
||||
{
|
||||
_logger = logger;
|
||||
_configService = configService;
|
||||
_serverTagConfig = serverTagConfig;
|
||||
_notesConfig = notesConfig;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_mareMediator = mareMediator;
|
||||
EnsureMainExists();
|
||||
}
|
||||
|
||||
@@ -92,7 +95,7 @@ public class ServerConfigurationManager
|
||||
{
|
||||
try
|
||||
{
|
||||
return _configService.Current.ServerStorage.ElementAt(idx);
|
||||
return _configService.Current.ServerStorage[idx];
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -107,20 +110,6 @@ public class ServerConfigurationManager
|
||||
return _configService.Current.ServerStorage.Select(v => v.ServerName).ToArray();
|
||||
}
|
||||
|
||||
public string? GetToken()
|
||||
{
|
||||
var charaName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult();
|
||||
var worldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult();
|
||||
var secretKey = GetSecretKey();
|
||||
if (secretKey == null) return null;
|
||||
if (_tokenDictionary.TryGetValue(new JwtCache(CurrentApiUrl, charaName, worldId, secretKey), out var token))
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool HasValidConfig()
|
||||
{
|
||||
return CurrentServer != null;
|
||||
@@ -129,19 +118,10 @@ public class ServerConfigurationManager
|
||||
public void Save()
|
||||
{
|
||||
var caller = new StackTrace().GetFrame(1)?.GetMethod()?.ReflectedType?.Name ?? "Unknown";
|
||||
_logger.LogDebug(caller + " Calling config save");
|
||||
_logger.LogDebug("{caller} Calling config save", caller);
|
||||
_configService.Save();
|
||||
}
|
||||
|
||||
public void SaveToken(string token)
|
||||
{
|
||||
var charaName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult();
|
||||
var worldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult();
|
||||
var secretKey = GetSecretKey();
|
||||
if (string.IsNullOrEmpty(secretKey)) throw new InvalidOperationException("No secret key set");
|
||||
_tokenDictionary[new JwtCache(CurrentApiUrl, charaName, worldId, secretKey)] = token;
|
||||
}
|
||||
|
||||
public void SelectServer(int idx)
|
||||
{
|
||||
_configService.Current.CurrentServer = idx;
|
||||
@@ -185,6 +165,7 @@ public class ServerConfigurationManager
|
||||
{
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Add(tag);
|
||||
_serverTagConfig.Save();
|
||||
_mareMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
|
||||
internal void AddTagForUid(string uid, string tagName)
|
||||
@@ -192,10 +173,11 @@ public class ServerConfigurationManager
|
||||
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
{
|
||||
tags.Add(tagName);
|
||||
_mareMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentServerTagStorage().UidServerPairedUserTags[uid] = new() { tagName };
|
||||
CurrentServerTagStorage().UidServerPairedUserTags[uid] = [tagName];
|
||||
}
|
||||
|
||||
_serverTagConfig.Save();
|
||||
@@ -295,6 +277,7 @@ public class ServerConfigurationManager
|
||||
RemoveTagForUid(uid, tag, save: false);
|
||||
}
|
||||
_serverTagConfig.Save();
|
||||
_mareMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
|
||||
internal void RemoveTagForUid(string uid, string tagName, bool save = true)
|
||||
@@ -302,8 +285,23 @@ public class ServerConfigurationManager
|
||||
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
|
||||
{
|
||||
tags.Remove(tagName);
|
||||
|
||||
if (save)
|
||||
{
|
||||
_serverTagConfig.Save();
|
||||
_mareMediator.Publish(new RefreshUiMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void RenameTag(string oldName, string newName)
|
||||
{
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Remove(oldName);
|
||||
CurrentServerTagStorage().ServerAvailablePairTags.Add(newName);
|
||||
foreach (var existingTags in CurrentServerTagStorage().UidServerPairedUserTags.Select(k => k.Value))
|
||||
{
|
||||
if (existingTags.Remove(oldName))
|
||||
existingTags.Add(newName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,6 +312,8 @@ public class ServerConfigurationManager
|
||||
|
||||
internal void SetNoteForGid(string gid, string note, bool save = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(gid)) return;
|
||||
|
||||
CurrentNotesStorage().GidServerComments[gid] = note;
|
||||
if (save)
|
||||
_notesConfig.Save();
|
||||
@@ -321,6 +321,8 @@ public class ServerConfigurationManager
|
||||
|
||||
internal void SetNoteForUid(string uid, string note, bool save = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uid)) return;
|
||||
|
||||
CurrentNotesStorage().UidServerComments[uid] = note;
|
||||
if (save)
|
||||
_notesConfig.Save();
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Interface.ImGuiFileDialog;
|
||||
using Dalamud.Interface.ImGuiFileDialog;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using MareSynchronos.UI;
|
||||
using Dalamud.Plugin;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MareSynchronos.PlayerData.Pairs;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.UI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronos.Services;
|
||||
|
||||
public sealed class UiService : DisposableMediatorSubscriberBase
|
||||
{
|
||||
private readonly List<WindowMediatorSubscriberBase> _createdWindows = new();
|
||||
private readonly List<WindowMediatorSubscriberBase> _createdWindows = [];
|
||||
private readonly DalamudPluginInterface _dalamudPluginInterface;
|
||||
private readonly FileDialogManager _fileDialogManager;
|
||||
private readonly ILogger<UiService> _logger;
|
||||
@@ -42,8 +42,8 @@ public sealed class UiService : DisposableMediatorSubscriberBase
|
||||
|
||||
Mediator.Subscribe<ProfileOpenStandaloneMessage>(this, (msg) =>
|
||||
{
|
||||
if (!_createdWindows.Any(p => p is StandaloneProfileUi
|
||||
&& string.Equals(((StandaloneProfileUi)p).Pair.UserData.AliasOrUID, msg.Pair.UserData.AliasOrUID, StringComparison.Ordinal)))
|
||||
if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui
|
||||
&& string.Equals(ui.Pair.UserData.AliasOrUID, msg.Pair.UserData.AliasOrUID, StringComparison.Ordinal)))
|
||||
{
|
||||
var window = standaloneProfileUiFactory(msg.Pair);
|
||||
_createdWindows.Add(window);
|
||||
@@ -59,14 +59,6 @@ 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())
|
||||
@@ -75,6 +67,14 @@ public sealed class UiService : DisposableMediatorSubscriberBase
|
||||
Mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
|
||||
}
|
||||
|
||||
public void ToggleUi()
|
||||
{
|
||||
if (_mareConfigService.Current.HasValidSetup())
|
||||
Mediator.Publish(new UiToggleMessage(typeof(SettingsUi)));
|
||||
else
|
||||
Mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
Reference in New Issue
Block a user