diff --git a/Ink Canvas/Helpers/DeviceIdentifier.cs b/Ink Canvas/Helpers/DeviceIdentifier.cs index 274d46e7..0ee14e12 100644 --- a/Ink Canvas/Helpers/DeviceIdentifier.cs +++ b/Ink Canvas/Helpers/DeviceIdentifier.cs @@ -2782,113 +2782,5 @@ namespace Ink_Canvas.Helpers } } } - - /// - /// 加载现有使用统计数据(从主文件或备份) - /// - private static UsageStats LoadUsageStats() - { - // 尝试从主文件加载 - if (File.Exists(UsageStatsFilePath)) - { - try - { - string json = File.ReadAllText(UsageStatsFilePath); - return JsonConvert.DeserializeObject(json); - } - catch - { - // 主文件损坏,尝试从备份加载 - if (File.Exists(BackupUsageStatsPath)) - { - try - { - string backupJson = File.ReadAllText(BackupUsageStatsPath); - return JsonConvert.DeserializeObject(backupJson); - } - catch - { - // 可继续尝试其他备份路径 - return LoadFromOtherBackups(); - } - } - } - } - return null; - } - - /// - /// 从其他备份路径加载数据 - /// - private static UsageStats LoadFromOtherBackups() - { - // 尝试二级备份 - if (File.Exists(SecondaryUsageBackupPath)) - { - try - { - return JsonConvert.DeserializeObject(File.ReadAllText(SecondaryUsageBackupPath)); - } - catch { } - } - - // 尝试三级备份 - if (File.Exists(TertiaryUsageBackupPath)) - { - try - { - return JsonConvert.DeserializeObject(File.ReadAllText(TertiaryUsageBackupPath)); - } - catch { } - } - - // 尝试四级备份 - if (File.Exists(QuaternaryUsageBackupPath)) - { - try - { - return JsonConvert.DeserializeObject(File.ReadAllText(QuaternaryUsageBackupPath)); - } - catch { } - } - - return null; - } - - /// - /// 保存使用统计数据到所有备份位置 - /// - private static void SaveUsageStatsToAllLocations(UsageStats stats) - { - string json = JsonConvert.SerializeObject(stats, Formatting.Indented); - - // 保存到主文件 - SaveToFile(UsageStatsFilePath, json); - // 保存到多重备份路径 - SaveToFile(BackupUsageStatsPath, json); - SaveToFile(SecondaryUsageBackupPath, json); - SaveToFile(TertiaryUsageBackupPath, json); - SaveToFile(QuaternaryUsageBackupPath, json); - } - - /// - /// 辅助方法:保存内容到文件(确保目录存在) - /// - private static void SaveToFile(string path, string content) - { - try - { - string dir = Path.GetDirectoryName(path); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - File.WriteAllText(path, content); - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"保存文件 {path} 失败: {ex.Message}", LogHelper.LogType.Warning); - } - } } }