From 42e2fe12a40ccd582cf98a9a065695d7506ec53d Mon Sep 17 00:00:00 2001 From: Infi Date: Sun, 21 Apr 2024 01:33:55 +0200 Subject: [PATCH] Add old database section --- ChatTwo/ChatTwo.csproj | 2 +- ChatTwo/MessageManager.cs | 4 +-- ChatTwo/Resources/Language.Designer.cs | 45 ++++++++++++++++++++++++++ ChatTwo/Resources/Language.resx | 15 +++++++++ ChatTwo/Ui/SettingsTabs/Database.cs | 27 +++++++++++++++- 5 files changed, 88 insertions(+), 5 deletions(-) diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index f466723..201b3a9 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -1,6 +1,6 @@ - 1.21.4 + 1.22.0 net8.0-windows enable enable diff --git a/ChatTwo/MessageManager.cs b/ChatTwo/MessageManager.cs index be16553..78d63e2 100644 --- a/ChatTwo/MessageManager.cs +++ b/ChatTwo/MessageManager.cs @@ -56,9 +56,7 @@ internal class MessageManager : IDisposable internal static string DatabasePath() { - var dir = Plugin.Interface.ConfigDirectory; - dir.Create(); - return Path.Join(dir.FullName, "chat-sqlite.db"); + return Path.Join(Plugin.Interface.ConfigDirectory.FullName, "chat-sqlite.db"); } private void Logout() diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index cb6e6a2..22c1b21 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -1787,6 +1787,51 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Delete. + /// + internal static string Options_Database_Old_Delete { + get { + return ResourceManager.GetString("Options_Database_Old_Delete", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unable to remove the old database, more information under /xllog.. + /// + internal static string Options_Database_Old_Delete_Error { + get { + return ResourceManager.GetString("Options_Database_Old_Delete_Error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The old database was successfully removed.. + /// + internal static string Options_Database_Old_Delete_Success { + get { + return ResourceManager.GetString("Options_Database_Old_Delete_Success", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removes the database from your disk. This is not recoverable! Hold Ctrl+Shift to click.. + /// + internal static string Options_Database_Old_Delete_Tooltip { + get { + return ResourceManager.GetString("Options_Database_Old_Delete_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Old database:. + /// + internal static string Options_Database_Old_Heading { + get { + return ResourceManager.GetString("Options_Database_Old_Heading", resourceCulture); + } + } + /// /// Looks up a localized string similar to Database. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index e938260..e53f337 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -994,4 +994,19 @@ An error occurred while loading chat history. Please see plugin logs for more information to report this issue. + + Old database: + + + Delete + + + Removes the database from your disk. This is not recoverable! Hold Ctrl+Shift to click. + + + Unable to remove the old database, more information under /xllog. + + + The old database was successfully removed. + diff --git a/ChatTwo/Ui/SettingsTabs/Database.cs b/ChatTwo/Ui/SettingsTabs/Database.cs index 3441550..0f5e7ed 100755 --- a/ChatTwo/Ui/SettingsTabs/Database.cs +++ b/ChatTwo/Ui/SettingsTabs/Database.cs @@ -54,7 +54,32 @@ internal sealed class Database : ISettingsTab ImGui.Separator(); ImGui.Spacing(); - ImGui.Text(Language.Options_Database_Metadata_Heading); + var old = new FileInfo(Path.Join(Plugin.Interface.ConfigDirectory.FullName, "chat.db")); + if (old.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 + { + old.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); var style = ImGui.GetStyle(); ImGui.Indent(style.IndentSpacing);