diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs
index 2b02dccb..b845042c 100644
--- a/Ink Canvas/MainWindow_cs/MW_PPT.cs
+++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs
@@ -194,9 +194,12 @@ namespace Ink_Canvas {
return;
}
+ // 使用更精确的文件标识符:文件名_页数_文件路径哈希值
+ string presentationPath = presentation.FullName;
+ string fileHash = GetFileHash(presentationPath);
+ string folderName = presentation.Name + "_" + presentation.Slides.Count + "_" + fileHash;
var folderPath = Settings.Automation.AutoSavedStrokesLocation +
- @"\Auto Saved - Presentations\" + presentation.Name + "_" +
- presentation.Slides.Count;
+ @"\Auto Saved - Presentations\" + folderName;
try {
if (!File.Exists(folderPath + "/Position")) return;
if (!int.TryParse(File.ReadAllText(folderPath + "/Position"), out var page)) return;
@@ -560,13 +563,17 @@ namespace Ink_Canvas {
//检查是否有已有墨迹,并加载
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint)
+ {
+ // 使用更精确的文件标识符:文件名_页数_文件路径哈希值
+ string presentationPath = Wn.Presentation.FullName;
+ string fileHash = GetFileHash(presentationPath);
+ string folderName = Wn.Presentation.Name + "_" + Wn.Presentation.Slides.Count + "_" + fileHash;
+
if (Directory.Exists(Settings.Automation.AutoSavedStrokesLocation +
- @"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
- Wn.Presentation.Slides.Count)) {
+ @"\Auto Saved - Presentations\" + folderName)) {
LogHelper.WriteLogToFile("Found saved strokes", LogHelper.LogType.Trace);
var files = new DirectoryInfo(Settings.Automation.AutoSavedStrokesLocation +
- @"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
- Wn.Presentation.Slides.Count).GetFiles();
+ @"\Auto Saved - Presentations\" + folderName).GetFiles();
var count = 0;
foreach (var file in files)
if (file.Name != "Position") {
@@ -586,6 +593,7 @@ namespace Ink_Canvas {
LogHelper.WriteLogToFile($"Loaded {count.ToString()} saved strokes");
}
+ }
StackPanelPPTControls.Visibility = Visibility.Visible;
UpdatePPTBtnDisplaySettingsStatus();
@@ -660,8 +668,11 @@ namespace Ink_Canvas {
isEnteredSlideShowEndEvent = true;
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
- var folderPath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - Presentations\" +
- Pres.Name + "_" + Pres.Slides.Count;
+ // 使用更精确的文件标识符:文件名_页数_文件路径哈希值
+ string presentationPath = Pres.FullName;
+ string fileHash = GetFileHash(presentationPath);
+ string folderName = Pres.Name + "_" + Pres.Slides.Count + "_" + fileHash;
+ var folderPath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - Presentations\" + folderName;
if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
try {
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
@@ -1463,5 +1474,31 @@ namespace Ink_Canvas {
wppProcessCheckCount = 0;
LogHelper.WriteLogToFile("停止 WPP 进程检测定时器", LogHelper.LogType.Trace);
}
+
+ ///
+ /// 计算文件路径的哈希值,用于生成唯一的文件夹标识符
+ ///
+ /// 文件路径
+ /// 文件路径的哈希值字符串
+ private string GetFileHash(string filePath)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(filePath))
+ return "unknown";
+
+ // 使用文件路径的哈希值作为唯一标识符
+ using (var md5 = System.Security.Cryptography.MD5.Create())
+ {
+ byte[] hashBytes = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(filePath));
+ return BitConverter.ToString(hashBytes).Replace("-", "").Substring(0, 8);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.WriteLogToFile($"计算文件哈希值失败: {ex.ToString()}", LogHelper.LogType.Error);
+ return "error";
+ }
+ }
}
}
diff --git a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs
index 7d3e2e57..6b5486f3 100644
--- a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs
@@ -168,6 +168,7 @@ namespace Ink_Canvas {
{
writer.WriteLine($"PPT名称: {pptApplication.SlideShowWindows[1].Presentation.Name}");
writer.WriteLine($"PPT总页数: {pptApplication.SlideShowWindows[1].Presentation.Slides.Count}");
+ writer.WriteLine($"PPT文件路径: {pptApplication.SlideShowWindows[1].Presentation.FullName}");
}
for (int i = 0; i < allPageStrokes.Count; i++)
@@ -432,6 +433,25 @@ namespace Ink_Canvas {
throw new InvalidOperationException("当前不在PPT放映模式,无法恢复PPT墨迹");
}
+ // 检查PPT文件路径是否匹配
+ if (metadata.ContainsKey("PPT文件路径"))
+ {
+ string savedPptPath = metadata["PPT文件路径"];
+ string currentPptPath = pptApplication.SlideShowWindows[1].Presentation.FullName;
+
+ if (!string.IsNullOrEmpty(savedPptPath) && !string.IsNullOrEmpty(currentPptPath))
+ {
+ // 使用文件路径哈希值进行比较,避免路径格式差异
+ string savedHash = GetFileHash(savedPptPath);
+ string currentHash = GetFileHash(currentPptPath);
+
+ if (savedHash != currentHash)
+ {
+ throw new InvalidOperationException($"墨迹文件与当前PPT文件不匹配。保存的PPT: {savedPptPath},当前PPT: {currentPptPath}");
+ }
+ }
+ }
+
// 清空当前墨迹
ClearStrokes(true);
timeMachine.ClearStrokeHistory();