Make the ChatTwo→HellionChat migration loud about locked files

A tester migrating from upstream Chat 2 ended up with a zero-row
database in the new layout: Chat 2 was still loaded when Hellion
Chat first started, the SQLite handle kept chat-sqlite.db locked,
and File.Move silently fell into the catch-all without telling
the user anything. Anyone hitting this would think Hellion Chat
lost their history when it just hadn't been allowed to take it.

Wrap each move on its own so a single locked file no longer
abandons the rest of the migration: the JSON config, font cache
and EmoteCacheV1 directory still travel even if the database
itself is held open. When any IOException fires during the moves,
flag a sticky 30-second warning notification on plugin start that
tells the user exactly what's going on — disable Chat 2, fully
close the game, restart — and points at the README troubleshooting
section.

The README now spells out the migration order step by step in two
sections (fresh install vs. coming from Chat 2) and includes the
manual mv/Move-Item one-liner for both Linux and Windows so users
can recover without waiting for the next plugin update.
This commit is contained in:
2026-05-01 23:22:02 +02:00
parent 2ad81cc3ef
commit cb90c6ab93
2 changed files with 131 additions and 36 deletions
+77 -30
View File
@@ -272,61 +272,108 @@ public sealed class Plugin : IDalamudPlugin
private static void MigrateFromChatTwoLayout()
{
var pluginConfigsDir = Interface.ConfigDirectory.Parent?.FullName;
if (pluginConfigsDir is null)
return;
var legacyConfigFile = Path.Combine(pluginConfigsDir, "ChatTwo.json");
var legacyConfigDir = Path.Combine(pluginConfigsDir, "ChatTwo");
var ourConfigFile = Path.Combine(pluginConfigsDir, "HellionChat.json");
var ourConfigDir = Interface.ConfigDirectory.FullName;
// Track whether anything legitimately blocked us. The most common
// cause is upstream Chat 2 still being loaded — its SQLite handle
// keeps chat-sqlite.db locked and File.Move throws IOException.
var lockedBlocker = false;
try
{
var pluginConfigsDir = Interface.ConfigDirectory.Parent?.FullName;
if (pluginConfigsDir is null)
return;
var legacyConfigFile = Path.Combine(pluginConfigsDir, "ChatTwo.json");
var legacyConfigDir = Path.Combine(pluginConfigsDir, "ChatTwo");
var ourConfigFile = Path.Combine(pluginConfigsDir, "HellionChat.json");
var ourConfigDir = Interface.ConfigDirectory.FullName;
if (!File.Exists(ourConfigFile) && File.Exists(legacyConfigFile))
{
File.Move(legacyConfigFile, ourConfigFile);
Log.Information($"HellionChat: migrated config file {legacyConfigFile} → {ourConfigFile}");
}
}
catch (IOException e)
{
Log.Warning(e, $"HellionChat: config file move blocked, leaving {legacyConfigFile} in place");
lockedBlocker = true;
}
// 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))
// 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. Each move is wrapped on its
// own so a single locked file (the SQLite db while ChatTwo still
// runs) does not abandon the rest of the migration.
if (!Directory.Exists(legacyConfigDir))
return;
try
{
Directory.CreateDirectory(ourConfigDir);
foreach (var file in Directory.EnumerateFiles(legacyConfigDir))
{
Directory.CreateDirectory(ourConfigDir);
foreach (var file in Directory.EnumerateFiles(legacyConfigDir))
var target = Path.Combine(ourConfigDir, Path.GetFileName(file));
if (File.Exists(target))
continue;
try
{
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))
catch (IOException e)
{
Log.Warning(e, $"HellionChat: file move blocked for {file}, will retry on next load");
lockedBlocker = true;
}
}
foreach (var dir in Directory.EnumerateDirectories(legacyConfigDir))
{
var target = Path.Combine(ourConfigDir, Path.GetFileName(dir));
if (Directory.Exists(target))
continue;
try
{
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())
catch (IOException e)
{
Directory.Delete(legacyConfigDir);
Log.Information($"HellionChat: removed empty legacy dir {legacyConfigDir}");
Log.Warning(e, $"HellionChat: subdir move blocked for {dir}, will retry on next load");
lockedBlocker = true;
}
}
if (!Directory.EnumerateFileSystemEntries(legacyConfigDir).Any())
{
Directory.Delete(legacyConfigDir);
Log.Information($"HellionChat: removed empty legacy dir {legacyConfigDir}");
}
}
catch (Exception e)
{
Log.Error(e, "HellionChat: layout migration failed, continuing with whatever exists");
}
if (lockedBlocker)
{
// Surface the most common cause to the user as a notification
// so they don't think Hellion Chat lost their history when in
// fact upstream Chat 2 was still holding the database file.
Notification.AddNotification(new Dalamud.Interface.ImGuiNotification.Notification
{
Title = "Hellion Chat",
Content = "Could not migrate the Chat 2 database — the file appears to be in use. " +
"Disable Chat 2, fully close the game, then start it again. " +
"See the README troubleshooting section if the issue persists.",
Type = Dalamud.Interface.ImGuiNotification.NotificationType.Warning,
InitialDuration = TimeSpan.FromSeconds(30),
});
}
}
private void OpenMainUi()