diff --git a/MareSynchronos/FileCacheDB/FileCacheContext.cs b/MareSynchronos/FileCacheDB/FileCacheContext.cs index 98c07a5..98f56f3 100644 --- a/MareSynchronos/FileCacheDB/FileCacheContext.cs +++ b/MareSynchronos/FileCacheDB/FileCacheContext.cs @@ -1,5 +1,7 @@ using System; using System.IO; +using Dalamud.Logging; +using MareSynchronos.Utils; using Microsoft.EntityFrameworkCore; #nullable disable @@ -24,7 +26,18 @@ namespace MareSynchronos.FileCacheDB { if (!optionsBuilder.IsConfigured) { - string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "XIVLauncher", "pluginConfigs", "FileCacheDebug.db"); + string dbPath = Path.Combine(Plugin.PluginInterface.ConfigDirectory.FullName, "FileCacheDebug.db"); + if(!Directory.Exists(Plugin.PluginInterface.ConfigDirectory.FullName)) + { + Directory.CreateDirectory(Plugin.PluginInterface.ConfigDirectory.FullName); + } + var oldDbPath = Path.Combine(Plugin.PluginInterface.ConfigDirectory.FullName, "..", "FileCacheDebug.db"); + if (File.Exists(oldDbPath)) + { + Logger.Debug("Migrated old path to new path"); + File.Move(oldDbPath, dbPath, true); + } + //PluginLog.Debug("Using Database " + dbPath); optionsBuilder.UseSqlite("Data Source=" + dbPath); } } diff --git a/MareSynchronos/Models/CachedPlayer.cs b/MareSynchronos/Models/CachedPlayer.cs index d4e7ccf..144f145 100644 --- a/MareSynchronos/Models/CachedPlayer.cs +++ b/MareSynchronos/Models/CachedPlayer.cs @@ -43,7 +43,7 @@ public class CachedPlayer } } - private CancellationTokenSource _downloadCancellationTokenSource = new(); + private CancellationTokenSource? _downloadCancellationTokenSource; private string _lastGlamourerData = string.Empty; @@ -93,9 +93,12 @@ public class CachedPlayer await _apiController.DownloadFiles(toDownloadReplacements, downloadToken); } - if (_downloadCancellationTokenSource.Token.IsCancellationRequested) + if (downloadToken.IsCancellationRequested) + { + return; + } - ApplyCharacterData(e.CharacterData, moddedPaths); + ApplyCharacterData(e.CharacterData, moddedPaths); }, downloadToken); } @@ -152,6 +155,7 @@ public class CachedPlayer { Logger.Debug("Restoring state for " + PlayerName); IsVisible = false; + _downloadCancellationTokenSource?.Dispose(); _watcher.RemovePlayerFromWatch(PlayerName); _ipcManager.PenumbraRemoveTemporaryCollection(PlayerName); _ipcManager.GlamourerRevertCharacterCustomization(PlayerName); diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 0ba1de2..50fc1e8 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -28,7 +28,7 @@ namespace MareSynchronos private readonly IntroUi _introUi; private readonly IpcManager _ipcManager; private readonly ObjectTable _objectTable; - private readonly DalamudPluginInterface _pluginInterface; + public static DalamudPluginInterface PluginInterface { get; set; } private readonly PluginUi _pluginUi; private readonly WindowSystem _windowSystem; private PlayerManager? _characterManager; @@ -41,13 +41,13 @@ namespace MareSynchronos Framework framework, ObjectTable objectTable, ClientState clientState) { Logger.Debug("Launching " + Name); - _pluginInterface = pluginInterface; + PluginInterface = pluginInterface; _commandManager = commandManager; _framework = framework; _objectTable = objectTable; _clientState = clientState; - _configuration = _pluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - _configuration.Initialize(_pluginInterface); + _configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); + _configuration.Initialize(PluginInterface); _windowSystem = new WindowSystem("MareSynchronos"); @@ -55,7 +55,7 @@ namespace MareSynchronos // those can be initialized outside of game login _apiController = new ApiController(_configuration); - _ipcManager = new IpcManager(_pluginInterface); + _ipcManager = new IpcManager(PluginInterface); _fileCacheManager = new FileCacheManager(_ipcManager, _configuration); @@ -121,8 +121,8 @@ namespace MareSynchronos { Logger.Debug("Client login"); - _pluginInterface.UiBuilder.Draw += Draw; - _pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi; + PluginInterface.UiBuilder.Draw += Draw; + PluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi; _commandManager.AddHandler(CommandName, new CommandInfo(OnCommand) { HelpMessage = "Opens the Mare Synchronos UI" @@ -142,8 +142,8 @@ namespace MareSynchronos Logger.Debug("Client logout"); _characterCacheManager?.Dispose(); _characterManager?.Dispose(); - _pluginInterface.UiBuilder.Draw -= Draw; - _pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi; + PluginInterface.UiBuilder.Draw -= Draw; + PluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi; _commandManager.RemoveHandler(CommandName); }