improve:信息保存

This commit is contained in:
2026-01-17 16:51:28 +08:00
parent 84167bbcfc
commit c4230a15c9
2 changed files with 34 additions and 22 deletions
+17
View File
@@ -960,6 +960,23 @@ namespace Ink_Canvas.Helpers
} }
} }
/// <summary>
/// 获取上次更新检查时间
/// </summary>
public static DateTime GetLastUpdateCheck()
{
try
{
var stats = LoadUsageStats();
return stats.LastUpdateCheck;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 获取上次更新检查时间失败: {ex.Message}", LogHelper.LogType.Error);
return DateTime.MinValue;
}
}
/// <summary> /// <summary>
/// 从备份文件恢复使用统计数据 /// 从备份文件恢复使用统计数据
@@ -53,11 +53,8 @@ namespace Ink_Canvas.Windows.SettingsViews
{ {
try try
{ {
var lastCheckTimePath = Path.Combine(App.RootPath, "last_update_check.dat"); var lastCheckTime = DeviceIdentifier.GetLastUpdateCheck();
if (File.Exists(lastCheckTimePath)) if (lastCheckTime != DateTime.MinValue)
{
var timeStr = File.ReadAllText(lastCheckTimePath);
if (DateTime.TryParse(timeStr, out var lastCheckTime))
{ {
var now = DateTime.Now; var now = DateTime.Now;
var timeDiff = now - lastCheckTime; var timeDiff = now - lastCheckTime;
@@ -76,7 +73,6 @@ namespace Ink_Canvas.Windows.SettingsViews
} }
return; return;
} }
}
LastCheckTimeText.Text = "上次检查时间: 从未"; LastCheckTimeText.Text = "上次检查时间: 从未";
} }
catch catch
@@ -89,8 +85,7 @@ namespace Ink_Canvas.Windows.SettingsViews
{ {
try try
{ {
var lastCheckTimePath = Path.Combine(App.RootPath, "last_update_check.dat"); DeviceIdentifier.RecordUpdateCheck();
File.WriteAllText(lastCheckTimePath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
LoadLastCheckTime(); LoadLastCheckTime();
} }
catch (Exception ex) catch (Exception ex)