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 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>(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)

View File

@@ -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()

View File

@@ -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<ILoggerProvider, DalamudLoggingProvider>
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog)));
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog, hasModifiedGameFiles)));
return builder;
}

View File

@@ -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;
}

View File

@@ -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<IpcProvider>());
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
})
.Build()
.RunAsync(_pluginCts.Token);
.Build();
_ = _host.StartAsync();
}
public void Dispose()
{
_pluginCts.Cancel();
_pluginCts.Dispose();
_hostBuilderRunTask.Wait();
_host.StopAsync().GetAwaiter().GetResult();
_host.Dispose();
}
}

View File

@@ -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()

View File

@@ -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<ApiController> 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<DalamudLoginMessage>(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);