diff --git a/MareSynchronos/Interop/DalamudLogger.cs b/MareSynchronos/Interop/DalamudLogger.cs index b244d7f..0b72ec9 100644 --- a/MareSynchronos/Interop/DalamudLogger.cs +++ b/MareSynchronos/Interop/DalamudLogger.cs @@ -10,12 +10,14 @@ internal sealed class DalamudLogger : ILogger private readonly MareConfigService _mareConfigService; private readonly string _name; private readonly IPluginLog _pluginLog; + private readonly bool _hasModifiedGameFiles; - public DalamudLogger(string name, MareConfigService mareConfigService, IPluginLog pluginLog) + public DalamudLogger(string name, MareConfigService mareConfigService, IPluginLog pluginLog, bool hasModifiedGameFiles) { _name = name; _mareConfigService = mareConfigService; _pluginLog = pluginLog; + _hasModifiedGameFiles = hasModifiedGameFiles; } public IDisposable BeginScope(TState state) => default!; @@ -29,12 +31,14 @@ internal sealed class DalamudLogger : ILogger { if (!IsEnabled(logLevel)) return; + string unsupported = _hasModifiedGameFiles ? "[UNSUPPORTED]" : string.Empty; + if ((int)logLevel <= (int)LogLevel.Information) - _pluginLog.Information($"[{_name}]{{{(int)logLevel}}} {state}"); + _pluginLog.Information($"{unsupported}[{_name}]{{{(int)logLevel}}} {state}{(_hasModifiedGameFiles ? "." : string.Empty)}"); else { StringBuilder sb = new(); - sb.AppendLine($"[{_name}]{{{(int)logLevel}}} {state}: {exception?.Message}"); + sb.AppendLine($"{unsupported}[{_name}]{{{(int)logLevel}}} {state}{(_hasModifiedGameFiles ? "." : string.Empty)}: {exception?.Message}"); sb.AppendLine(exception?.StackTrace); var innerException = exception?.InnerException; while (innerException != null) diff --git a/MareSynchronos/Interop/DalamudLoggingProvider.cs b/MareSynchronos/Interop/DalamudLoggingProvider.cs index 5ee0eeb..06364f0 100644 --- a/MareSynchronos/Interop/DalamudLoggingProvider.cs +++ b/MareSynchronos/Interop/DalamudLoggingProvider.cs @@ -14,11 +14,13 @@ public sealed class DalamudLoggingProvider : ILoggerProvider private readonly MareConfigService _mareConfigService; private readonly IPluginLog _pluginLog; + private readonly bool _hasModifiedGameFiles; - public DalamudLoggingProvider(MareConfigService mareConfigService, IPluginLog pluginLog) + public DalamudLoggingProvider(MareConfigService mareConfigService, IPluginLog pluginLog, bool hasModifiedGameFiles) { _mareConfigService = mareConfigService; _pluginLog = pluginLog; + _hasModifiedGameFiles = hasModifiedGameFiles; } public ILogger CreateLogger(string categoryName) @@ -33,7 +35,7 @@ public sealed class DalamudLoggingProvider : ILoggerProvider catName = string.Join("", Enumerable.Range(0, 15 - catName.Length).Select(_ => " ")) + catName; } - return _loggers.GetOrAdd(catName, name => new DalamudLogger(name, _mareConfigService, _pluginLog)); + return _loggers.GetOrAdd(catName, name => new DalamudLogger(name, _mareConfigService, _pluginLog, _hasModifiedGameFiles)); } public void Dispose() diff --git a/MareSynchronos/Interop/DalamudLoggingProviderExtensions.cs b/MareSynchronos/Interop/DalamudLoggingProviderExtensions.cs index 392e5d0..3704dd2 100644 --- a/MareSynchronos/Interop/DalamudLoggingProviderExtensions.cs +++ b/MareSynchronos/Interop/DalamudLoggingProviderExtensions.cs @@ -8,12 +8,12 @@ namespace MareSynchronos.Interop; public static class DalamudLoggingProviderExtensions { - public static ILoggingBuilder AddDalamudLogging(this ILoggingBuilder builder, IPluginLog pluginLog) + public static ILoggingBuilder AddDalamudLogging(this ILoggingBuilder builder, IPluginLog pluginLog, bool hasModifiedGameFiles) { builder.ClearProviders(); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton - (b => new DalamudLoggingProvider(b.GetRequiredService(), pluginLog))); + (b => new DalamudLoggingProvider(b.GetRequiredService(), pluginLog, hasModifiedGameFiles))); return builder; } diff --git a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs index 8392327..81f7923 100644 --- a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs +++ b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs @@ -50,6 +50,7 @@ public class MareConfig : IMareConfiguration public int TransferBarsWidth { get; set; } = 250; public bool UseAlternativeFileUpload { get; set; } = false; public bool UseCompactor { get; set; } = false; + public bool DebugStopWhining { get; set; } = false; public int Version { get; set; } = 1; public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both; } \ No newline at end of file diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index d3e6018..25bcb92 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -31,19 +31,18 @@ namespace MareSynchronos; public sealed class Plugin : IDalamudPlugin { - private readonly CancellationTokenSource _pluginCts = new(); - private readonly Task _hostBuilderRunTask; + private readonly IHost _host; public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData, IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui, IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager) { - _hostBuilderRunTask = new HostBuilder() + _host = new HostBuilder() .UseContentRoot(pluginInterface.ConfigDirectory.FullName) .ConfigureLogging(lb => { lb.ClearProviders(); - lb.AddDalamudLogging(pluginLog); + lb.AddDalamudLogging(pluginLog, gameData.HasModifiedGameDataFiles); lb.SetMinimumLevel(LogLevel.Trace); }) .ConfigureServices(collection => @@ -168,14 +167,14 @@ public sealed class Plugin : IDalamudPlugin collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); }) - .Build() - .RunAsync(_pluginCts.Token); + .Build(); + + _ = _host.StartAsync(); } public void Dispose() { - _pluginCts.Cancel(); - _pluginCts.Dispose(); - _hostBuilderRunTask.Wait(); + _host.StopAsync().GetAwaiter().GetResult(); + _host.Dispose(); } } \ No newline at end of file diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 7e8f77a..94d6d14 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -405,16 +405,25 @@ public class SettingsUi : WindowMediatorSubscriberBase } _uiShared.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended."); - using var disabled = ImRaii.Disabled(!logPerformance); - if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) + using (ImRaii.Disabled(!logPerformance)) { - _performanceCollector.PrintPerformanceStats(); + if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) + { + _performanceCollector.PrintPerformanceStats(); + } + ImGui.SameLine(); + if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) + { + _performanceCollector.PrintPerformanceStats(60); + } } - ImGui.SameLine(); - if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) + + bool stopWhining = _configService.Current.DebugStopWhining; + if (ImGui.Checkbox("Do not notify for modified game files", ref stopWhining)) { - _performanceCollector.PrintPerformanceStats(60); + _configService.Current.DebugStopWhining = stopWhining; } + _uiShared.DrawHelpText("Having modified game files will still mark your logs with UNSUPPORTED and you will not receive support, message shown or not."); } private void DrawFileStorageSettings() diff --git a/MareSynchronos/WebAPI/SignalR/ApiController.cs b/MareSynchronos/WebAPI/SignalR/ApiController.cs index b3e408b..66fd4c1 100644 --- a/MareSynchronos/WebAPI/SignalR/ApiController.cs +++ b/MareSynchronos/WebAPI/SignalR/ApiController.cs @@ -4,6 +4,7 @@ using MareSynchronos.API.Data.Extensions; using MareSynchronos.API.Dto; using MareSynchronos.API.Dto.User; using MareSynchronos.API.SignalR; +using MareSynchronos.MareConfiguration; using MareSynchronos.PlayerData.Pairs; using MareSynchronos.Services; using MareSynchronos.Services.Mediator; @@ -27,6 +28,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM private readonly PairManager _pairManager; private readonly ServerConfigurationManager _serverManager; private readonly TokenProvider _tokenProvider; + private readonly MareConfigService _mareConfigService; private CancellationTokenSource _connectionCancellationTokenSource; private ConnectionDto? _connectionDto; private bool _doNotNotifyOnNextInfo = false; @@ -39,13 +41,14 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM public ApiController(ILogger logger, HubFactory hubFactory, DalamudUtilService dalamudUtil, PairManager pairManager, ServerConfigurationManager serverManager, MareMediator mediator, - TokenProvider tokenProvider) : base(logger, mediator) + TokenProvider tokenProvider, MareConfigService mareConfigService) : base(logger, mediator) { _hubFactory = hubFactory; _dalamudUtil = dalamudUtil; _pairManager = pairManager; _serverManager = serverManager; _tokenProvider = tokenProvider; + _mareConfigService = mareConfigService; _connectionCancellationTokenSource = new CancellationTokenSource(); Mediator.Subscribe(this, (_) => DalamudUtilOnLogIn()); @@ -208,10 +211,11 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM if (_dalamudUtil.HasModifiedGameFiles) { Logger.LogError("Detected modified game files on connection"); - Mediator.Publish(new NotificationMessage("Modified Game Files detected", - "Mare has detected modified game files in your FFXIV installation. You will be able to connect, but the synchronization functionality might be (partially) broken. " + - "Exit the game and repair it through XIVLauncher to get rid of this message.", - Dalamud.Interface.Internal.Notifications.NotificationType.Error, TimeSpan.FromSeconds(15))); + if (!_mareConfigService.Current.DebugStopWhining) + Mediator.Publish(new NotificationMessage("Modified Game Files detected", + "Mare has detected modified game files in your FFXIV installation. You will be able to connect, but the synchronization functionality might be (partially) broken. " + + "Exit the game and repair it through XIVLauncher to get rid of this message.", + Dalamud.Interface.Internal.Notifications.NotificationType.Error, TimeSpan.FromSeconds(15))); } await LoadIninitialPairs().ConfigureAwait(false);