优化代码
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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<string, HotkeyInfo>();
|
||||
_hotkeysShouldBeRegistered = true; // 启动时注册热键
|
||||
|
||||
// 启动时确保配置文件存在
|
||||
EnsureConfigFileExists();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -500,6 +503,26 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确保配置文件存在,如果不存在则创建
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的快捷键配置文件
|
||||
/// </summary>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user