refactor(settings-refactor): regroup Database tab into storage, viewer, stats tree nodes
This commit is contained in:
+5
@@ -228,4 +228,9 @@ internal class HellionStrings
|
|||||||
internal static string Settings_Chat_Behaviour_Heading => Get(nameof(Settings_Chat_Behaviour_Heading));
|
internal static string Settings_Chat_Behaviour_Heading => Get(nameof(Settings_Chat_Behaviour_Heading));
|
||||||
internal static string Settings_Chat_Preview_Heading => Get(nameof(Settings_Chat_Preview_Heading));
|
internal static string Settings_Chat_Preview_Heading => Get(nameof(Settings_Chat_Preview_Heading));
|
||||||
internal static string Settings_Chat_Emotes_Heading => Get(nameof(Settings_Chat_Emotes_Heading));
|
internal static string Settings_Chat_Emotes_Heading => Get(nameof(Settings_Chat_Emotes_Heading));
|
||||||
|
|
||||||
|
// Hellion Chat — Database-Tab section headings
|
||||||
|
internal static string Settings_Database_Storage_Heading => Get(nameof(Settings_Database_Storage_Heading));
|
||||||
|
internal static string Settings_Database_Viewer_Heading => Get(nameof(Settings_Database_Viewer_Heading));
|
||||||
|
internal static string Settings_Database_Stats_Heading => Get(nameof(Settings_Database_Stats_Heading));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -522,4 +522,15 @@
|
|||||||
<data name="Settings_Chat_Emotes_Heading" xml:space="preserve">
|
<data name="Settings_Chat_Emotes_Heading" xml:space="preserve">
|
||||||
<value>Emotes</value>
|
<value>Emotes</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
<!-- Hellion Chat — Sektions-Überschriften des Database-Tabs -->
|
||||||
|
<data name="Settings_Database_Storage_Heading" xml:space="preserve">
|
||||||
|
<value>Speicherung</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Database_Viewer_Heading" xml:space="preserve">
|
||||||
|
<value>DB-Viewer</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Database_Stats_Heading" xml:space="preserve">
|
||||||
|
<value>Statistiken</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -522,4 +522,15 @@
|
|||||||
<data name="Settings_Chat_Emotes_Heading" xml:space="preserve">
|
<data name="Settings_Chat_Emotes_Heading" xml:space="preserve">
|
||||||
<value>Emotes</value>
|
<value>Emotes</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
<!-- Hellion Chat — Database-Tab section headings -->
|
||||||
|
<data name="Settings_Database_Storage_Heading" xml:space="preserve">
|
||||||
|
<value>Storage</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Database_Viewer_Heading" xml:space="preserve">
|
||||||
|
<value>DB Viewer</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Database_Stats_Heading" xml:space="preserve">
|
||||||
|
<value>Statistics</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
@@ -33,127 +33,158 @@ internal sealed class Database : ISettingsTab
|
|||||||
|
|
||||||
public void Draw(bool changed)
|
public void Draw(bool changed)
|
||||||
{
|
{
|
||||||
|
// Shift-on-open keeps the Advanced tools available without a permanent
|
||||||
|
// toggle in the UI, mirroring upstream Chat 2 behaviour.
|
||||||
if (changed)
|
if (changed)
|
||||||
ShowAdvanced = ImGui.GetIO().KeyShift;
|
ShowAdvanced = ImGui.GetIO().KeyShift;
|
||||||
|
|
||||||
ImGuiUtil.OptionCheckbox(ref Mutable.DatabaseBattleMessages, Language.Options_DatabaseBattleMessages_Name, Language.Options_DatabaseBattleMessages_Description);
|
DrawStorageSection();
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
DrawViewerSection();
|
||||||
if (ImGuiUtil.OptionCheckbox(ref Mutable.LoadPreviousSession, Language.Options_LoadPreviousSession_Name, Language.Options_LoadPreviousSession_Description))
|
|
||||||
if (Mutable.LoadPreviousSession)
|
|
||||||
Mutable.FilterIncludePreviousSessions = true;
|
|
||||||
|
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
|
DrawStatsSection();
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGuiUtil.OptionCheckbox(ref Mutable.FilterIncludePreviousSessions, Language.Options_FilterIncludePreviousSessions_Name, Language.Options_FilterIncludePreviousSessions_Description))
|
private void DrawStorageSection()
|
||||||
if (!Mutable.FilterIncludePreviousSessions)
|
{
|
||||||
Mutable.LoadPreviousSession = false;
|
using var tree = ImRaii.TreeNode(HellionStrings.Settings_Database_Storage_Heading);
|
||||||
|
if (!tree.Success)
|
||||||
|
return;
|
||||||
|
|
||||||
ImGui.Spacing();
|
|
||||||
ImGui.Separator();
|
|
||||||
ImGui.Spacing();
|
|
||||||
|
|
||||||
var old = new FileInfo(Path.Join(Plugin.Interface.ConfigDirectory.FullName, "chat.db"));
|
|
||||||
var migratedOld = new FileInfo(Path.Join(Plugin.Interface.ConfigDirectory.FullName, "chat-litedb.db"));
|
|
||||||
if (old.Exists || migratedOld.Exists)
|
|
||||||
{
|
|
||||||
ImGui.TextUnformatted(Language.Options_Database_Old_Heading);
|
|
||||||
ImGui.Spacing();
|
|
||||||
|
|
||||||
if (ImGuiUtil.CtrlShiftButton(Language.Options_Database_Old_Delete, Language.Options_Database_Old_Delete_Tooltip))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (old.Exists)
|
|
||||||
old.Delete();
|
|
||||||
else
|
|
||||||
migratedOld.Delete();
|
|
||||||
WrapperUtil.AddNotification(Language.Options_Database_Old_Delete_Success, NotificationType.Success);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Plugin.Log.Error(e, "Unable to delete old database");
|
|
||||||
WrapperUtil.AddNotification(Language.Options_Database_Old_Delete_Error, NotificationType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.Spacing();
|
|
||||||
ImGui.Separator();
|
|
||||||
ImGui.Spacing();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.TextUnformatted(Language.Options_Database_Metadata_Heading);
|
|
||||||
using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false))
|
using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false))
|
||||||
{
|
{
|
||||||
// Refresh the database size and message count every 5 seconds to avoid
|
ImGui.Checkbox(Language.Options_DatabaseBattleMessages_Name, ref Mutable.DatabaseBattleMessages);
|
||||||
// constant stat calls and spamming the database.
|
ImGuiUtil.HelpMarker(Language.Options_DatabaseBattleMessages_Description);
|
||||||
if (DatabaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64)
|
|
||||||
|
if (ImGui.Checkbox(Language.Options_LoadPreviousSession_Name, ref Mutable.LoadPreviousSession))
|
||||||
|
if (Mutable.LoadPreviousSession)
|
||||||
|
Mutable.FilterIncludePreviousSessions = true;
|
||||||
|
ImGuiUtil.HelpMarker(Language.Options_LoadPreviousSession_Description);
|
||||||
|
|
||||||
|
if (ImGui.Checkbox(Language.Options_FilterIncludePreviousSessions_Name, ref Mutable.FilterIncludePreviousSessions))
|
||||||
|
if (!Mutable.FilterIncludePreviousSessions)
|
||||||
|
Mutable.LoadPreviousSession = false;
|
||||||
|
ImGuiUtil.HelpMarker(Language.Options_FilterIncludePreviousSessions_Description);
|
||||||
|
|
||||||
|
var old = new FileInfo(Path.Join(Plugin.Interface.ConfigDirectory.FullName, "chat.db"));
|
||||||
|
var migratedOld = new FileInfo(Path.Join(Plugin.Interface.ConfigDirectory.FullName, "chat-litedb.db"));
|
||||||
|
if (old.Exists || migratedOld.Exists)
|
||||||
{
|
{
|
||||||
DatabaseSize = Plugin.MessageManager.Store.DatabaseSize();
|
ImGui.Spacing();
|
||||||
DatabaseLogSize = Plugin.MessageManager.Store.DatabaseLogSize();
|
ImGui.Separator();
|
||||||
DatabaseMessageCount = Plugin.MessageManager.Store.MessageCount();
|
ImGui.Spacing();
|
||||||
DatabaseLastRefreshTicks = Environment.TickCount64;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the directory path instead of the file path so people can
|
ImGui.TextUnformatted(Language.Options_Database_Old_Heading);
|
||||||
// paste it into their file explorer.
|
ImGui.Spacing();
|
||||||
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, MessageManager.DatabasePath()));
|
|
||||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
|
|
||||||
{
|
|
||||||
var path = Path.GetDirectoryName(MessageManager.DatabasePath());
|
|
||||||
ImGui.SetClipboardText(path);
|
|
||||||
WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGuiUtil.CtrlShiftButton(Language.Options_Database_Old_Delete, Language.Options_Database_Old_Delete_Tooltip))
|
||||||
{
|
{
|
||||||
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
|
try
|
||||||
ImGuiUtil.Tooltip(Language.Options_Database_Metadata_CopyConfigPath);
|
{
|
||||||
}
|
if (old.Exists)
|
||||||
|
old.Delete();
|
||||||
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize)));
|
else
|
||||||
if (ImGui.IsItemHovered())
|
migratedOld.Delete();
|
||||||
ImGuiUtil.Tooltip(StringUtil.BytesToString(DatabaseSize));
|
WrapperUtil.AddNotification(Language.Options_Database_Old_Delete_Success, NotificationType.Success);
|
||||||
|
}
|
||||||
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize)));
|
catch (Exception e)
|
||||||
if (ImGui.IsItemHovered())
|
{
|
||||||
ImGuiUtil.Tooltip(StringUtil.BytesToString(DatabaseLogSize));
|
Plugin.Log.Error(e, "Unable to delete old database");
|
||||||
|
WrapperUtil.AddNotification(Language.Options_Database_Old_Delete_Error, NotificationType.Error);
|
||||||
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount));
|
}
|
||||||
|
}
|
||||||
if (ImGuiUtil.CtrlShiftButton(Language.Options_ClearDatabase_Button, Language.Options_ClearDatabase_Tooltip))
|
|
||||||
{
|
|
||||||
Plugin.Log.Warning("Clearing messages from database");
|
|
||||||
Plugin.MessageManager.Store.ClearMessages();
|
|
||||||
Plugin.MessageManager.ClearAllTabs();
|
|
||||||
|
|
||||||
// Refresh on next draw
|
|
||||||
DatabaseLastRefreshTicks = 0;
|
|
||||||
WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.Spacing();
|
private void DrawViewerSection()
|
||||||
|
{
|
||||||
|
using var tree = ImRaii.TreeNode(HellionStrings.Settings_Database_Viewer_Heading);
|
||||||
|
if (!tree.Success)
|
||||||
|
return;
|
||||||
|
|
||||||
|
using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false))
|
||||||
|
{
|
||||||
|
ImGui.TextUnformatted(Language.Options_Database_Metadata_Heading);
|
||||||
|
using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false))
|
||||||
|
{
|
||||||
|
// Refresh the database size and message count every 5 seconds to avoid
|
||||||
|
// constant stat calls and spamming the database.
|
||||||
|
if (DatabaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64)
|
||||||
|
{
|
||||||
|
DatabaseSize = Plugin.MessageManager.Store.DatabaseSize();
|
||||||
|
DatabaseLogSize = Plugin.MessageManager.Store.DatabaseLogSize();
|
||||||
|
DatabaseMessageCount = Plugin.MessageManager.Store.MessageCount();
|
||||||
|
DatabaseLastRefreshTicks = Environment.TickCount64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the directory path instead of the file path so people can
|
||||||
|
// paste it into their file explorer.
|
||||||
|
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, MessageManager.DatabasePath()));
|
||||||
|
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
|
||||||
|
{
|
||||||
|
var path = Path.GetDirectoryName(MessageManager.DatabasePath());
|
||||||
|
ImGui.SetClipboardText(path);
|
||||||
|
WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
{
|
||||||
|
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
|
||||||
|
ImGuiUtil.Tooltip(Language.Options_Database_Metadata_CopyConfigPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize)));
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
ImGuiUtil.Tooltip(StringUtil.BytesToString(DatabaseSize));
|
||||||
|
|
||||||
|
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize)));
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
ImGuiUtil.Tooltip(StringUtil.BytesToString(DatabaseLogSize));
|
||||||
|
|
||||||
|
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount));
|
||||||
|
|
||||||
|
if (ImGuiUtil.CtrlShiftButton(Language.Options_ClearDatabase_Button, Language.Options_ClearDatabase_Tooltip))
|
||||||
|
{
|
||||||
|
Plugin.Log.Warning("Clearing messages from database");
|
||||||
|
Plugin.MessageManager.Store.ClearMessages();
|
||||||
|
Plugin.MessageManager.ClearAllTabs();
|
||||||
|
|
||||||
|
// Refresh on next draw
|
||||||
|
DatabaseLastRefreshTicks = 0;
|
||||||
|
WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawStatsSection()
|
||||||
|
{
|
||||||
if (!ShowAdvanced)
|
if (!ShowAdvanced)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using var treeNode = ImRaii.TreeNode(Language.Options_Database_Advanced);
|
using var tree = ImRaii.TreeNode(HellionStrings.Settings_Database_Stats_Heading);
|
||||||
using var wrap = ImRaii.TextWrapPos(0.0f);
|
if (!tree.Success)
|
||||||
|
return;
|
||||||
|
|
||||||
ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning);
|
using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false))
|
||||||
if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()"))
|
|
||||||
Plugin.MessageManager.Store.PerformMaintenance();
|
|
||||||
|
|
||||||
if (ImGuiUtil.CtrlShiftButton("Reload messages from database", "Ctrl+Shift: MessageManager.FilterAllTabs()"))
|
|
||||||
{
|
{
|
||||||
Plugin.MessageManager.ClearAllTabs();
|
using var treeNode = ImRaii.TreeNode(Language.Options_Database_Advanced);
|
||||||
Plugin.MessageManager.FilterAllTabsAsync();
|
using var wrap = ImRaii.TextWrapPos(0.0f);
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGuiUtil.CtrlShiftButton("Inject 10,000 messages", "Ctrl+Shift: creates 10,000 unique messages (async)"))
|
ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning);
|
||||||
new Thread(() => InsertMessages(10_000)).Start();
|
if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()"))
|
||||||
ImGui.Spacing();
|
Plugin.MessageManager.Store.PerformMaintenance();
|
||||||
|
|
||||||
|
if (ImGuiUtil.CtrlShiftButton("Reload messages from database", "Ctrl+Shift: MessageManager.FilterAllTabs()"))
|
||||||
|
{
|
||||||
|
Plugin.MessageManager.ClearAllTabs();
|
||||||
|
Plugin.MessageManager.FilterAllTabsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGuiUtil.CtrlShiftButton("Inject 10,000 messages", "Ctrl+Shift: creates 10,000 unique messages (async)"))
|
||||||
|
new Thread(() => InsertMessages(10_000)).Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertMessages(int count)
|
private void InsertMessages(int count)
|
||||||
|
|||||||
Reference in New Issue
Block a user