improve:墨迹保存
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using Ink_Canvas.Helpers;
|
using Ink_Canvas.Helpers;
|
||||||
using iNKORE.UI.WPF.Modern;
|
using iNKORE.UI.WPF.Modern;
|
||||||
using Microsoft.Office.Core;
|
using Microsoft.Office.Core;
|
||||||
using Microsoft.Office.Interop.PowerPoint;
|
using Microsoft.Office.Interop.PowerPoint;
|
||||||
@@ -592,6 +592,13 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
private async void PptApplication_SlideShowBegin(SlideShowWindow Wn) {
|
private async void PptApplication_SlideShowBegin(SlideShowWindow Wn) {
|
||||||
try {
|
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)
|
if (Settings.Automation.IsAutoFoldInPPTSlideShow && !isFloatingBarFolded)
|
||||||
await FoldFloatingBar(new object());
|
await FoldFloatingBar(new object());
|
||||||
else if (isFloatingBarFolded) await UnFoldFloatingBar(new object());
|
else if (isFloatingBarFolded) await UnFoldFloatingBar(new object());
|
||||||
@@ -630,13 +637,9 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
//检查是否有已有墨迹,并加载
|
//检查是否有已有墨迹,并加载
|
||||||
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint)
|
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint)
|
||||||
if (Directory.Exists(Settings.Automation.AutoSavedStrokesLocation +
|
if (Directory.Exists(folderPath)) {
|
||||||
@"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
|
|
||||||
Wn.Presentation.Slides.Count)) {
|
|
||||||
LogHelper.WriteLogToFile("Found saved strokes", LogHelper.LogType.Trace);
|
LogHelper.WriteLogToFile("Found saved strokes", LogHelper.LogType.Trace);
|
||||||
var files = new DirectoryInfo(Settings.Automation.AutoSavedStrokesLocation +
|
var files = new DirectoryInfo(folderPath).GetFiles();
|
||||||
@"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
|
|
||||||
Wn.Presentation.Slides.Count).GetFiles();
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
if (file.Name != "Position") {
|
if (file.Name != "Position") {
|
||||||
@@ -718,9 +721,16 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
isEnteredSlideShowEndEvent = true;
|
isEnteredSlideShowEndEvent = true;
|
||||||
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
|
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
|
||||||
var folderPath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - Presentations\" +
|
// 修改保存路径到软件根目录下的Saves文件夹
|
||||||
Pres.Name + "_" + Pres.Slides.Count;
|
var folderPath = Path.Combine(
|
||||||
|
AppDomain.CurrentDomain.BaseDirectory,
|
||||||
|
"Saves",
|
||||||
|
@"Auto Saved - Presentations\" + Pres.Name + "_" + Pres.Slides.Count
|
||||||
|
);
|
||||||
|
|
||||||
|
// 确保目录存在
|
||||||
if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
|
if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
|
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
|
||||||
}
|
}
|
||||||
@@ -735,21 +745,16 @@ namespace Ink_Canvas {
|
|||||||
var srcBuf = new byte[memoryStreams[i].Length];
|
var srcBuf = new byte[memoryStreams[i].Length];
|
||||||
memoryStreams[i].Position = 0;
|
memoryStreams[i].Position = 0;
|
||||||
var byteLength = memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
|
var byteLength = memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
|
||||||
File.WriteAllBytes(folderPath + @"\" + i.ToString("0000") + ".icstk", srcBuf);
|
// 使用Path.Combine构建文件路径
|
||||||
LogHelper.WriteLogToFile(string.Format(
|
File.WriteAllBytes(Path.Combine(folderPath, i.ToString("0000") + ".icstk"), srcBuf);
|
||||||
"Saved strokes for Slide {0}, size={1}, byteLength={2}", i.ToString(),
|
|
||||||
memoryStreams[i].Length, byteLength));
|
|
||||||
} else {
|
} else {
|
||||||
if (File.Exists(folderPath + @"\" + i.ToString("0000") + ".icstk"))
|
var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
|
||||||
File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
|
if (File.Exists(filePath)) File.Delete(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
LogHelper.WriteLogToFile(
|
// 新增错误处理逻辑
|
||||||
$"Failed to save strokes for Slide {i}\n{ex.ToString()}",
|
LogHelper.WriteLogToFile($"保存第{i}页墨迹失败: {ex.Message}", LogHelper.LogType.Error);
|
||||||
LogHelper.LogType.Error);
|
|
||||||
if (File.Exists(folderPath + @"\" + i.ToString("0000") + ".icstk"))
|
|
||||||
File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,35 +36,28 @@ namespace Ink_Canvas {
|
|||||||
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
|
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
|
||||||
string savePathWithName;
|
string savePathWithName;
|
||||||
if (currentMode != 0) // 黑板模式下
|
if (currentMode != 0) // 黑板模式下
|
||||||
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + " Page-" +
|
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + " Page-" +
|
||||||
CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk";
|
CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk";
|
||||||
else
|
else
|
||||||
//savePathWithName = savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".icstk";
|
|
||||||
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk";
|
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
using (FileStream fs = new FileStream(savePathWithName, FileMode.Create)) { // 修复未定义的filePath引用
|
using (FileStream fs = new FileStream(savePathWithName, FileMode.Create)) {
|
||||||
inkCanvas.Strokes.Save(fs);
|
inkCanvas.Strokes.Save(fs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is DirectoryNotFoundException) {
|
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is DirectoryNotFoundException) {
|
||||||
var docPath = Path.Combine(
|
// 修改异常处理中的备用路径为软件根目录下的Saves文件夹
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
|
string fallbackPath = Path.Combine(appDirectory, "Saves");
|
||||||
"Auto Saved - Annotation Strokes",
|
Directory.CreateDirectory(fallbackPath);
|
||||||
DateTime.Now.ToString("yyyyMMdd"),
|
|
||||||
Path.GetFileNameWithoutExtension(savePathWithName) + "_retry.icstk"); // 使用正确的原始文件名
|
string fileName = Path.GetFileNameWithoutExtension(savePathWithName) + "_retry.icstk";
|
||||||
|
string newPath = Path.Combine(fallbackPath, fileName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 修改保存路径为软件所在目录下的 Saves 文件夹
|
|
||||||
string saveDirectory = Path.Combine(appDirectory, "Saves");
|
|
||||||
Directory.CreateDirectory(saveDirectory); // 自动创建 Saves 目录
|
|
||||||
|
|
||||||
string fileName = Path.GetFileNameWithoutExtension(savePathWithName) + "_retry.icstk"; // 使用正确的原始文件名
|
|
||||||
string newPath = Path.Combine(saveDirectory, fileName); // 新路径组合
|
|
||||||
|
|
||||||
using (FileStream fs = new FileStream(newPath, FileMode.Create)) {
|
using (FileStream fs = new FileStream(newPath, FileMode.Create)) {
|
||||||
inkCanvas.Strokes.Save(fs);
|
inkCanvas.Strokes.Save(fs);
|
||||||
savePathWithName = newPath; // 更新通知使用的路径变量
|
savePathWithName = newPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception fallbackEx) {
|
catch (Exception fallbackEx) {
|
||||||
@@ -91,7 +84,6 @@ namespace Ink_Canvas {
|
|||||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
||||||
|
|
||||||
var openFileDialog = new OpenFileDialog();
|
var openFileDialog = new OpenFileDialog();
|
||||||
openFileDialog.InitialDirectory = Settings.Automation.AutoSavedStrokesLocation;
|
|
||||||
openFileDialog.Title = "打开墨迹文件";
|
openFileDialog.Title = "打开墨迹文件";
|
||||||
openFileDialog.Filter = "Ink Canvas Strokes File (*.icstk)|*.icstk";
|
openFileDialog.Filter = "Ink Canvas Strokes File (*.icstk)|*.icstk";
|
||||||
if (openFileDialog.ShowDialog() != true) return;
|
if (openFileDialog.ShowDialog() != true) return;
|
||||||
|
|||||||
@@ -84,16 +84,9 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
// 获取日期文件夹路径
|
// 获取日期文件夹路径
|
||||||
private string GetDateFolderPath(string fileName) {
|
private string GetDateFolderPath(string fileName) {
|
||||||
if (string.IsNullOrWhiteSpace(fileName)) {
|
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves");
|
||||||
fileName = DateTime.Now.ToString("HH-mm-ss");
|
|
||||||
}
|
|
||||||
|
|
||||||
var basePath = Settings.Automation.AutoSavedStrokesLocation;
|
|
||||||
var dateFolder = DateTime.Now.ToString("yyyyMMdd");
|
var dateFolder = DateTime.Now.ToString("yyyyMMdd");
|
||||||
var fullPath = Path.Combine(
|
var fullPath = Path.Combine(basePath, "Auto Saved - Screenshots", dateFolder);
|
||||||
basePath,
|
|
||||||
"Auto Saved - Screenshots",
|
|
||||||
dateFolder);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!Directory.Exists(fullPath)) {
|
if (!Directory.Exists(fullPath)) {
|
||||||
@@ -115,7 +108,7 @@ namespace Ink_Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private string GetDefaultFolderPath() {
|
private string GetDefaultFolderPath() {
|
||||||
var basePath = Settings.Automation.AutoSavedStrokesLocation;
|
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves");
|
||||||
var screenshotsFolder = Path.Combine(basePath, "Auto Saved - Screenshots");
|
var screenshotsFolder = Path.Combine(basePath, "Auto Saved - Screenshots");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user