From 0065a1f81f89505d8c920c6b562d319489d71a89 Mon Sep 17 00:00:00 2001
From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
Date: Sat, 12 Jul 2025 09:00:51 +0800
Subject: [PATCH 01/10] Update MW_Screenshot.cs
---
Ink Canvas/MainWindow_cs/MW_Screenshot.cs | 87 +++++------------------
1 file changed, 19 insertions(+), 68 deletions(-)
diff --git a/Ink Canvas/MainWindow_cs/MW_Screenshot.cs b/Ink Canvas/MainWindow_cs/MW_Screenshot.cs
index 977d0a42..fa6d7e25 100644
--- a/Ink Canvas/MainWindow_cs/MW_Screenshot.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Screenshot.cs
@@ -1,7 +1,6 @@
using System;
using System.Drawing.Imaging;
using System.IO;
-using System.Runtime.InteropServices;
using System.Windows;
namespace Ink_Canvas {
@@ -36,90 +35,42 @@ namespace Ink_Canvas {
using (var memoryGraphics = System.Drawing.Graphics.FromImage(bitmap)) {
memoryGraphics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, System.Drawing.CopyPixelOperation.SourceCopy);
+ // 确保目录存在
var directory = Path.GetDirectoryName(savePath);
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
-
- try {
- // 新增双重目录检查
- Directory.CreateDirectory(directory); // 防止多线程场景下的竞争条件
- bitmap.Save(savePath, ImageFormat.Png);
- }
- catch (Exception ex) when (ex is IOException ||
- ex is UnauthorizedAccessException ||
- ex is ExternalException) { // 新增GDI+异常捕获
- // 改进备用路径处理
- var docPath = Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
- "Auto Saved - Screenshots",
- DateTime.Now.ToString("yyyyMMdd"),
- Path.GetFileNameWithoutExtension(savePath) + "_retry.png"); // 添加重试后缀
-
- try {
- var docDir = Path.GetDirectoryName(docPath);
- Directory.CreateDirectory(docDir);
- bitmap.Save(docPath, ImageFormat.Png);
- savePath = docPath;
- }
- catch (Exception fallbackEx) {
- // 最终错误处理
- if (!isHideNotification) {
- ShowNotification($"截图保存失败: {fallbackEx.Message}");
- }
- return;
- }
- }
+
+ bitmap.Save(savePath, ImageFormat.Png);
}
if (!isHideNotification) {
- try {
- ShowNotification($"截图成功保存至 {savePath}");
- }
- catch {
- // 防止通知系统自身异常导致崩溃
- }
+ ShowNotification($"截图成功保存至 {savePath}");
}
}
// 获取日期文件夹路径
private string GetDateFolderPath(string fileName) {
- var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves");
- var dateFolder = DateTime.Now.ToString("yyyyMMdd");
- var fullPath = Path.Combine(basePath, "Auto Saved - Screenshots", dateFolder);
-
- try {
- if (!Directory.Exists(fullPath)) {
- Directory.CreateDirectory(fullPath);
- }
- }
- catch (Exception ex) when
- (ex is IOException ||
- ex is UnauthorizedAccessException)
- {
- // 如果创建失败则使用软件根目录作为最终备选
- basePath = AppDomain.CurrentDomain.BaseDirectory;
- fullPath = Path.Combine(basePath, "Auto Saved - Screenshots", dateFolder);
-
- Directory.CreateDirectory(fullPath);
+ if (string.IsNullOrWhiteSpace(fileName)) {
+ fileName = DateTime.Now.ToString("HH-mm-ss");
}
- return Path.Combine(fullPath, $"{fileName}.png");
+ var basePath = Settings.Automation.AutoSavedStrokesLocation;
+ var dateFolder = DateTime.Now.ToString("yyyyMMdd");
+
+ return Path.Combine(
+ basePath,
+ "Auto Saved - Screenshots",
+ dateFolder,
+ $"{fileName}.png");
}
+ // 获取默认文件夹路径
private string GetDefaultFolderPath() {
- var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Saves");
+ var basePath = Settings.Automation.AutoSavedStrokesLocation;
var screenshotsFolder = Path.Combine(basePath, "Auto Saved - Screenshots");
-
- try {
- if (!Directory.Exists(screenshotsFolder)) {
- Directory.CreateDirectory(screenshotsFolder);
- }
- }
- catch (Exception) {
- // 如果创建失败则使用文档目录
- basePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- screenshotsFolder = Path.Combine(basePath, "Auto Saved - Screenshots");
+
+ if (!Directory.Exists(screenshotsFolder)) {
Directory.CreateDirectory(screenshotsFolder);
}
@@ -128,4 +79,4 @@ namespace Ink_Canvas {
$"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png");
}
}
-}
\ No newline at end of file
+}
From c4180eba6f1745ab55cf2efa3ffc76351c3f5a72 Mon Sep 17 00:00:00 2001
From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
Date: Sat, 12 Jul 2025 09:01:49 +0800
Subject: [PATCH 02/10] Update MW_Save&OpenStrokes.cs
---
.../MainWindow_cs/MW_Save&OpenStrokes.cs | 69 ++++---------------
1 file changed, 15 insertions(+), 54 deletions(-)
diff --git a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs
index 9590fda9..abada6e0 100644
--- a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs
@@ -20,61 +20,21 @@ namespace Ink_Canvas {
SaveInkCanvasStrokes(true, true);
}
- private void SaveInkCanvasStrokes(Boolean newNotice, Boolean saveByUser, string userSavePath = null) {
+ private void SaveInkCanvasStrokes(bool newNotice = true, bool saveByUser = false) {
try {
- // 优先使用用户指定的保存路径,否则使用默认路径
+ var savePath = Settings.Automation.AutoSavedStrokesLocation
+ + (saveByUser ? @"\User Saved - " : @"\Auto Saved - ")
+ + (currentMode == 0 ? "Annotation Strokes" : "BlackBoard Strokes");
+ if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
string savePathWithName;
- if (!string.IsNullOrEmpty(userSavePath)) {
- // 用户指定了完整保存路径(含文件名)
- savePathWithName = userSavePath;
- string dir = Path.GetDirectoryName(savePathWithName);
- if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
- } else {
- // 默认保存到软件根目录下的Saves文件夹
- string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
- if (string.IsNullOrEmpty(appDirectory))
- appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- string savePath = Path.Combine(appDirectory, "Saves",
- (saveByUser ? @"User Saved - " : @"Auto Saved - ") +
- (currentMode == 0 ? "Annotation Strokes" : "BlackBoard Strokes"));
- if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
- if (currentMode != 0) // 黑板模式下
- savePathWithName = Path.Combine(savePath, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") +
- " Page-" + CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk");
- else
- savePathWithName = Path.Combine(savePath, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk");
- }
-
- try {
- using (FileStream fs = new FileStream(savePathWithName, FileMode.Create)) {
- inkCanvas.Strokes.Save(fs);
- }
- }
- catch (Exception ex) when (ex is UnauthorizedAccessException || ex is DirectoryNotFoundException) {
- // 异常时备用路径仍为默认Saves文件夹
- string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
- if (string.IsNullOrEmpty(appDirectory))
- appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- string fallbackPath = Path.Combine(appDirectory, "Saves");
- Directory.CreateDirectory(fallbackPath);
- string fileName = Path.GetFileNameWithoutExtension(savePathWithName) + "_retry.icstk";
- string newPath = Path.Combine(fallbackPath, fileName);
- try {
- using (FileStream fs = new FileStream(newPath, FileMode.Create)) {
- inkCanvas.Strokes.Save(fs);
- savePathWithName = newPath;
- }
- }
- catch (Exception fallbackEx) {
- ShowNotification($"墨迹保存失败: {fallbackEx.Message}");
- return;
- }
- }
- catch (Exception ex) {
- ShowNotification($"墨迹保存失败: {ex.Message}");
- return;
- }
-
+ if (currentMode != 0) // 黑板模式下
+ savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + " Page-" +
+ CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk";
+ else
+ //savePathWithName = savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".icstk";
+ savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk";
+ var fs = new FileStream(savePathWithName, FileMode.Create);
+ inkCanvas.Strokes.Save(fs);
if (newNotice) ShowNotification("墨迹成功保存至 " + savePathWithName);
}
catch (Exception ex) {
@@ -89,6 +49,7 @@ namespace Ink_Canvas {
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
var openFileDialog = new OpenFileDialog();
+ openFileDialog.InitialDirectory = Settings.Automation.AutoSavedStrokesLocation;
openFileDialog.Title = "打开墨迹文件";
openFileDialog.Filter = "Ink Canvas Strokes File (*.icstk)|*.icstk";
if (openFileDialog.ShowDialog() != true) return;
@@ -124,4 +85,4 @@ namespace Ink_Canvas {
}
}
}
-}
\ No newline at end of file
+}
From 5ed28b121eaa565e1900e015e314118ed3c41351 Mon Sep 17 00:00:00 2001
From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
Date: Sat, 12 Jul 2025 09:09:20 +0800
Subject: [PATCH 03/10] Update MW_PPT.cs
---
Ink Canvas/MainWindow_cs/MW_PPT.cs | 43 ++++++++++++++----------------
1 file changed, 20 insertions(+), 23 deletions(-)
diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs
index 91de8465..d31ef87e 100644
--- a/Ink Canvas/MainWindow_cs/MW_PPT.cs
+++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs
@@ -665,12 +665,6 @@ 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());
@@ -710,9 +704,13 @@ namespace Ink_Canvas {
//检查是否有已有墨迹,并加载
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint)
- if (Directory.Exists(folderPath)) {
+ if (Directory.Exists(Settings.Automation.AutoSavedStrokesLocation +
+ @"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
+ Wn.Presentation.Slides.Count)) {
LogHelper.WriteLogToFile("Found saved strokes", LogHelper.LogType.Trace);
- var files = new DirectoryInfo(folderPath).GetFiles();
+ var files = new DirectoryInfo(Settings.Automation.AutoSavedStrokesLocation +
+ @"\Auto Saved - Presentations\" + Wn.Presentation.Name + "_" +
+ Wn.Presentation.Slides.Count).GetFiles();
var count = 0;
foreach (var file in files)
if (file.Name != "Position") {
@@ -794,16 +792,9 @@ namespace Ink_Canvas {
isEnteredSlideShowEndEvent = true;
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
- // 修改保存路径到软件根目录下的Saves文件夹
- var folderPath = Path.Combine(
- AppDomain.CurrentDomain.BaseDirectory,
- "Saves",
- @"Auto Saved - Presentations\" + Pres.Name + "_" + Pres.Slides.Count
- );
-
- // 确保目录存在
+ var folderPath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - Presentations\" +
+ Pres.Name + "_" + Pres.Slides.Count;
if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
-
try {
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
}
@@ -819,15 +810,21 @@ namespace Ink_Canvas {
memoryStreams[i].Position = 0;
var byteLength = memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
// 使用Path.Combine构建文件路径
- File.WriteAllBytes(Path.Combine(folderPath, i.ToString("0000") + ".icstk"), srcBuf);
+ 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));
} else {
- var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
- if (File.Exists(filePath)) File.Delete(filePath);
+ if (File.Exists(folderPath + @"\" + i.ToString("0000") + ".icstk"))
+ File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
}
}
catch (Exception ex) {
- // 新增错误处理逻辑
- LogHelper.WriteLogToFile($"保存第{i}页墨迹失败: {ex.Message}", LogHelper.LogType.Error);
+ 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");
}
}
@@ -1230,4 +1227,4 @@ namespace Ink_Canvas {
BtnPPTSlideShowEnd_Click(BtnPPTSlideShowEnd, null);
}
}
-}
\ No newline at end of file
+}
From cac0fca3bb8e187b446b1040926595d128f3a11b Mon Sep 17 00:00:00 2001
From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
Date: Sat, 12 Jul 2025 10:49:24 +0800
Subject: [PATCH 04/10] Update MW_Settings.cs
---
Ink Canvas/MainWindow_cs/MW_Settings.cs | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs
index 074e9dd6..3f2af46d 100644
--- a/Ink Canvas/MainWindow_cs/MW_Settings.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs
@@ -1262,10 +1262,7 @@ namespace Ink_Canvas {
}
private void SetAutoSavedStrokesLocationToDiskDButton_Click(object sender, RoutedEventArgs e) {
- // 修改默认路径为软件根目录下的 Saves 文件夹
- string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
- string savesPath = System.IO.Path.Combine(appDirectory, "Saves");
- AutoSavedStrokesLocation.Text = savesPath;
+ AutoSavedStrokesLocation.Text = @"D:\Ink Canvas";
}
private void SetAutoSavedStrokesLocationToDocumentFolderButton_Click(object sender, RoutedEventArgs e) {
@@ -1814,12 +1811,12 @@ namespace Ink_Canvas {
}
private void HyperlinkSourceToPresentRepository_Click(object sender, RoutedEventArgs e) {
- Process.Start("https://github.com/ChangSakura/Ink-Canvas");
+ Process.Start("https://bgithub.xyz/ChangSakura/Ink-Canvas");
HideSubPanels();
}
private void HyperlinkSourceToOringinalRepository_Click(object sender, RoutedEventArgs e) {
- Process.Start("https://github.com/WXRIW/Ink-Canvas");
+ Process.Start("https://bgithub.xyz/WXRIW/Ink-Canvas");
HideSubPanels();
}
@@ -1879,4 +1876,4 @@ namespace Ink_Canvas {
}
}
}
-}
\ No newline at end of file
+}
From 816748833c873ecd94c0c22ff4c1d350a80f9f20 Mon Sep 17 00:00:00 2001
From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
Date: Sat, 12 Jul 2025 12:14:43 +0800
Subject: [PATCH 05/10] Update MainWindow.xaml
---
Ink Canvas/MainWindow.xaml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml
index 546a061f..78234815 100644
--- a/Ink Canvas/MainWindow.xaml
+++ b/Ink Canvas/MainWindow.xaml
@@ -2347,8 +2347,7 @@
-