This commit is contained in:
rootdarkarchon
2024-03-24 16:40:01 +01:00
parent 73828ce717
commit 59ade9dc0c
7 changed files with 46 additions and 27 deletions

View File

@@ -10,12 +10,14 @@ internal sealed class DalamudLogger : ILogger
private readonly MareConfigService _mareConfigService; private readonly MareConfigService _mareConfigService;
private readonly string _name; private readonly string _name;
private readonly IPluginLog _pluginLog; 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; _name = name;
_mareConfigService = mareConfigService; _mareConfigService = mareConfigService;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_hasModifiedGameFiles = hasModifiedGameFiles;
} }
public IDisposable BeginScope<TState>(TState state) => default!; public IDisposable BeginScope<TState>(TState state) => default!;
@@ -29,12 +31,14 @@ internal sealed class DalamudLogger : ILogger
{ {
if (!IsEnabled(logLevel)) return; if (!IsEnabled(logLevel)) return;
string unsupported = _hasModifiedGameFiles ? "[UNSUPPORTED]" : string.Empty;
if ((int)logLevel <= (int)LogLevel.Information) if ((int)logLevel <= (int)LogLevel.Information)
_pluginLog.Information($"[{_name}]{{{(int)logLevel}}} {state}"); _pluginLog.Information($"{unsupported}[{_name}]{{{(int)logLevel}}} {state}{(_hasModifiedGameFiles ? "." : string.Empty)}");
else else
{ {
StringBuilder sb = new(); 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); sb.AppendLine(exception?.StackTrace);
var innerException = exception?.InnerException; var innerException = exception?.InnerException;
while (innerException != null) while (innerException != null)

View File

@@ -14,11 +14,13 @@ public sealed class DalamudLoggingProvider : ILoggerProvider
private readonly MareConfigService _mareConfigService; private readonly MareConfigService _mareConfigService;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly bool _hasModifiedGameFiles;
public DalamudLoggingProvider(MareConfigService mareConfigService, IPluginLog pluginLog) public DalamudLoggingProvider(MareConfigService mareConfigService, IPluginLog pluginLog, bool hasModifiedGameFiles)
{ {
_mareConfigService = mareConfigService; _mareConfigService = mareConfigService;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_hasModifiedGameFiles = hasModifiedGameFiles;
} }
public ILogger CreateLogger(string categoryName) 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; 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() public void Dispose()

View File

@@ -8,12 +8,12 @@ namespace MareSynchronos.Interop;
public static class DalamudLoggingProviderExtensions 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.ClearProviders();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, DalamudLoggingProvider> builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, DalamudLoggingProvider>
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog))); (b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog, hasModifiedGameFiles)));
return builder; return builder;
} }

View File

@@ -50,6 +50,7 @@ public class MareConfig : IMareConfiguration
public int TransferBarsWidth { get; set; } = 250; public int TransferBarsWidth { get; set; } = 250;
public bool UseAlternativeFileUpload { get; set; } = false; public bool UseAlternativeFileUpload { get; set; } = false;
public bool UseCompactor { get; set; } = false; public bool UseCompactor { get; set; } = false;
public bool DebugStopWhining { get; set; } = false;
public int Version { get; set; } = 1; public int Version { get; set; } = 1;
public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both; public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both;
} }

View File

@@ -31,19 +31,18 @@ namespace MareSynchronos;
public sealed class Plugin : IDalamudPlugin public sealed class Plugin : IDalamudPlugin
{ {
private readonly CancellationTokenSource _pluginCts = new(); private readonly IHost _host;
private readonly Task _hostBuilderRunTask;
public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData, public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData,
IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui, IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui,
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager) IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager)
{ {
_hostBuilderRunTask = new HostBuilder() _host = new HostBuilder()
.UseContentRoot(pluginInterface.ConfigDirectory.FullName) .UseContentRoot(pluginInterface.ConfigDirectory.FullName)
.ConfigureLogging(lb => .ConfigureLogging(lb =>
{ {
lb.ClearProviders(); lb.ClearProviders();
lb.AddDalamudLogging(pluginLog); lb.AddDalamudLogging(pluginLog, gameData.HasModifiedGameDataFiles);
lb.SetMinimumLevel(LogLevel.Trace); lb.SetMinimumLevel(LogLevel.Trace);
}) })
.ConfigureServices(collection => .ConfigureServices(collection =>
@@ -168,14 +167,14 @@ public sealed class Plugin : IDalamudPlugin
collection.AddHostedService(p => p.GetRequiredService<IpcProvider>()); collection.AddHostedService(p => p.GetRequiredService<IpcProvider>());
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>()); collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
}) })
.Build() .Build();
.RunAsync(_pluginCts.Token);
_ = _host.StartAsync();
} }
public void Dispose() public void Dispose()
{ {
_pluginCts.Cancel(); _host.StopAsync().GetAwaiter().GetResult();
_pluginCts.Dispose(); _host.Dispose();
_hostBuilderRunTask.Wait();
} }
} }

