From f0d6d64666d5f4ac15c4cbffc6bfed7d6aec79a0 Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Fri, 1 May 2026 18:40:06 +0200 Subject: [PATCH] Migrate from ChatTwo layout at file level, not directory level The original migration skipped the database move whenever pluginConfigs/HellionChat already existed. In practice that directory is materialised by Dalamud before our plugin constructor runs, so the check was effectively always true and the legacy chat-sqlite.db plus the EmoteCacheV1 directory stayed behind. Walk the legacy directory entry by entry instead. Move every file or subdirectory whose name is not already present on the target side, then delete the legacy directory if it ends up empty. This handles both fresh installs and the realistic case where Dalamud has pre-created an empty config directory for the new plugin. --- ChatTwo/Plugin.cs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/ChatTwo/Plugin.cs b/ChatTwo/Plugin.cs index beb7713..36ccf6f 100755 --- a/ChatTwo/Plugin.cs +++ b/ChatTwo/Plugin.cs @@ -265,10 +265,38 @@ public sealed class Plugin : IDalamudPlugin Log.Information($"HellionChat: migrated config file {legacyConfigFile} → {ourConfigFile}"); } - if (!Directory.Exists(ourConfigDir) && Directory.Exists(legacyConfigDir)) + // The plugin's ConfigDirectory may already exist on first load + // (Dalamud creates it), so check at the file level instead of + // skipping when the directory is present. Move every legacy + // entry whose target name is not occupied yet, then remove the + // source dir if it ends up empty. + if (Directory.Exists(legacyConfigDir)) { - Directory.Move(legacyConfigDir, ourConfigDir); - Log.Information($"HellionChat: migrated config dir {legacyConfigDir} → {ourConfigDir}"); + Directory.CreateDirectory(ourConfigDir); + + foreach (var file in Directory.EnumerateFiles(legacyConfigDir)) + { + var target = Path.Combine(ourConfigDir, Path.GetFileName(file)); + if (File.Exists(target)) + continue; + File.Move(file, target); + Log.Information($"HellionChat: migrated file {file} → {target}"); + } + + foreach (var dir in Directory.EnumerateDirectories(legacyConfigDir)) + { + var target = Path.Combine(ourConfigDir, Path.GetFileName(dir)); + if (Directory.Exists(target)) + continue; + Directory.Move(dir, target); + Log.Information($"HellionChat: migrated subdir {dir} → {target}"); + } + + if (!Directory.EnumerateFileSystemEntries(legacyConfigDir).Any()) + { + Directory.Delete(legacyConfigDir); + Log.Information($"HellionChat: removed empty legacy dir {legacyConfigDir}"); + } } } catch (Exception e)