improve:墨迹保存

This commit is contained in:
CJK_mkp
2025-06-09 08:41:23 +08:00
parent 11369aedf8
commit 4b4aaae001
3 changed files with 38 additions and 48 deletions
+25 -20
View File
@@ -1,4 +1,4 @@
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
@@ -592,6 +592,13 @@ namespace Ink_Canvas {
private async void PptApplication_SlideShowBegin(SlideShowWindow Wn) {
try {
// 修改加载路径到软件根目录下的Saves文件夹
var folderPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"Saves",
@"Auto Saved - Presentations\" + Wn.Presentation.Name + "_" + Wn.Presentation.Slides.Count
);
if (Settings.Automation.IsAutoFoldInPPTSlideShow && !isFloatingBarFolded)
await FoldFloatingBar(new object());
else if (isFloatingBarFolded) await UnFoldFloatingBar(new object());
@@ -630,13 +637,9 @@ namespace Ink_Canvas {
//检查是否有已有墨迹,并加载
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint)
if (Directory.Exists(Settings.Automation.AutoSavedStrokesLocation +
@"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
Wn.Presentation.Slides.Count)) {
if (Directory.Exists(folderPath)) {
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();
var files = new DirectoryInfo(folderPath).GetFiles();
var count = 0;
foreach (var file in files)
if (file.Name != "Position") {
@@ -718,9 +721,16 @@ namespace Ink_Canvas {
isEnteredSlideShowEndEvent = true;
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
var folderPath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - Presentations\" +
Pres.Name + "_" + Pres.Slides.Count;
// 修改保存路径到软件根目录下的Saves文件夹
var folderPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"Saves",
@"Auto Saved - Presentations\" + Pres.Name + "_" + Pres.Slides.Count
);
// 确保目录存在
if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
try {
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
}
@@ -735,21 +745,16 @@ namespace Ink_Canvas {
var srcBuf = new byte[memoryStreams[i].Length];
memoryStreams[i].Position = 0;
var byteLength = memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
File.WriteAllBytes(folderPath + @"\" + i.ToString("0000") + ".icstk", srcBuf);
LogHelper.WriteLogToFile(string.Format(
"Saved strokes for Slide {0}, size={1}, byteLength={2}", i.ToString(),
memoryStreams[i].Length, byteLength));
// 使用Path.Combine构建文件路径
File.WriteAllBytes(Path.Combine(folderPath, i.ToString("0000") + ".icstk"), srcBuf);
} else {
if (File.Exists(folderPath + @"\" + i.ToString("0000") + ".icstk"))
File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
if (File.Exists(filePath)) File.Delete(filePath);
}
}
catch (Exception ex) {
LogHelper.WriteLogToFile(
$"Failed to save strokes for Slide {i}\n{ex.ToString()}",
LogHelper.LogType.Error);
if (File.Exists(folderPath + @"\" + i.ToString("0000") + ".icstk"))
File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
// 新增错误处理逻辑
LogHelper.WriteLogToFile($"保存第{i}页墨迹失败: {ex.Message}", LogHelper.LogType.Error);
}
}