View File

@@ -405,7 +405,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
} }
_uiShared.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended."); _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); using (ImRaii.Disabled(!logPerformance))
{
if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog"))
{ {
_performanceCollector.PrintPerformanceStats(); _performanceCollector.PrintPerformanceStats();
@@ -417,6 +418,14 @@ public class SettingsUi : WindowMediatorSubscriberBase
} }
} }
bool stopWhining = _configService.Current.DebugStopWhining;
if (ImGui.Checkbox("Do not notify for modified game files", ref stopWhining))
{
_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() private void DrawFileStorageSettings()
{ {
_lastTab = "FileCache"; _lastTab = "FileCache";

View File

@@ -4,6 +4,7 @@ using MareSynchronos.API.Data.Extensions;
using MareSynchronos.API.Dto; using MareSynchronos.API.Dto;
using MareSynchronos.API.Dto.User; using MareSynchronos.API.Dto.User;
using MareSynchronos.API.SignalR; using MareSynchronos.API.SignalR;
using MareSynchronos.MareConfiguration;
using MareSynchronos.PlayerData.Pairs; using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services; using MareSynchronos.Services;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
@@ -27,6 +28,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
private readonly PairManager _pairManager; private readonly PairManager _pairManager;
private readonly ServerConfigurationManager _serverManager; private readonly ServerConfigurationManager _serverManager;
private readonly TokenProvider _tokenProvider; private readonly TokenProvider _tokenProvider;
private readonly MareConfigService _mareConfigService;
private CancellationTokenSource _connectionCancellationTokenSource; private CancellationTokenSource _connectionCancellationTokenSource;
private ConnectionDto? _connectionDto; private ConnectionDto? _connectionDto;
private bool _doNotNotifyOnNextInfo = false; private bool _doNotNotifyOnNextInfo = false;
@@ -39,13 +41,14 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
public ApiController(ILogger<ApiController> logger, HubFactory hubFactory, DalamudUtilService dalamudUtil, public ApiController(ILogger<ApiController> logger, HubFactory hubFactory, DalamudUtilService dalamudUtil,
PairManager pairManager, ServerConfigurationManager serverManager, MareMediator mediator, PairManager pairManager, ServerConfigurationManager serverManager, MareMediator mediator,
TokenProvider tokenProvider) : base(logger, mediator) TokenProvider tokenProvider, MareConfigService mareConfigService) : base(logger, mediator)
{ {
_hubFactory = hubFactory; _hubFactory = hubFactory;
_dalamudUtil = dalamudUtil; _dalamudUtil = dalamudUtil;
_pairManager = pairManager; _pairManager = pairManager;
_serverManager = serverManager; _serverManager = serverManager;
_tokenProvider = tokenProvider; _tokenProvider = tokenProvider;
_mareConfigService = mareConfigService;
_connectionCancellationTokenSource = new CancellationTokenSource(); _connectionCancellationTokenSource = new CancellationTokenSource();
Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn()); Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
@@ -208,6 +211,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
if (_dalamudUtil.HasModifiedGameFiles) if (_dalamudUtil.HasModifiedGameFiles)
{ {
Logger.LogError("Detected modified game files on connection"); Logger.LogError("Detected modified game files on connection");
if (!_mareConfigService.Current.DebugStopWhining)
Mediator.Publish(new NotificationMessage("Modified Game Files detected", 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. " + "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.", "Exit the game and repair it through XIVLauncher to get rid of this message.",