diff --git a/MareSynchronos/FileCache/FileCacheManager.cs b/MareSynchronos/FileCache/FileCacheManager.cs index 66f8609..7e134bf 100644 --- a/MareSynchronos/FileCache/FileCacheManager.cs +++ b/MareSynchronos/FileCache/FileCacheManager.cs @@ -383,6 +383,7 @@ public sealed class FileCacheManager : IHostedService public Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("Starting FileCacheManager"); + lock (_fileWriteLock) { try @@ -413,6 +414,13 @@ public sealed class FileCacheManager : IHostedService if (File.Exists(_csvPath)) { + if (!_ipcManager.Penumbra.APIAvailable || string.IsNullOrEmpty(_ipcManager.Penumbra.ModDirectory)) + { + _mareMediator.Publish(new NotificationMessage("Penumbra not connected", + "Could not load local file cache data. Penumbra is not connected or not properly set up. Please enable and/or configure Penumbra properly to use Mare. After, reload Mare in the Plugin installer.", + MareConfiguration.Models.NotificationType.Error)); + } + _logger.LogInformation("{csvPath} found, parsing", _csvPath); bool success = false; diff --git a/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs b/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs index 1277c18..104ebce 100644 --- a/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs +++ b/MareSynchronos/Interop/Ipc/IpcCallerPenumbra.cs @@ -103,7 +103,14 @@ public sealed class IpcCallerPenumbra : DisposableMediatorSubscriberBase, IIpcCa .FirstOrDefault(p => string.Equals(p.InternalName, "Penumbra", StringComparison.OrdinalIgnoreCase)) ?.Version ?? new Version(0, 0, 0, 0)); penumbraAvailable = penumbraVersion >= new Version(1, 1, 0, 0); - penumbraAvailable &= _penumbraEnabled.Invoke(); + try + { + penumbraAvailable &= _penumbraEnabled.Invoke(); + } + catch + { + penumbraAvailable = false; + } _shownPenumbraUnavailable = _shownPenumbraUnavailable && !penumbraAvailable; APIAvailable = penumbraAvailable; } diff --git a/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs b/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs index f347b2f..094f687 100644 --- a/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs +++ b/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs @@ -43,7 +43,10 @@ public class PlayerDataFactory { if (!_ipcManager.Initialized) { - throw new InvalidOperationException("Penumbra is not connected"); + _mareMediator.Publish(new NotificationMessage("Penumbra/Glamourer inactive", + "Mare attempted to process building your character data, but Penumbra or Glamourer are inactive. Enable and set up Penumbra and Glamourer for Mare to be able to function.", + NotificationType.Error)); + throw new InvalidOperationException("Penumbra or Glamourer is not connected"); } if (playerRelatedObject == null) return; diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 240b266..82ebf42 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -106,7 +106,8 @@ public sealed class Plugin : IDalamudPlugin s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); - + collection.AddSingleton((s) => new NotificationService(s.GetRequiredService>(), + s.GetRequiredService(), notificationManager, chatGui, s.GetRequiredService())); collection.AddSingleton((s) => new MareConfigService(pluginInterface.ConfigDirectory.FullName)); collection.AddSingleton((s) => new ServerConfigService(pluginInterface.ConfigDirectory.FullName)); collection.AddSingleton((s) => new NotesConfigService(pluginInterface.ConfigDirectory.FullName)); @@ -149,14 +150,13 @@ public sealed class Plugin : IDalamudPlugin collection.AddScoped((s) => new CommandManagerService(commandManager, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); - collection.AddScoped((s) => new NotificationService(s.GetRequiredService>(), - s.GetRequiredService(), notificationManager, chatGui, s.GetRequiredService())); collection.AddScoped((s) => new UiSharedService(s.GetRequiredService>(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), pluginInterface, textureProvider, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); - collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); + collection.AddHostedService(p => p.GetRequiredService()); + collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); diff --git a/MareSynchronos/Services/NotificationService.cs b/MareSynchronos/Services/NotificationService.cs index 0e16930..34053f2 100644 --- a/MareSynchronos/Services/NotificationService.cs +++ b/MareSynchronos/Services/NotificationService.cs @@ -4,12 +4,13 @@ using Dalamud.Plugin.Services; using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration.Models; using MareSynchronos.Services.Mediator; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NotificationType = MareSynchronos.MareConfiguration.Models.NotificationType; namespace MareSynchronos.Services; -public class NotificationService : DisposableMediatorSubscriberBase +public class NotificationService : DisposableMediatorSubscriberBase, IHostedService { private readonly INotificationManager _notificationManager; private readonly IChatGui _chatGui; @@ -21,8 +22,17 @@ public class NotificationService : DisposableMediatorSubscriberBase _notificationManager = notificationManager; _chatGui = chatGui; _configurationService = configurationService; + } + public Task StartAsync(CancellationToken cancellationToken) + { Mediator.Subscribe(this, ShowNotification); + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; } private void PrintErrorChat(string? message) diff --git a/MareSynchronos/Services/XivDataAnalyzer.cs b/MareSynchronos/Services/XivDataAnalyzer.cs index 151810a..1e09228 100644 --- a/MareSynchronos/Services/XivDataAnalyzer.cs +++ b/MareSynchronos/Services/XivDataAnalyzer.cs @@ -203,6 +203,8 @@ public sealed class XivDataAnalyzer } catch (Exception e) { + _configService.Current.TriangleDictionary[hash] = 0; + _configService.Save(); _logger.LogWarning(e, "Could not parse file {file}", filePath); return Task.FromResult((long)0); }