From 326a9f1d75f43e6d6d1c3381d19d2361398d0c7f Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sat, 13 Sep 2025 21:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/App.xaml.cs | 6 ++--- Ink Canvas/Helpers/DeviceIdentifier.cs | 2 +- Ink Canvas/Helpers/GlobalHotkeyManager.cs | 25 ++++++++++++++++++++- Ink Canvas/Helpers/Plugins/PluginManager.cs | 6 ++--- Ink Canvas/MainWindow.xaml.cs | 4 ++-- Ink Canvas/MainWindow_cs/MW_Settings.cs | 6 +++++ Ink Canvas/Resources/Settings.cs | 2 +- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index b6efba67..9a4cc745 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -431,7 +431,7 @@ namespace Ink_Canvas try { // 优先从 Settings.json 直接读取 - var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.json"); + var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "Settings.json"); if (File.Exists(settingsPath)) { var json = File.ReadAllText(settingsPath); @@ -829,7 +829,7 @@ namespace Ink_Canvas } // 备份路径更改为软件根目录下的saves/RegistryBackups文件夹 - string backupPath = Path.Combine(RootPath, "saves", "RegistryBackups"); + string backupPath = Path.Combine(RootPath, "Saves", "RegistryBackups"); LogHelper.WriteLogToFile($"备份路径: {backupPath}"); if (!Directory.Exists(backupPath)) @@ -1343,7 +1343,7 @@ namespace Ink_Canvas try { // 准备备份目录 - string backupPath = Path.Combine(RootPath, "saves", "RegistryBackups"); + string backupPath = Path.Combine(RootPath, "Saves", "RegistryBackups"); if (!Directory.Exists(backupPath)) { Directory.CreateDirectory(backupPath); diff --git a/Ink Canvas/Helpers/DeviceIdentifier.cs b/Ink Canvas/Helpers/DeviceIdentifier.cs index 4ae80370..0fc47e56 100644 --- a/Ink Canvas/Helpers/DeviceIdentifier.cs +++ b/Ink Canvas/Helpers/DeviceIdentifier.cs @@ -17,7 +17,7 @@ namespace Ink_Canvas.Helpers // 文件路径策略 private static readonly string DeviceIdFilePath = Path.Combine(App.RootPath, "device_id.dat"); private static readonly string UsageStatsFilePath = Path.Combine(App.RootPath, "usage_stats.enc"); - private static readonly string UsageStatsBackupPath = Path.Combine(App.RootPath, "saves", "usage_stats_backup.enc"); + private static readonly string UsageStatsBackupPath = Path.Combine(App.RootPath, "Saves", "usage_stats_backup.enc"); private static readonly string DeviceId; private static readonly object fileLock = new object(); diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index 999016a4..70d6ecb6 100644 --- a/Ink Canvas/Helpers/GlobalHotkeyManager.cs +++ b/Ink Canvas/Helpers/GlobalHotkeyManager.cs @@ -21,7 +21,7 @@ namespace Ink_Canvas.Helpers private bool _hotkeysShouldBeRegistered = true; // 启动时注册热键 // 配置文件路径 - private static readonly string HotkeyConfigFile = Path.Combine(App.RootPath, "HotkeyConfig.json"); + private static readonly string HotkeyConfigFile = Path.Combine(App.RootPath, "Configs", "HotkeyConfig.json"); #endregion #region Constructor @@ -30,6 +30,9 @@ namespace Ink_Canvas.Helpers _mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow)); _registeredHotkeys = new Dictionary(); _hotkeysShouldBeRegistered = true; // 启动时注册热键 + + // 启动时确保配置文件存在 + EnsureConfigFileExists(); } #endregion @@ -500,6 +503,26 @@ namespace Ink_Canvas.Helpers } } + /// + /// 确保配置文件存在,如果不存在则创建 + /// + private void EnsureConfigFileExists() + { + try + { + // 如果配置文件不存在,创建默认配置文件 + if (!File.Exists(HotkeyConfigFile)) + { + LogHelper.WriteLogToFile($"快捷键配置文件不存在,创建默认配置文件: {HotkeyConfigFile}", LogHelper.LogType.Event); + CreateDefaultConfigFile(); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"确保快捷键配置文件存在时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + /// /// 创建默认的快捷键配置文件 /// diff --git a/Ink Canvas/Helpers/Plugins/PluginManager.cs b/Ink Canvas/Helpers/Plugins/PluginManager.cs index 27b7742e..9e018183 100644 --- a/Ink Canvas/Helpers/Plugins/PluginManager.cs +++ b/Ink Canvas/Helpers/Plugins/PluginManager.cs @@ -20,8 +20,8 @@ namespace Ink_Canvas.Helpers.Plugins public class PluginManager { private static readonly string PluginsDirectory = Path.Combine(App.RootPath, "Plugins"); - private static readonly string PluginConfigFile = Path.Combine(App.RootPath, "PluginConfig.json"); - private static readonly string PluginConfigBackupFile = Path.Combine(App.RootPath, "PluginConfig.json.bak"); + private static readonly string PluginConfigFile = Path.Combine(App.RootPath, "Configs", "PluginConfig.json"); + private static readonly string PluginConfigBackupFile = Path.Combine(App.RootPath, "Configs", "PluginConfig.json.bak"); private static PluginManager _instance; private static SemaphoreSlim _configLock = new SemaphoreSlim(1, 1); @@ -79,8 +79,6 @@ namespace Ink_Canvas.Helpers.Plugins Directory.CreateDirectory(PluginsDirectory); } - // 加载插件配置 - LoadConfig(); // 初始化自动保存计时器(3秒) _autoSaveTimer = new Timer(3000); diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 8489e5ca..dbb4c2ea 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -383,7 +383,7 @@ namespace Ink_Canvas #region Definations and Loading public static Settings Settings = new Settings(); - public static string settingsFileName = "Settings.json"; + public static string settingsFileName = Path.Combine("Configs", "Settings.json"); private bool isLoaded; private bool forcePointEraser; @@ -417,7 +417,7 @@ namespace Ink_Canvas } if (needFix) { - string newPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "saves"); + string newPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves"); Settings.Automation.AutoSavedStrokesLocation = newPath; if (!Directory.Exists(newPath)) Directory.CreateDirectory(newPath); diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs index d0bb42dd..fee71d5f 100644 --- a/Ink Canvas/MainWindow_cs/MW_Settings.cs +++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs @@ -2762,6 +2762,12 @@ namespace Ink_Canvas var text = JsonConvert.SerializeObject(Settings, Formatting.Indented); try { + string configsDir = Path.Combine(App.RootPath, "Configs"); + if (!Directory.Exists(configsDir)) + { + Directory.CreateDirectory(configsDir); + } + File.WriteAllText(App.RootPath + settingsFileName, text); } catch { } diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index fd466d93..d1997e4e 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -440,7 +440,7 @@ namespace Ink_Canvas public int MinimumAutomationStrokeNumber { get; set; } [JsonProperty("autoSavedStrokesLocation")] - public string AutoSavedStrokesLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "saves"); + public string AutoSavedStrokesLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves"); [JsonProperty("autoDelSavedFiles")] public bool AutoDelSavedFiles;