From f15a293a691103fc41a5074723b219028b19bbbb Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Fri, 1 May 2026 14:51:56 +0800 Subject: [PATCH] =?UTF-8?q?add:=E8=87=AA=E5=AE=9A=E4=B9=89=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Controls/PptNavBar.xaml | 2 +- Ink Canvas/Helpers/SaveFileNameHelper.cs | 68 +++++++++++++++++++ .../MainWindow_cs/MW_Save&OpenStrokes.cs | 14 +++- Ink Canvas/MainWindow_cs/MW_Screenshot.cs | 40 +++++++++-- Ink Canvas/Properties/Strings.en-US.resx | 6 ++ Ink Canvas/Properties/Strings.resx | 6 ++ Ink Canvas/Resources/Settings.cs | 6 ++ .../SettingsViews/Pages/AutomationPage.xaml | 33 +++++++++ .../Pages/AutomationPage.xaml.cs | 63 +++++++++++++++++ 9 files changed, 230 insertions(+), 8 deletions(-) create mode 100644 Ink Canvas/Helpers/SaveFileNameHelper.cs diff --git a/Ink Canvas/Controls/PptNavBar.xaml b/Ink Canvas/Controls/PptNavBar.xaml index 6de155d7..045195ca 100644 --- a/Ink Canvas/Controls/PptNavBar.xaml +++ b/Ink Canvas/Controls/PptNavBar.xaml @@ -44,7 +44,7 @@ - + diff --git a/Ink Canvas/Helpers/SaveFileNameHelper.cs b/Ink Canvas/Helpers/SaveFileNameHelper.cs new file mode 100644 index 00000000..f8ef2a2f --- /dev/null +++ b/Ink Canvas/Helpers/SaveFileNameHelper.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using System.Text.RegularExpressions; + +namespace Ink_Canvas.Helpers +{ + /// + /// 渲染保存文件名模板。支持占位符: {date} {time} {datetime} {mode} {page} {count} {type}。 + /// 当模板为空、渲染结果非法或仅含分隔符时,回退到默认时间戳命名。 + /// + public static class SaveFileNameHelper + { + private const string DefaultDateTime = "yyyy-MM-dd HH-mm-ss-fff"; + + public static string Render(string template, SaveFileNameContext ctx) + { + if (ctx == null) ctx = new SaveFileNameContext(); + var now = ctx.Time ?? DateTime.Now; + + if (string.IsNullOrWhiteSpace(template)) + return now.ToString(DefaultDateTime); + + try + { + string result = template + .Replace("{date}", now.ToString("yyyy-MM-dd")) + .Replace("{time}", now.ToString("HH-mm-ss")) + .Replace("{datetime}", now.ToString(DefaultDateTime)) + .Replace("{mode}", ctx.Mode ?? "") + .Replace("{page}", ctx.Page?.ToString() ?? "") + .Replace("{count}", ctx.Count?.ToString() ?? "") + .Replace("{type}", ctx.Type ?? ""); + + result = SanitizeFileName(result); + + if (string.IsNullOrWhiteSpace(result) || Regex.IsMatch(result, @"^[\s\-_]+$")) + return now.ToString(DefaultDateTime); + + return result; + } + catch + { + return now.ToString(DefaultDateTime); + } + } + + private static string SanitizeFileName(string name) + { + if (string.IsNullOrEmpty(name)) return name; + foreach (var c in Path.GetInvalidFileNameChars()) + { + name = name.Replace(c, '_'); + } + return name.Trim(); + } + } + + public class SaveFileNameContext + { + public DateTime? Time { get; set; } + /// "Annotation" or "BlackBoard" or "Screenshot" etc. + public string Mode { get; set; } + /// "User" or "Auto" + public string Type { get; set; } + public int? Page { get; set; } + public int? Count { get; set; } + } +} \ No newline at end of file diff --git a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs index bb42d7c5..12354943 100644 --- a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs +++ b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs @@ -132,7 +132,19 @@ namespace Ink_Canvas + (currentMode == 0 ? "Annotation Strokes" : "BlackBoard Strokes"); if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); string savePathWithName; - if (currentMode != 0) // 黑板模式下 + if (Settings.Automation.IsUseCustomSaveFileName) + { + var ctx = new SaveFileNameContext + { + Mode = currentMode == 0 ? "Annotation" : "BlackBoard", + Type = saveByUser ? "User" : "Auto", + Page = currentMode != 0 ? CurrentWhiteboardIndex : (int?)null, + Count = inkCanvas.Strokes.Count + }; + var fname = SaveFileNameHelper.Render(Settings.Automation.CustomSaveFileNameTemplate, ctx); + savePathWithName = savePath + @"\" + fname + ".icstk"; + } + else if (currentMode != 0) // 黑板模式下 savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + " Page-" + CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk"; else diff --git a/Ink Canvas/MainWindow_cs/MW_Screenshot.cs b/Ink Canvas/MainWindow_cs/MW_Screenshot.cs index 3e083cbe..a520752b 100644 --- a/Ink Canvas/MainWindow_cs/MW_Screenshot.cs +++ b/Ink Canvas/MainWindow_cs/MW_Screenshot.cs @@ -43,8 +43,23 @@ namespace Ink_Canvas var basePath = Settings.Automation.AutoSavedStrokesLocation + @"\Auto Saved - BlackBoard Strokes"; if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); - strokeSavePath = Path.Combine(basePath, - $"{DateTime.Now:yyyy-MM-dd HH-mm-ss-fff} Page-{pageIndexForStrokes} StrokesCount-{strokesToSave.Count}.icstk"); + string stem; + if (Settings.Automation.IsUseCustomSaveFileName) + { + stem = SaveFileNameHelper.Render(Settings.Automation.CustomSaveFileNameTemplate, + new SaveFileNameContext + { + Mode = "BlackBoard", + Type = "Auto", + Page = pageIndexForStrokes, + Count = strokesToSave.Count + }); + } + else + { + stem = $"{DateTime.Now:yyyy-MM-dd HH-mm-ss-fff} Page-{pageIndexForStrokes} StrokesCount-{strokesToSave.Count}"; + } + strokeSavePath = Path.Combine(basePath, stem + ".icstk"); } } catch (Exception ex) @@ -149,7 +164,7 @@ namespace Ink_Canvas { var desktopPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), - $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png"); + $"{GetScreenshotFileNameStem()}.png"); CaptureAndSaveScreenshot(desktopPath, false); @@ -188,7 +203,7 @@ namespace Ink_Canvas var desktopPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), - $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png"); + $"{GetScreenshotFileNameStem()}.png"); using (var originalBitmap = CaptureScreenArea(screenshotResult.Value.Area)) { @@ -437,7 +452,10 @@ namespace Ink_Canvas { if (string.IsNullOrWhiteSpace(fileName)) { - fileName = DateTime.Now.ToString("HH-mm-ss"); + fileName = Settings.Automation.IsUseCustomSaveFileName + ? SaveFileNameHelper.Render(Settings.Automation.CustomSaveFileNameTemplate, + new SaveFileNameContext { Mode = "Screenshot", Type = "Auto", Count = inkCanvas?.Strokes?.Count }) + : DateTime.Now.ToString("HH-mm-ss"); } var basePath = Settings.Automation.AutoSavedStrokesLocation; @@ -473,7 +491,17 @@ namespace Ink_Canvas return Path.Combine( screenshotsFolder, - $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png"); + $"{GetScreenshotFileNameStem()}.png"); + } + + private string GetScreenshotFileNameStem() + { + if (Settings.Automation.IsUseCustomSaveFileName) + { + return SaveFileNameHelper.Render(Settings.Automation.CustomSaveFileNameTemplate, + new SaveFileNameContext { Mode = "Screenshot", Type = "Auto", Count = inkCanvas?.Strokes?.Count }); + } + return DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); } } } diff --git a/Ink Canvas/Properties/Strings.en-US.resx b/Ink Canvas/Properties/Strings.en-US.resx index 5bf4f832..7b084d0d 100644 --- a/Ink Canvas/Properties/Strings.en-US.resx +++ b/Ink Canvas/Properties/Strings.en-US.resx @@ -1458,6 +1458,12 @@ Auto kill + + Fold mode + + + Auto save + Auto kill Seewo PPT tools diff --git a/Ink Canvas/Properties/Strings.resx b/Ink Canvas/Properties/Strings.resx index 0de63ead..cef07867 100644 --- a/Ink Canvas/Properties/Strings.resx +++ b/Ink Canvas/Properties/Strings.resx @@ -1501,6 +1501,12 @@ 自动查杀 + + 收纳模式 + + + 自动保存 + 自动查杀希沃“PPT 小工具” diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 50fd6ff8..ebdca2de 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -581,6 +581,12 @@ namespace Ink_Canvas [JsonProperty("isSaveFullPageStrokes")] public bool IsSaveFullPageStrokes; + [JsonProperty("isUseCustomSaveFileName")] + public bool IsUseCustomSaveFileName { get; set; } = false; + + [JsonProperty("customSaveFileNameTemplate")] + public string CustomSaveFileNameTemplate { get; set; } = "{datetime}"; + [JsonProperty("isSaveStrokesAsXML")] public bool IsSaveStrokesAsXML { get; set; } = false; diff --git a/Ink Canvas/Windows/SettingsViews/Pages/AutomationPage.xaml b/Ink Canvas/Windows/SettingsViews/Pages/AutomationPage.xaml index c382a142..349fe365 100644 --- a/Ink Canvas/Windows/SettingsViews/Pages/AutomationPage.xaml +++ b/Ink Canvas/Windows/SettingsViews/Pages/AutomationPage.xaml @@ -372,6 +372,39 @@ Icon="{x:Static ui:SegoeFluentIcons.Save}" Toggled="ToggleSwitchSaveFullPageStrokes_Toggled"/> + + + + + + + + + + + + + + + + + + + + + + = 0) + { + ComboBoxSaveFileNamePreset.SelectedIndex = matchedIndex; + CardCustomSaveFileNameTemplate.Visibility = Visibility.Collapsed; + } + else + { + ComboBoxSaveFileNamePreset.SelectedIndex = ComboBoxSaveFileNamePreset.Items.Count - 1; + CardCustomSaveFileNameTemplate.Visibility = Visibility.Visible; + } + } + #endregion #region Floating Window Interceptor