优化代码
This commit is contained in:
@@ -431,7 +431,7 @@ namespace Ink_Canvas
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 优先从 Settings.json 直接读取
|
// 优先从 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))
|
if (File.Exists(settingsPath))
|
||||||
{
|
{
|
||||||
var json = File.ReadAllText(settingsPath);
|
var json = File.ReadAllText(settingsPath);
|
||||||
@@ -829,7 +829,7 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 备份路径更改为软件根目录下的saves/RegistryBackups文件夹
|
// 备份路径更改为软件根目录下的saves/RegistryBackups文件夹
|
||||||
string backupPath = Path.Combine(RootPath, "saves", "RegistryBackups");
|
string backupPath = Path.Combine(RootPath, "Saves", "RegistryBackups");
|
||||||
LogHelper.WriteLogToFile($"备份路径: {backupPath}");
|
LogHelper.WriteLogToFile($"备份路径: {backupPath}");
|
||||||
|
|
||||||
if (!Directory.Exists(backupPath))
|
if (!Directory.Exists(backupPath))
|
||||||
@@ -1343,7 +1343,7 @@ namespace Ink_Canvas
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 准备备份目录
|
// 准备备份目录
|
||||||
string backupPath = Path.Combine(RootPath, "saves", "RegistryBackups");
|
string backupPath = Path.Combine(RootPath, "Saves", "RegistryBackups");
|
||||||
if (!Directory.Exists(backupPath))
|
if (!Directory.Exists(backupPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(backupPath);
|
Directory.CreateDirectory(backupPath);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
// 文件路径策略
|
// 文件路径策略
|
||||||
private static readonly string DeviceIdFilePath = Path.Combine(App.RootPath, "device_id.dat");
|
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 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 string DeviceId;
|
||||||
private static readonly object fileLock = new object();
|
private static readonly object fileLock = new object();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
private bool _hotkeysShouldBeRegistered = true; // 启动时注册热键
|
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
|
#endregion
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
@@ -30,6 +30,9 @@ namespace Ink_Canvas.Helpers
|
|||||||
_mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow));
|
_mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow));
|
||||||
_registeredHotkeys = new Dictionary<string, HotkeyInfo>();
|
_registeredHotkeys = new Dictionary<string, HotkeyInfo>();
|
||||||
_hotkeysShouldBeRegistered = true; // 启动时注册热键
|
_hotkeysShouldBeRegistered = true; // 启动时注册热键
|
||||||
|
|
||||||
|
// 启动时确保配置文件存在
|
||||||
|
EnsureConfigFileExists();
|
||||||
}
|
}
|
||||||
#endregion
|
#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>
|
||||||
/// 创建默认的快捷键配置文件
|
/// 创建默认的快捷键配置文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace Ink_Canvas.Helpers.Plugins
|
|||||||
public class PluginManager
|
public class PluginManager
|
||||||
{
|
{
|
||||||
private static readonly string PluginsDirectory = Path.Combine(App.RootPath, "Plugins");
|
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 PluginConfigFile = Path.Combine(App.RootPath, "Configs", "PluginConfig.json");
|
||||||
private static readonly string PluginConfigBackupFile = Path.Combine(App.RootPath, "PluginConfig.json.bak");
|
private static readonly string PluginConfigBackupFile = Path.Combine(App.RootPath, "Configs", "PluginConfig.json.bak");
|
||||||
|
|
||||||
private static PluginManager _instance;
|
private static PluginManager _instance;
|
||||||
private static SemaphoreSlim _configLock = new SemaphoreSlim(1, 1);
|
private static SemaphoreSlim _configLock = new SemaphoreSlim(1, 1);
|
||||||
@@ -79,8 +79,6 @@ namespace Ink_Canvas.Helpers.Plugins
|
|||||||
Directory.CreateDirectory(PluginsDirectory);
|
Directory.CreateDirectory(PluginsDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载插件配置
|
|
||||||
LoadConfig();
|
|
||||||
|
|
||||||
// 初始化自动保存计时器(3秒)
|
// 初始化自动保存计时器(3秒)
|
||||||
_autoSaveTimer = new Timer(3000);
|
_autoSaveTimer = new Timer(3000);
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ namespace Ink_Canvas
|
|||||||
#region Definations and Loading
|
#region Definations and Loading
|
||||||
|
|
||||||
public static Settings Settings = new Settings();
|
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 isLoaded;
|
||||||
private bool forcePointEraser;
|
private bool forcePointEraser;
|
||||||
|
|
||||||
@@ -417,7 +417,7 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
if (needFix)
|
if (needFix)
|
||||||
{
|
{
|
||||||
string newPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "saves");
|
string newPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves");
|
||||||
Settings.Automation.AutoSavedStrokesLocation = newPath;
|
Settings.Automation.AutoSavedStrokesLocation = newPath;
|
||||||
if (!Directory.Exists(newPath))
|
if (!Directory.Exists(newPath))
|
||||||
Directory.CreateDirectory(newPath);
|
Directory.CreateDirectory(newPath);
|
||||||
|
|||||||
@@ -2762,6 +2762,12 @@ namespace Ink_Canvas
|
|||||||
var text = JsonConvert.SerializeObject(Settings, Formatting.Indented);
|
var text = JsonConvert.SerializeObject(Settings, Formatting.Indented);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
string configsDir = Path.Combine(App.RootPath, "Configs");
|
||||||
|
if (!Directory.Exists(configsDir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(configsDir);
|
||||||
|
}
|
||||||
|
|
||||||
File.WriteAllText(App.RootPath + settingsFileName, text);
|
File.WriteAllText(App.RootPath + settingsFileName, text);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ namespace Ink_Canvas
|
|||||||
public int MinimumAutomationStrokeNumber { get; set; }
|
public int MinimumAutomationStrokeNumber { get; set; }
|
||||||
|
|
||||||
[JsonProperty("autoSavedStrokesLocation")]
|
[JsonProperty("autoSavedStrokesLocation")]
|
||||||
public string AutoSavedStrokesLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "saves");
|
public string AutoSavedStrokesLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves");
|
||||||
|
|
||||||
[JsonProperty("autoDelSavedFiles")]
|
[JsonProperty("autoDelSavedFiles")]
|
||||||
public bool AutoDelSavedFiles;
|
public bool AutoDelSavedFiles;
|
||||||
|
|||||||
Reference in New Issue
Block a user