Compare commits

..

753 Commits

Author SHA1 Message Date
CJKmkp 578ffb7c56 improve:兼容性变更提示 2026-04-25 16:31:11 +08:00
CJKmkp feca1aa46d add:兼容性变更提示 2026-04-19 08:40:50 +08:00
CJKmkp b399429d9d improve:墨迹纠正 2026-04-19 08:38:27 +08:00
CJKmkp 5388bef3ea fix:墨迹纠正 2026-04-19 08:10:45 +08:00
CJKmkp cbb17ee03f add:兼容性变更提示 2026-04-18 17:53:13 +08:00
CJKmkp 51dcc374ce add:兼容性变更提示 2026-04-18 17:23:21 +08:00
CJKmkp 1640238728 improve:墨迹纠正 2026-04-18 17:10:27 +08:00
CJKmkp 0fa4010625 代码优化 2026-04-18 17:01:18 +08:00
CJKmkp e6d391e98b 更新版本号 2026-04-18 16:58:35 +08:00
CJKmkp 6659db651d add:禁用硬件加速 & improve:UI 2026-04-18 16:50:44 +08:00
CJKmkp b50049c822 improve:UI面板弹出 2026-04-12 09:08:33 +08:00
CJK_mkp c1d584e3e7 Merge pull request #438 from InkCanvasForClass/All-Contributers/chore
docs: 更新贡献者配置和排版
2026-04-11 16:44:50 +08:00
CJK_mkp f776dac04d Merge pull request #436 from Tayasui-rainnya/beta
feat: add '包含墨迹' toggle and ink-overlay support for area screenshots
2026-04-11 16:44:34 +08:00
doudou0720 6e7a0e36f4 docs: 更新贡献者配置和README排版
- 添加JSON schema验证
- 调整每行贡献者显示数量为5
- 更新贡献者贡献类型
- 重构README表格布局为每行5列

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-04-11 13:06:26 +08:00
tayasui rainnya! 585b712c4c Enhance XML comments for ShowScreenshotSelector method
Updated XML documentation for ShowScreenshotSelector method to provide clearer details on parameters and return values.
2026-04-11 06:27:19 +08:00
tayasui rainnya! 2ca7d2a337 Merge pull request #1 from Tayasui-rainnya/codex/add-toggle-for-ink-inclusion-in-screenshot
feat: add '包含墨迹' toggle and ink-overlay support for area screenshots
2026-04-09 13:44:34 +08:00
tayasui rainnya! ea03e8e7c7 fix: keep include-ink available for image-only canvas and tighten bitmap disposal 2026-04-09 13:36:08 +08:00
tayasui rainnya! 778894482f fix: disambiguate WPF Matrix type in ink overlay render path 2026-04-09 13:22:19 +08:00
tayasui rainnya! 1035f7ef92 fix: render ink overlay from strokes to remove capture offset 2026-04-09 13:19:47 +08:00
tayasui rainnya! 6e4f8bc982 fix: correct ink overlay alignment in screenshot capture 2026-04-09 13:16:43 +08:00
tayasui rainnya! 36e47cec43 fix: align ink overlay DPI and ignore include-ink toolbar clicks 2026-04-09 13:07:28 +08:00
tayasui rainnya! 8b2bc352a6 feat: add include-ink toggle for area screenshot selector 2026-04-09 12:54:31 +08:00
CJKmkp 057fb35d00 improve:UI
快捷键设置UI改进
2026-04-05 22:03:16 +08:00
CJKmkp bcbece5bd6 文件更名 2026-04-05 21:50:53 +08:00
PrefacedCorg 5aad206e0d Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-04-05 21:37:05 +08:00
CJKmkp 74344c4782 improve:issue #423 2026-04-05 21:35:43 +08:00
PrefacedCorg f280358f56 删除新的旧插件 2026-04-05 21:35:40 +08:00
CJKmkp 243201502b add:issue #402 2026-04-05 21:32:01 +08:00
CJKmkp 8c090218d1 improve:新设置 2026-04-05 21:19:19 +08:00
CJKmkp 6ca1c598d4 improve:UI 2026-04-05 21:08:38 +08:00
CJK_mkp 0c078ef863 fix:手掌擦 (#419) 2026-04-05 20:43:40 +08:00
CJKmkp fea6576dfb improve:pdf插入 2026-04-05 20:37:48 +08:00
PrefacedCorg 24bc2cf138 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-04-05 19:36:35 +08:00
PrefacedCorg e6b707ea51 Merge branch 'New-New-Settings' into beta 2026-04-05 19:35:17 +08:00
CJKmkp 6183011952 improve:UI 2026-04-05 19:23:00 +08:00
CJKmkp d80a59556e Revert "improve:pdf插入"
This reverts commit bad05f77b5.
2026-04-05 19:07:31 +08:00
CJKmkp ebbe018bae 代码优化 2026-04-05 18:52:19 +08:00
CJKmkp bad05f77b5 improve:pdf插入 2026-04-05 18:42:06 +08:00
CJKmkp ea375a9ce6 add:pdf插入 2026-04-05 18:36:47 +08:00
CJKmkp d3382d7856 add:pdf插入 2026-04-05 18:30:05 +08:00
CJKmkp acf0c17d7a add:pdf插入 2026-04-05 18:22:37 +08:00
CJKmkp 83568c8b33 improve:UI 2026-04-05 18:18:18 +08:00
CJKmkp cc80529498 add:pdf插入 2026-04-05 18:15:23 +08:00
PrefacedCorg 002970921d Update MainWindow.xaml 2026-04-05 18:08:48 +08:00
CJKmkp ea74592e89 add:pdf插入 2026-04-05 18:06:21 +08:00
PrefacedCorg fa38d3d664 remove:旧的新设置 2026-04-05 17:58:57 +08:00
CJKmkp cffedb8cb7 add:pdf插入 2026-04-05 17:49:05 +08:00
CJKmkp c77beb662e add:pdf插入 2026-04-05 17:31:35 +08:00
PrefacedCorg 77dd83c2d6 新设置
删除插件管理
2026-04-05 17:31:15 +08:00
PrefacedCorg ceb99cea2b 重命名和补回i18n 2026-04-05 17:27:00 +08:00
PrefacedCorg 04a8224484 Merge branch 'beta' into New-New-Settings 2026-04-05 17:08:03 +08:00
PrefacedCorg 2f54e9d7b3 add:复制按钮 2026-04-05 17:01:20 +08:00
CJKmkp 1165e5bbf2 add:临时窗口显示 2026-04-05 15:49:06 +08:00
doudou0720 24c6ca60a3 refactor: 替换任务栏图标库为 H.NotifyIcon (#425)
更新所有相关文件和引用,从 Hardcodet.Wpf.TaskbarNotification 迁移到 H.NotifyIcon
调整通知显示方式并添加 ForceCreate 调用确保图标正确显示

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-04-05 15:04:37 +08:00
CJKmkp 8f3b65c6d4 improve:仅PPT模式 2026-04-05 14:58:32 +08:00
CJKmkp 4835e3db50 优化代码 2026-04-05 14:18:33 +08:00
CJKmkp 7a30c93ff5 delete:插件系统 2026-04-05 14:12:35 +08:00
CJKmkp 1fca17d557 add:插件系统 2026-04-05 14:06:49 +08:00
CJKmkp 069a478559 improve:手写体识别 2026-04-05 12:17:02 +08:00
CJKmkp c70d8e1c4e improve:手写体识别 2026-04-05 11:35:14 +08:00
CJKmkp 25dc6a00d3 Revert "feat:Downgrade to .NET Framework 4.6.2 project (#415)"
This reverts commit eb2f65e6e5.
2026-04-05 10:52:45 +08:00
doudou0720 eb2f65e6e5 feat:Downgrade to .NET Framework 4.6.2 project (#415)
* chore:Init net 462

* feat: 将 .NET Framework 依赖从 4.7.2 降级至 4.6.2

更新应用配置、安装程序和文档以支持 .NET Framework 4.6.2

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-04-05 10:47:00 +08:00
PANDAJSR 16c86cd02d feat:为托盘右键菜单添加设置入口 (#405)
* 软件设置内的贡献者列表添加了 PANDA-JSR

* feat(tray): add separate entries for new/legacy settings

* feat(tray): merge settings menu entries

* fix: use ikw namespace for tray menu stack panel
2026-04-05 09:53:14 +08:00
CJKmkp f5a657d5c3 improve:展台
新增将展台替换为希沃展台快捷启动功能
2026-04-05 09:38:16 +08:00
CJKmkp dfc23b4428 fix:一言API设置重复写入 2026-04-05 09:25:53 +08:00
CJKmkp b62055e705 Revert "fix:一言API设置重复写入"
This reverts commit 3cf1ea438b.
2026-04-05 09:12:31 +08:00
CJKmkp 3190211f9a fix:一言API设置重复写入 2026-04-05 09:06:20 +08:00
CJKmkp e138f600a1 improve:自动更新 2026-04-05 07:56:47 +08:00
CJKmkp 2173b82fb4 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-04-05 07:42:27 +08:00
CJKmkp ceeb9bffba 更新版本号 2026-04-05 07:42:26 +08:00
doudou0720 ba70d67c89 ci:尝试修复softprops/action-gh-release@v2令牌疑似使用Action Token而非Octo-sts Token的未说明问题
神秘Action

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-04-05 00:34:56 +08:00
CJKmkp 74341cc162 优化注释 2026-04-04 23:34:56 +08:00
CJKmkp fc4a3a1194 improve:UI 2026-04-04 23:34:26 +08:00
CJKmkp c33ac03255 improve:墨迹渲染 2026-04-04 23:06:16 +08:00
CJKmkp 66afe271c5 improve:实时笔锋 2026-04-04 22:56:34 +08:00
PrefacedCorg 9279783fc3 Revert "新设置"
This reverts commit 140e92eeda.
2026-04-04 22:26:32 +08:00
CJKmkp 3cf1ea438b fix:一言API设置重复写入 2026-04-04 22:21:34 +08:00
CJKmkp 277e46030d improve:WinRT墨迹识别及笔锋 2026-04-04 22:16:37 +08:00
CJKmkp af19ffb736 fix:一言API设置重复写入 2026-04-04 22:16:32 +08:00
CJKmkp 1f00962c47 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-04-04 21:08:56 +08:00
PrefacedCorg 742a62b6ff Revert "新设置"
This reverts commit 140e92eeda.
2026-04-04 19:43:06 +08:00
PrefacedCorg 140e92eeda 新设置 2026-04-04 18:45:59 +08:00
PrefacedCorg 34c2dab82a i1145141919810n 2026-04-04 16:37:08 +08:00
PrefacedCorg fa2366c373 i1145141919810n 2026-04-04 15:40:36 +08:00
PrefacedCorg e2d898df14 Update SettingsWindow2.xaml 2026-04-04 12:45:47 +08:00
PrefacedCorg cacc67b11d 新设置 2026-04-04 11:33:47 +08:00
doudou0720 aef860a8cc ci: 修复发布工作流中的变量引用格式,避免changelog带有双引号而被Shell解析
神秘问题

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-04-04 11:22:54 +08:00
PrefacedCorg c890f95092 i18n
添加注释
2026-04-04 07:50:30 +08:00
PrefacedCorg 7c9a5f8265 Merge branch 'beta' into New-New-Settings 2026-04-04 00:56:43 +08:00
PrefacedCorg 7eafcb02cb 新设置 2026-04-04 00:54:22 +08:00
PrefacedCorg d4517d3c53 Update SettingsWindow2.xaml.cs 2026-04-04 00:54:04 +08:00
PrefacedCorg 62a9a097aa i18n 2026-04-04 00:00:52 +08:00
PrefacedCorg e7fa1caf6c Update SettingsWindow2.xaml 2026-04-03 22:11:57 +08:00
PrefacedCorg e347443a0a Update SettingsWindow2.xaml 2026-04-03 19:46:30 +08:00
PrefacedCorg b77e540863 Reapply "更新 SettingsWindow2.xaml.cs"
This reverts commit a6fdb07e8b.
2026-04-03 19:30:44 +08:00
PrefacedCorg df4168e8fa Reapply "更新 SettingsWindow2.xaml"
This reverts commit 11cb1815ad.
2026-04-03 19:30:40 +08:00
PrefacedCorg 576f86ce48 Reapply "add:高dpi适配 插件接口 设置窗口多显示器优化 fix:触摸后鼠标指针显示异常"
This reverts commit 26f79da2f9.
2026-04-03 19:30:29 +08:00
PrefacedCorg c3335c0c24 Update SettingsWindow.xaml.cs 2026-04-03 19:30:06 +08:00
PrefacedCorg 26f79da2f9 Revert "add:高dpi适配 插件接口 设置窗口多显示器优化 fix:触摸后鼠标指针显示异常"
This reverts commit ca53624149.
2026-04-03 00:14:28 +08:00
PrefacedCorg 11cb1815ad Revert "更新 SettingsWindow2.xaml"
This reverts commit 5f9b01ef04.
2026-04-03 00:14:23 +08:00
PrefacedCorg a6fdb07e8b Revert "更新 SettingsWindow2.xaml.cs"
This reverts commit ffdb3cd431.
2026-04-03 00:14:10 +08:00
PrefacedCorg ffdb3cd431 更新 SettingsWindow2.xaml.cs 2026-04-02 00:17:25 +08:00
PrefacedCorg 5f9b01ef04 更新 SettingsWindow2.xaml 2026-04-02 00:01:02 +08:00
PrefacedCorg ca53624149 add:高dpi适配 插件接口 设置窗口多显示器优化 fix:触摸后鼠标指针显示异常 2026-04-01 23:57:50 +08:00
PrefacedCorg 6484450ad3 更新 SettingsWindow2.xaml.cs 2026-04-01 13:56:46 +08:00
PrefacedCorg 7c97b683ea 新新设置的第一个开关设置选项 开机时启动 2026-04-01 00:46:40 +08:00
PrefacedCorg 378b3e73f2 1 2026-04-01 00:16:36 +08:00
PrefacedCorg a2f21357b6 我服了 2026-03-31 00:25:08 +08:00
doudou0720 79e03dc0d5 fix(ci):尝试使用通用指令获取文件大小
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-29 22:31:16 +08:00
PrefacedCorg e0f35450e1 add:NewNewSettings 2026-03-29 17:39:52 +08:00
PrefacedCorg cc9f58fb6a add:NewNewSettings 2026-03-29 14:21:27 +08:00
PrefacedCorg e8be85141b add:NewNewSettings 2026-03-29 13:47:19 +08:00
PrefacedCorg 1bf57ea2f5 1 2026-03-29 12:38:46 +08:00
CJKmkp 18b737b22b add:手写体识别 2026-03-29 12:24:13 +08:00
CJKmkp 4ec3332808 fix:自动收纳 2026-03-29 12:23:26 +08:00
doudou0720 b2290ecf65 feat(ci):支持多架构编译
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-28 23:56:31 +08:00
CJKmkp 55c336daab 更新项目文件 2026-03-28 23:19:14 +08:00
CJKmkp f2ed3f619c 更新项目文件 2026-03-28 22:32:35 +08:00
CJKmkp 114f400bd9 更新项目文件 2026-03-28 22:29:38 +08:00
CJKmkp 506d1118b2 更新项目文件 2026-03-28 22:25:50 +08:00
PrefacedCorg 20441543f0 Merge pull request #420 from InkCanvasForClass/beta
...
2026-03-28 22:05:28 +08:00
doudou0720 2dbc47ac3c chore:调整构建配置
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-28 21:53:10 +08:00
doudou0720 bbe99649cd chore:更新Nightly下载链接
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-28 21:41:11 +08:00
doudou0720 04806d2004 refactor(ci): 重构构建配置和CI工作流
统一项目构建输出路径结构,移除冗余的x86 Debug配置
简化CI工作流中的artifact上传逻辑,支持多架构构建
更新PR检查工作流名称以更准确反映其用途

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-28 21:35:24 +08:00
doudou0720 759a635026 chore:修复工作流语法错误
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-28 21:04:20 +08:00
doudou0720 e68bd9286f feat(ci): 分离PR检查工作流并添加多架构构建支持
将PR检查从主工作流中分离为独立文件,并添加对x86架构的构建支持

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-28 21:00:38 +08:00
CJKmkp a6b31e82c0 优化代码 2026-03-28 20:29:12 +08:00
CJKmkp bc3e37e541 improve:自动更新 2026-03-28 20:28:42 +08:00
CJKmkp 1124bb6bfa improve:自动更新 2026-03-28 20:20:44 +08:00
CJKmkp b19c19d73c 优化日志 2026-03-28 19:21:47 +08:00
CJKmkp feb3fad4da add:WinRT墨迹识别 2026-03-28 19:05:54 +08:00
CJKmkp 3db745d684 add:WinRT墨迹识别 2026-03-28 18:45:42 +08:00
CJKmkp b4089ae62e add:WinRT墨迹识别 2026-03-28 18:43:29 +08:00
CJKmkp 97bdf78b08 add:WinRT墨迹识别 2026-03-28 18:40:18 +08:00
CJKmkp dc9fb26260 add:WinRT墨迹识别 2026-03-28 18:30:40 +08:00
CJKmkp 97b0972fdf add:WinRT墨迹识别 2026-03-28 18:10:28 +08:00
CJKmkp ea23145349 add:WinRT墨迹识别 2026-03-28 18:01:14 +08:00
CJKmkp f7013196f7 delete:墨迹预测 2026-03-28 17:52:30 +08:00
CJKmkp 9d0baa0799 add:WinRT墨迹识别 2026-03-28 17:40:14 +08:00
CJK_mkp 91c2fa4eee Revert "feat: 选区截图时保留屏幕笔迹 (#406)" (#418)
This reverts commit f7aa107a62.
2026-03-28 17:23:27 +08:00
CJKmkp 837311b2b7 add:实时笔锋及墨迹预测 2026-03-28 17:16:47 +08:00
CJKmkp bc53eab669 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-03-28 17:12:23 +08:00
CJKmkp 55eb811193 add:实时笔锋及墨迹预测 2026-03-28 17:11:30 +08:00
tayasui rainnya! f7aa107a62 feat: 选区截图时保留屏幕笔迹 (#406)
* feat: 使用选区截图时,不清除 Strokes(Keep it on screen)

* fix: 浮动栏选区截图前强制保持墨迹可见

* fix: 避免选区截图回滚 inkCanvas 运行时状态

* fix: 截图前退出并在结束后恢复批注状态

* fix: 截图流程改用轻量批注暂停避免副作用

* feat: 选区截图添加包含墨迹开关

* fix: 避免选区截图墨迹重复渲染

* fix: 全屏基础截图排除主窗口后再叠加墨迹

* fix: 隐藏浮动栏后再进入选区截图

* fix: 添加到白板时不强制恢复浮动栏可见性

* fix: 防止重复启动选区截图实例

* fix: 仅在白板接管成功后跳过浮动栏恢复

* feat: 选区截图时实时预览包含墨迹开关

* fix: 合并截图选择器OnClosed逻辑避免重复定义
2026-03-28 17:11:18 +08:00
CJKmkp 56a65af9a7 add:实时笔锋及墨迹预测 2026-03-28 17:06:16 +08:00
CJKmkp de3f5d16a2 add:实时笔锋及墨迹预测 2026-03-28 17:04:50 +08:00
CJKmkp d325a58f17 add:实时笔锋及墨迹预测 2026-03-28 16:59:02 +08:00
CJKmkp fd137ae787 improve:安全面板 2026-03-28 16:46:35 +08:00
CJKmkp bb1b893961 improve:自动收纳 2026-03-28 16:46:21 +08:00
CJKmkp 01c247ac29 add:unget for 现代化墨迹识别 2026-03-27 17:45:21 +08:00
CJKmkp 1fa75640ee 更新nuget 2026-03-27 17:36:10 +08:00
CJKmkp 6e0191af6b 更新nuget 2026-03-27 17:30:01 +08:00
PrefacedCorg 9ac4070e4e fix:窗口标题栏最小化隐藏 oobe 上下一步无法触摸 2026-03-24 01:21:57 +08:00
CJK_mkp 2590ea5bdb Fix PPT disconnect null check crash (#413) 2026-03-23 16:46:28 +08:00
CJK_mkp 290e031f77 Handle RPC failures during PPT disconnect (#412) 2026-03-23 16:41:50 +08:00
PrefacedCorg 9bc9af5eec 改了下标题栏
不会约定式提交
2026-03-22 14:35:19 +08:00
PrefacedCorg 8faffe9d4e Revert "新设置右侧下部添加触摸支持"
This reverts commit c9dd98fa8d.
2026-03-21 23:09:45 +08:00
PrefacedCorg 95dfad64ce 空值检测?
去你的空值
炸了不关我事
2026-03-21 23:06:16 +08:00
PrefacedCorg c9dd98fa8d 新设置右侧下部添加触摸支持
右侧顶部依旧无法触摸 不会修 等重写标题栏
2026-03-21 23:04:52 +08:00
doudou0720 3ae99c82cc fix(SymbolIcon):修复SymbolIcon问题并修改打包过程以正确构建单文件程序 (#407)
* refactor(Icon): 将SymbolIcon替换为FontIcon以使用Segoe Fluent Icons

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* chore: 移除 Costura.Fody 的 IncludeAssets 配置

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-21 22:15:36 +08:00
doudou0720 016abafee4 fix(UI): 为新设置、云储存管理添加基本触控支持 (#409)
实测部分按钮(如新设置的云储存按钮)仍然有问题

统一设置所有ScrollViewer控件的PanningMode为VerticalOnly,防止水平滚动干扰用户体验

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-21 17:46:19 +08:00
doudou0720 dca606cf5f chore(deps):Bump microsoft/setup-msbuild v2 to v3
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-21 17:43:33 +08:00
CJKmkp e7c77b173d improve:PPT模块 2026-03-21 16:57:14 +08:00
CJKmkp 68b588ee7b improve:外部点名 2026-03-21 16:49:37 +08:00
CJKmkp b4c753dfb4 improve:PPT模块 2026-03-21 16:41:39 +08:00
CJKmkp 037bcf6007 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-03-21 16:40:32 +08:00
CJKmkp b2e0e7b9e2 improve:安全面板 2026-03-21 16:30:55 +08:00
PrefacedCorg 03c1399768 看得不够长 调长点 2026-03-21 16:29:19 +08:00
PrefacedCorg 9b3a59f089 改漏了再改一下 2026-03-21 16:28:27 +08:00
PrefacedCorg e8f824a046 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-03-21 16:19:38 +08:00
PrefacedCorg 4772b9cce7 改了两ui 适配了触摸 2026-03-21 16:18:36 +08:00
CJKmkp 74b64bd21f 代码优化 2026-03-21 16:13:42 +08:00
doudou0720 3934270ed2 refactor: 移除未使用的VBIDE COM引用
Github Action都没有这个lib怎么构建.jpg

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-14 21:20:40 +08:00
CJKmkp 664ec925e9 add:i18n 2026-03-14 17:58:01 +08:00
CJKmkp 3806454b18 improve:遥测 2026-03-14 17:35:55 +08:00
PANDAJSR bea92f3483 新设置窗口:新增可拖动区域 (#401)
* 软件设置内的贡献者列表添加了 PANDA-JSR

* 设置窗口:新增可拖动区域
2026-03-14 17:24:54 +08:00
CJKmkp 133542d7fa Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-03-14 17:19:38 +08:00
doudou0720 7a363f7f79 feat:支持交叉编译并完成iNKORE.UI.WPF.Modern升级 (#398)
* fix(deps):仅更新SimpleStackPanel

* feat:支持交叉编译并完成iNKORE.UI升级

* chore:fix com

* fix(Build/logic):在非.Net Framework MSBuild下使用预生成的互操作dll而非依据系统判断

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat:添加devcontainer.json

* chore(devcontainer.json):精简Dev Container

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-14 17:19:05 +08:00
doudou0720 2322efcc00 chore(Workflow):对prerelease添加警告
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-14 17:10:54 +08:00
CJKmkp 3cc830b37b improve:展台 2026-03-14 17:08:26 +08:00
CJKmkp 7a1a9be3ab improve:墨迹渐隐 2026-03-14 16:51:26 +08:00
CJKmkp 082c9ed005 improve:计时器 2026-03-14 16:45:19 +08:00
CJKmkp dfd327d7fc improve:PPT模块 2026-03-14 16:19:12 +08:00
CJKmkp 3354850216 fix:心跳机制 2026-03-14 16:04:01 +08:00
CJK_mkp d330d0bf26 回滚134c905
Removed unnecessary comments related to heartbeat reset during startup.
2026-03-09 19:55:17 +08:00
CJK_mkp 13b9b597ce Fix heartbeat false positive right after startup (#400) 2026-03-09 17:08:43 +08:00
doudou0720 96491f3bf5 chore(deps):更新工作流action版本
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-07 20:36:19 +08:00
CJK_mkp 4f99f11a33 撤销至c760211 2026-03-07 12:15:14 +08:00
CJK_mkp 134c90508d 撤销至4c874f 2026-03-07 12:13:29 +08:00
doudou0720 863829bb41 feat(ISSUE_TEMPLATE):为议题模板(.yml)添加上传文件功能
由于.md模板可以直接上传,故未添加

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-03-07 11:21:53 +08:00
CJK_mkp 9802ab92e0 fix: stabilize PPT slideshow state sync on transient COM states (#394) 2026-03-05 11:55:55 +08:00
CJK_mkp b7eebeecb4 refactor: 移除启动完成后的额外保护窗口逻辑 (#393) 2026-03-05 11:47:24 +08:00
CJK_mkp a406778d35 Revert "improve:PPT模块" (#390)
This reverts commit 7d0de8b5a3.
2026-03-05 11:30:07 +08:00
CJKmkp c9cef8ca86 add:i18n 2026-03-04 14:06:21 +08:00
CJKmkp c099870352 add:i18n 2026-03-04 11:48:43 +08:00
CJKmkp ad921dcfe7 add:i18n 2026-03-04 11:42:22 +08:00
CJKmkp 0bdf8ea81b add:i18n 2026-03-04 11:17:05 +08:00
CJKmkp 079c3cf1a6 add:i18n 2026-03-04 10:50:59 +08:00
CJKmkp e29b4f3ff3 add:i18n 2026-03-04 10:25:25 +08:00
CJKmkp b67476ae19 add:i18n 2026-03-03 17:22:48 +08:00
CJKmkp 2e4b841e7e 更新版本号 2026-03-03 17:22:33 +08:00
CJKmkp 1dd49c6d93 fix:issue #387 2026-03-03 16:07:58 +08:00
CJKmkp a948c0d7fb 优化代码 2026-03-03 16:04:20 +08:00
CJKmkp 62e79ff5b3 add:i18n 2026-03-03 15:58:26 +08:00
CJKmkp 6300a06a44 add:i18n 2026-03-03 15:18:31 +08:00
CJKmkp a80c4e709f add:i18n 2026-03-03 14:39:47 +08:00
CJKmkp 08f7afc3f1 add:i18n 2026-03-03 14:33:41 +08:00
CJKmkp 1e65cee4ad add:i18n 2026-03-03 14:08:01 +08:00
CJKmkp bbe262df7e improve:崩溃重启 2026-03-03 12:20:26 +08:00
CJKmkp 7d0de8b5a3 improve:PPT模块 2026-03-03 12:13:49 +08:00
doudou0720 244da46ac2 fix(iss):修复Inno Setup文件格式错误
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-24 18:04:35 +08:00
doudou0720 bd6a4bf298 feat(Inno Setup) 添加.NET Framework 4.7.2安装检查
在安装脚本中添加初始化检查,确保系统已安装.NET Framework 4.7.2或兼容版本。如果未安装,则显示错误提示信息。

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-24 17:54:47 +08:00
CJK_mkp ef6f3adc3f Update README.md 2026-02-24 16:49:53 +08:00
allcontributors[bot] 2047fb3a3a docs: add Super-Yyt as a contributor for blog (#384)
* docs: update README.md

* docs: update .all-contributorsrc

* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
2026-02-24 16:48:16 +08:00
allcontributors[bot] 57594d7e4d docs: add doudou0720 as a contributor for blog (#385)
* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2026-02-24 16:46:25 +08:00
allcontributors[bot] ba60aa6eb0 docs: add Super-Yyt as a contributor for infra (#383)
* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2026-02-24 16:34:34 +08:00
allcontributors[bot] 11c7c0f83f docs: add LiuYan-xwx as a contributor for code (#382)
* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2026-02-24 16:28:15 +08:00
CJKmkp 1108433b99 文件更名 2026-02-24 15:09:38 +08:00
CJKmkp 3ac4802d44 improve:云存储管理UI 2026-02-24 14:57:31 +08:00
CJKmkp 884d015b88 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-24 14:56:09 +08:00
CJKmkp 69ed0fc1ec improve:云存储管理UI 2026-02-24 14:56:04 +08:00
doudou0720 4a9d492571 fix(UI/Dlass): 修改Dlass设置界面文本和样式
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-24 14:51:53 +08:00
doudou0720 8a9a4c8b0f fix(云储存设置窗口): 优化自动上传Dlass笔记开关状态的同步逻辑
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-24 14:45:17 +08:00
CJKmkp 2ce6088e74 优化代码 2026-02-24 14:13:19 +08:00
doudou0720 0ad74d9f7f feat(Upload/WebDav):迁移Dlass并添加WebDav管理 (#381)
* feat(Upload/Common): 重构上传功能以添加通用设置管理

- 新增UploadSettings类用于管理上传通用设置
- 重构上传逻辑,将延迟上传功能移至UploadHelper
- 在Dlass设置窗口添加通用设置标签页
- 支持多上传提供者管理及取消操作
- 增强文件上传前的验证和错误处理

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat(upload): 添加WebDav文件上传支持

- 新增WebDavUploader工具类实现文件上传功能
- 添加WebDavUploadProvider作为上传提供者
- 在设置界面增加WebDav配置选项
- 添加WebDav.Client NuGet包依赖

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat(WebDAV): 实现WebDAV上传队列管理

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat(Upload): 重命名Dlass设置项为云存储以支持WebDav保存

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat(Dlass):迁移Dlass注册位置

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* refactor(Upload): 优化上传逻辑和界面交互

- 修改Dlass标签页检测逻辑,使用Tag属性替代Header
- 限制WebDav上传队列的批量处理大小
- 移除多处上传延迟逻辑,统一在通用设置中配置
- 更新Dlass设置界面提示文本

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* chore:修改窗口命名

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* refactor(upload): 重构上传队列为统一管理架构

重构上传队列系统,引入BaseUploadQueue基类实现通用队列管理逻辑,创建UploadQueueHelper统一管理所有上传队列。将DlassUploadQueue和WebDavUploadQueue重构为继承自BaseUploadQueue的具体实现,简化代码并提高可维护性。修改MainWindow初始化代码以使用新的统一初始化方法。

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* refactor(Upload): 重构上传队列系统,改进错误处理和资源管理

- 将上传队列改为可释放资源,实现IDisposable接口
- 移除硬编码的文件验证逻辑,改为可重写方法
- 改进API客户端,支持取消操作和更好的资源管理
- 优化队列初始化流程,增加错误处理
- 统一上传提供者的队列注册方式
- 改进日志记录和错误信息

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* Update Settings.cs

* refactor(UpLoad/Queue): 移除冗余的上传成功/失败日志记录

优化WebDav上传逻辑,增加目录创建重试机制

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* refactor(MW_Settings): 重构全选复选框状态更新逻辑

将直接设置全选复选框状态的逻辑拆分为两步,先计算所有分类复选框状态,再更新全选复选框,提高代码可读性

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
Co-authored-by: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
2026-02-24 14:08:57 +08:00
CJKmkp c76021194a improve:ROT模块 2026-02-24 12:21:46 +08:00
CJKmkp 5c3056aea0 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-23 23:13:33 +08:00
doudou0720 7deb5b1aae fix: 延迟显示通知以避免截图包含通知
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-23 23:08:52 +08:00
CJKmkp a7bd58a6bd improve:OOBE 2026-02-23 19:48:03 +08:00
CJKmkp f690612fae improve:展台 2026-02-23 19:32:39 +08:00
CJKmkp 59d1c4b4ab Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-23 17:36:28 +08:00
doudou0720 ccd9398a53 feat(build): 更新 DSN 文件的嵌入逻辑
添加条件判断和生成逻辑,当 DLASS_SENTRY_DSN 环境变量存在时,自动生成 telemetry_dsn.generated.txt 文件并嵌入。同时添加清理目标确保构建后清理生成的文件。
2026-02-23 17:35:12 +08:00
CJKmkp 1db9ed8169 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-23 17:08:02 +08:00
doudou0720 7fbef51237 fix(ci):为构建流程上传Sentry DSN
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-23 17:06:17 +08:00
CJKmkp efe3308325 add:i18n 2026-02-23 15:45:49 +08:00
CJKmkp 4c874fa50b add:i18n 2026-02-23 14:31:48 +08:00
CJKmkp 1704ad37d2 add:i18n
i18n准备
2026-02-23 14:14:35 +08:00
CJKmkp a019c27c8b improve:配置切换
支持URL联动
2026-02-23 13:46:13 +08:00
CJKmkp 5119652ca5 improve:展台 2026-02-23 13:40:19 +08:00
CJKmkp 1fb0ea29a3 improve:展台 2026-02-23 13:29:12 +08:00
CJKmkp 1ca9fbd023 improve:展台UI 2026-02-23 13:24:32 +08:00
CJKmkp 9eb70de1bc improve:展台UI 2026-02-23 13:20:52 +08:00
CJKmkp fccfca8890 improve:展台 2026-02-23 13:17:20 +08:00
CJKmkp 06e12e2899 add:配置切换 2026-02-23 12:31:53 +08:00
CJKmkp 559822686c add:配置切换 2026-02-23 12:18:59 +08:00
CJKmkp c46ac64a9c add:配置切换 2026-02-23 12:11:03 +08:00
CJKmkp ea7233bc1b add:配置切换 2026-02-23 12:04:54 +08:00
doudou0720 a6bc7552f4 feat(Upload):解耦Dlass上传并使用UploadHelper接管 (#380)
* feat(Upload):解耦Dlass笔记上传

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(上传): 修复多线程环境下的上传提供者管理问题

添加线程同步锁确保上传提供者列表的线程安全
修改AutoUploadDelayMinutes属性确保最小值为0
优化提供者注册逻辑避免重复注册

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-22 23:53:12 +08:00
CJKmkp 7b04f18d4e improve:Dlass服务 2026-02-22 23:39:36 +08:00
CJKmkp 99f0e25acf improve:ROT联动 2026-02-22 22:04:58 +08:00
CJKmkp 7b7ce4320b Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-22 20:54:09 +08:00
CJKmkp 1023ef87f7 add:issue #317 2026-02-22 20:52:14 +08:00
doudou0720 84365130df fix(Workflows/post-release):尝试修改流程以上传大文件
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-22 20:24:33 +08:00
CJKmkp 4097e6d20c add:issue #296 2026-02-22 20:03:26 +08:00
CJKmkp 940a8024ac add:PPT侧边栏 2026-02-22 19:58:47 +08:00
CJKmkp 15196b39c3 更新版本号 2026-02-22 19:34:52 +08:00
CJKmkp 81864d4947 improve:点名算法 2026-02-22 19:19:44 +08:00
CJKmkp 73a4a044ee improve:保存截屏 2026-02-22 19:12:59 +08:00
CJKmkp 8155aac25d improve:Dlass设置窗口 2026-02-22 18:47:33 +08:00
CJKmkp 6e8d1f5d9e improve:白板 2026-02-22 18:41:53 +08:00
CJKmkp 30852376dc fix:PPT记忆上次页码 2026-02-22 18:04:56 +08:00
CJKmkp ad986043aa Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-22 17:55:39 +08:00
CJKmkp 17c020284d improve:PPT模块 2026-02-22 17:52:33 +08:00
doudou0720 1d280a3a35 chore(MW_PPT): 修正XML注释的闭合标签和格式 2026-02-22 17:34:52 +08:00
doudou0720 8394c6d6d6 fix: 修复应用退出时未及时关闭PPT监控的问题
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-22 16:29:30 +08:00
CJKmkp e2da207965 improve:UI 2026-02-22 14:47:25 +08:00
CJKmkp 6f00a332c1 improve:PPT模块 2026-02-22 14:30:23 +08:00
tayasui rainnya! 1c8bdcf352 fix: 全选后点击添加到白板显示已取消 (#379)
* 调整截图按钮默认行为为选区/白板全屏

* 截图选择器新增添加到白板按钮并支持新建白板页插入

* 修复添加到白板不生效:改为剪贴板复制粘贴插入

* 修复添加到白板截图时序:先截到内存再进白板

* Fix screenshot insert flow honoring add-to-whiteboard option

* Refine screenshot selector freehand confirm and blank double-click full select

* Fix freehand whiteboard insert alpha transparency

* Fix screenshot insert notification text for whiteboard flow

* Adjust screenshot selection: right-click/double-click full-select and keep selector on single click

* Show unmasked freehand selection area like rectangle mode

* Remove freehand cutout mask rendering from screenshot selector

* Restore freehand selected-area unmask behavior in selector

* fix: always restore window visibility after area screenshot

* fix: allow add-to-whiteboard after full-screen selection
2026-02-22 14:14:10 +08:00
CJKmkp 31fe3c858e improve:白板翻页性能 2026-02-22 14:12:26 +08:00
tayasui rainnya! c06be8f502 feat: 浮动栏截图修改为选区截图,添加“添加到白板”按钮 (#377)
* 调整截图按钮默认行为为选区/白板全屏

* 截图选择器新增添加到白板按钮并支持新建白板页插入

* 修复添加到白板不生效:改为剪贴板复制粘贴插入

* 修复添加到白板截图时序:先截到内存再进白板

* Fix screenshot insert flow honoring add-to-whiteboard option

* Refine screenshot selector freehand confirm and blank double-click full select

* Fix freehand whiteboard insert alpha transparency

* Fix screenshot insert notification text for whiteboard flow

* Adjust screenshot selection: right-click/double-click full-select and keep selector on single click

* Show unmasked freehand selection area like rectangle mode

* Remove freehand cutout mask rendering from screenshot selector

* Restore freehand selected-area unmask behavior in selector
2026-02-22 14:04:11 +08:00
CJKmkp 2d51eb73b5 improve:白板翻页性能 2026-02-22 13:57:56 +08:00
CJKmkp 30bc0b03e5 improve:UI 2026-02-22 13:28:35 +08:00
CJKmkp dd9cb1825e improve:白板翻页性能 2026-02-22 13:02:38 +08:00
CJKmkp 6d5c4b4e08 improve:白板翻页性能 2026-02-22 12:55:00 +08:00
CJKmkp 3d0a960337 improve:白板翻页性能 2026-02-22 12:42:47 +08:00
CJKmkp 705f4fd155 improve:白板翻页性能 2026-02-22 12:26:43 +08:00
CJKmkp ac98a76797 add:白板页面删除 2026-02-22 12:23:13 +08:00
CJKmkp 13396f418b improve:白板翻页性能 2026-02-22 12:20:37 +08:00
CJKmkp e70696cd6f improve:直线拉直 2026-02-22 11:42:03 +08:00
CJKmkp d8bbee8c76 add:使用橡皮后自动切回批注 2026-02-22 11:25:30 +08:00
CJKmkp 3e701718d3 add:PPT动画跳过 2026-02-22 10:50:11 +08:00
doudou0720 656863a7d0 feat(docstring):添加部分docstring (#376)
* feat(docstring):添加docstring

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(docstring):修复部分docstring格式错误

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(docstring):修复部分docstring

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* chore(Docstring):MW_* 前14

* chore(Docstring):MW_* part 2

* chore(Docstring):MW_* part 3

* chore:优化缩进

* fix: 修复数学计算中的潜在除零错误和数值稳定性问题

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* chore:删除Rebase时多余的OOBE函数

* chore: 更新代码注释和文档格式

修复XML文档注释中的格式问题,统一使用<c>和<see>标签
更新ConfigHelper类的预留说明,明确未来扩展用途
优化TimerDisplayDate_Elapsed方法的注释,说明UI异步更新机制
合并重复的注释摘要行,提高文档可读性
添加形状识别功能的64位进程限制说明
修正视频呈现器设备选择逻辑的文档说明

* chore(IPPTLinkManager): 更新TryEndSlideShow方法的XML注释格式

* chore: 修正代码注释中的术语和格式问题

更新多个文件中的XML注释,统一使用<see langword="..."/>标记代替<c>...</c>标记
规范术语使用(如"延迟初始化"代替"懒惰初始化")
修正注释中的格式错误和补充说明
调整代码区域的注释对齐格式

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-22 10:14:12 +08:00
CJKmkp 3e3db27296 add:一言名言种类自定义 2026-02-21 18:47:30 +08:00
CJKmkp 86cdb231d0 improve:OOBE 2026-02-21 17:54:22 +08:00
CJKmkp 5d6c9bb76b 代码优化 2026-02-21 17:49:10 +08:00
CJKmkp d02f1e99c8 代码优化 2026-02-21 17:46:22 +08:00
CJKmkp 26b6de9149 improve:安全功能 2026-02-21 17:44:35 +08:00
CJKmkp 2b3d1c11de improve:PPT模块 2026-02-21 17:44:30 +08:00
CJKmkp 51e3377b38 improve:展台 2026-02-21 17:44:20 +08:00
CJKmkp 99ec2d7609 代码优化 2026-02-21 16:51:34 +08:00
CJKmkp 469dbd1497 improve:PPT模块 2026-02-21 15:29:21 +08:00
CJKmkp b1513ca587 improve:PPT墨迹管理 2026-02-21 15:23:42 +08:00
CJKmkp b1e384e52d improve:PPT墨迹管理 2026-02-21 15:06:46 +08:00
CJKmkp 14cb2e836b improve:PPT墨迹管理 2026-02-20 15:19:27 +08:00
CJKmkp 1c50edd8be improve:PPT墨迹管理 2026-02-20 14:59:41 +08:00
CJKmkp 87570e16ce improve:展台UI 2026-02-20 14:27:23 +08:00
doudou0720 abf4bf0254 fix(MW_AutoTheme): 异步加载资源字典以优化启动性能 (#375)
* fix(MW_AutoTheme): 异步加载资源字典以优化启动性能、

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(MW_AutoTheme): 异步加载dark主题

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-20 14:22:47 +08:00
CJKmkp 092fd1c3ee improve:OOBE 2026-02-20 14:20:25 +08:00
CJKmkp c1105df271 improve:展台功能 2026-02-20 14:01:53 +08:00
CJKmkp 8292b2ef25 improve:PPT墨迹管理 2026-02-20 13:23:20 +08:00
CJKmkp d032293a0d improve:PPT墨迹管理 2026-02-20 12:51:20 +08:00
CJKmkp d038beb07a improve:PPT墨迹管理 2026-02-20 12:29:40 +08:00
CJKmkp edac024ad9 improve:展台 2026-02-20 12:06:11 +08:00
CJKmkp dc422a2ccc add:展台 2026-02-20 12:00:22 +08:00
CJKmkp bcb7002b22 add:展台 2026-02-19 19:28:21 +08:00
CJKmkp 1a585d353f add:展台 2026-02-19 18:34:30 +08:00
CJKmkp b16ec37df3 improve:安全面板 2026-02-19 18:28:01 +08:00
CJKmkp d2abadd69b add:展台 2026-02-19 18:24:55 +08:00
CJKmkp 432cc3825e add:展台 2026-02-19 18:18:47 +08:00
CJKmkp 9ef764ffa1 add:展台 2026-02-19 18:12:19 +08:00
doudou0720 c2ca1c9702 fix(Selection/Touch): 修复触摸拖动选择时的坐标计算问题
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-18 22:37:54 +08:00
CJKmkp 07de74b775 improve:安全面板 2026-02-18 22:22:58 +08:00
CJKmkp a7d0f022dc improve:联动模块 2026-02-18 22:21:44 +08:00
CJKmkp 2e03cb1db1 improve:白板列表 2026-02-18 22:19:15 +08:00
CJKmkp 7f82312b96 improve:墨迹颜色切换 2026-02-18 22:13:55 +08:00
CJKmkp 10ba2db0f1 improve:进程保护 2026-02-18 22:10:38 +08:00
CJKmkp 8c99492518 improve:联动模块 2026-02-18 22:10:14 +08:00
CJKmkp b5b2d97786 improve:进程保护 2026-02-18 22:09:40 +08:00
CJKmkp 3d601189f1 improve:进程保护 2026-02-18 22:04:46 +08:00
CJKmkp 681b674eb2 improve:自动更新 2026-02-18 22:03:30 +08:00
CJKmkp c838b9d077 improve:联动模块 2026-02-18 22:00:44 +08:00
CJKmkp 703e710006 improve:OOBE 2026-02-18 22:00:39 +08:00
CJKmkp 3ab1c59a05 更新nuget 2026-02-18 20:32:00 +08:00
CJKmkp 45dc3cb537 add:安全中心 2026-02-16 20:22:41 +08:00
doudou0720 2f8c368eef fix(Touch):添加控制点触控支持以及移动墨迹问题 (#374)
* feat(MW_SelectionGestures.cs): 为缩放选择框添加触摸事件

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* refactor(MW_SelectionGestures.cs): 清理PreviewTouch

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(MW_SelectionGestures.cs): 单指触摸时阻止缩放处理以允许拖动操作

当检测到单指触摸且存在选中笔迹时,直接返回以允许TouchMove处理拖动操作,避免与缩放手势冲突

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-16 17:15:33 +08:00
doudou0720 78302ca426 feat(cliff.toml):更新Changelog格式
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-16 14:43:14 +08:00
doudou0720 0675a369c3 chore(ci):为日常构建使用预安装SDK
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-16 12:58:44 +08:00
doudou0720 85f92ca9a5 feat(ci):使用Runner提供的.Net SDK版本以加快构建速度
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-16 12:55:25 +08:00
doudou0720 f252eb068a feat(ci): 在构建解决方案时禁用分析器
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-16 12:18:59 +08:00
doudou0720 8c65075823 fix(MW_SelectionGestures.cs): 调整选择框和手柄的扩展偏移量 (#373)
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-15 08:07:35 +08:00
PANDAJSR 7d78f677b8 chore:软件设置内的贡献者列表添加了 PANDA-JSR (#372) 2026-02-15 08:07:17 +08:00
CJKmkp 41e9e9cc04 fix:issue #348 2026-02-15 02:33:42 +08:00
CJKmkp fefd8424b7 fix:issue #339 2026-02-15 02:05:15 +08:00
CJKmkp 60bdc64730 fix:issue #339 2026-02-15 02:04:23 +08:00
CJKmkp 7b6b2a30e6 fix:issue #358 2026-02-15 01:57:12 +08:00
CJKmkp 9b55eff11d improve:板刷模式 2026-02-15 01:43:46 +08:00
CJKmkp 07a03d3e60 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-15 01:36:18 +08:00
doudou0720 cf3063f3e4 fix(StartupTimer):分离启动时间和启动画面时间
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-14 21:40:01 +08:00
CJKmkp 1d46818eec add:OOBE 2026-02-14 16:09:39 +08:00
CJKmkp ec3a826e01 add:OOBE 2026-02-14 15:59:10 +08:00
CJKmkp 97d5b12732 improve:UI布局 2026-02-14 15:33:21 +08:00
CJKmkp e0cb877162 improve:ROT联动 2026-02-14 15:10:00 +08:00
CJKmkp 698478d826 improve:ROT联动 2026-02-14 15:01:39 +08:00
CJKmkp f722f3516b improve:ROT联动 2026-02-14 14:39:15 +08:00
CJKmkp 27a9f965a9 add:板刷模式 2026-02-14 13:47:44 +08:00
CJKmkp a95effabdd add:板刷模式 2026-02-14 13:12:39 +08:00
CJKmkp 08eb9d892d add:定时恢复墨迹设置 2026-02-14 12:49:39 +08:00
CJKmkp d7530d0c4c add:定时恢复墨迹设置 2026-02-14 12:35:08 +08:00
CJKmkp 967243e705 improve:快捷调色盘 2026-02-14 09:39:03 +08:00
CJKmkp 47eac7e70e add:定时恢复墨迹设置 2026-02-14 09:35:16 +08:00
CJKmkp f35075de9d add:定时恢复墨迹设置 2026-02-14 09:13:24 +08:00
CJKmkp b983cbe094 add:定时恢复墨迹设置 2026-02-14 00:23:05 +08:00
CJKmkp 3ea6da4790 improve:快抽 2026-02-13 18:25:57 +08:00
CJKmkp b658bf4fd0 improve:图片插入 2026-02-13 13:20:50 +08:00
CJKmkp 4aa12638f1 improve:图片插入 2026-02-13 12:35:27 +08:00
CJKmkp 54e9e3b10d Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-13 12:33:27 +08:00
CJKmkp 12a13bb97b improve:图片插入 2026-02-13 12:32:33 +08:00
doudou0720 8b35926b2d chore(Sentry):移除无效Sentry.Profiling
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-13 10:33:08 +08:00
CJKmkp 1d71f809cc improve:优化timer 2026-02-13 09:29:24 +08:00
CJKmkp a9fefadec9 优化代码结构 2026-02-13 09:17:47 +08:00
CJKmkp bdf4b7e495 improve:Dlass服务 2026-02-13 09:17:18 +08:00
CJKmkp 12c8384347 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-13 01:12:32 +08:00
doudou0720 272782ba4c fix(AutoSync CI):修改AutomaticUpdateVersionControl体积位置为beta
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-13 01:11:45 +08:00
doudou0720 a75d7876e2 fix(AutoSync CI):为正式版补充额外逻辑
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-13 00:52:08 +08:00
doudou0720 890f3e890c feat(ci):添加多仓库同步功能以及Draft Release支持
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-13 00:44:09 +08:00
CJKmkp 1c2e513c34 improve:PPT联动 2026-02-13 00:35:32 +08:00
CJKmkp ed239929f3 improve:Dlass遥测 2026-02-13 00:09:38 +08:00
CJKmkp 2d65224389 improve:PPT联动 2026-02-12 23:19:55 +08:00
CJKmkp 418810d542 improve:PPT联动 2026-02-12 22:53:05 +08:00
CJKmkp 4a2d015b97 improve:PPT联动 2026-02-12 22:39:28 +08:00
CJKmkp 15cb1aa5f2 improve:PPT联动 2026-02-12 22:33:04 +08:00
CJKmkp 7226187ac6 improve:PPT联动 2026-02-12 22:18:05 +08:00
CJKmkp 6de2e49047 Revert "improve:PPT联动"
This reverts commit f0b31c15a6.
2026-02-12 21:57:02 +08:00
CJKmkp f0b31c15a6 improve:PPT联动 2026-02-12 21:53:37 +08:00
CJKmkp 80decf5656 improve:Dlass笔记上传服务 2026-02-12 21:52:28 +08:00
CJKmkp 376790330d improve:自动更新 2026-02-12 17:22:47 +08:00
2,2,3-三甲基戊烷 200317a0f5 Merge pull request #371 from InkCanvasForClass/all-contributors/add-PANDAJSR 2026-02-10 23:25:46 +08:00
allcontributors[bot] 92a405f833 docs: update .all-contributorsrc 2026-02-10 15:25:29 +00:00
allcontributors[bot] 2a3e759890 docs: update README.md 2026-02-10 15:25:28 +00:00
doudou0720 46e0b04dd1 improve(cliff.toml):更新Release模板
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-07 23:35:29 +08:00
doudou0720 88a8d8fa4b 更新版本号
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-07 17:22:38 +08:00
CJKmkp bf5c4ab188 improve:遥测服务 2026-02-07 16:42:45 +08:00
CJKmkp 14d314e0a2 add:新设置 2026-02-07 15:29:15 +08:00
CJKmkp 324d514f10 add:新设置 2026-02-07 15:21:42 +08:00
CJKmkp e11e1989ad add:新设置 2026-02-07 15:08:00 +08:00
CJKmkp a5b99c25ed add:新设置 2026-02-07 14:58:35 +08:00
CJKmkp 3c908feb95 add:新设置 2026-02-07 14:53:37 +08:00
CJKmkp 840eca88c8 add:新设置 2026-02-07 14:49:52 +08:00
CJKmkp fa7caf3592 add:新设置 2026-02-07 14:02:26 +08:00
CJKmkp 654e15f845 add:Dlass遥测 2026-02-07 12:43:03 +08:00
CJKmkp 7a81344aea add:Dlass遥测 2026-02-07 12:23:46 +08:00
CJKmkp 803d267687 add:Dlass遥测 2026-02-07 12:16:37 +08:00
CJKmkp c8e4d18364 improve:自动更新 2026-02-07 11:54:40 +08:00
CJKmkp aeecca1260 add:Dlass遥测 2026-02-07 11:37:33 +08:00
CJKmkp 49aaa2d58b add:Dlass遥测 2026-02-07 11:23:59 +08:00
CJKmkp dd22b119b7 add:Dlass遥测 2026-02-07 11:15:39 +08:00
CJKmkp 42984ea5fa 更新文件 2026-02-07 10:56:13 +08:00
CJKmkp ce0147091a improve:PPT联动 2026-02-07 10:44:17 +08:00
CJKmkp 884abf5b0e add:Dlass遥测 2026-02-07 10:43:25 +08:00
CJKmkp 5cc1c7093a add:新设置 2026-02-07 10:37:51 +08:00
CJKmkp 87aae93f4b add:Dlass遥测 2026-02-07 07:39:05 +08:00
CJKmkp 77002b59b2 add:Dlass遥测 2026-02-07 00:10:13 +08:00
CJKmkp 5601f72d59 add:Dlass遥测 2026-02-06 23:54:33 +08:00
CJKmkp afcc8050ce add:Dlass遥测 2026-02-06 23:46:05 +08:00
CJKmkp 17c043668c Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-02-06 23:37:07 +08:00
CJKmkp 2495fc7b26 add:Dlass遥测 2026-02-06 23:36:57 +08:00
doudou0720 61404ff852 feat(Workflow):改进工作流流程 (#370)
* feat 常态构建 : 使用官方action附带缓存选项

* feat(dotnet-build):Remove comment part

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(BuildDotnet):use "/" instead of "\\"

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix:fall back to msbuild

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix:Change to restore

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix:Change to bash

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat(prerelease):修改发版流程

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* fix(PreRelease):尝试修复神秘问题

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* feat(Release):添加统计信息

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

* chore:Delete Temp Workflow

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>

---------

Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-02-06 23:24:45 +08:00
CJKmkp a62ae3c6e0 add:Dlass遥测 2026-02-06 23:14:41 +08:00
CJKmkp 28f65b3790 add:Dlass遥测 2026-02-06 23:12:54 +08:00
CJKmkp ce4b83dbe0 add:Dlass遥测 2026-02-06 23:00:57 +08:00
CJKmkp 7a24faece1 add:Dlass遥测 2026-02-06 22:47:41 +08:00
CJKmkp 22555b835b add:新设置 2026-02-06 22:06:50 +08:00
CJKmkp b2648fecac add:新设置 2026-02-06 22:01:01 +08:00
CJKmkp 15a6799d7b improve:PPT联动模块 2026-02-06 21:49:11 +08:00
CJKmkp 13b24aeb7c add:新设置 2026-02-06 21:45:48 +08:00
CJKmkp 674ce28420 improve:设备ID 2026-02-06 17:21:31 +08:00
CJKmkp 60c07c3738 add:双联动架构 2026-02-06 16:47:02 +08:00
CJKmkp 2b7f3c1f73 add:双联动架构 2026-02-06 16:38:33 +08:00
CJKmkp 04ff617e3c 优化日志 2026-02-06 16:28:54 +08:00
CJKmkp 5ee247d423 add:双联动架构 2026-02-06 16:26:18 +08:00
CJKmkp 0bd2c4eff7 文件更名 2026-02-06 16:12:58 +08:00
2,2,3-三甲基戊烷 0408729a1d Merge pull request #369 from PANDAJSR/beta
根据 https://github.com/doudou0720/ICC-CE/pull/20 中的修改建议修改了代码
2026-02-04 14:52:44 +08:00
PANDA-JSR 61e9a456af 根据 https://github.com/doudou0720/ICC-CE/pull/20 中的修改建议修改了代码 2026-02-04 14:49:56 +08:00
2,2,3-三甲基戊烷 93f89e7a41 Merge pull request #368 from PANDAJSR/feat-uri
根据 https://github.com/doudou0720/ICC-CE/pull/21 修改了代码
2026-02-04 14:42:03 +08:00
PANDA-JSR bb26c9ce55 fixed the XAML compilation error 2026-02-04 14:37:48 +08:00
PANDAJSR bd2107378b Merge branch 'InkCanvasForClass:beta' into feat-uri 2026-02-04 14:32:34 +08:00
PANDA-JSR 0b0714c166 根据 https://github.com/doudou0720/ICC-CE/pull/21 中的建议修改代码 2026-02-04 14:30:27 +08:00
2,2,3-三甲基戊烷 696ed84f4c Merge pull request #366 from PANDAJSR/feat--允许第三方程序通过系统URI来控制部分功能 2026-02-04 12:54:27 +08:00
2,2,3-三甲基戊烷 c8a467af9d Merge pull request #365 from PANDAJSR/beta 2026-02-04 12:54:06 +08:00
PANDA-JSR 8f6383cbe6 添加注册uri的功能 2026-02-04 11:09:49 +08:00
PANDA-JSR 25e64dd6f8 fix(自动折叠): 优化浮动栏自动折叠逻辑和日志记录
调整自动折叠检查间隔从200ms增加到500ms以提高性能
重构自动折叠处理逻辑,移除冗余代码并优化异常处理
增强日志记录信息,包含更多上下文用于调试
2026-02-03 22:34:17 +08:00
PANDA-JSR 745bc65379 improve: 自动收纳逻辑 2026-02-03 22:23:45 +08:00
CJKmkp a4868215f2 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-01-31 17:20:08 +08:00
2,2,3-三甲基戊烷 8e2d8045c0 Merge pull request #359 from PANDAJSR/beta
feat(墨迹渐隐): 添加在笔工具菜单中隐藏墨迹渐隐控制开关的功能
2026-01-31 17:19:47 +08:00
doudou0720 5b290ef5c0 chore (MainWindow.xaml):Delete unuseful string
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
2026-01-31 10:42:16 +08:00
PANDA-JSR b68a50431f feat(墨迹渐隐): 添加在笔工具菜单中隐藏墨迹渐隐控制开关的功能
添加新设置选项,允许用户在笔工具菜单中隐藏墨迹渐隐控制开关。该功能包括:
- 新增设置属性 HideInkFadeControlInPenMenu
- 在设置界面添加对应的开关控件
- 实现开关状态同步和可见性更新逻辑
- 更新主界面笔工具菜单中的控制面板可见性

终于不怕课间有人玩墨迹渐隐了!!!
2026-01-23 12:21:28 +08:00
CJKmkp 4f8c7d66e1 improve:PPT联动 2026-01-19 21:02:24 +08:00
CJKmkp 48bf15457d Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-01-19 18:26:36 +08:00
CJKmkp d85bea7872 improve:PPT联动 2026-01-19 18:17:07 +08:00
CJKmkp 02fe33da5a improve:卡死检测 2026-01-19 18:16:03 +08:00
CJKmkp 3f17cc705b improve:PPT联动 2026-01-19 18:13:27 +08:00
doudou0720 8078d0f137 fix (Issue Template):修正格式问题 2026-01-18 22:35:58 +08:00
doudou0720 51ed642c35 fix (Issue Template):更改模板部分笔误
Close #353
2026-01-18 22:29:16 +08:00
doudou0720 842e1c0d6c feat (OpenSourceManagement):Issue模板 (#354) 2026-01-18 21:26:09 +08:00
CJKmkp f76cfe648f improve:PPT联动 2026-01-18 08:35:45 +08:00
CJKmkp 1b66473ae0 improve:PPT联动 2026-01-18 08:30:02 +08:00
CJKmkp f0bae76b78 imporve:PPT联动 2026-01-18 08:24:33 +08:00
CJKmkp ff58675069 improve:PPT联动 2026-01-18 08:18:38 +08:00
CJKmkp b3cb53b482 improve:PPT联动 2026-01-18 08:06:03 +08:00
CJKmkp 4eb9773398 improve:PPT联动 2026-01-18 07:58:41 +08:00
CJKmkp 748ab0fff2 improve:PPT联动 2026-01-18 07:51:50 +08:00
CJKmkp ae22162020 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-01-18 07:42:30 +08:00
PrefacedCorg 7390e59ab0 优化自动收纳
在开启了 退出白板时自动收纳 时,当处于PPT放映模式时打开了白板退出后改为不自动收纳 不在PPT放映模式时则仍然自动收纳
2026-01-18 05:35:28 +08:00
PrefacedCorg 57e0331c58 fix:选择或套索选下扔处于橡皮擦模式 2026-01-18 04:23:51 +08:00
PrefacedCorg 862374bec4 修复ui错误 2026-01-18 04:05:55 +08:00
CJKmkp 266c5c0dc8 improve:PPT联动 2026-01-18 02:27:48 +08:00
CJKmkp 9fee9a1d6a improve:PPT联动 2026-01-18 02:07:39 +08:00
CJKmkp f65341d906 improve:PPT联动 2026-01-18 02:03:39 +08:00
CJKmkp c11ca7a3f7 improve:PPT联动 2026-01-18 01:30:24 +08:00
CJKmkp b7f3a38826 improve:PPT联动 2026-01-18 01:26:36 +08:00
CJKmkp 6ebe50e71b impsove:PPT联动 2026-01-18 01:20:30 +08:00
CJKmkp 6ce2aea000 improve:PPT联动 2026-01-18 01:05:54 +08:00
CJKmkp 60c341927f improve:PPT联动 2026-01-18 00:58:58 +08:00
CJKmkp ed03d40ff3 improve:PPT联动 2026-01-18 00:28:47 +08:00
CJKmkp 6c616f2b6b Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-01-18 00:13:20 +08:00
CJKmkp 84f026f1dd improve:PPT联动 2026-01-18 00:10:47 +08:00
CJKmkp 89c9c0d9ef improve:PPT联动 2026-01-17 23:02:06 +08:00
CJKmkp 9d631cc980 improve:PPT联动 2026-01-17 22:49:03 +08:00
CJKmkp 786d4fc719 improve:PPT联动 2026-01-17 22:38:40 +08:00
CJKmkp 9c68a5350b improve:PPT联动 2026-01-17 22:29:31 +08:00
CJKmkp e26bf83bb0 improve:PPT联动 2026-01-17 22:11:28 +08:00
CJKmkp 52583a6092 fix:浮动栏定位异常 2026-01-17 22:11:20 +08:00
CJKmkp de9056739b improve:PPT翻页 2026-01-17 20:23:33 +08:00
CJKmkp 9c611698c7 fix:issue #346 2026-01-17 20:05:33 +08:00
CJKmkp a6357abc15 improve:PPT联动 2026-01-17 19:46:18 +08:00
CJKmkp b83facb14e improve:PPT联动 2026-01-17 18:55:44 +08:00
PrefacedCorg 2dc16c13bc 更改注释 2026-01-17 17:52:12 +08:00
CJKmkp a46f8b36a0 improve:PPT联动模块 2026-01-17 17:44:46 +08:00
CJKmkp c0453ea1fc improve:PPT联动 2026-01-17 17:31:22 +08:00
CJKmkp 41b8f9c962 add:新设置 2026-01-17 17:24:27 +08:00
CJKmkp e69175e5c4 improve:主题适配 2026-01-17 17:22:46 +08:00
CJKmkp 76babf4dd3 improve:PPT联动 2026-01-17 17:11:11 +08:00
CJKmkp 5d6f53dc58 更新版本号 2026-01-17 17:10:56 +08:00
CJKmkp 72a49b7bf2 improve:自动更新 2026-01-17 17:05:55 +08:00
CJKmkp c4230a15c9 improve:信息保存 2026-01-17 16:51:28 +08:00
CJKmkp 84167bbcfc improve:自动收纳 2026-01-17 16:50:37 +08:00
CJKmkp 7f154ba1db improve:自动收纳 2026-01-17 16:46:37 +08:00
CJKmkp 7abb7e2ef1 improve:卡死检测 2026-01-17 16:32:57 +08:00
PrefacedCorg 04d21ac890 fix:颜色错误 2026-01-16 21:17:14 +08:00
CJKmkp a6992874f8 add:新设置 2026-01-11 08:23:09 +08:00
CJKmkp 1b2db81dde add:新设置 2026-01-11 00:16:22 +08:00
CJKmkp 17e6d23650 improve:PPT时间胶囊 2026-01-11 00:14:44 +08:00
CJKmkp 2aa1ba537f Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-01-10 23:32:06 +08:00
CJKmkp 981ca7629e add:新设置 2026-01-10 23:20:31 +08:00
PrefacedCorg 1aaef3d554 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2026-01-10 23:16:16 +08:00
PrefacedCorg 2fd83a4a80 更新注释 2026-01-10 23:15:13 +08:00
CJKmkp fc89dce7c2 add:新设置 2026-01-10 23:06:27 +08:00
CJKmkp 62b85a4bbd add:新设置 2026-01-10 23:00:52 +08:00
CJKmkp 927d85ea68 improve:PPT模块 2026-01-10 22:13:00 +08:00
CJKmkp 89ccf700c3 更新注释 2026-01-10 21:40:22 +08:00
CJKmkp b3c29f2e27 更新信息 2026-01-10 21:39:08 +08:00
CJKmkp 06af63a10a add:PPT联动备用方法 2026-01-10 21:16:12 +08:00
CJKmkp 50742e5e4d add:PPT联动备用方法 2026-01-10 21:14:35 +08:00
CJKmkp 570c701b93 add:PPT联动备用方法 2026-01-10 21:10:13 +08:00
CJKmkp a1c4d53d7c add:PPT联动备用方法 2026-01-10 21:00:45 +08:00
CJKmkp 3250b81a23 add:PPT联动备用方法 2026-01-10 20:47:15 +08:00
CJKmkp fb914734c8 add:PPT联动备用方法 2026-01-10 20:38:55 +08:00
CJKmkp be6eb73671 improve:PPT侧边面板 2026-01-10 20:09:20 +08:00
CJKmkp 221a0f8e85 add:PPT联动备用方法 2026-01-10 19:51:00 +08:00
CJKmkp d5e5ec8c46 improve:卡死检测 2026-01-10 18:25:02 +08:00
CJKmkp b10215aec9 improve:开关逻辑 2026-01-10 18:22:58 +08:00
CJKmkp ea20f84d91 improve:自动更新 2026-01-10 18:14:55 +08:00
CJKmkp 008e843b39 Revert "fix:issue #339"
This reverts commit 172dd4f81b.
2026-01-10 18:06:58 +08:00
CJKmkp 172dd4f81b fix:issue #339 2026-01-10 18:02:07 +08:00
CJKmkp 4697fb4664 撤销新设置部分修改 2026-01-10 17:46:39 +08:00
CJKmkp c9e6ba972b 优化代码 2026-01-10 17:39:40 +08:00
CJKmkp 758f414302 Revert "add:新设置"
This reverts commit 0776071454.
2026-01-10 17:32:14 +08:00
CJKmkp 0fb5c04deb Revert "add:新设置"
This reverts commit fbfac18ca0.
2026-01-10 17:31:55 +08:00
CJKmkp 47885685fe Revert "add:新设置"
This reverts commit 89eb93aa67.
2026-01-10 17:31:50 +08:00
CJKmkp 8e87dddcd2 Revert "add:新设置"
This reverts commit 9d14f16fe2.
2026-01-10 17:31:46 +08:00
CJKmkp 4649649cf3 Revert "add:新设置"
This reverts commit acafdcc991.
2026-01-10 17:31:43 +08:00
CJKmkp 68a74be279 Revert "add:新设置"
This reverts commit 63585911a7.
2026-01-10 17:31:39 +08:00
CJKmkp 483e0757b7 撤销commit3cd2632 2026-01-10 17:31:10 +08:00
CJKmkp 9abce33257 Revert "improve:PPT墨迹加载"
This reverts commit e792f2637d.
2026-01-10 17:28:14 +08:00
CJKmkp 337d4d7288 撤销commit4fb73c1 2026-01-10 17:27:13 +08:00
CJKmkp bde0680f81 撤销commitf3ddd5a 2026-01-10 17:26:23 +08:00
CJKmkp ec579288a8 Revert "improve:PPT翻页打断"
This reverts commit ddfa9c2676.
2026-01-10 17:23:40 +08:00
CJK_mkp e2c222a156 Update copyright year in AssemblyInfo.cs 2026-01-08 11:32:46 +08:00
CJK_mkp 23de7e3575 更新信息 2026-01-08 11:32:16 +08:00
doudou0720 18a8f41bf3 fix(ci):扩大pr review范围到main,beta (#344)
* fix(ci):扩大pr review范围到main,beta

* fix(ci):将comment action v4 bump到 v5

* fix(ci):临时解决Action权限问题

* feat(ci):为nightly.link添加镜像

我估计应该没有外国人会用...
2026-01-08 11:31:43 +08:00
CJKmkp 63585911a7 add:新设置 2026-01-02 14:17:40 +08:00
CJKmkp acafdcc991 add:新设置 2026-01-02 13:38:04 +08:00
CJKmkp 9d14f16fe2 add:新设置 2026-01-02 13:14:10 +08:00
CJKmkp 89eb93aa67 add:新设置
主题优化
2026-01-02 12:59:04 +08:00
CJKmkp fbfac18ca0 add:新设置 2026-01-02 12:22:50 +08:00
CJKmkp 78b2f94bae 更新版本号 2026-01-02 11:18:19 +08:00
CJKmkp 89f0a401ef 代码优化 2026-01-02 10:05:57 +08:00
CJKmkp 0776071454 add:新设置 2026-01-02 09:47:34 +08:00
CJKmkp 56fb29fe15 improve:自动收纳 2026-01-02 09:28:00 +08:00
CJKmkp d7ed3884d6 add:新设置 2026-01-02 01:35:22 +08:00
CJKmkp ba673ccf41 add:新设置 2026-01-01 19:39:20 +08:00
CJKmkp 44c1071d49 add:新设置 2026-01-01 19:30:55 +08:00
CJKmkp 7789240f64 add:新设置 2026-01-01 18:39:24 +08:00
CJKmkp 7eee02dc94 improve:显示画笔光标 2026-01-01 18:21:28 +08:00
CJKmkp 965957aa1b add:新设置 2026-01-01 18:18:48 +08:00
CJKmkp 65a3917f62 improve:xml上传Dlass 2026-01-01 18:15:33 +08:00
CJKmkp 6ba4a57bbc add:新设置 2026-01-01 17:57:42 +08:00
CJKmkp 4e13817509 improve:PPT翻页按钮透明度设置 2026-01-01 17:42:02 +08:00
CJKmkp a8330fa2e9 fix:issue #339 2026-01-01 17:41:48 +08:00
doudou0720 be0d444db9 docs(README):Add DeepWiki badge to README (#340)
用于触发deepwiki的每周重新更新索引,方便相对快速地找到问题

Copied from Classisland
2026-01-01 12:30:04 +08:00
CJKmkp ecf3c1ad04 improve:PPT时间胶囊 2026-01-01 12:17:27 +08:00
CJKmkp 6bf439f493 improve:窗口检测模型 2026-01-01 12:09:00 +08:00
CJKmkp 94b52941af add:PPT侧边栏 2025-12-31 19:24:10 +08:00
CJKmkp a80fb33880 improve:图片选中 2025-12-31 18:51:57 +08:00
CJKmkp 30e4c35165 add:issue #314 2025-12-31 18:42:26 +08:00
CJKmkp 9bd1214567 improve:直线拉直
水平直线算法改进
2025-12-31 16:57:03 +08:00
CJKmkp c28a2bd792 improve:PPT时间胶囊
动画改进
2025-12-31 16:49:54 +08:00
CJKmkp 45a7e586c7 improve:Dlass服务
支持xml上传
2025-12-31 16:40:47 +08:00
CJKmkp 5903bab81f fix:issue #339 2025-12-31 16:38:02 +08:00
CJKmkp 295f8f56e3 fix:光标显示功能
修复开启后不显示的问题
2025-12-31 16:36:21 +08:00
CJKmkp 4cc8af7ff0 improve:PPT时间胶囊
改进主题
2025-12-31 16:28:04 +08:00
CJKmkp bca2dde497 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2025-12-31 16:01:59 +08:00
CJKmkp a8a72159f0 improve:颜色选择后行为 2025-12-31 16:01:37 +08:00
CreeperAWA 8ea7cb6ac2 Remove redundant SHA256 hash calculations from release workflow (#338)
Removed hash calculations for ZIP and installer files in the prerelease workflow.
2025-12-31 15:55:07 +08:00
2,2,3-三甲基戊烷 2b721b111b Merge pull request #337 from InkCanvasForClass/all-contributors/add-2-2-3-trimethylpentane
docs: add 2-2-3-trimethylpentane as a contributor for test, tutorial, and video
2025-12-28 15:24:02 +08:00
allcontributors[bot] d7e080a579 docs: update .all-contributorsrc 2025-12-28 07:23:37 +00:00
allcontributors[bot] 6429c242e4 docs: update README.md 2025-12-28 07:23:36 +00:00
CJKmkp aa7b593b65 更新版本号 2025-12-28 15:11:55 +08:00
CJKmkp fabac7e2bb improve:点名UI
优化显示范围
2025-12-28 14:32:22 +08:00
CJKmkp 9b5ee56a09 improve:issue #175 2025-12-28 14:30:02 +08:00
CJKmkp c78d3d74c2 improve:更新提示 2025-12-28 13:59:25 +08:00
CJKmkp b1459901d0 fix:issue #329 2025-12-28 12:35:05 +08:00
CJKmkp aba56ac340 improve:直线拉直 2025-12-28 11:00:24 +08:00
CJKmkp 3d4e1872f1 add:新设置
增加搜索功能
2025-12-28 10:40:13 +08:00
doudou0720 7a4d33b7da fix(Workflow):删除obj缓存 (#336)
Removed caching of obj/ folders to prevent cross-version incremental build issues while retaining NuGet package caching.
2025-12-28 10:22:18 +08:00
CJKmkp afb65eb908 fix:触摸墨迹选中问题 2025-12-28 10:01:02 +08:00
CJKmkp df5daeeb75 add:新设置 2025-12-28 08:48:09 +08:00
CJKmkp 792779e5b2 Revert "fix:触摸墨迹选中"
This reverts commit 8172b7c776.
2025-12-28 08:37:05 +08:00
CJKmkp 3313a0a182 add:xml格式墨迹保存 2025-12-28 00:08:08 +08:00
CJKmkp 88dd53302f improve:PPT时间胶囊 2025-12-27 23:00:50 +08:00
CJKmkp e972adfbcb fix:issue #332 2025-12-27 22:57:22 +08:00
CJKmkp ab6425e0d9 fix:浮动栏收纳 2025-12-27 22:53:34 +08:00
CJKmkp a81ee5b3db add:PPT时间胶囊(没做完不好看) 2025-12-27 22:41:24 +08:00
CJKmkp fae08a5285 Revert "improve:issue #332"
This reverts commit ca4d2ac4a2.
2025-12-27 21:16:55 +08:00
CJKmkp eeb4a25d7a fix:issue #327 2025-12-27 19:46:08 +08:00
CJK_mkp fdf07180dd Merge branches 'beta' and 'beta' of https://github.com/InkCanvasForClass/community into beta 2025-12-27 18:40:55 +08:00
CJK_mkp 6387a6fcda fix:issue #334 2025-12-27 18:27:30 +08:00
CJK_mkp a6e400629a improve:墨迹纠正
纠正后补点
2025-12-27 18:22:00 +08:00
CJK_mkp 8172b7c776 fix:触摸墨迹选中 2025-12-27 18:13:54 +08:00
CJK_mkp ca4d2ac4a2 improve:issue #332 2025-12-27 17:58:53 +08:00
allcontributors[bot] abd9f850eb docs: add CJKmkp as a contributor for design (#333)
* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-12-27 17:31:08 +08:00
CJK_mkp 3aef6f5e05 fix:issue #327 2025-12-27 16:55:59 +08:00
CJK_mkp 2f957374e3 fix:issue #330 2025-12-27 16:51:46 +08:00
CJK_mkp 3f8cabc7e0 improve:PPT放映时的浮动栏定位 2025-12-27 16:41:30 +08:00
CJK_mkp 73d1dc8f48 improve:注释 2025-12-27 16:31:50 +08:00
CJK_mkp 2bfb78a257 撤销commitc99bd2b 2025-12-27 16:29:47 +08:00
PrefacedCorg 783e5c43a5 代码清理 2025-12-27 12:05:34 +08:00
PrefacedCorg d7e8330016 优化代码可读性
其实单纯就是强迫症
2025-12-27 10:51:42 +08:00
CJK_mkp 80d3836e9e fix:墨迹质量问题 2025-12-21 17:31:06 +08:00
CJK_mkp c26d1c348e fix:墨迹质量问题 2025-12-21 17:30:29 +08:00
PrefacedCorg 95c307cc0b 修改任务栏高度计算方式
应该可以解决 dock 栏偏移的问题 可能会炸 炸了再说
2025-12-21 16:32:23 +08:00
allcontributors[bot] 6e7299e445 docs: add doudou0720 as a contributor for code (#328)
* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2025-12-21 00:44:06 +08:00
CJKmkp 01fa047591 improve:pre-release
优化注释
2025-12-21 00:38:27 +08:00
CJKmkp 8c741c1fb7 improve:pre-release 2025-12-21 00:36:17 +08:00
CJK_mkp b0bfc8d5ed Update prerelease.yml 2025-12-21 00:00:52 +08:00
doudou0720 ad8d8f94ff Merge pull request #320 from doudou0720/beta-image
!refactor(CI/CD):构建工作流重构
2025-12-20 23:46:37 +08:00
PrefacedCorg c99bd2bb63 Update MainWindow.xaml 2025-12-20 23:00:04 +08:00
CJKmkp 468df7dad7 add:PPT按钮透明度设置 2025-12-20 22:56:13 +08:00
CJKmkp 3c2e4a0990 delete:新设置内选项 2025-12-20 21:26:03 +08:00
CJKmkp 87b717f6a9 improve:倒计时音效 2025-12-20 21:04:48 +08:00
PrefacedCorg 51dc45988e Revert "撤回commit8042b91"
This reverts commit 81621cb9d0.
2025-12-20 20:46:18 +08:00
CJKmkp 2f8b986f1f 更新版本号 2025-12-20 20:23:38 +08:00
CJKmkp 7f01e7acb6 improve:点名算法
改进不放回随机
2025-12-20 19:57:11 +08:00
CJKmkp d011d2ba8a improve:多指书写
优化性能
2025-12-20 19:55:37 +08:00
CJKmkp a922654c17 improve:多指书写 2025-12-20 19:36:16 +08:00
CJKmkp e70a486362 add:一言API
新增名言种类
2025-12-20 19:28:47 +08:00
CJKmkp 1683bc8418 improve:自动更新
优化线路自动测速
2025-12-20 19:18:58 +08:00
CJKmkp b6368fb0e4 add:有更新时系统级弹窗 2025-12-20 19:16:39 +08:00
CJKmkp ddfa9c2676 improve:PPT翻页打断
改进打断逻辑
2025-12-20 18:42:25 +08:00
CJKmkp f3ddd5a11a improve:PPT翻页打断
新增设置项
2025-12-20 18:37:57 +08:00
CJKmkp 39e8b2359e improve:PPT自动播放及记忆上次播放页码
改进弹窗出现时机
2025-12-20 18:25:07 +08:00
CJKmkp 4fb73c155b improve:PPT翻页打断 2025-12-20 18:11:27 +08:00
CJKmkp 3287603d0a fix:快捷键问题 2025-12-20 18:04:08 +08:00
CJKmkp 1abb317054 add;自动清理过期配置
避免老版本配置保留
2025-12-20 17:52:56 +08:00
CJKmkp 719e37c26b improve:清空点名名单
改进清空历史记录
2025-12-20 17:50:00 +08:00
CJKmkp 45d2f99fd7 improve:历史版本回滚
支持最近不再接收更新
2025-12-20 17:45:35 +08:00
CJKmkp f75fdded98 fix:开关显示异常 2025-12-20 17:38:36 +08:00
CJKmkp 22a6d87771 fix:几何绘制中断
解决绘制过程中增加触摸点导致后续失效
2025-12-20 17:33:50 +08:00
CJKmkp 2479da4bbc fix:错误注释 2025-12-20 17:31:57 +08:00
CJKmkp c22424d798 Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2025-12-20 17:31:03 +08:00
CJKmkp bbb30b7c25 improve:几何长按状态显示 2025-12-20 17:30:18 +08:00
CJKmkp 71cbe12cee improve:浮动栏按钮UI
优化按钮显示
2025-12-20 17:28:11 +08:00
CJKmkp 011effa047 优化代码 2025-12-20 17:22:17 +08:00
PrefacedCorg b1648dd702 更改避免全屏的解释说明 2025-12-20 17:07:52 +08:00
CJKmkp 81621cb9d0 撤回commit8042b91 2025-12-20 16:05:37 +08:00
PrefacedCorg 3f460d7a5c 代码清理 2025-12-20 13:56:46 +08:00
PrefacedCorg 6fe34c1250 feat: 白板和批注模式自动全屏 2025-12-20 13:28:47 +08:00
PrefacedCorg d5cac938c2 feat: 启用避免全屏助手时自动全屏处理白板和批注模式
- 进入白板/批注模式时自动全屏
- 退出时恢复工作区域大小
- 添加状态跟踪避免重复处理
- PPT放映模式和白板模式切换时正确管理全屏状态
2025-12-20 13:03:31 +08:00
CJKmkp 6222fabdd4 add:新下载新路 2025-12-13 22:01:21 +08:00
CJKmkp 8ed4f25499 improve:GitHub工作流 2025-12-13 21:12:18 +08:00
CJKmkp 3afd4641cd 更新版本号 2025-12-13 21:06:31 +08:00
CJKmkp e9fde97453 improve:GitHub工作流 2025-12-13 21:02:11 +08:00
CJKmkp 441f8b6e26 优化按钮名称 2025-12-13 20:47:30 +08:00
CJKmkp 8042b917a0 improve:浮动栏按钮UI
优化按钮显示
2025-12-13 20:45:31 +08:00
CJKmkp 343e7281fe improve:端点吸附
避免点线和虚线吸附
2025-12-13 20:32:43 +08:00
CJKmkp c64e6a4554 improve:issue #252
改进双指拖动
2025-12-13 20:22:23 +08:00
CJKmkp 8190bf275c Merge branch 'beta' of https://github.com/InkCanvasForClass/community into beta 2025-12-13 20:13:14 +08:00
CJKmkp e792f2637d improve:PPT墨迹加载 2025-12-13 20:13:08 +08:00
CJKmkp 3cd26323dc improve:翻页墨迹加载及浮动栏定位 2025-12-13 20:07:25 +08:00
PrefacedCorg 40e1c4d467 Update MW_FloatingBarIcons.cs 2025-12-13 19:54:10 +08:00
PrefacedCorg 86c22d373a Revert "feat: 添加白板模式自动全屏功能" 2025-12-13 19:48:21 +08:00
PrefacedCorg cb7a76efc5 Delete .vscode directory 2025-12-13 19:39:08 +08:00
PrefacedCorg 545425c4d3 Delete .kiro/steering directory 2025-12-13 19:38:34 +08:00
PrefacedCorg eb1aaa10e4 feat: 添加白板模式自动全屏功能
- 新增"白板模式自动全屏"设置选项
- 进入白板模式时自动全屏,退出时恢复工作区域大小
- 需配合"避免全屏助手"功能使用
- 用户可独立控制白板模式的全屏行为
2025-12-13 19:27:47 +08:00
CJKmkp daf0db312b improve:仅PPT模式
优化浮动栏显示
2025-12-13 18:02:05 +08:00
CJKmkp 8b2bc2f064 improve:退出放映时收纳及PPT记忆上次播放页数 2025-12-13 17:38:35 +08:00
CJKmkp 2e343cbbf9 improve:计时器
优化计时器行为
2025-12-13 17:20:18 +08:00
CJKmkp a75f0470bc improve:点名算法
缩小极差
2025-12-13 17:12:00 +08:00
CJKmkp 287d31a3a9 improve:窗口模式 2025-12-13 17:03:58 +08:00
CJKmkp 430fff0515 优化注释 2025-12-06 23:04:27 +08:00
CJKmkp fbbb7b8ad7 improve:issue #252
改进几何绘制
2025-12-06 23:01:41 +08:00
CJKmkp 54b74d7411 improve:issue #252
改进手掌擦及手势
2025-12-06 22:55:55 +08:00
CJKmkp 82dba31b2a improve:直线拉直
改进高精度拉直
2025-12-06 22:06:28 +08:00
CJKmkp 38d7e782e0 improve:issue #252
修复了几何绘制和多指书写状态问题
2025-11-30 11:51:19 +08:00
CJKmkp 05e5ceeb43 improve:计时器
改进主题加载
2025-11-29 23:11:01 +08:00
CJKmkp fcbbad71d2 更新版本号 2025-11-29 22:23:14 +08:00
CJKmkp 6f9161439f improve:直线拉直
改进直线拉直算法
2025-11-29 22:20:13 +08:00
CJKmkp aa0c4fb841 improve:Dlass服务
优化上传体验
2025-11-29 17:26:47 +08:00
CJKmkp cff50d1f81 fix:快捷键管理 2025-11-29 17:26:41 +08:00
CJKmkp b8581b6368 improve:点名算法
优化概率模型
2025-11-29 16:58:40 +08:00
CJKmkp 094f1223d1 improve:崩溃日志位置 2025-11-29 16:46:33 +08:00
CJKmkp 6802476afa improve:计时器UI
将计时器窗口整合至主窗口,优化全屏计时逻辑
2025-11-29 16:27:35 +08:00
CJKmkp a0539dce9b 更新版本号 2025-11-15 21:36:49 +08:00
CJKmkp bf2b8fec35 improve:计时器UI与点名UI
改进视觉反馈和按钮逻辑及窗口置顶
2025-11-15 21:14:08 +08:00
CJKmkp 082c9a03ec fix:issue #287 2025-11-15 20:48:04 +08:00
CJKmkp 4ccdd862ba improve:PPT模块
修复无焦点状态下键盘翻页无效
2025-11-15 20:24:28 +08:00
CJKmkp e5a20ed0fc improve:点名历史查看 2025-11-15 20:20:56 +08:00
CJKmkp a72022704e improve:点名算法 2025-11-15 19:34:52 +08:00
CJKmkp 2acc7ada30 improve:错误检测 2025-11-15 19:31:57 +08:00
CJKmkp e61882c331 improve:点名
点名算法优化
2025-11-15 19:20:35 +08:00
CJKmkp 61c145689a fix:issue #281 2025-11-15 18:41:42 +08:00
CJKmkp 40ea9664a7 improve:快抽置顶 2025-11-15 18:37:23 +08:00
CJKmkp bccd2d0f3e improve:PPT墨迹保存 2025-11-15 18:19:53 +08:00
CJKmkp b918809dca improve:线擦擦除 2025-11-15 18:06:36 +08:00
CJKmkp e7c2e92879 improve:PPT联动及墨迹管理
改回原处理模式,优化翻页操作
2025-11-15 18:04:22 +08:00
CJK_mkp cf03c921a7 更新版本号 2025-11-08 23:16:36 +08:00
CJK_mkp 2c45c839b1 Revert "improve:无焦点模式"
This reverts commit 83f5fc58d1.
2025-11-08 23:09:04 +08:00
CJK_mkp 83f5fc58d1 improve:无焦点模式 2025-11-08 22:55:18 +08:00
CJK_mkp 1a267f1e5a improve:点名 2025-11-08 22:23:44 +08:00
CJK_mkp c3fd5551d8 improve:快抽按钮 2025-11-08 22:17:52 +08:00
CJK_mkp 1baa74bb69 improve:快抽按钮 2025-11-08 22:07:38 +08:00
CJK_mkp 261ecefb17 improve:注释 2025-11-08 21:42:33 +08:00
CJK_mkp d81d8f7c5d improve:Dlass联动 2025-11-08 21:01:50 +08:00
CJK_mkp de1af12157 更新版本号 2025-11-08 20:41:43 +08:00
CJK_mkp 803cbbdee9 improve:默认设置 2025-11-08 20:29:18 +08:00
CJK_mkp 008477d5fa improve:默认设置 2025-11-08 20:17:51 +08:00
CJK_mkp 7f0d29ebd2 improve:快抽窗口 2025-11-08 20:07:00 +08:00
CJK_mkp 11bf8cffb2 improve:PPT墨迹加载 2025-11-08 19:55:10 +08:00
CJK_mkp 87b9ebc7e1 improve:PPT墨迹显示 2025-11-08 19:36:05 +08:00
CJK_mkp b89d27411b improve:计时器逻辑 2025-11-08 19:20:26 +08:00
CJK_mkp 24c37f1d3e fix:计时器时间不一致 2025-11-08 19:17:58 +08:00
CJK_mkp 58b0a0a3be fix:负数导致的计时器崩溃 2025-11-08 19:15:16 +08:00
CJK_mkp ed58873a82 fix:issue #272 2025-11-08 19:02:37 +08:00
CJK_mkp a8dcbd4af0 add:点名历史查看 2025-11-08 18:01:56 +08:00
CJK_mkp 4b2f29442a improve:点名 2025-11-07 10:36:24 +08:00
CJK_mkp dfab0d7ddf improvve:点名快抽 2025-11-07 10:35:27 +08:00
CJK_mkp ce1998b701 improve:Dlass 界面UI 2025-11-07 09:46:21 +08:00
CJK_mkp 92c631d6ce improve:操作逻辑 2025-11-02 12:34:50 +08:00
CJK_mkp 01009f9e35 更新版本号 2025-11-02 11:47:52 +08:00
CJK_mkp 74eca093da improve:悬浮快抽按钮 2025-11-02 11:40:27 +08:00
CJK_mkp e7d89e65b2 improve:AutoUpdate 2025-11-02 11:27:46 +08:00
CJK_mkp 24b2bffe8e improve:计时器窗口 2025-11-02 11:12:13 +08:00
CJK_mkp d2906476c8 add:Dlass联动 2025-11-02 10:46:16 +08:00
CJK_mkp 2b31a355ae add:Dlass联动 2025-11-02 10:30:36 +08:00
CJK_mkp b602048186 add:Dlass联动 2025-11-02 10:16:31 +08:00
CJK_mkp 4fb7031060 add:Dlass联动 2025-11-02 10:11:15 +08:00
CJK_mkp 4ef77c2e72 add:Dlass联动 2025-11-02 09:41:53 +08:00
CJK_mkp 72ba1a9f58 add:Dlass联动 2025-11-02 09:29:06 +08:00
CJK_mkp 0c3938b652 Merge pull request #274 from MKStoler1024/patch-1
Readme
2025-11-01 22:18:46 +08:00
CJK_mkp 16f80adb0d fix:issue #210 2025-11-01 22:12:47 +08:00
CJK_mkp 637b6bb4f9 fix:issue #210 2025-11-01 22:05:19 +08:00
CJK_mkp 12e91927a5 fix:issue #210 2025-11-01 21:56:31 +08:00
CJK_mkp 8f6f22ba7f 更新版本号 2025-11-01 21:37:55 +08:00
CJK_mkp b520d6a334 fix:issue #210 2025-11-01 21:00:23 +08:00
CJK_mkp b7bff30445 improve:UI 2025-11-01 20:49:37 +08:00
CJK_mkp 0d790bbd80 add:墨迹自动保存 2025-11-01 20:42:18 +08:00
CJK_mkp 8394e99127 improve:主题切换 2025-11-01 20:26:52 +08:00
CJK_mkp 16ae32bfd7 improve:点名UI 2025-11-01 19:17:52 +08:00
CJK_mkp cc6423e384 improve:点名UI 2025-11-01 18:56:38 +08:00
CJK_mkp 06cc587599 improve:启动动画 2025-11-01 18:46:04 +08:00
CJK_mkp 9d36088f1d fix:issue #210 2025-11-01 18:39:52 +08:00
CJK_mkp f9f73b015c improve:启动动画 2025-11-01 18:31:27 +08:00
CJK_mkp 77ffd696bb fix:手势面板不显示 2025-11-01 18:29:58 +08:00
CJK_mkp bdb8bed053 fix:issue #210 2025-11-01 18:25:35 +08:00
MKStoler1024 4b17c8e96e chore: remove sth in readme 2025-10-31 17:56:02 +08:00
MKStoler1024 8109711f4e chore: readme 2025-10-31 16:07:03 +08:00
CJK_mkp 327eba3fa7 Update MW_FloatingBarIcons.cs 2025-10-31 15:35:27 +08:00
CJK_mkp f3dccb2e99 Update MW_FloatingBarIcons.cs 2025-10-31 14:46:20 +08:00
CJK_mkp 7112d58e7c Update MW_ShapeDrawing.cs 2025-10-31 14:44:59 +08:00
CJK_mkp 6e0aad853c Update MW_TouchEvents.cs 2025-10-31 14:44:05 +08:00
CJK_mkp c64b1d0846 Update MW_BoardIcons.cs 2025-10-31 14:43:15 +08:00
CJK_mkp 6eba16ce99 Update MW_BoardIcons.cs 2025-10-31 12:19:30 +08:00
CJK_mkp 2f6f719843 Update MW_ShapeDrawing.cs 2025-10-31 12:18:45 +08:00
CJK_mkp f34bac49e4 Update MW_TouchEvents.cs 2025-10-31 12:16:52 +08:00
CJK_mkp 39cdc6231f Update MW_FloatingBarIcons.cs 2025-10-31 12:16:05 +08:00
CJK_mkp 745e24da70 Update MW_FloatingBarIcons.cs 2025-10-31 12:15:26 +08:00
CJK_mkp a4f4f4fb15 Update MW_TouchEvents.cs 2025-10-31 12:12:51 +08:00
CJK_mkp 3833c229c6 Update MW_FloatingBarIcons.cs 2025-10-31 12:11:02 +08:00
CJK_mkp 3dc3e9b5a8 Update MW_FloatingBarIcons.cs 2025-10-31 10:49:10 +08:00
CJK_mkp 12eeb79e9f 回滚一下 2025-10-30 12:02:29 +08:00
CJK_mkp e08c84f70d improve:点名快抽 2025-10-27 17:54:58 +08:00
CJK_mkp 10f55d5b65 fix:抽选结果截断 2025-10-27 17:45:41 +08:00
CJKmkp 761992d089 Delete PositionConverters.cs 2025-10-26 00:31:32 +08:00
229 changed files with 55586 additions and 23163 deletions
+51 -5
View File
@@ -1,4 +1,5 @@
{
"$schema": "https://www.schemastore.org/all-contributors.json",
"projectName": "community",
"projectOwner": "InkCanvasForClass",
"files": [
@@ -6,7 +7,7 @@
],
"commitType": "docs",
"commitConvention": "angular",
"contributorsPerLine": 7,
"contributorsPerLine": 5,
"contributors": [
{
"login": "CJKmkp",
@@ -16,7 +17,8 @@
"contributions": [
"maintenance",
"doc",
"code"
"code",
"design"
]
},
{
@@ -36,7 +38,10 @@
"contributions": [
"blog",
"doc",
"design"
"design",
"test",
"tutorial",
"video"
]
},
{
@@ -96,8 +101,49 @@
"avatar_url": "https://avatars.githubusercontent.com/u/156585442?v=4",
"profile": "https://github.com/Tayasui-rainnya",
"contributions": [
"design"
"design",
"code"
]
},
{
"login": "doudou0720",
"name": "doudou0720",
"avatar_url": "https://avatars.githubusercontent.com/u/98651603?v=4",
"profile": "https://github.com/doudou0720",
"contributions": [
"code",
"blog",
"infra"
]
},
{
"login": "PANDAJSR",
"name": "PANDAJSR",
"avatar_url": "https://avatars.githubusercontent.com/u/170189561?v=4",
"profile": "https://github.com/PANDAJSR",
"contributions": [
"code"
]
},
{
"login": "LiuYan-xwx",
"name": "流焰xwx",
"avatar_url": "https://avatars.githubusercontent.com/u/66517348?v=4",
"profile": "http://lyxwx.top",
"contributions": [
"code"
]
},
{
"login": "Super-Yyt",
"name": "Super-Yyt",
"avatar_url": "https://avatars.githubusercontent.com/u/206630707?v=4",
"profile": "https://github.com/Super-Yyt",
"contributions": [
"infra",
"blog"
]
}
]
],
"repoType": "github"
}
+12
View File
@@ -0,0 +1,12 @@
{
"image": "mcr.microsoft.com/devcontainers/dotnet",
"postCreateCommand": "dotnet restore",
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csdevkit",
"ms-dotnettools.csharp"
]
}
}
}
@@ -1,12 +1,15 @@
name: Bug 报告 | Bug Report
description: 反馈软件缺陷或异常 | Report a bug to help us improve
labels: [bug]
type: Bug
body:
- type: markdown
attributes:
value: |
感谢你的反馈!请详细填写以下内容,便于我们定位问题。
Thank you for your feedback! Please fill out the following information to help us locate the issue.
在报告问题之前,请确保你的软件已经更新到最新Beta版本,否则我们可能会无条件直接关闭该Issue,感谢配合!
Before reporting the issue, please make sure your software has been updated to the latest Beta version. Otherwise, we may unconditionally close this Issue without any further notice. Thank you for your cooperation!
- type: input
id: version
attributes:
@@ -33,7 +36,7 @@ body:
id: steps
attributes:
label: 复现步骤 | Steps to Reproduce
description: 如何复现该问题?如有必要可附截图/录屏 | How to reproduce this bug? Screenshots/recordings if needed
description: 如何复现该问题?如有必要可附截图/录屏/触发该问题的文件 | How to reproduce this bug? Screenshots/recordings/specific files if needed
placeholder: |
1.
2.
@@ -51,6 +54,13 @@ body:
id: extra
attributes:
label: 其他补充信息 | Additional Info
description: 其他相关信息(如日志、配置、特殊环境等)| Any other context, logs, configs, special environment, etc.
description: 其他相关信息(如日志文件、崩溃日志文件、配置文件、特殊环境等)| Any other context, logs, crash logs, configs, special environment, etc.
validations:
required: false
- type: upload
id: files
attributes:
label: 上传有关文件 | Upload relevant files
description: "你可以在此处上传相关文件 | You can upload relevant files here."
validations:
required: false
@@ -1,6 +1,6 @@
name: 功能请求 | Feature Request
description: 提出你对本项目的功能建议 | Suggest an idea for this project
labels: [enhancement]
type: Feature
body:
- type: markdown
attributes:
@@ -35,3 +35,10 @@ body:
description: 其他补充说明或建议 | Any other context or suggestions
validations:
required: false
- type: upload
id: files
attributes:
label: 上传有关文件 | Upload relevant files
description: "你可以在此处上传相关文件 | You can upload relevant files here."
validations:
required: false
+36
View File
@@ -0,0 +1,36 @@
---
name: (Markdown Template) Bug 报告 | Bug Report
about: 反馈软件缺陷或异常 | Report a bug to help us improve
title: "[Version x.x.x] <your title>"
type: Bug
---
<!---请注意,你正在使用Markdown格式的Issue模板,如果你删除该模板的框架、更改问题的tag/类型/受理人或者不按照规范填写,你的Issue可能被直接关闭,如果你对Markdown不熟悉,请使用位于该选项下方的反馈入口继续反馈,感谢配合!-->
<!---感谢你的反馈!请详细填写以下内容,便于我们定位问题。-->
<!---Thank you for your feedback! Please fill out the following information to help us locate the issue.-->
<!---在报告问题之前,请确保你的软件已经更新到最新Beta版本,否则我们可能会无条件直接关闭该Issue,感谢配合!-->
<!---Before reporting the issue, please make sure your software has been updated to the latest Beta version. Otherwise, we may unconditionally close this Issue without any further notice. Thank you for your cooperation!-->
### 软件版本 | App Version (必填 | Required)
<!---可在设置中的"关于"界面查看 | You can find it on the "About" interface in the settings-->
<!---例如 v1.2.3 | e.g. v1.2.3-->
### 操作系统及版本 | OS & Version (必填 | Required)
<!---例如 Windows 10 22H2 64位 | e.g. Windows 10 22H2 64bit-->
### 问题描述 | Description (必填 | Required)
<!---简要描述遇到的问题 | Briefly describe the problem-->
### 复现步骤 | Steps to Reproduce (必填 | Required)
<!---如何复现该问题?如有必要可附截图/录屏/触发该问题的文件 | How to reproduce this bug? Screenshots/recordings/specific files if needed-->
1.
2.
3.
### 期望结果 | Expected Behavior (必填 | Required)
<!---你期望的正确行为或结果 | What did you expect to happen?-->
### 其他补充信息 | Additional Info (可选 | Optional)
<!---其他相关信息(如日志文件、崩溃日志文件、配置文件、特殊环境等)| Any other context, logs, crash logs, configs, special environment, etc.-->
@@ -0,0 +1,23 @@
---
name: (Markdown Template) 功能请求 | Feature Request
about: 提出你对本项目的功能建议 | Suggest an idea for this project
title: "[Feature Request] "
type: Feature
---
<!---请注意,你正在使用Markdown格式的Issue模板,如果你删除该模板的框架、更改问题的tag/类型/受理人或者不按照规范填写,你的Issue可能被直接关闭,如果你对Markdown不熟悉,请使用位于该选项下方的反馈入口继续反馈,感谢配合!-->
<!---感谢你的建议!请详细描述你的需求。-->
<!---Thank you for your suggestion! Please describe your needs in detail.-->
### 功能描述 | Description (必填 | Required)
<!---请描述你希望添加的功能 | Describe the feature you want-->
### 需求动机 | Motivation (必填 | Required)
<!---为什么需要这个功能?| Why do you need this feature?-->
### 期望设计 | Expected Design (可选 | Optional)
<!---描述或画出你期望的界面或交互 | Describe or sketch the expected UI/UX-->
### 其他补充信息 | Additional Info (可选 | Optional)
<!---其他补充说明或建议 | Any other context or suggestions-->
+96 -25
View File
@@ -1,35 +1,106 @@
name: .NET Build
name: .NET Build & Package
on:
push:
branches: [ main,beta ]
pull_request:
branches: [ main ]
branches: [ main, beta ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build:
build-and-package:
name: Build & Package
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
architecture: [AnyCPU, x86]
steps:
- uses: actions/checkout@v4.2.2
- name: Setup MSbuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: NuGet/setup-nuget@v2.0.1
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Restore NuGet Packages
run: nuget restore "Ink Canvas.sln"
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v5
with:
cache: true
cache-dependency-path: '**/packages.lock.json'
- name: Restore Package
run: dotnet restore "Ink Canvas.sln" --locked-mode
- name: Build the Solution
env:
DLASS_SENTRY_DSN: ${{ secrets.DLASS_SENTRY_DSN }}
run: msbuild /p:platform="${{ matrix.architecture }}" /p:configuration="Debug" /p:GitFlow="$GITFLOW" "Ink Canvas/InkCanvasForClass.csproj" /m /p:UseMultiToolTask=true /p:EnforceProcessCountAcrossBuilds=true /verbosity:minimal -maxcpucount /p:RunAnalyzers=false
- name: Build the Solution
run: |
msbuild -t:restore /p:GitFlow="Github Action"
msbuild /p:platform="AnyCPU" /p:configuration="Debug" /p:GitFlow="Github Action" "Ink Canvas/InkCanvasForClass.csproj"
- name: Check if exe file is generated
id: check-exe
run: |
$exePath = "Ink Canvas\bin\Debug\${{ matrix.architecture }}\net472\InkCanvasForClass.exe"
if (Test-Path $exePath) {
echo "build_success=true" >> $env:GITHUB_OUTPUT
} else {
echo "build_success=false" >> $env:GITHUB_OUTPUT
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
exit 1
}
}
- name: Upload to artifact
uses: actions/upload-artifact@v4.5.0
with:
name: InkCanvasForClass
path: "Ink Canvas/bin/Debug/net472"
- name: Create Package (if build succeeded)
id: create-archive
if: steps.check-exe.outputs.build_success == 'true'
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
run: |
$shortSha = $env:GITHUB_SHA.Substring(0, 7)
$version = "debug-$shortSha-$env:GITHUB_RUN_NUMBER"
echo "archive_name=$version" >> $env:GITHUB_OUTPUT
- name: Upload Artifact (if build succeeded)
if: steps.check-exe.outputs.build_success == 'true'
uses: actions/upload-artifact@v7
with:
name: InkCanvasForClass.CE.debug.${{ matrix.architecture }}
path: "Ink Canvas/bin/Debug/${{ matrix.architecture }}/net472/*"
- name: Create Summary
if: always()
shell: bash
run: |
echo "# Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check-exe.outputs.build_success }}" = "true" ]; then
echo "## ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Run:** #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.create-archive.outputs.archive_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Architecture:** ${{ matrix.architecture }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[Download Artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[Nightly.link Download](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/InkCanvasForClass.CE.debug.${{ matrix.architecture }}.zip) \([GhProxy Fastly Mirror](https://cdn.gh-proxy.com/nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/InkCanvasForClass.CE.debug.${{ matrix.architecture }}.zip) / [GhProxy Mirror](https://gh-proxy.com/nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/InkCanvasForClass.CE.debug.${{ matrix.architecture }}.zip)\)" >> $GITHUB_STEP_SUMMARY
else
echo "## ❌ Build Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Event:** ${{ github.event_name }} (${{ github.event.action || 'N/A' }})" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Architecture:** ${{ matrix.architecture }}" >> $GITHUB_STEP_SUMMARY
echo "**Run:** #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check build logs for details." >> $GITHUB_STEP_SUMMARY
fi
+104
View File
@@ -0,0 +1,104 @@
name: PR Check
on:
pull_request:
types: [opened, synchronize]
branches: [ main, beta ]
paths-ignore:
- '**/*.md'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build-and-package:
name: Build & Package
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
architecture: [AnyCPU, x86]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v5
- name: Restore Package
run: dotnet restore "Ink Canvas.sln" --locked-mode
- name: Build the Solution
run: msbuild /p:platform="${{ matrix.architecture }}" /p:configuration="Debug" /p:GitFlow="$GITFLOW" "Ink Canvas/InkCanvasForClass.csproj" /m /p:UseMultiToolTask=true /p:EnforceProcessCountAcrossBuilds=true /verbosity:minimal -maxcpucount /p:RunAnalyzers=false
- name: Check if exe file is generated
id: check-exe
run: |
$exePath = "Ink Canvas\bin\Debug\${{ matrix.architecture }}\net472\InkCanvasForClass.exe"
if (Test-Path $exePath) {
echo "build_success=true" >> $env:GITHUB_OUTPUT
} else {
echo "build_success=false" >> $env:GITHUB_OUTPUT
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
exit 1
}
}
- name: Create Package (if build succeeded)
id: create-archive
if: steps.check-exe.outputs.build_success == 'true'
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
run: |
$shortSha = $env:GITHUB_SHA.Substring(0, 7)
$version = "debug-$shortSha-$env:GITHUB_RUN_NUMBER"
echo "archive_name=$version" >> $env:GITHUB_OUTPUT
- name: Upload Artifact (if build succeeded)
if: steps.check-exe.outputs.build_success == 'true'
uses: actions/upload-artifact@v7
with:
name: InkCanvasForClass.CE.debug.${{ matrix.architecture }}
path: "Ink Canvas/bin/Debug/${{ matrix.architecture }}/net472/*"
- name: Create Summary
if: always()
shell: bash
run: |
echo "# Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check-exe.outputs.build_success }}" = "true" ]; then
echo "## ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Run:** #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.create-archive.outputs.archive_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Architecture:** ${{ matrix.architecture }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[Download Artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[Nightly.link Download](https://nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/InkCanvasForClass.CE.debug.${{ matrix.architecture }}.zip) \([GhProxy Fastly Mirror](https://cdn.gh-proxy.com/nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/InkCanvasForClass.CE.debug.${{ matrix.architecture }}.zip) / [GhProxy Mirror](https://gh-proxy.com/nightly.link/${{ github.repository }}/actions/runs/${{ github.run_id }}/InkCanvasForClass.CE.debug.${{ matrix.architecture }}.zip)\)" >> $GITHUB_STEP_SUMMARY
else
echo "## ❌ Build Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Event:** ${{ github.event_name }} (${{ github.event.action || 'N/A' }})" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Architecture:** ${{ matrix.architecture }}" >> $GITHUB_STEP_SUMMARY
echo "**Run:** #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check build logs for details." >> $GITHUB_STEP_SUMMARY
fi
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -425,4 +425,8 @@ FodyWeavers.xsd
*.msi
*.msix
*.msm
*.msp
*.msp
# Telemetry DSN configuration file (contains sensitive information)
telemetry_dsn.txt
**/telemetry_dsn.txt
+1 -1
View File
@@ -1 +1 @@
1.7.16.0
1.7.18.0
+10 -10
View File
@@ -23,22 +23,22 @@ Global
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|ARM.ActiveCfg = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|ARM.Build.0 = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|ARM64.ActiveCfg = Debug|ARM64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|ARM64.Build.0 = Debug|ARM64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|ARM64.Build.0 = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|x64.ActiveCfg = Debug|x64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|x64.Build.0 = Debug|x64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|x86.ActiveCfg = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|x86.Build.0 = Debug|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|x86.ActiveCfg = Debug|x86
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Debug|x86.Build.0 = Debug|x86
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|Any CPU.Build.0 = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|ARM.ActiveCfg = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|ARM.Build.0 = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|ARM64.ActiveCfg = Release|ARM64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|ARM64.Build.0 = Release|ARM64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x64.ActiveCfg = Release|x64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x64.Build.0 = Release|x64
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x86.ActiveCfg = Release|x86
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x86.Build.0 = Release|x86
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|ARM64.ActiveCfg = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|ARM64.Build.0 = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x64.ActiveCfg = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x64.Build.0 = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x86.ActiveCfg = Release|Any CPU
{8D0EDFC7-F974-4571-BC49-6F3A6653FE81}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+59 -27
View File
@@ -1,9 +1,11 @@
<Application x:Class="Ink_Canvas.App"
<Application x:Class="Ink_Canvas.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Ink_Canvas"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:props="clr-namespace:Ink_Canvas.Properties"
xmlns:tb="clr-namespace:H.NotifyIcon;assembly=H.NotifyIcon.Wpf"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
>
<Application.Resources>
<ResourceDictionary>
@@ -13,9 +15,9 @@
<ContextMenu Opened="SysTrayMenu_Opened" Closed="SysTrayMenu_Closed" x:Shared="false" x:Key="SysTrayMenu" Padding="6" ui:ThemeManager.RequestedTheme="Light">
<MenuItem IsCheckable="True" IsChecked="False" Checked="HideICCMainWindowTrayIconMenuItem_Checked" Unchecked="HideICCMainWindowTrayIconMenuItem_UnChecked" Name="HideICCMainWindowTrayIconMenuItem">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock Name="HideICCMainWindowTrayIconMenuItemHeaderText" FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="隐藏ICC主窗口" />
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="28" Height="28" Margin="-2">
@@ -31,12 +33,42 @@
</Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="TempShowMainWindowTrayIconMenuItem" Click="TempShowMainWindowTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="{x:Static props:Strings.Tray_TempShowMainWindow}" />
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="28" Height="28" Margin="-2">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
<GeometryDrawing Brush="#27272a" Geometry="F0 M24,24z M0,0z M5,6C4.73478,6 4.48043,6.10536 4.29289,6.29289 4.10536,6.48043 4,6.73478 4,7L4,17C4,17.2652 4.10536,17.5196 4.29289,17.7071 4.48043,17.8946 4.73478,18 5,18L19,18C19.2652,18 19.5196,17.8946 19.7071,17.7071 19.8946,17.5196 20,17.2652 20,17L20,7C20,6.73478 19.8946,6.48043 19.7071,6.29289 19.5196,6.10536 19.2652,6 19,6L5,6z M2.87868,4.87868C3.44129,4.31607,4.20435,4,5,4L19,4C19.7957,4 20.5587,4.31607 21.1213,4.87868 21.6839,5.44129 22,6.20435 22,7L22,17C22,17.7957 21.6839,18.5587 21.1213,19.1213 20.5587,19.6839 19.7957,20 19,20L5,20C4.20435,20 3.44129,19.6839 2.87868,19.1213 2.31607,18.5587 2,17.7956 2,17L2,7C2,6.20435,2.31607,5.44129,2.87868,4.87868z M5,8C5,7.44772,5.44772,7,6,7L6.01,7C6.56228,7 7.01,7.44772 7.01,8 7.01,8.55228 6.56228,9 6.01,9L6,9C5.44772,9,5,8.55228,5,8z M9,7C8.44772,7 8,7.44772 8,8 8,8.55228 8.44772,9 9,9L9.01,9C9.56228,9 10.01,8.55228 10.01,8 10.01,7.44772 9.56228,7 9.01,7L9,7z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Name="OpenSettingsTrayIconMenuItem" Click="OpenSettingsTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="{x:Static props:Strings.Tray_OpenSettings}" />
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="28" Height="28" Margin="-2" Source="/Resources/Icons-Fluent/ic_fluent_settings_24_regular.png" />
</MenuItem.Icon>
</MenuItem>
<Separator Margin="0,3" />
<MenuItem Name="DisableAllHotkeysMenuItem" Click="DisableAllHotkeysMenuItem_Clicked">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="禁用所有快捷键" />
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="28" Height="28" Margin="-2">
@@ -54,9 +86,9 @@
</MenuItem>
<MenuItem Name="ForceFullScreenTrayIconMenuItem" Click="ForceFullScreenTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="强制全屏化" />
<ui:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="CTRL" />
</Border>
@@ -64,8 +96,8 @@
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="F" />
</Border>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="28" Height="28" Margin="-2">
@@ -87,9 +119,9 @@
</MenuItem>
<MenuItem Name="FoldFloatingBarTrayIconMenuItem" Click="FoldFloatingBarTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock Name="FoldFloatingBarTrayIconMenuItemHeaderText" FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="切换为收纳模式" />
<ui:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="CTRL" />
</Border>
@@ -97,8 +129,8 @@
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="S" />
</Border>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Grid>
@@ -132,9 +164,9 @@
</MenuItem>
<MenuItem Name="ResetFloatingBarPositionTrayIconMenuItem" Click="ResetFloatingBarPositionTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" VerticalAlignment="Center" Foreground="#18181b" Text="重置工具栏位置" />
<ui:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="CTRL" />
</Border>
@@ -142,8 +174,8 @@
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="T" />
</Border>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="28" Height="28" Margin="-2">
@@ -163,9 +195,9 @@
<Separator Margin="0,3" />
<MenuItem Name="RestartAppTrayIconMenuItem" Click="RestartAppTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" FontWeight="Bold" VerticalAlignment="Center" Foreground="#2563eb" Text="重启软件" />
<ui:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="CTRL" />
</Border>
@@ -173,8 +205,8 @@
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="R" />
</Border>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="24" Height="24">
@@ -195,9 +227,9 @@
</MenuItem>
<MenuItem Name="CloseAppTrayIconMenuItem" Click="CloseAppTrayIconMenuItem_Clicked">
<MenuItem.Header>
<ui:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" Margin="-4,0,0,0">
<TextBlock FontSize="14" FontWeight="Bold" VerticalAlignment="Center" Foreground="#dc2626" Text="退出软件" />
<ui:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<ikw:SimpleStackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4" Margin="16,0,0,0">
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="CTRL" />
</Border>
@@ -205,8 +237,8 @@
<Border Padding="4,2,4,1" Background="#e4e4e7" BorderBrush="#a1a1aa" BorderThickness="1" CornerRadius="2.5">
<TextBlock FontSize="8" Foreground="#3f3f46" FontWeight="Bold" Text="Q" />
</Border>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
</MenuItem.Header>
<MenuItem.Icon>
<Image Width="24" Height="24">
@@ -231,7 +263,7 @@
ToolTipText="InkCanvasForClass"
ContextMenu="{StaticResource SysTrayMenu}"
IconSource="/Resources/icc.ico"/>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources/>
<ui:XamlControlsResources />
<ResourceDictionary Source="Resources/SeewoImageDictionary.xaml"/>
+390 -52
View File
@@ -1,8 +1,10 @@
using Hardcodet.Wpf.TaskbarNotification;
using H.NotifyIcon;
using Ink_Canvas.Helpers;
using Ink_Canvas.Properties;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
using Newtonsoft.Json;
using Sentry;
using System;
using System.Diagnostics;
using System.IO;
@@ -31,7 +33,7 @@ namespace Ink_Canvas
Mutex mutex;
public static string[] StartArgs;
public static string RootPath = Environment.GetEnvironmentVariable("APPDATA") + "\\Ink Canvas\\";
public static string RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
// 新增:标记是否通过--board参数启动
public static bool StartWithBoardMode = false;
@@ -41,12 +43,16 @@ namespace Ink_Canvas
public static Process watchdogProcess;
// 新增:标记是否为软件内主动退出
public static bool IsAppExitByUser;
// 新增:标记是否正在触发安装更新(用于跳过某些交互确认)
public static bool IsUpdateInstalling;
// 新增:标记是否启用了UIA置顶功能
public static bool IsUIAccessTopMostEnabled;
// 新增:标记是否正在显示 OOBE(首次启动向导),看门狗在此期间不判定为卡死/假死
public static bool IsOobeShowing;
// 新增:退出信号文件路径
private static string watchdogExitSignalFile = Path.Combine(Path.GetTempPath(), "icc_watchdog_exit_" + Process.GetCurrentProcess().Id + ".flag");
// 新增:崩溃日志文件路径
private static string crashLogFile = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "Ink Canvas", "crash_logs");
private static string crashLogFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Crashes");
// 新增:进程ID
private static int currentProcessId = Process.GetCurrentProcess().Id;
// 新增:应用启动时间
@@ -59,8 +65,39 @@ namespace Ink_Canvas
private static SplashScreen _splashScreen;
private static bool _isSplashScreenShown = false;
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int SetCurrentProcessExplicitAppUserModelID(string appId);
public App()
{
try
{
SetCurrentProcessExplicitAppUserModelID("InkCanvasForClass.CE");
}
catch
{
}
try
{
var dsn = GetDlassTelemetryDsn();
if (!string.IsNullOrWhiteSpace(dsn))
{
SentrySdk.Init(options =>
{
options.Dsn = dsn;
options.Debug = false;
options.SendDefaultPii = true;
options.TracesSampleRate = 1.0;
options.IsGlobalModeEnabled = true;
});
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"初始化 Dlass 遥测失败: {ex}", LogHelper.LogType.Warning);
}
// 配置TLS协议以支持Windows 7
ConfigureTlsForWindows7();
@@ -107,7 +144,6 @@ namespace Ink_Canvas
if (isWindows7)
{
LogHelper.WriteLogToFile("检测到Windows 7系统,配置TLS协议支持");
// 启用所有TLS版本以支持Windows 7
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
@@ -117,17 +153,14 @@ namespace Ink_Canvas
ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;
LogHelper.WriteLogToFile("TLS协议配置完成,已启用TLS 1.2/1.1/1.0支持");
}
else
{
// 对于更新的Windows版本,不进行任何TLS配置,使用系统默认设置
LogHelper.WriteLogToFile($"检测到Windows版本: {osVersion.VersionString},使用系统默认TLS配置");
}
}
catch (Exception ex)
catch (Exception)
{
LogHelper.WriteLogToFile($"配置TLS协议时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
@@ -346,6 +379,25 @@ namespace Ink_Canvas
try
{
var exception = e.ExceptionObject as Exception;
if (exception is InvalidOperationException invalidOpEx)
{
string exceptionMessage = invalidOpEx.Message ?? "";
string exceptionStackTrace = invalidOpEx.StackTrace ?? "";
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
exceptionMessage.Contains("because another thread owns it") ||
exceptionStackTrace.Contains("DynamicRenderer") ||
exceptionStackTrace.Contains("CompositionTarget.get_RootVisual"))
{
LogHelper.WriteLogToFile(
$"检测到DynamicRenderer线程访问异常: {invalidOpEx.Message}",
LogHelper.LogType.Warning
);
return;
}
}
string errorMessage = exception?.ToString() ?? "未知异常";
lastErrorMessage = errorMessage;
@@ -361,12 +413,15 @@ namespace Ink_Canvas
// 尝试在最后时刻记录错误
try
{
string timeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
: DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
File.AppendAllText(
Path.Combine(crashLogFile, $"critical_error_{DateTime.Now:yyyyMMdd_HHmmss}.log"),
Path.Combine(crashLogFile, $"Crash_{timeStr}.txt"),
$"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 记录未处理异常时发生错误: {ex.Message}\r\n"
);
}
catch { }
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
@@ -420,6 +475,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile("启动画面对象创建成功,准备显示...");
_splashScreen.Show();
_isSplashScreenShown = true;
splashScreenStartTime = DateTime.Now;
LogHelper.WriteLogToFile("启动画面已显示");
}
catch (Exception ex)
@@ -489,6 +545,19 @@ namespace Ink_Canvas
}
}
private static bool IsLaunchByFileOrUri(string[] args)
{
if (args == null || args.Length == 0) return false;
foreach (string a in args)
{
if (string.IsNullOrWhiteSpace(a)) continue;
string t = a.Trim();
if (t.StartsWith("icc:", StringComparison.OrdinalIgnoreCase)) return true;
if (Path.GetExtension(t).Equals(".icstk", StringComparison.OrdinalIgnoreCase)) return true;
}
return false;
}
// 记录崩溃日志
private static void WriteCrashLog(string message)
{
@@ -500,7 +569,10 @@ namespace Ink_Canvas
Directory.CreateDirectory(crashLogFile);
}
string logFileName = Path.Combine(crashLogFile, $"crash_{DateTime.Now:yyyyMMdd}.log");
string appStartTimeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
: DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string logFileName = Path.Combine(crashLogFile, $"Crash_{appStartTimeStr}.txt");
// 收集系统状态信息
string memoryUsage = (Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024)) + " MB";
@@ -518,7 +590,7 @@ namespace Ink_Canvas
// 同时记录到主日志
LogHelper.WriteLogToFile(message, LogHelper.LogType.Error);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
// 增加字段保存崩溃后操作设置
@@ -535,7 +607,7 @@ namespace Ink_Canvas
var json = File.ReadAllText(settingsPath);
dynamic obj = JsonConvert.DeserializeObject(json);
int crashAction = 0;
try { crashAction = (int)(obj["startup"]["crashAction"] ?? 0); } catch { }
try { crashAction = (int)(obj["startup"]["crashAction"] ?? 0); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
CrashAction = (CrashActionType)crashAction;
}
// 从主窗口同步
@@ -544,12 +616,37 @@ namespace Ink_Canvas
CrashAction = (CrashActionType)Ink_Canvas.MainWindow.Settings.Startup.CrashAction;
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Ink_Canvas.MainWindow.ShowNewMessage("抱歉,出现未预期的异常,可能导致 InkCanvasForClass 运行不稳定。\n建议保存墨迹后重启应用。");
// 检查是否是DynamicRenderer线程访问UI对象的已知问题
if (e.Exception is InvalidOperationException invalidOpEx)
{
string exceptionMessage = invalidOpEx.Message ?? "";
string exceptionStackTrace = invalidOpEx.StackTrace ?? "";
// 检查是否是DynamicRenderer相关的线程访问问题
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
exceptionMessage.Contains("because another thread owns it") ||
exceptionStackTrace.Contains("DynamicRenderer") ||
exceptionStackTrace.Contains("CompositionTarget.get_RootVisual"))
{
// 这是WPF InkCanvas的已知问题,DynamicRenderer的后台线程尝试访问UI对象
// 这个异常不会影响应用程序功能,可以安全地忽略
LogHelper.WriteLogToFile(
$"检测到DynamicRenderer线程访问异常(已安全处理): {invalidOpEx.Message}",
LogHelper.LogType.Warning
);
// 标记为已处理,不显示错误消息,不触发重启
e.Handled = true;
return;
}
}
Ink_Canvas.MainWindow.ShowNewMessage(Strings.GetString("Msg_UnexpectedError"));
LogHelper.NewLog(e.Exception.ToString());
// 记录到崩溃日志
@@ -565,7 +662,7 @@ namespace Ink_Canvas
StartupCount.Increment();
if (StartupCount.GetCount() >= 5)
{
MessageBox.Show("检测到程序已连续重启5次,已停止自动重启。请联系开发者或检查系统环境。", "重启次数过多", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Strings.GetString("Msg_RestartLimit"), Strings.GetString("Msg_RestartLimitTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
StartupCount.Reset();
Environment.Exit(1);
}
@@ -574,7 +671,7 @@ namespace Ink_Canvas
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(1);
}
// CrashActionType.NoAction 时不做处理
@@ -582,16 +679,28 @@ namespace Ink_Canvas
private TaskbarIcon _taskbar;
/// <summary>
/// 处理应用启动流程:根据命令行与设置显示启动画面、初始化组件与遥测、处理更新相关逻辑、单实例检查并在必要时通过 IPC 与已运行实例通信,最终创建并显示主窗口并启动文件关联与 IPC 监听器。
/// </summary>
/// <param name="sender">事件的发送者(通常为 Application 对象)。</param>
/// <param name="e">启动事件参数;其 Args 可包含控制启动流程的标志,例如:
/// - "--final-app":表示这是更新后的最终应用启动(会清理更新标记等)
/// - "--update-mode":表示以更新模式启动(跳过主窗口显示)
/// - "--board":直接进入白板模式
/// - "--show":退出收纳模式并恢复浮动栏
/// - "--skip-mutex-check":跳过单实例互斥检查
/// - "-m":允许多实例启动
/// 另外也可能包含以 "icc:" 开头的 URI 参数或 .icstk 文件路径用于启动时的 IPC 交互。</param>
async void App_Startup(object sender, StartupEventArgs e)
{
// 初始化应用启动时间
appStartTime = DateTime.Now;
appStartupStartTime = DateTime.Now;
// 根据设置决定是否显示启动画面
if (ShouldShowSplashScreen())
if (ShouldShowSplashScreen() && !IsLaunchByFileOrUri(e.Args))
{
ShowSplashScreen();
SetSplashMessage("正在启动 Ink Canvas...");
SetSplashMessage(Strings.GetString("Splash_Starting"));
SetSplashProgress(20);
await Task.Delay(500);
@@ -599,7 +708,7 @@ namespace Ink_Canvas
Application.Current.Dispatcher.Invoke(() => { }, DispatcherPriority.Render);
}
System.Threading.Thread.Sleep(500);
await Task.Delay(500);
RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
LogHelper.NewLog(string.Format("Ink Canvas Starting (Version: {0})", Assembly.GetExecutingAssembly().GetName().Version));
@@ -670,6 +779,21 @@ namespace Ink_Canvas
await Task.Delay(500);
}
DeviceIdentifier.RecordAppLaunch();
try
{
var systemVersion = DeviceIdentifier.GetSystemVersion();
if (!string.IsNullOrWhiteSpace(systemVersion))
{
SentrySdk.ConfigureScope(scope =>
{
scope.SetTag("system_version", systemVersion);
});
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"App | 初始化系统版本遥测标签失败: {ex.Message}", LogHelper.LogType.Warning);
}
LogHelper.WriteLogToFile($"App | 设备ID: {DeviceIdentifier.GetDeviceId()}");
LogHelper.WriteLogToFile($"App | 使用频率: {DeviceIdentifier.GetUsageFrequency()}");
LogHelper.WriteLogToFile($"App | 更新优先级: {DeviceIdentifier.GetUpdatePriority()}");
@@ -706,6 +830,20 @@ namespace Ink_Canvas
{
LogHelper.WriteLogToFile($"App | 清理更新标记文件失败: {ex.Message}", LogHelper.LogType.Warning);
}
Task.Run(async () =>
{
try
{
await Task.Delay(3000);
LogHelper.WriteLogToFile("App | 最终应用启动,删除AutoUpdate文件夹");
AutoUpdateHelper.DeleteUpdatesFolder();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"App | 删除AutoUpdate文件夹失败: {ex.Message}", LogHelper.LogType.Warning);
}
});
}
// 如果不是最终应用启动,才检查更新标记文件
@@ -797,7 +935,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile("App | 清理损坏的更新标记文件");
}
}
catch { }
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
@@ -857,6 +995,22 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile("通过IPC发送展开浮动栏命令失败", LogHelper.LogType.Warning);
}
}
// 检查是否有URI参数
else if (e.Args.Any(a => a.StartsWith("icc:", StringComparison.OrdinalIgnoreCase)))
{
string uriArg = e.Args.FirstOrDefault(a => a.StartsWith("icc:", StringComparison.OrdinalIgnoreCase));
LogHelper.WriteLogToFile($"检测到已运行实例且有URI参数: {uriArg}", LogHelper.LogType.Event);
// 尝试通过IPC发送URI命令给已运行实例
if (FileAssociationManager.TrySendUriCommandToExistingInstance(uriArg))
{
LogHelper.WriteLogToFile("URI命令已通过IPC发送给已运行实例", LogHelper.LogType.Event);
}
else
{
LogHelper.WriteLogToFile("通过IPC发送URI命令失败", LogHelper.LogType.Warning);
}
}
else
{
LogHelper.WriteLogToFile("检测到已运行实例,但无文件参数", LogHelper.LogType.Event);
@@ -874,7 +1028,7 @@ namespace Ink_Canvas
watchdogProcess.Kill();
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(0);
}
}
@@ -902,11 +1056,12 @@ namespace Ink_Canvas
mutex = new Mutex(true, mutexName, out bool tempRet);
// 额外等待一小段时间确保更新进程完全退出
Thread.Sleep(1000);
await Task.Delay(1000);
LogHelper.WriteLogToFile("App | 特殊模式等待完成,继续启动");
}
_taskbar = (TaskbarIcon)FindResource("TaskbarTrayIcon");
_taskbar.ForceCreate();
StartArgs = e.Args;
@@ -923,6 +1078,18 @@ namespace Ink_Canvas
// 主窗口加载完成后关闭启动画面
mainWindow.Loaded += (s, args) =>
{
isStartupComplete = true;
startupCompleteHeartbeat = DateTime.Now;
if (_isSplashScreenShown && splashScreenStartTime != DateTime.MinValue)
{
LogHelper.WriteLogToFile($"启动完成心跳已记录,启动画面显示时长: {(startupCompleteHeartbeat - splashScreenStartTime).TotalSeconds:F2}秒");
}
else
{
LogHelper.WriteLogToFile($"启动完成心跳已记录");
}
LogHelper.WriteLogToFile($"启动时长: {(startupCompleteHeartbeat - appStartupStartTime).TotalSeconds:F2}秒");
if (_isSplashScreenShown)
{
SetSplashMessage("完成初始化...");
@@ -945,6 +1112,21 @@ namespace Ink_Canvas
mainWindow.Show();
// 处理启动时的URI参数
string startupUriArg = e.Args.FirstOrDefault(a => a.StartsWith("icc:", StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(startupUriArg))
{
LogHelper.WriteLogToFile($"App | 处理启动URI参数: {startupUriArg}", LogHelper.LogType.Event);
// 延迟一点执行,确保窗口初始化完成
Task.Delay(1000).ContinueWith(_ =>
{
mainWindow.Dispatcher.Invoke(() =>
{
mainWindow.HandleUriCommand(startupUriArg);
});
});
}
// 注册.icstk文件关联
try
{
@@ -968,6 +1150,17 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"启动IPC监听器时出错: {ex.Message}", LogHelper.LogType.Error);
}
// 初始化上传帮助类
try
{
LogHelper.WriteLogToFile("初始化上传帮助类");
Helpers.UploadHelper.Initialize();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"初始化上传帮助类时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
@@ -983,9 +1176,9 @@ namespace Ink_Canvas
SenderScrollViewer.ScrollToVerticalOffset(SenderScrollViewer.VerticalOffset - e.Delta * 10 * SystemInformation.MouseWheelScrollLines / (double)120);
e.Handled = true;
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
// 用于设置崩溃后操作类型
@@ -996,37 +1189,105 @@ namespace Ink_Canvas
}
// 心跳相关
private static Timer heartbeatTimer;
private static DispatcherTimer heartbeatTimer;
private static DateTime lastHeartbeat = DateTime.Now;
private static Timer watchdogTimer;
private static bool isStartupComplete = false;
private static DateTime startupCompleteHeartbeat = DateTime.MinValue;
private static DateTime splashScreenStartTime = DateTime.MinValue;
private static DateTime appStartupStartTime = DateTime.MinValue;
/// <summary>
/// 启动并管理应用的心跳与守护检查定时器,监测启动阶段与主线程是否无响应,并在符合配置的情况下尝试静默重启应用。
/// </summary>
/// <remarks>
/// - 启动一个每秒更新心跳时间戳的调度定时器和一个每3秒运行的守护定时器。
/// - 守护定时器在首次运行的启动阶段若检测到超过两分钟未完成启动,会根据 CrashAction 配置尝试静默重启。
/// - 在启动完成后若检测到主线程超过10秒无响应,会根据 CrashAction 配置尝试静默重启。
/// - 对连续重启次数有保护:若重启计数达到或超过5次,会弹出提示并停止自动重启(重置重启计数并退出进程)。
/// - 在 OOBE(首次引导)展示期间不执行守护检查。
/// - 该方法会产生外部可观察的副作用:可能启动新进程并调用 Environment.Exit 终止当前进程,或显示消息框。
/// </remarks>
private void StartHeartbeatMonitor()
{
// 主线程定时更新心跳
heartbeatTimer = new Timer(_ => lastHeartbeat = DateTime.Now, null, 0, 1000);
// 辅助线程检测心跳超时
heartbeatTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
heartbeatTimer.Tick += (_, __) => lastHeartbeat = DateTime.Now;
heartbeatTimer.Start();
watchdogTimer = new Timer(_ =>
{
if ((DateTime.Now - lastHeartbeat).TotalSeconds > 10)
if (IsOobeShowing)
return;
if (!isStartupComplete && appStartupStartTime != DateTime.MinValue)
{
LogHelper.NewLog("检测到主线程无响应,自动重启。");
SyncCrashActionFromSettings(); // 新增:心跳检测时同步最新设置
if (CrashAction == CrashActionType.SilentRestart)
DateTime startTime = _isSplashScreenShown && splashScreenStartTime != DateTime.MinValue
? splashScreenStartTime
: appStartupStartTime;
TimeSpan elapsedSinceStart = DateTime.Now - startTime;
if (elapsedSinceStart.TotalMinutes >= 2)
{
StartupCount.Increment();
if (StartupCount.GetCount() >= 5)
string timeType = _isSplashScreenShown ? "启动画面已显示" : "应用启动开始";
LogHelper.WriteLogToFile($"检测到启动假死:{timeType}{elapsedSinceStart.TotalMinutes:F2}分钟,但未收到启动完成心跳,自动重启。", LogHelper.LogType.Error);
SyncCrashActionFromSettings();
if (CrashAction == CrashActionType.SilentRestart)
{
MessageBox.Show("检测到程序已连续重启5次,已停止自动重启。请联系开发者或检查系统环境。", "重启次数过多", MessageBoxButton.OK, MessageBoxImage.Error);
StartupCount.Reset();
StartupCount.Increment();
if (StartupCount.GetCount() >= 5)
{
MessageBox.Show(Strings.GetString("Msg_RestartLimit"), Strings.GetString("Msg_RestartLimitTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
StartupCount.Reset();
Environment.Exit(1);
}
try
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(1);
}
try
return;
}
}
if (isStartupComplete)
{
var now = DateTime.Now;
var sinceHeartbeat = now - lastHeartbeat;
var sinceStartupComplete = startupCompleteHeartbeat == DateTime.MinValue
? TimeSpan.Zero
: now - startupCompleteHeartbeat;
if (sinceStartupComplete.TotalSeconds < 30)
{
return;
}
if (sinceHeartbeat.TotalSeconds > 10)
{
LogHelper.NewLog("检测到主线程无响应,自动重启。");
SyncCrashActionFromSettings();
if (CrashAction == CrashActionType.SilentRestart)
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
StartupCount.Increment();
if (StartupCount.GetCount() >= 5)
{
MessageBox.Show(Strings.GetString("Msg_RestartLimit"), Strings.GetString("Msg_RestartLimitTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
StartupCount.Reset();
Environment.Exit(1);
}
try
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(1);
}
catch { }
Environment.Exit(1);
}
}
}, null, 0, 3000);
@@ -1050,7 +1311,16 @@ namespace Ink_Canvas
watchdogProcess = Process.Start(psi);
}
// 看门狗主逻辑
/// <summary>
/// 作为守护进程监视指定的主进程,并在主进程异常退出时根据配置执行重启或退出操作。
/// </summary>
/// <remarks>
/// 该方法期望命令行参数格式为:"--watchdog &lt;pid&gt; &lt;exitSignalFile&gt;"args[1..3])。
/// - 每 2 秒检查一次指定的主进程是否仍在运行;同时检测退出信号文件,若存在则删除该文件并以代码 0 退出守护进程。
/// - 当主进程退出时,会同步崩溃处理设置(SyncCrashActionFromSettings)。若启用了 UIA 顶层访问(IsUIAccessTopMostEnabled),守护进程直接退出。
/// - 若崩溃动作为 SilentRestart,则增加启动计数并:当连续重启计数达到 5 次及以上时弹出错误对话框、重置计数并以代码 1 退出;否则启动新的主进程实例。
/// 方法对内部异常静默处理,并在完成后确保进程退出。
/// </remarks>
public static void RunWatchdogIfNeeded()
{
var args = Environment.GetCommandLineArgs();
@@ -1066,37 +1336,105 @@ namespace Ink_Canvas
// 检查退出信号文件
if (File.Exists(exitSignalFile))
{
try { File.Delete(exitSignalFile); } catch { }
try { File.Delete(exitSignalFile); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(0);
}
Thread.Sleep(2000);
}
// 主进程异常退出,自动重启前判断崩溃后操作
SyncCrashActionFromSettings(); // 同步设置
if (IsUIAccessTopMostEnabled)
{
Environment.Exit(0);
}
if (CrashAction == CrashActionType.SilentRestart)
{
StartupCount.Increment();
if (StartupCount.GetCount() >= 5)
{
MessageBox.Show("检测到程序已连续重启5次,已停止自动重启。请联系开发者或检查系统环境。", "重启次数过多", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Strings.GetString("Msg_RestartLimit"), Strings.GetString("Msg_RestartLimitTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
StartupCount.Reset();
Environment.Exit(1);
}
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
else
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
}
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(0);
}
}
internal static string GetDlassTelemetryDsn()
{
try
{
var envDsn = Environment.GetEnvironmentVariable("DLASS_SENTRY_DSN");
if (!string.IsNullOrWhiteSpace(envDsn))
{
return envDsn;
}
try
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Ink_Canvas.telemetry_dsn.txt";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream != null)
{
using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
{
string dsn = reader.ReadToEnd().Trim();
if (!string.IsNullOrWhiteSpace(dsn))
{
return dsn;
}
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"从程序集资源读取遥测 DSN 失败: {ex.Message}", LogHelper.LogType.Warning);
}
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
string currentDir = Path.GetDirectoryName(assemblyLocation);
for (int i = 0; i < 5; i++)
{
string dsnFilePath = Path.Combine(currentDir, "telemetry_dsn.txt");
if (File.Exists(dsnFilePath))
{
string dsn = File.ReadAllText(dsnFilePath, System.Text.Encoding.UTF8).Trim();
if (!string.IsNullOrWhiteSpace(dsn))
{
return dsn;
}
}
DirectoryInfo parentDir = Directory.GetParent(currentDir);
if (parentDir == null)
{
break;
}
currentDir = parentDir.FullName;
}
return string.Empty;
}
catch
{
return string.Empty;
}
}
private void App_Exit(object sender, ExitEventArgs e)
{
// 仅在软件内主动退出时关闭看门狗,并写入退出信号
@@ -1135,7 +1473,7 @@ namespace Ink_Canvas
{
LogHelper.WriteLogToFile($"退出处理时发生错误: {ex.Message}", LogHelper.LogType.Error);
}
catch { }
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
}
+5 -11
View File
@@ -10,7 +10,7 @@ using System.Windows;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CJK_mkp")]
[assembly: AssemblyProduct("InkCanvasForClass")]
[assembly: AssemblyCopyright("Copyright © CJK_mkp 2025")]
[assembly: AssemblyCopyright("Copyright © CJK_mkp 2025-2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -19,14 +19,8 @@ using System.Windows;
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
// i18n: 默认/回退语言为简体中文,与 Strings.resx 默认文案一致。
[assembly: System.Resources.NeutralResourcesLanguage("zh-CN", System.Resources.UltimateResourceFallbackLocation.MainAssembly)]
[assembly: ThemeInfo(
@@ -49,5 +43,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.16.0")]
[assembly: AssemblyFileVersion("1.7.16.0")]
[assembly: AssemblyVersion("1.7.18.10")]
[assembly: AssemblyFileVersion("1.7.18.10")]
+24
View File
@@ -0,0 +1,24 @@
<UserControl x:Class="Ink_Canvas.Controls.CopyButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern">
<Button x:Name="CopyButtonControl" Padding="6" Click="CopyButton_Click"
ToolTipService.ToolTip="Copy">
<Grid>
<ui:FontIcon x:Name="FontIcon_Copy" FontSize="16"
Icon="{x:Static ui:SegoeFluentIcons.Copy}" RenderTransformOrigin="0.5 0.5">
<FrameworkElement.RenderTransform>
<ScaleTransform x:Name="ScaleTransform_Copy"
ScaleX="1" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}"/>
</FrameworkElement.RenderTransform>
</ui:FontIcon>
<ui:FontIcon x:Name="FontIcon_Success" FontSize="16"
Icon="{x:Static ui:SegoeFluentIcons.CheckMark}" RenderTransformOrigin="0.5 0.5">
<FrameworkElement.RenderTransform>
<ScaleTransform x:Name="ScaleTransform_Success"
ScaleX="0" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}"/>
</FrameworkElement.RenderTransform>
</ui:FontIcon>
</Grid>
</Button>
</UserControl>
+115
View File
@@ -0,0 +1,115 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace Ink_Canvas.Controls
{
public partial class CopyButton : UserControl
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
nameof(Text), typeof(string), typeof(CopyButton), new PropertyMetadata(string.Empty));
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public event EventHandler Click;
public CopyButton()
{
InitializeComponent();
}
private void CopyButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(Text))
{
Clipboard.SetText(Text);
}
ShowSuccessAnimation();
Click?.Invoke(this, EventArgs.Empty);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Unable to Perform Copy", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async void ShowSuccessAnimation()
{
var copyScaleAnim = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.FromMilliseconds(150)
};
ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim);
var copyOpacityAnim = new DoubleAnimation
{
To = 0,
BeginTime = TimeSpan.FromMilliseconds(100),
Duration = TimeSpan.FromMilliseconds(10)
};
FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim);
await Task.Delay(150);
var successScaleAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromMilliseconds(150),
EasingFunction = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.2 }
};
ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim);
var successOpacityAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromMilliseconds(15)
};
FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim);
await Task.Delay(1000);
ShowCopyAnimation();
}
private async void ShowCopyAnimation()
{
var successOpacityAnim = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.FromMilliseconds(150)
};
FontIcon_Success.BeginAnimation(UIElement.OpacityProperty, successOpacityAnim);
await Task.Delay(150);
var copyScaleAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.Zero
};
ScaleTransform_Copy.BeginAnimation(ScaleTransform.ScaleXProperty, copyScaleAnim);
var copyOpacityAnim = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromMilliseconds(150)
};
FontIcon_Copy.BeginAnimation(UIElement.OpacityProperty, copyOpacityAnim);
var successScaleAnim = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.Zero
};
ScaleTransform_Success.BeginAnimation(ScaleTransform.ScaleXProperty, successScaleAnim);
}
}
}
+145
View File
@@ -0,0 +1,145 @@
using Ink_Canvas.Helpers;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Ink_Canvas.Controls
{
/// <summary>
/// 画布上的多页 PDF:仅显示当前页;翻页与页码由主窗口 PDF 侧栏控制(无 XAML 文件)。
/// </summary>
public class PdfEmbeddedView : UserControl
{
private readonly Image _pageImage;
private string _pdfPath;
private uint _pageCount;
private uint _currentIndex;
private bool _compressLargePictures;
private bool _isPagingBusy;
private bool _layoutSizeCommitted;
/// <summary>页码或可翻页状态变化(用于更新侧栏)。</summary>
public event EventHandler PageNavigationStateChanged;
public PdfEmbeddedView()
{
MinWidth = 80;
MinHeight = 60;
var grid = new Grid { ClipToBounds = true };
_pageImage = new Image
{
Stretch = Stretch.Uniform,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
grid.Children.Add(_pageImage);
Content = grid;
}
/// <summary>
/// 初始化并显示指定页;由 MainWindow 在 UI 线程创建后调用。
/// </summary>
/// <param name="initialPageIndex">从 0 开始的页码,超出范围时夹紧到合法区间。</param>
public async Task InitializeAsync(string pdfFilePath, uint pageCount, bool compressLargePictures, uint initialPageIndex = 0)
{
_pdfPath = pdfFilePath ?? throw new ArgumentNullException(nameof(pdfFilePath));
_pageCount = pageCount;
_compressLargePictures = compressLargePictures;
if (_pageCount == 0)
_currentIndex = 0;
else
_currentIndex = initialPageIndex >= _pageCount ? _pageCount - 1 : initialPageIndex;
await ShowPageAsync(_currentIndex);
}
public string PdfPath => _pdfPath;
public uint PageCount => _pageCount;
public uint CurrentPageIndex => _currentIndex;
public string PageLabelText => _pageCount == 0 ? "" : $"{_currentIndex + 1} / {_pageCount}";
public bool CanGoPrevious => !_isPagingBusy && _pageCount > 1 && _currentIndex > 0;
public bool CanGoNext => !_isPagingBusy && _pageCount > 1 && _currentIndex < _pageCount - 1;
public async Task GoToPreviousPageAsync()
{
await GoRelativeAsync(-1);
}
public async Task GoToNextPageAsync()
{
await GoRelativeAsync(1);
}
private void NotifyPageNavigationStateChanged()
{
PageNavigationStateChanged?.Invoke(this, EventArgs.Empty);
}
private async Task GoRelativeAsync(int delta)
{
if (_isPagingBusy || _pageCount <= 1)
return;
int next = (int)_currentIndex + delta;
if (next < 0 || next >= _pageCount)
return;
_currentIndex = (uint)next;
await ShowPageAsync(_currentIndex);
}
private async Task ShowPageAsync(uint pageIndex)
{
_isPagingBusy = true;
NotifyPageNavigationStateChanged();
try
{
BitmapSource raw = await PdfWinRtHelper.RenderPageToBitmapSourceAsync(_pdfPath, pageIndex);
if (raw == null)
return;
BitmapSource display = ApplyCompressionIfNeeded(raw);
_pageImage.Source = display;
if (!_layoutSizeCommitted)
{
bool callerSized = !double.IsNaN(Width) && Width > 0 && !double.IsNaN(Height) && Height > 0;
if (!callerSized)
{
Width = display.PixelWidth;
Height = display.PixelHeight;
}
_layoutSizeCommitted = true;
}
}
finally
{
_isPagingBusy = false;
NotifyPageNavigationStateChanged();
}
}
private BitmapSource ApplyCompressionIfNeeded(BitmapSource rendered)
{
int width = rendered.PixelWidth;
int height = rendered.PixelHeight;
if (_compressLargePictures && (width > 1920 || height > 1080))
{
double scaleX = 1920.0 / width;
double scaleY = 1080.0 / height;
double scale = Math.Min(scaleX, scaleY);
return new TransformedBitmap(rendered, new ScaleTransform(scale, scale));
}
return rendered;
}
}
}
@@ -0,0 +1,77 @@
<UserControl x:Class="Ink_Canvas.Controls.QuickDrawFloatingButtonControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="65" Height="45">
<Border Background="{DynamicResource QuickDrawFloatingButtonBackground}"
CornerRadius="8"
BorderThickness="1"
BorderBrush="{DynamicResource QuickDrawFloatingButtonBorderBrush}">
<Border.Effect>
<DropShadowEffect Color="Black" Direction="315" ShadowDepth="3" Opacity="0.3" BlurRadius="5"/>
</Border.Effect>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- 拖动区域 -->
<Border Grid.Column="0"
MouseLeftButtonDown="DragArea_MouseLeftButtonDown"
MouseMove="DragArea_MouseMove"
MouseLeftButtonUp="DragArea_MouseLeftButtonUp"
Cursor="SizeAll"
Background="Transparent">
<Grid VerticalAlignment="Center" Height="14" IsHitTestVisible="False">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 三个白色横线 -->
<Border Grid.Row="0" Background="{DynamicResource QuickDrawFloatingButtonIconForeground}" Height="2" Width="10"
HorizontalAlignment="Center"
CornerRadius="1" Opacity="0.8" IsHitTestVisible="False"/>
<Border Grid.Row="2" Background="{DynamicResource QuickDrawFloatingButtonIconForeground}" Height="2" Width="10"
HorizontalAlignment="Center"
CornerRadius="1" Opacity="0.8" IsHitTestVisible="False"/>
<Border Grid.Row="4" Background="{DynamicResource QuickDrawFloatingButtonIconForeground}" Height="2" Width="10"
HorizontalAlignment="Center"
CornerRadius="1" Opacity="0.8" IsHitTestVisible="False"/>
</Grid>
</Border>
<!-- 半透明分割线 -->
<Rectangle Grid.Column="1" Width="1" Fill="#20FFFFFF" Margin="0,8,0,8"/>
<!-- 按钮区域 -->
<Border Grid.Column="2"
MouseLeftButtonDown="FloatingButton_Click"
Cursor="Hand"
Background="Transparent">
<Grid IsHitTestVisible="False">
<Path Data="M5 7C5 8.06087 5.42143 9.07828 6.17157 9.82843C6.92172 10.5786 7.93913 11 9 11C10.0609 11 11.0783 10.5786 11.8284 9.82843C12.5786 9.07828 13 8.06087 13 7C13 5.93913 12.5786 4.92172 11.8284 4.17157C11.0783 3.42143 10.0609 3 9 3C7.93913 3 6.92172 3.42143 6.17157 4.17157C5.42143 4.92172 5 5.93913 5 7Z M3 21V19C3 17.9391 3.42143 16.9217 4.17157 16.1716C4.92172 15.4214 5.93913 15 7 15H11C12.0609 15 13.0783 15.4214 13.8284 16.1716C14.5786 16.9217 15 17.9391 15 19V21 M16 3.13C16.8604 3.35031 17.623 3.85071 18.1676 4.55232C18.7122 5.25392 19.0078 6.11683 19.0078 7.005C19.0078 7.89318 18.7122 8.75608 18.1676 9.45769C17.623 10.1593 16.8604 10.6597 16 10.88 M21 21V19C20.9949 18.1172 20.6979 17.2608 20.1553 16.5644C19.6126 15.868 18.8548 15.3707 18 15.15"
Stroke="{DynamicResource QuickDrawFloatingButtonIconForeground}"
StrokeThickness="2"
StrokeLineJoin="Round"
Fill="Transparent"
Width="20" Height="20"
Stretch="Uniform"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsHitTestVisible="False"/>
</Grid>
</Border>
</Grid>
</Border>
</UserControl>
@@ -0,0 +1,148 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using VerticalAlignment = System.Windows.VerticalAlignment;
namespace Ink_Canvas.Controls
{
/// <summary>
/// 快抽悬浮按钮控件
/// </summary>
public partial class QuickDrawFloatingButtonControl : UserControl
{
private bool _isDragging = false;
private Point _dragStartPoint;
private Point _controlStartPoint;
public QuickDrawFloatingButtonControl()
{
InitializeComponent();
}
/// <summary>
/// 快抽按钮点击事件
/// </summary>
private void FloatingButton_Click(object sender, MouseButtonEventArgs e)
{
try
{
// 如果正在拖动,不触发点击事件
if (_isDragging) return;
// 打开快抽窗口
var quickDrawWindow = new QuickDrawWindow();
quickDrawWindow.ShowDialog();
}
catch (Exception ex)
{
Helpers.LogHelper.WriteLogToFile($"打开快抽窗口失败: {ex.Message}", Helpers.LogHelper.LogType.Error);
}
}
/// <summary>
/// 拖动区域鼠标按下事件
/// </summary>
private void DragArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_isDragging = false;
// 记录鼠标在屏幕上的初始位置
_dragStartPoint = this.PointToScreen(e.GetPosition(this));
// 记录控件的初始位置
var parent = this.Parent as FrameworkElement;
if (parent != null)
{
var transform = this.TransformToVisual(parent);
var currentPos = transform.Transform(new Point(0, 0));
_controlStartPoint = currentPos;
}
else
{
var currentMargin = this.Margin;
_controlStartPoint = new Point(
double.IsNaN(currentMargin.Left) ? 0 : currentMargin.Left,
double.IsNaN(currentMargin.Top) ? 0 : currentMargin.Top);
}
((UIElement)sender).CaptureMouse();
e.Handled = true;
}
/// <summary>
/// 拖动区域鼠标移动事件
/// </summary>
private void DragArea_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && ((UIElement)sender).IsMouseCaptured)
{
// 获取鼠标在屏幕上的当前位置
Point currentScreenPoint = this.PointToScreen(e.GetPosition(this));
Vector diff = currentScreenPoint - _dragStartPoint;
if (!_isDragging && (Math.Abs(diff.X) > 3 || Math.Abs(diff.Y) > 3))
{
_isDragging = true;
// 切换到绝对定位模式
this.HorizontalAlignment = HorizontalAlignment.Left;
this.VerticalAlignment = VerticalAlignment.Top;
}
if (_isDragging)
{
// 计算新位置
var parent = this.Parent as FrameworkElement;
if (parent != null)
{
// 计算屏幕坐标相对于父容器的位置
var parentPoint = parent.PointFromScreen(currentScreenPoint);
var startParentPoint = parent.PointFromScreen(_dragStartPoint);
// 计算相对于初始位置的偏移
double offsetX = parentPoint.X - startParentPoint.X;
double offsetY = parentPoint.Y - startParentPoint.Y;
// 新位置 = 初始位置 + 偏移
double newLeft = _controlStartPoint.X + offsetX;
double newTop = _controlStartPoint.Y + offsetY;
// 限制在父容器范围内
newLeft = Math.Max(0, Math.Min(newLeft, parent.ActualWidth - this.ActualWidth));
newTop = Math.Max(0, Math.Min(newTop, parent.ActualHeight - this.ActualHeight));
// 更新Margin
this.Margin = new Thickness(newLeft, newTop, 0, 0);
}
}
}
}
/// <summary>
/// 拖动区域鼠标释放事件
/// </summary>
private void DragArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (((UIElement)sender).IsMouseCaptured)
{
((UIElement)sender).ReleaseMouseCapture();
}
if (_isDragging)
{
Dispatcher.BeginInvoke(new Action(() => { _isDragging = false; }),
DispatcherPriority.Background);
}
else
{
_isDragging = false;
}
e.Handled = true;
}
}
}
@@ -1,35 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Ink_Canvas.Converters
{
/// <summary>
/// 位置计算转换器
/// </summary>
public class PositionConverters
{
/// <summary>
/// 减法转换器
/// </summary>
public class SubtractConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double baseValue && parameter is string paramStr)
{
if (double.TryParse(paramStr, out double subtractValue))
{
return baseValue - subtractValue;
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}
+6 -6
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
@@ -73,7 +73,7 @@ namespace Ink_Canvas.Helpers
sb.Begin((FrameworkElement)element);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
public static void ShowWithSlideFromLeftAndFade(UIElement element, double duration = 0.25)
@@ -113,7 +113,7 @@ namespace Ink_Canvas.Helpers
sb.Begin((FrameworkElement)element);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
public static void ShowWithScaleFromLeft(UIElement element, double duration = 0.2)
@@ -156,7 +156,7 @@ namespace Ink_Canvas.Helpers
sb.Begin((FrameworkElement)element);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
public static void ShowWithScaleFromRight(UIElement element, double duration = 0.2)
@@ -200,7 +200,7 @@ namespace Ink_Canvas.Helpers
sb.Begin((FrameworkElement)element);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
public static void HideWithSlideAndFade(UIElement element, double duration = 0.15)
@@ -246,7 +246,7 @@ namespace Ink_Canvas.Helpers
element.RenderTransform = new TranslateTransform();
sb.Begin((FrameworkElement)element);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
public static void HideWithFadeOut(UIElement element, double duration = 0.15)
+19 -9
View File
@@ -19,7 +19,7 @@ namespace Ink_Canvas.Helpers
/// 检查是否需要执行自动备份
/// </summary>
/// <param name="settings">设置对象</param>
/// <returns>如果需要备份返回true,否则返回false</returns>
/// <returns>如果需要备份返回<see langword="true"/>,否则返回<see langword="false"/></returns>
public static bool ShouldPerformAutoBackup(Settings settings)
{
try
@@ -50,8 +50,11 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 执行自动备份
/// </summary>
/// <param name="settings">设置对象</param>
/// <returns>备份是否成功</returns>
/// <remarks>
/// 为主配置文件创建一次自动备份并在成功后更新并保存设置中的最后备份时间。
/// </remarks>
/// <param name="settings">应用的设置对象;在成功备份后会更新 settings.Advanced.LastAutoBackupTime 并调用保存操作。</param>
/// <returns><see langword="true"/> 表示备份成功,<see langword="false"/> 表示备份失败或被跳过。</returns>
public static bool PerformAutoBackup(Settings settings)
{
try
@@ -59,7 +62,7 @@ namespace Ink_Canvas.Helpers
// 确保备份目录存在
if (!Directory.Exists(BackupDir))
{
Directory.CreateDirectory(BackupDir);
ProcessProtectionManager.WithWriteAccess(BackupDir, () => Directory.CreateDirectory(BackupDir));
}
// 检查主配置文件是否存在
@@ -74,7 +77,7 @@ namespace Ink_Canvas.Helpers
string backupPath = Path.Combine(BackupDir, backupFileName);
// 复制主配置文件到备份位置
File.Copy(SettingsFile, backupPath, true);
ProcessProtectionManager.WithWriteAccess(backupPath, () => File.Copy(SettingsFile, backupPath, true));
// 更新最后备份时间
settings.Advanced.LastAutoBackupTime = DateTime.Now;
@@ -91,7 +94,10 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 尝试从备份恢复配置文件
/// </summary>
/// <returns>恢复是否成功</returns>
/// <remarks>
/// 从最新可用的自动备份恢复主设置文件(Settings.json)。如果当前设置文件存在,会先将其复制到备份目录并加上时间戳作为“损坏”的备份副本,然后用最新备份覆盖原文件。
/// </remarks>
/// <returns><see langword="true"/> 如果恢复成功,<see langword="false"/> 否则。</returns>
public static bool TryRestoreFromBackup()
{
try
@@ -138,11 +144,11 @@ namespace Ink_Canvas.Helpers
if (File.Exists(SettingsFile))
{
string corruptedBackup = Path.Combine(BackupDir, $"Settings_Corrupted_{DateTime.Now:yyyyMMdd_HHmmss}.json");
File.Copy(SettingsFile, corruptedBackup, true);
ProcessProtectionManager.WithWriteAccess(corruptedBackup, () => File.Copy(SettingsFile, corruptedBackup, true));
}
// 从备份恢复配置文件
File.Copy(latestBackup, SettingsFile, true);
ProcessProtectionManager.WithWriteAccess(SettingsFile, () => File.Copy(latestBackup, SettingsFile, true));
return true;
}
catch (Exception ex)
@@ -156,6 +162,10 @@ namespace Ink_Canvas.Helpers
/// 清理过期的备份文件
/// 保留最近30天的备份文件
/// </summary>
/// <remarks>
/// 删除备份目录中按“备份前缀”匹配且创建时间早于 30 天的自动备份文件(即自动备份文件的命名前缀),不会删除诸如 Settings_Corrupted_*.json 之类的其他备份或错误状态文件。
/// 如果备份目录不存在则不执行任何操作;删除操作在受写入保护的上下文中执行,任何错误会被记录但不会抛出异常。
/// </remarks>
public static void CleanupOldBackups()
{
try
@@ -173,7 +183,7 @@ namespace Ink_Canvas.Helpers
{
if (File.GetCreationTime(file) < cutoffDate)
{
File.Delete(file);
ProcessProtectionManager.WithWriteAccess(file, () => File.Delete(file));
deletedCount++;
}
}
+444
View File
@@ -0,0 +1,444 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Threading;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// Automatically shrinks text to fit available width.
/// Supports TextBlock and Label.
/// Only shrinks, never enlarges above MaxFontSize.
/// </summary>
public static class AutoFontSizeHelper
{
public static readonly DependencyProperty IsEnabledProperty =
DependencyProperty.RegisterAttached(
"IsEnabled",
typeof(bool),
typeof(AutoFontSizeHelper),
new PropertyMetadata(false, OnIsEnabledChanged));
public static void SetIsEnabled(DependencyObject element, bool value) => element.SetValue(IsEnabledProperty, value);
public static bool GetIsEnabled(DependencyObject element) => (bool)element.GetValue(IsEnabledProperty);
public static readonly DependencyProperty MinFontSizeProperty =
DependencyProperty.RegisterAttached(
"MinFontSize",
typeof(double),
typeof(AutoFontSizeHelper),
new PropertyMetadata(6d, OnSizingPropertyChanged));
public static void SetMinFontSize(DependencyObject element, double value) => element.SetValue(MinFontSizeProperty, value);
public static double GetMinFontSize(DependencyObject element) => (double)element.GetValue(MinFontSizeProperty);
public static readonly DependencyProperty MaxFontSizeProperty =
DependencyProperty.RegisterAttached(
"MaxFontSize",
typeof(double),
typeof(AutoFontSizeHelper),
new PropertyMetadata(double.NaN, OnSizingPropertyChanged));
public static void SetMaxFontSize(DependencyObject element, double value) => element.SetValue(MaxFontSizeProperty, value);
public static double GetMaxFontSize(DependencyObject element) => (double)element.GetValue(MaxFontSizeProperty);
public static readonly DependencyProperty StepProperty =
DependencyProperty.RegisterAttached(
"Step",
typeof(double),
typeof(AutoFontSizeHelper),
new PropertyMetadata(0.5d, OnSizingPropertyChanged));
public static void SetStep(DependencyObject element, double value) => element.SetValue(StepProperty, value);
public static double GetStep(DependencyObject element) => (double)element.GetValue(StepProperty);
private static readonly DependencyProperty IsAdjustingProperty =
DependencyProperty.RegisterAttached(
"IsAdjusting",
typeof(bool),
typeof(AutoFontSizeHelper),
new PropertyMetadata(false));
private static void SetIsAdjusting(DependencyObject element, bool value) => element.SetValue(IsAdjustingProperty, value);
private static bool GetIsAdjusting(DependencyObject element) => (bool)element.GetValue(IsAdjustingProperty);
private static readonly DependencyProperty OriginalFontSizeProperty =
DependencyProperty.RegisterAttached(
"OriginalFontSize",
typeof(double),
typeof(AutoFontSizeHelper),
new PropertyMetadata(double.NaN));
private static void SetOriginalFontSize(DependencyObject element, double value) => element.SetValue(OriginalFontSizeProperty, value);
private static double GetOriginalFontSize(DependencyObject element) => (double)element.GetValue(OriginalFontSizeProperty);
private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is FrameworkElement fe)) return;
if (!(fe is TextBlock) && !(fe is Label)) return;
if ((bool)e.NewValue)
{
var originalFontSize = GetElementFontSize(fe);
if (!double.IsNaN(originalFontSize) && originalFontSize > 0)
{
SetOriginalFontSize(fe, originalFontSize);
}
fe.SizeChanged += Element_OnSizeChanged;
fe.Loaded += Element_OnLoaded;
fe.Unloaded += Element_OnUnloaded;
TryHookContentChanged(fe, true);
fe.Dispatcher.BeginInvoke(new Action(() => TryAdjust(fe)), DispatcherPriority.Loaded);
}
else
{
fe.SizeChanged -= Element_OnSizeChanged;
fe.Loaded -= Element_OnLoaded;
fe.Unloaded -= Element_OnUnloaded;
TryHookContentChanged(fe, false);
}
}
private static void OnSizingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is FrameworkElement fe && GetIsEnabled(fe))
{
fe.Dispatcher.BeginInvoke(new Action(() => TryAdjust(fe)), DispatcherPriority.Loaded);
}
}
private static void Element_OnLoaded(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement fe)
{
fe.Dispatcher.BeginInvoke(new Action(() => TryAdjust(fe)), DispatcherPriority.Loaded);
}
}
private static void Element_OnUnloaded(object sender, RoutedEventArgs e)
{
// No extra cleanup required here.
}
private static void Element_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
if (sender is FrameworkElement fe) TryAdjust(fe);
}
private static void Element_OnTextChanged(object sender, EventArgs e)
{
if (sender is FrameworkElement fe)
{
fe.Dispatcher.BeginInvoke(new Action(() => TryAdjust(fe)), DispatcherPriority.Loaded);
}
}
private static void TryHookContentChanged(FrameworkElement fe, bool add)
{
try
{
DependencyPropertyDescriptor dpd = null;
if (fe is TextBlock)
{
dpd = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));
}
else if (fe is Label)
{
dpd = DependencyPropertyDescriptor.FromProperty(ContentControl.ContentProperty, typeof(ContentControl));
}
if (dpd == null) return;
if (add) dpd.AddValueChanged(fe, Element_OnTextChanged);
else dpd.RemoveValueChanged(fe, Element_OnTextChanged);
}
catch
{
// Ignore descriptor issues in rare runtime cases.
}
}
private static void TryAdjust(FrameworkElement fe)
{
if (fe == null) return;
if (!GetIsEnabled(fe)) return;
if (GetIsAdjusting(fe)) return;
var text = GetElementText(fe);
if (string.IsNullOrEmpty(text)) return;
if (!ShouldAutoScaleForCurrentCulture(text))
{
RestoreOriginalFontSize(fe);
return;
}
var availableWidth = GetAvailableWidth(fe);
if (double.IsNaN(availableWidth) || availableWidth <= 1) return;
var min = GetMinFontSize(fe);
if (double.IsNaN(min) || min <= 0) min = 6d;
var step = GetStep(fe);
if (double.IsNaN(step) || step < 0.1) step = 0.5d;
var current = GetElementFontSize(fe);
if (double.IsNaN(current) || current <= 0) return;
var max = GetMaxFontSize(fe);
if (double.IsNaN(max) || max <= 0) max = current;
// Never enlarge: auto-fit should only reduce font size when needed.
if (max > current) max = current;
var startFont = Math.Min(current, max);
if (startFont < min) startFont = min;
SetIsAdjusting(fe, true);
try
{
var font = startFont;
var desired = MeasureTextWidth(fe, text, font);
if (desired <= 0) return;
while (font > min && desired > availableWidth + 0.5)
{
font = Math.Max(min, font - step);
desired = MeasureTextWidth(fe, text, font);
if (desired <= 0) break;
}
// Hard-fit fallback: when very narrow slots (e.g., 28px) still overflow at MinFontSize,
// keep shrinking proportionally so text always fits in the available width.
if (desired > availableWidth + 0.5)
{
var hardFont = font;
for (var i = 0; i < 6 && desired > availableWidth + 0.5; i++)
{
var ratio = availableWidth / Math.Max(1.0, desired);
hardFont = Math.Max(1.0, hardFont * ratio);
desired = MeasureTextWidth(fe, text, hardFont);
if (desired <= 0) break;
}
font = hardFont;
}
if (!double.IsNaN(font) && font > 0 && Math.Abs(current - font) > 0.01)
{
SetElementFontSize(fe, font);
}
}
finally
{
SetIsAdjusting(fe, false);
}
}
private static string GetElementText(FrameworkElement fe)
{
if (fe is TextBlock tb) return tb.Text;
if (fe is Label label) return label.Content as string ?? label.Content?.ToString();
return null;
}
private static bool ShouldAutoScaleForCurrentCulture(string text)
{
// Requirement: auto-scale for English UI only, keep Chinese font size unchanged.
var culture = CultureInfo.CurrentUICulture;
var name = culture?.Name ?? string.Empty;
if (name.StartsWith("en", StringComparison.OrdinalIgnoreCase))
{
return true;
}
// Fallback: if actual rendered text is Latin-heavy, still auto-scale.
// This avoids clipping when culture detection is out of sync.
if (string.IsNullOrWhiteSpace(text)) return false;
foreach (var ch in text)
{
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
{
return true;
}
}
return false;
}
private static void RestoreOriginalFontSize(FrameworkElement fe)
{
var original = GetOriginalFontSize(fe);
if (double.IsNaN(original) || original <= 0) return;
var current = GetElementFontSize(fe);
if (double.IsNaN(current) || current <= 0) return;
if (Math.Abs(current - original) > 0.01)
{
SetElementFontSize(fe, original);
}
}
private static double GetElementFontSize(FrameworkElement fe)
{
if (fe is TextBlock tb) return tb.FontSize;
if (fe is Label label) return label.FontSize;
return double.NaN;
}
private static void SetElementFontSize(FrameworkElement fe, double value)
{
if (fe is TextBlock tb) tb.FontSize = value;
else if (fe is Label label) label.FontSize = value;
}
private static double GetAvailableWidth(FrameworkElement fe)
{
double width = double.PositiveInfinity;
// Explicit width on the element itself should be a hard cap.
if (!double.IsNaN(fe.Width) && !double.IsInfinity(fe.Width) && fe.Width > 1)
{
width = Math.Min(width, fe.Width - fe.Margin.Left - fe.Margin.Right);
}
if (!double.IsNaN(fe.MaxWidth) && !double.IsInfinity(fe.MaxWidth) && fe.MaxWidth > 1)
{
width = Math.Min(width, fe.MaxWidth - fe.Margin.Left - fe.Margin.Right);
}
// Prefer the real layout slot first. This is usually the most accurate
// "space actually assigned by layout" for the element.
var slot = LayoutInformation.GetLayoutSlot(fe);
if (!double.IsNaN(slot.Width) && !double.IsInfinity(slot.Width))
{
var slotWidth = slot.Width - fe.Margin.Left - fe.Margin.Right;
if (slotWidth > 1) width = Math.Min(width, slotWidth);
}
if (fe.ActualWidth > 1) width = Math.Min(width, fe.ActualWidth);
// Immediate parent may be a StackPanel that does not constrain width.
// Walk a few ancestors and take the tightest finite width as fallback.
DependencyObject ancestor = fe.Parent ?? VisualTreeHelper.GetParent(fe);
var depth = 0;
while (ancestor != null && depth < 8)
{
if (ancestor is FrameworkElement af && af.ActualWidth > 1)
{
var candidate = af.ActualWidth;
// If ancestor sets explicit width, treat it as a stronger cap.
if (!double.IsNaN(af.Width) && !double.IsInfinity(af.Width) && af.Width > 1)
{
candidate = Math.Min(candidate, af.Width);
}
if (!double.IsNaN(af.MaxWidth) && !double.IsInfinity(af.MaxWidth) && af.MaxWidth > 1)
{
candidate = Math.Min(candidate, af.MaxWidth);
}
if (ancestor is Control ac)
{
candidate -= ac.Padding.Left + ac.Padding.Right;
candidate -= ac.BorderThickness.Left + ac.BorderThickness.Right;
}
else if (ancestor is Border ab)
{
candidate -= ab.Padding.Left + ab.Padding.Right;
candidate -= ab.BorderThickness.Left + ab.BorderThickness.Right;
}
if (candidate > 1) width = Math.Min(width, candidate);
}
ancestor = (ancestor as FrameworkElement)?.Parent ?? VisualTreeHelper.GetParent(ancestor);
depth++;
}
if (double.IsInfinity(width) || double.IsNaN(width) || width <= 1) return -1;
// Keep width as inner text area.
if (fe is Control control)
{
width -= control.Padding.Left + control.Padding.Right;
width -= control.BorderThickness.Left + control.BorderThickness.Right;
}
else if (fe is Border border)
{
width -= border.Padding.Left + border.Padding.Right;
width -= border.BorderThickness.Left + border.BorderThickness.Right;
}
return width;
}
private static double MeasureTextWidth(FrameworkElement fe, string text, double fontSize)
{
try
{
var dpi = VisualTreeHelper.GetDpi(fe);
var culture = CultureInfo.CurrentUICulture;
if (fe.Language != null)
{
try
{
culture = fe.Language.GetEquivalentCulture();
}
catch
{
}
}
var fontFamily = SystemFonts.MessageFontFamily;
var fontStyle = FontStyles.Normal;
var fontWeight = FontWeights.Normal;
var fontStretch = FontStretches.Normal;
Brush foreground = Brushes.Black;
var flowDirection = FlowDirection.LeftToRight;
if (fe is TextBlock tb)
{
fontFamily = tb.FontFamily;
fontStyle = tb.FontStyle;
fontWeight = tb.FontWeight;
fontStretch = tb.FontStretch;
foreground = tb.Foreground;
flowDirection = tb.FlowDirection;
}
else if (fe is Label label)
{
fontFamily = label.FontFamily;
fontStyle = label.FontStyle;
fontWeight = label.FontWeight;
fontStretch = label.FontStretch;
foreground = label.Foreground;
flowDirection = label.FlowDirection;
}
var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
var formatted = new FormattedText(
text,
culture,
flowDirection,
typeface,
fontSize,
foreground,
dpi.PixelsPerDip);
return formatted.WidthIncludingTrailingWhitespace;
}
catch
{
return -1;
}
}
}
}
+395 -67
View File
@@ -27,6 +27,87 @@ namespace Ink_Canvas.Helpers
private static readonly string updatesFolderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate");
private static string statusFilePath;
public static bool IsX64UpdatePackageSelected()
{
try
{
return MainWindow.Settings?.Startup?.UpdatePackageArchitecture == UpdatePackageArchitecture.X64;
}
catch
{
return false;
}
}
private static string NormalizeVersionForUpdate(string version)
{
if (string.IsNullOrWhiteSpace(version)) return version;
return version.Trim().TrimStart('v', 'V');
}
public static string AppendX64SuffixBeforeZipExtension(string url)
{
if (string.IsNullOrEmpty(url) || !IsX64UpdatePackageSelected()) return url;
int query = url.IndexOf('?');
string pathPart = query >= 0 ? url.Substring(0, query) : url;
string qs = query >= 0 ? url.Substring(query) : "";
const string ext = ".zip";
int idx = pathPart.LastIndexOf(ext, StringComparison.OrdinalIgnoreCase);
if (idx < 0) return url;
var basePart = pathPart.Substring(0, idx);
if (basePart.EndsWith("-x64", StringComparison.OrdinalIgnoreCase)) return url;
return basePart + "-x64" + ext + qs;
}
public static string GetUpdateZipFileName(string version)
{
var v = NormalizeVersionForUpdate(version);
return IsX64UpdatePackageSelected()
? $"InkCanvasForClass.CE.{v}-x64.zip"
: $"InkCanvasForClass.CE.{v}.zip";
}
public static string GetUpdateDownloadStatusFilePath(string version)
{
var v = NormalizeVersionForUpdate(version);
string name = IsX64UpdatePackageSelected()
? $"DownloadV{v}_x64Status.txt"
: $"DownloadV{v}Status.txt";
return Path.Combine(updatesFolderPath, name);
}
public static string GetLocalUpdateZipFilePath(string version)
{
return Path.Combine(updatesFolderPath, GetUpdateZipFileName(version));
}
private static string PickBrowserDownloadUrlFromAssets(JToken assets)
{
if (assets == null || !assets.Any()) return null;
bool wantX64 = IsX64UpdatePackageSelected();
string anyZip = null;
string x64Zip = null;
string nonX64Zip = null;
foreach (JToken a in assets)
{
string name = a["name"]?.ToString();
string url = a["browser_download_url"]?.ToString();
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(url)) continue;
if (!name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) continue;
if (anyZip == null) anyZip = url;
if (name.EndsWith("-x64.zip", StringComparison.OrdinalIgnoreCase))
{
if (x64Zip == null) x64Zip = url;
}
else
{
if (nonX64Zip == null) nonX64Zip = url;
}
}
if (wantX64)
return x64Zip ?? anyZip;
return nonX64Zip ?? anyZip;
}
// 线路组结构体(包含版本、下载、日志地址)
public class UpdateLineGroup
@@ -74,6 +155,99 @@ namespace Ink_Canvas.Helpers
GroupName = "inkeys",
DownloadUrlFormat = "https://iccce.inkeys.top/Release/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://bgithub.xyz/InkCanvasForClass/community/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "gh-proxy",
VersionUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://gh-proxy.org/https://github.com/InkCanvasForClass/community/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "hk.gh-proxy",
VersionUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://hk.gh-proxy.org/https://github.com/InkCanvasForClass/community/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "cdn.gh-proxy",
VersionUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://cdn.gh-proxy.org/https://github.com/InkCanvasForClass/community/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "edgeone.gh-proxy",
VersionUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://edgeone.gh-proxy.org/https://github.com/InkCanvasForClass/community/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community/refs/heads/main/UpdateLog.md"
}
}
},
{ UpdateChannel.Preview, new List<UpdateLineGroup>
{
new UpdateLineGroup
{
GroupName = "GitHub主线",
VersionUrl = "https://github.com/InkCanvasForClass/community-beta/raw/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://github.com/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "bgithub备用",
VersionUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://bgithub.xyz/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "kkgithub线路",
VersionUrl = "https://kkgithub.com/InkCanvasForClass/community-beta/raw/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://kkgithub.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://kkgithub.com/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "智教联盟",
DownloadUrlFormat = "https://get.smart-teach.cn/d/Ningbo-S3/shared/jiangling/community-beta/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "inkeys",
DownloadUrlFormat = "https://iccce.inkeys.top/Beta/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "gh-proxy",
VersionUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "hk.gh-proxy",
VersionUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://hk.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "cdn.gh-proxy",
VersionUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://cdn.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "edgeone.gh-proxy",
VersionUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://edgeone.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
}
}
},
@@ -111,6 +285,34 @@ namespace Ink_Canvas.Helpers
GroupName = "inkeys",
DownloadUrlFormat = "https://iccce.inkeys.top/Beta/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "gh-proxy",
VersionUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "hk.gh-proxy",
VersionUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://hk.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "cdn.gh-proxy",
VersionUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://cdn.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
},
new UpdateLineGroup
{
GroupName = "edgeone.gh-proxy",
VersionUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt",
DownloadUrlFormat = "https://edgeone.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip",
LogUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md"
}
}
}
@@ -167,7 +369,7 @@ namespace Ink_Canvas.Helpers
}
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return -1;
}
@@ -188,14 +390,46 @@ namespace Ink_Canvas.Helpers
foreach (var group in groups)
{
// 跳过"智教联盟"和"inkeys"线路组,不参与延迟检测和排序
string testUrl = null;
if (group.GroupName == "智教联盟" || group.GroupName == "inkeys")
{
LogHelper.WriteLogToFile($"AutoUpdate | 跳过{group.GroupName}线路组延迟检测");
try
{
if (!string.IsNullOrEmpty(group.DownloadUrlFormat))
{
testUrl = group.DownloadUrlFormat.Replace("{0}", "test");
testUrl = AppendX64SuffixBeforeZipExtension(testUrl);
}
}
catch
{
testUrl = null;
}
}
else
{
testUrl = group.VersionUrl;
}
if (string.IsNullOrEmpty(testUrl))
{
LogHelper.WriteLogToFile($"AutoUpdate | 线路组 {group.GroupName} 缺少可用测速地址,跳过", LogHelper.LogType.Warning);
continue;
}
LogHelper.WriteLogToFile($"AutoUpdate | 检测线路组: {group.GroupName} ({group.VersionUrl})");
var delay = await GetUrlDelay(group.VersionUrl);
LogHelper.WriteLogToFile($"AutoUpdate | 检测线路组: {group.GroupName} ({testUrl})");
long delay;
if (group.GroupName == "智教联盟" || group.GroupName == "inkeys")
{
delay = await GetDownloadUrlDelay(testUrl);
}
else
{
delay = await GetUrlDelay(testUrl);
}
if (delay >= 0)
{
LogHelper.WriteLogToFile($"AutoUpdate | 线路组 {group.GroupName} 延迟: {delay}ms");
@@ -213,20 +447,12 @@ namespace Ink_Canvas.Helpers
.Select(x => x.group)
.ToList();
// 将"inkeys"线路组插入到最前面(如果存在)
var inkeysGroup = groups.FirstOrDefault(g => g.GroupName == "inkeys");
var inkeysGroup = orderedGroups.FirstOrDefault(g => g.GroupName == "inkeys");
if (inkeysGroup != null)
{
orderedGroups.Remove(inkeysGroup);
orderedGroups.Insert(0, inkeysGroup);
LogHelper.WriteLogToFile("AutoUpdate | inkeys线路组已插入到首位");
}
// 将"智教联盟"线路组插入到第二位(如果存在)
var zhiJiaoGroup = groups.FirstOrDefault(g => g.GroupName == "智教联盟");
if (zhiJiaoGroup != null)
{
orderedGroups.Insert(1, zhiJiaoGroup);
LogHelper.WriteLogToFile("AutoUpdate | 智教联盟线路组已插入到第二位");
LogHelper.WriteLogToFile("AutoUpdate | inkeys线路组已默认优先");
}
if (orderedGroups.Count > 0)
@@ -245,6 +471,47 @@ namespace Ink_Canvas.Helpers
return orderedGroups;
}
private static async Task<long> GetDownloadUrlDelay(string url)
{
try
{
var osVersion = Environment.OSVersion;
bool isWindows7 = osVersion.Version.Major == 6 && osVersion.Version.Minor == 1;
if (isWindows7)
{
using (var handler = new HttpClientHandler())
{
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
using (var client = new HttpClient(handler))
{
client.Timeout = TimeSpan.FromSeconds(5);
var sw = Stopwatch.StartNew();
var resp = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, url));
sw.Stop();
return sw.ElapsedMilliseconds;
}
}
}
else
{
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromSeconds(5);
var sw = Stopwatch.StartNew();
var resp = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, url));
sw.Stop();
return sw.ElapsedMilliseconds;
}
}
}
catch
{
return -1;
}
}
// 获取远程版本号
private static async Task<string> GetRemoteVersion(string fileUrl)
{
@@ -407,7 +674,7 @@ namespace Ink_Canvas.Helpers
{
try
{
string apiUrl = channel == UpdateChannel.Beta
string apiUrl = (channel == UpdateChannel.Beta || channel == UpdateChannel.Preview)
? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases"
: "https://api.github.com/repos/InkCanvasForClass/community/releases";
using (var client = new HttpClient())
@@ -423,7 +690,7 @@ namespace Ink_Canvas.Helpers
if (version == targetVersion || version == $"v{targetVersion}" || version == $"V{targetVersion}")
{
string releaseNotes = release["body"]?.ToString();
string downloadUrl = release["assets"]?.First?["browser_download_url"]?.ToString();
string downloadUrl = PickBrowserDownloadUrlFromAssets(release["assets"]);
// 解析发布时间
DateTime? releaseTime = null;
@@ -449,28 +716,58 @@ namespace Ink_Canvas.Helpers
{
try
{
string apiUrl = channel == UpdateChannel.Beta
? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases/latest"
: "https://api.github.com/repos/InkCanvasForClass/community/releases/latest";
using (var client = new HttpClient())
if (channel == UpdateChannel.Beta)
{
client.DefaultRequestHeaders.Add("User-Agent", "ICC-CE Auto Updater");
LogHelper.WriteLogToFile("AutoUpdate | 使用GitHub API调用");
var response = await client.GetStringAsync(apiUrl);
var json = JObject.Parse(response);
string version = json["tag_name"]?.ToString();
string releaseNotes = json["body"]?.ToString();
string downloadUrl = json["assets"]?.First?["browser_download_url"]?.ToString();
// 解析发布时间
DateTime? releaseTime = null;
if (json["published_at"] != null && DateTime.TryParse(json["published_at"].ToString(), out DateTime parsedTime))
string apiUrl = "https://api.github.com/repos/InkCanvasForClass/community-beta/releases";
using (var client = new HttpClient())
{
releaseTime = parsedTime;
}
client.DefaultRequestHeaders.Add("User-Agent", "ICC-CE Auto Updater");
LogHelper.WriteLogToFile("AutoUpdate | 使用GitHub API调用");
var response = await client.GetStringAsync(apiUrl);
var releases = JArray.Parse(response);
if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl))
return (version, downloadUrl, releaseNotes, releaseTime);
if (releases.Count > 0)
{
var latestRelease = releases[0];
string version = latestRelease["tag_name"]?.ToString();
string releaseNotes = latestRelease["body"]?.ToString();
string downloadUrl = PickBrowserDownloadUrlFromAssets(latestRelease["assets"]);
DateTime? releaseTime = null;
if (latestRelease["published_at"] != null && DateTime.TryParse(latestRelease["published_at"].ToString(), out DateTime parsedTime))
{
releaseTime = parsedTime;
}
if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl))
return (version, downloadUrl, releaseNotes, releaseTime);
}
}
}
else
{
string apiUrl = channel == UpdateChannel.Preview
? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases/latest"
: "https://api.github.com/repos/InkCanvasForClass/community/releases/latest";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent", "ICC-CE Auto Updater");
LogHelper.WriteLogToFile("AutoUpdate | 使用GitHub API调用");
var response = await client.GetStringAsync(apiUrl);
var json = JObject.Parse(response);
string version = json["tag_name"]?.ToString();
string releaseNotes = json["body"]?.ToString();
string downloadUrl = PickBrowserDownloadUrlFromAssets(json["assets"]);
DateTime? releaseTime = null;
if (json["published_at"] != null && DateTime.TryParse(json["published_at"].ToString(), out DateTime parsedTime))
{
releaseTime = parsedTime;
}
if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl))
return (version, downloadUrl, releaseNotes, releaseTime);
}
}
}
catch (Exception ex)
@@ -650,7 +947,8 @@ namespace Ink_Canvas.Helpers
{
try
{
statusFilePath = Path.Combine(updatesFolderPath, $"DownloadV{version}Status.txt");
version = NormalizeVersionForUpdate(version);
statusFilePath = GetUpdateDownloadStatusFilePath(version);
if (File.Exists(statusFilePath) && File.ReadAllText(statusFilePath).Trim().ToLower() == "true")
{
@@ -666,34 +964,25 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"AutoUpdate | 创建更新目录: {updatesFolderPath}");
}
string zipFilePath = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip");
string zipFilePath = GetLocalUpdateZipFilePath(version);
LogHelper.WriteLogToFile($"AutoUpdate | 目标文件路径: {zipFilePath}");
SaveDownloadStatus(false);
// 优先尝试"inkeys"线路组和"智教联盟"线路组
var zhiJiaoGroup = groups.FirstOrDefault(g => g.GroupName == "智教联盟");
// 优先尝试"inkeys"线路组
var inkeysGroup = groups.FirstOrDefault(g => g.GroupName == "inkeys");
if (inkeysGroup != null || zhiJiaoGroup != null)
if (inkeysGroup != null)
{
var priorityGroups = new List<UpdateLineGroup>();
if (inkeysGroup != null)
{
priorityGroups.Add(inkeysGroup);
LogHelper.WriteLogToFile("AutoUpdate | 下载时优先尝试inkeys线路组");
}
if (zhiJiaoGroup != null)
{
priorityGroups.Add(zhiJiaoGroup);
LogHelper.WriteLogToFile("AutoUpdate | 下载时优先尝试智教联盟线路组");
}
groups = priorityGroups.Concat(groups.Where(g => g.GroupName != "智教联盟" && g.GroupName != "inkeys")).ToList();
groups.Remove(inkeysGroup);
groups.Insert(0, inkeysGroup);
LogHelper.WriteLogToFile("AutoUpdate | 下载时优先尝试inkeys线路组");
}
// 依次尝试每个线路组
foreach (var group in groups)
{
string url = string.Format(group.DownloadUrlFormat, version);
url = AppendX64SuffixBeforeZipExtension(url);
// 智教联盟需要先获取真实下载地址
if (group.GroupName == "智教联盟")
{
@@ -925,7 +1214,7 @@ namespace Ink_Canvas.Helpers
// 清理可能损坏的分块文件
if (File.Exists(tempPath))
{
try { File.Delete(tempPath); } catch { }
try { File.Delete(tempPath); } catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
// 增加重试间隔,避免频繁重试
@@ -1111,11 +1400,17 @@ namespace Ink_Canvas.Helpers
return resp.Content.Headers.ContentLength.Value;
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return -1;
}
// 保存下载状态
/// <summary>
/// 将下载完成状态写入预定义的状态文件以供后续检查。
/// </summary>
/// <param name="isSuccess">指示下载是否成功;将以字符串形式写入状态文件("True" 或 "False")。</param>
/// <remarks>
/// 如果状态文件路径为空则不执行任何操作;方法内部捕获异常并记录日志,不会向调用方抛出异常。
/// </remarks>
private static void SaveDownloadStatus(bool isSuccess)
{
try
@@ -1136,11 +1431,32 @@ namespace Ink_Canvas.Helpers
}
}
// 安装新版本应用 - 优化版本,不使用命令行
/// <summary>
/// 安装指定版本的更新包并启动新版本进程以完成替换,然后退出当前应用程序。
/// </summary>
/// <remarks>
/// 该方法会临时将 App.IsUpdateInstalling 置为 true、尝试关闭进程保护(并在结束时还原)、在必要时备份当前设置、解压更新 ZIP、启动解压后的新可执行文件(以更新模式传递旧进程 ID、解压路径和目标路径等参数),并在新进程启动后关闭当前进程。方法会记录日志并在遇到错误时安全退出相应步骤,但不会抛出异常给调用方以外的上下文。</remarks>
/// <param name="version">要安装的版本号,用于定位更新包文件名(与 <see cref="GetLocalUpdateZipFilePath"/> 一致;选择 x64 包时为 InkCanvasForClass.CE.{version}-x64.zip)。</param>
/// <param name="isInSilence">指示是否以静默模式启动新版本(影响传递给新进程的参数和可能的用户提示)。</param>
public static void InstallNewVersionApp(string version, bool isInSilence)
{
bool wasProcessProtectionEnabled = false;
try
{
wasProcessProtectionEnabled = ProcessProtectionManager.Enabled;
}
catch
{
}
try
{
App.IsUpdateInstalling = true;
if (wasProcessProtectionEnabled)
{
try { ProcessProtectionManager.SetEnabled(false); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
// 在更新前备份设置文件
try
{
@@ -1171,7 +1487,7 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"更新前自动备份设置时出错: {ex.Message}", LogHelper.LogType.Error);
}
string zipFilePath = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip");
string zipFilePath = GetLocalUpdateZipFilePath(version);
LogHelper.WriteLogToFile($"AutoUpdate | 检查ZIP文件: {zipFilePath}");
if (!File.Exists(zipFilePath))
@@ -1226,7 +1542,7 @@ namespace Ink_Canvas.Helpers
try
{
LogHelper.WriteLogToFile($"AutoUpdate | 开始解压ZIP文件到: {extractPath}");
ZipFile.ExtractToDirectory(zipFilePath, extractPath);
SafeZipExtractor.ExtractZipSafely(zipFilePath, extractPath, overwrite: true);
LogHelper.WriteLogToFile("AutoUpdate | ZIP文件解压完成");
}
catch (Exception ex)
@@ -1301,6 +1617,18 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"AutoUpdate | 内部异常: {ex.InnerException.Message}", LogHelper.LogType.Error);
}
}
finally
{
// 确保无论更新成功还是失败,都恢复标志位和进程保护状态
App.IsUpdateInstalling = false;
try
{
ProcessProtectionManager.SetEnabled(wasProcessProtectionEnabled);
}
catch
{
}
}
}
// 处理更新模式的启动参数
@@ -1854,16 +2182,16 @@ namespace Ink_Canvas.Helpers
{
foreach (string file in Directory.GetFiles(updatesFolderPath, "*", SearchOption.AllDirectories))
{
try { File.Delete(file); } catch { }
try { File.Delete(file); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
foreach (string dir in Directory.GetDirectories(updatesFolderPath))
{
try { Directory.Delete(dir, true); } catch { }
try { Directory.Delete(dir, true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
try { Directory.Delete(updatesFolderPath, true); } catch { }
try { Directory.Delete(updatesFolderPath, true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
// 版本修复方法,强制下载并安装指定通道的最新版本
@@ -1913,7 +2241,7 @@ namespace Ink_Canvas.Helpers
var result = new List<(string, string, string)>();
try
{
string apiUrl = channel == UpdateChannel.Beta
string apiUrl = (channel == UpdateChannel.Beta || channel == UpdateChannel.Preview)
? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases"
: "https://api.github.com/repos/InkCanvasForClass/community/releases";
using (var client = new HttpClient())
@@ -1926,7 +2254,7 @@ namespace Ink_Canvas.Helpers
{
string version = item["tag_name"]?.ToString();
string releaseNotes = item["body"]?.ToString();
string downloadUrl = item["assets"]?.First?["browser_download_url"]?.ToString();
string downloadUrl = PickBrowserDownloadUrlFromAssets(item["assets"]);
if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl))
result.Add((version, downloadUrl, releaseNotes));
}
@@ -2072,4 +2400,4 @@ namespace Ink_Canvas.Helpers
return currentTime >= StartTime || currentTime <= EndTime;
}
}
}
}
+603
View File
@@ -0,0 +1,603 @@
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 上传队列项数据(用于序列化)
/// </summary>
public class UploadQueueItemData
{
[JsonProperty("file_path")]
public string FilePath { get; set; }
[JsonProperty("retry_count")]
public int RetryCount { get; set; }
[JsonProperty("added_time")]
public DateTime AddedTime { get; set; }
}
/// <summary>
/// 上传队列项
/// </summary>
public class UploadQueueItem
{
public string FilePath { get; set; }
public int RetryCount { get; set; }
}
/// <summary>
/// 通用上传队列基类
/// </summary>
public abstract class BaseUploadQueue : IDisposable
{
protected const int BATCH_SIZE = 10; // 批量上传大小
protected const int MAX_RETRY_COUNT = 3; // 最大重试次数
/// <summary>
/// 上传队列
/// </summary>
protected readonly ConcurrentQueue<UploadQueueItem> _uploadQueue = new ConcurrentQueue<UploadQueueItem>();
/// <summary>
/// 队列处理锁,防止并发处理
/// </summary>
protected readonly SemaphoreSlim _queueProcessingLock = new SemaphoreSlim(1, 1);
/// <summary>
/// 队列保存锁,防止并发保存
/// </summary>
protected readonly SemaphoreSlim _queueSaveLock = new SemaphoreSlim(1, 1);
/// <summary>
/// 是否已初始化队列
/// </summary>
protected bool _isQueueInitialized = false;
/// <summary>
/// 是否已释放资源
/// </summary>
private bool _disposed = false;
/// <summary>
/// 队列文件名
/// </summary>
protected abstract string QueueFileName { get; }
/// <summary>
/// 允许的文件扩展名
/// </summary>
protected virtual HashSet<string> AllowedExtensions => new HashSet<string> { ".png", ".icstk", ".xml", ".zip" };
/// <summary>
/// 获取队列文件路径
/// </summary>
protected string GetQueueFilePath()
{
var configsDir = Path.Combine(App.RootPath, "Configs");
if (!Directory.Exists(configsDir))
{
Directory.CreateDirectory(configsDir);
}
return Path.Combine(configsDir, QueueFileName);
}
/// <summary>
/// 获取最大文件大小
/// </summary>
/// <param name="extension">文件扩展名</param>
/// <returns>最大文件大小(字节)</returns>
protected virtual long GetMaxFileSize(string extension)
{
return extension == ".zip" ? 50 * 1024 * 1024 : 10 * 1024 * 1024;
}
/// <summary>
/// 初始化上传队列
/// </summary>
public void InitializeQueue()
{
if (_isQueueInitialized)
{
return;
}
try
{
var queueFilePath = GetQueueFilePath();
if (!File.Exists(queueFilePath))
{
_isQueueInitialized = true;
return;
}
var jsonContent = File.ReadAllText(queueFilePath);
if (string.IsNullOrWhiteSpace(jsonContent))
{
_isQueueInitialized = true;
return;
}
var queueData = JsonConvert.DeserializeObject<List<UploadQueueItemData>>(jsonContent);
if (queueData == null || queueData.Count == 0)
{
_isQueueInitialized = true;
return;
}
int restoredCount = 0;
int skippedCount = 0;
foreach (var item in queueData)
{
// 验证文件是否存在
if (!File.Exists(item.FilePath))
{
skippedCount++;
continue;
}
// 验证文件格式和大小
if (!IsValidFile(item.FilePath))
{
skippedCount++;
continue;
}
// 恢复队列项
_uploadQueue.Enqueue(new UploadQueueItem
{
FilePath = item.FilePath,
RetryCount = item.RetryCount
});
restoredCount++;
}
_isQueueInitialized = true;
if (restoredCount > 0)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 已恢复上传队列:{restoredCount}个文件,跳过{skippedCount}个无效文件", LogHelper.LogType.Event);
// 如果恢复了队列,触发处理
_ = Task.Run(async () =>
{
try
{
await ProcessUploadQueueAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 恢复上传队列后处理时出错: {ex}", LogHelper.LogType.Error);
}
});
}
else if (skippedCount > 0)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 队列恢复完成:跳过{skippedCount}个无效文件", LogHelper.LogType.Event);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 恢复上传队列时出错: {ex.Message}", LogHelper.LogType.Error);
_isQueueInitialized = true; // 即使出错也标记为已初始化,避免重复尝试
}
}
/// <summary>
/// 保存队列到文件
/// </summary>
protected async Task SaveQueueToFileAsync(CancellationToken cancellationToken = default)
{
if (!await _queueSaveLock.WaitAsync(1000, cancellationToken)) // 最多等待1秒
{
return; // 如果无法获取锁,跳过保存(避免阻塞)
}
try
{
cancellationToken.ThrowIfCancellationRequested();
var queueData = new List<UploadQueueItemData>();
// 将队列转换为可序列化的格式
foreach (var item in _uploadQueue)
{
cancellationToken.ThrowIfCancellationRequested();
queueData.Add(new UploadQueueItemData
{
FilePath = item.FilePath,
RetryCount = item.RetryCount,
AddedTime = DateTime.Now
});
}
var queueFilePath = GetQueueFilePath();
// 如果队列为空,清空文件
if (queueData.Count == 0)
{
ClearQueueFile();
return;
}
var jsonContent = JsonConvert.SerializeObject(queueData, Formatting.Indented);
// 使用进程保护的写入门控,避免安全面板中"进程文件保护"占用导致无法写入
var tempFilePath = queueFilePath + ".tmp";
ProcessProtectionManager.WithWriteAccess(queueFilePath, () =>
{
File.WriteAllText(tempFilePath, jsonContent);
if (File.Exists(queueFilePath))
File.Delete(queueFilePath);
File.Move(tempFilePath, queueFilePath);
});
}
catch (OperationCanceledException)
{
// 取消操作,静默处理
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 保存上传队列时出错: {ex.Message}", LogHelper.LogType.Error);
}
finally
{
_queueSaveLock.Release();
}
}
/// <summary>
/// 清空队列文件
/// </summary>
protected void ClearQueueFile()
{
try
{
var queueFilePath = GetQueueFilePath();
ProcessProtectionManager.WithWriteAccess(queueFilePath, () =>
{
if (File.Exists(queueFilePath))
File.WriteAllText(queueFilePath, "[]");
});
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 清空队列文件时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 将文件加入上传队列
/// </summary>
protected void EnqueueFile(string filePath, int retryCount = 0, CancellationToken cancellationToken = default)
{
_uploadQueue.Enqueue(new UploadQueueItem
{
FilePath = filePath,
RetryCount = retryCount
});
// 异步保存队列到文件
_ = Task.Run(async () =>
{
try
{
cancellationToken.ThrowIfCancellationRequested();
await SaveQueueToFileAsync(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// 取消操作,静默处理
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 保存上传队列时出错(后台任务): {ex}", LogHelper.LogType.Error);
}
}, cancellationToken);
// 触发队列处理
_ = ProcessUploadQueueAsync(cancellationToken);
}
/// <summary>
/// 处理上传队列,批量上传文件
/// </summary>
protected async Task ProcessUploadQueueAsync(CancellationToken cancellationToken = default)
{
// 使用信号量防止并发处理
if (!await _queueProcessingLock.WaitAsync(0, cancellationToken))
{
return; // 已有处理任务在运行
}
try
{
cancellationToken.ThrowIfCancellationRequested();
var filesToUpload = new List<UploadQueueItem>();
// 从队列中取出最多BATCH_SIZE个文件
int count = 0;
while (count < BATCH_SIZE && _uploadQueue.TryDequeue(out UploadQueueItem item))
{
cancellationToken.ThrowIfCancellationRequested();
// 再次检查文件是否存在
if (File.Exists(item.FilePath) && IsValidFile(item.FilePath))
{
filesToUpload.Add(item);
count++;
}
}
if (filesToUpload.Count == 0)
{
return;
}
// 检查是否启用
if (!IsUploadEnabled())
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败:上传未启用", LogHelper.LogType.Error);
// 将文件重新加入队列
foreach (var item in filesToUpload)
{
EnqueueFile(item.FilePath, item.RetryCount, cancellationToken);
}
return;
}
// 并发上传所有文件,并处理失败重试
var uploadTasks = filesToUpload.Select(async item =>
{
try
{
cancellationToken.ThrowIfCancellationRequested();
var success = await UploadFileInternalAsync(item.FilePath, cancellationToken);
if (!success)
{
// 检查是否是可重试的错误
if (IsRetryableError(item.FilePath))
{
// 检查重试次数
if (item.RetryCount < MAX_RETRY_COUNT)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败,将重试 ({item.RetryCount + 1}/{MAX_RETRY_COUNT}): {Path.GetFileName(item.FilePath)}", LogHelper.LogType.Event);
EnqueueFile(item.FilePath, item.RetryCount + 1, cancellationToken);
}
else
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败,已达到最大重试次数: {Path.GetFileName(item.FilePath)}", LogHelper.LogType.Error);
}
}
}
return success;
}
catch (OperationCanceledException)
{
// 取消操作,将文件重新加入队列
EnqueueFile(item.FilePath, item.RetryCount, cancellationToken);
throw;
}
catch (Exception ex)
{
// 检查是否是可重试的错误(超时、网络错误等)
var errorMessage = ex.Message.ToLower();
bool isRetryable = errorMessage.Contains("超时") ||
errorMessage.Contains("timeout") ||
errorMessage.Contains("网络错误") ||
errorMessage.Contains("network") ||
errorMessage.Contains("408") || // 请求超时
errorMessage.Contains("423") || // 资源锁定
errorMessage.Contains("429") || // 请求过多
errorMessage.Contains("500") || // 服务器错误
errorMessage.Contains("502") || // 网关错误
errorMessage.Contains("503") || // 服务不可用
errorMessage.Contains("504"); // 网关超时
if (isRetryable && IsRetryableError(item.FilePath))
{
// 检查重试次数
if (item.RetryCount < MAX_RETRY_COUNT)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败({ex.Message}),将重试 ({item.RetryCount + 1}/{MAX_RETRY_COUNT}): {Path.GetFileName(item.FilePath)}", LogHelper.LogType.Error);
EnqueueFile(item.FilePath, item.RetryCount + 1, cancellationToken);
}
else
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败,已达到最大重试次数: {Path.GetFileName(item.FilePath)}", LogHelper.LogType.Error);
}
}
else
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败(不可重试): {Path.GetFileName(item.FilePath)} - {ex.Message}", LogHelper.LogType.Error);
}
return false;
}
});
await Task.WhenAll(uploadTasks).ConfigureAwait(false);
// 上传完成后保存队列状态
await SaveQueueToFileAsync(cancellationToken).ConfigureAwait(false);
// 检查队列中是否还有文件,如果有就继续处理
if (_uploadQueue.Count > 0)
{
_ = Task.Run(async () =>
{
try
{
await ProcessUploadQueueAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 继续处理上传队列时出错: {ex}", LogHelper.LogType.Error);
}
}, cancellationToken);
}
}
finally
{
_queueProcessingLock.Release();
}
}
/// <summary>
/// 验证文件是否有效
/// </summary>
protected virtual bool IsValidFile(string filePath)
{
try
{
var fileExtension = Path.GetExtension(filePath).ToLower();
if (!AllowedExtensions.Contains(fileExtension))
{
return false;
}
var fileInfo = new FileInfo(filePath);
long maxSize = GetMaxFileSize(fileExtension);
if (fileInfo.Length > maxSize)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败:文件过大({fileInfo.Length / 1024 / 1024:F2}MB),超过{maxSize / 1024 / 1024}MB限制", LogHelper.LogType.Error);
return false;
}
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 判断错误是否可重试
/// </summary>
protected bool IsRetryableError(string filePath)
{
// 检查文件是否存在
if (!File.Exists(filePath))
{
return false; // 文件不存在,不可重试
}
// 检查文件是否有效
if (!IsValidFile(filePath))
{
return false; // 文件无效,不可重试
}
// 检查是否启用
if (!IsUploadEnabled())
{
return false; // 上传未启用,不可重试
}
// 其他错误(超时、网络错误等)可以重试
return true;
}
/// <summary>
/// 检查上传是否启用
/// </summary>
protected abstract bool IsUploadEnabled();
/// <summary>
/// 内部上传方法,执行实际上传操作
/// </summary>
protected abstract Task<bool> UploadFileInternalAsync(string filePath, CancellationToken cancellationToken);
/// <summary>
/// 异步上传文件
/// </summary>
public async Task<bool> UploadFileAsync(string filePath, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
// 检查是否启用
if (!IsUploadEnabled())
{
return false;
}
// 基本验证
if (!File.Exists(filePath))
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败:文件不存在 - {filePath}", LogHelper.LogType.Error);
return false;
}
if (!IsValidFile(filePath))
{
return false;
}
// 确保队列已初始化
if (!_isQueueInitialized)
{
InitializeQueue();
}
// 加入队列
EnqueueFile(filePath, 0, cancellationToken);
return true;
}
catch (OperationCanceledException)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传被取消: {Path.GetFileName(filePath)}", LogHelper.LogType.Event);
throw;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[{GetType().Name}] 加入上传队列时出错: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// 释放资源
/// </summary>
/// <param name="disposing">是否手动释放</param>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_queueProcessingLock?.Dispose();
_queueSaveLock?.Dispose();
}
_disposed = true;
}
}
/// <summary>
/// 析构函数
/// </summary>
~BaseUploadQueue()
{
Dispose(false);
}
}
}
+39 -4
View File
@@ -40,13 +40,13 @@ namespace Ink_Canvas.Helpers
public int ResolutionWidth
{
get => _resolutionWidth;
set => _resolutionWidth = Math.Max(320, Math.Min(1920, value));
set => _resolutionWidth = Math.Max(320, Math.Min(3840, value));
}
public int ResolutionHeight
{
get => _resolutionHeight;
set => _resolutionHeight = Math.Max(240, Math.Min(1080, value));
set => _resolutionHeight = Math.Max(240, Math.Min(2160, value));
}
public CameraService()
@@ -281,8 +281,16 @@ namespace Ink_Canvas.Helpers
// 应用旋转
Bitmap rotatedFrame = ApplyRotation(sourceFrame);
// 应用分辨率调整
_currentFrame = ResizeImage(rotatedFrame, _resolutionWidth, _resolutionHeight);
int targetWidth = _resolutionWidth;
int targetHeight = _resolutionHeight;
if (_rotationAngle == 1 || _rotationAngle == 3)
{
targetWidth = _resolutionHeight;
targetHeight = _resolutionWidth;
}
_currentFrame = ResizeImageWithAspectRatio(rotatedFrame, targetWidth, targetHeight);
rotatedFrame?.Dispose();
}
@@ -357,6 +365,33 @@ namespace Ink_Canvas.Helpers
return rotated;
}
/// <summary>
/// 调整图像大小
/// </summary>
private Bitmap ResizeImageWithAspectRatio(Bitmap source, int targetWidth, int targetHeight)
{
if (source.Width == targetWidth && source.Height == targetHeight)
return new Bitmap(source);
double scaleX = (double)targetWidth / source.Width;
double scaleY = (double)targetHeight / source.Height;
double scale = Math.Min(scaleX, scaleY);
// 计算实际尺寸
int actualWidth = (int)(source.Width * scale);
int actualHeight = (int)(source.Height * scale);
var resized = new Bitmap(actualWidth, actualHeight, PixelFormat.Format24bppRgb);
using (var graphics = Graphics.FromImage(resized))
{
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphics.DrawImage(source, 0, 0, actualWidth, actualHeight);
}
return resized;
}
/// <summary>
/// 调整图像大小
/// </summary>
+109
View File
@@ -0,0 +1,109 @@
using System;
namespace Ink_Canvas.Helpers
{
public class ComPPTLinkManager : IPPTLinkManager
{
private readonly PPTManager _inner;
public ComPPTLinkManager()
{
_inner = new PPTManager();
_inner.SlideShowBegin += wn => SlideShowBegin?.Invoke(wn);
_inner.SlideShowNextSlide += wn => SlideShowNextSlide?.Invoke(wn);
_inner.SlideShowEnd += pres => SlideShowEnd?.Invoke(pres);
_inner.PresentationOpen += pres => PresentationOpen?.Invoke(pres);
_inner.PresentationClose += pres => PresentationClose?.Invoke(pres);
_inner.PPTConnectionChanged += connected => PPTConnectionChanged?.Invoke(connected);
_inner.SlideShowStateChanged += inSlideShow => SlideShowStateChanged?.Invoke(inSlideShow);
}
#region IPPTLinkManager
public event Action<object> SlideShowBegin;
public event Action<object> SlideShowNextSlide;
public event Action<object> SlideShowEnd;
public event Action<object> PresentationOpen;
public event Action<object> PresentationClose;
public event Action<bool> PPTConnectionChanged;
public event Action<bool> SlideShowStateChanged;
#endregion
#region IPPTLinkManager
public bool IsConnected => _inner.IsConnected;
public bool IsInSlideShow => _inner.IsInSlideShow;
public bool IsSupportWPS
{
get => _inner.IsSupportWPS;
set => _inner.IsSupportWPS = value;
}
public bool SkipAnimationsWhenNavigating
{
get => _inner.SkipAnimationsWhenNavigating;
set => _inner.SkipAnimationsWhenNavigating = value;
}
public int SlidesCount => _inner.SlidesCount;
public object PPTApplication => _inner.PPTApplication;
#endregion
#region
/// <summary>
/// 开始监控本地 PowerPoint 的连接与运行状态,并在状态变化时触发相应事件。
/// </summary>
public void StartMonitoring() => _inner.StartMonitoring();
/// <summary>
/// 停止对 PowerPoint 的监控,断开当前连接并停止触发相关事件。
/// </summary>
public void StopMonitoring() => _inner.StopMonitoring();
/// <summary>
/// 强制断开当前 COM PPT 连接并停止对其监控,同时写入事件日志。
/// </summary>
/// <remarks>
/// 会向日志记录一条事件信息并调用内部管理器停止监控;该方法不会重新启动监控或重新初始化内部管理器实例。
/// </remarks>
public void ReloadConnection()
{
LogHelper.WriteLogToFile("COM PPT 执行热重载:强制断开并重新连接", LogHelper.LogType.Event);
_inner.StopMonitoring();
}
#endregion
#region
public bool TryStartSlideShow() => _inner.TryStartSlideShow();
public bool TryEndSlideShow() => _inner.TryEndSlideShow();
#endregion
#region
public bool TryNavigateToSlide(int slideNumber) => _inner.TryNavigateToSlide(slideNumber);
public bool TryNavigateNext() => _inner.TryNavigateNext();
public bool TryNavigatePrevious() => _inner.TryNavigatePrevious();
#endregion
#region
public int GetCurrentSlideNumber() => _inner.GetCurrentSlideNumber();
public string GetPresentationName() => _inner.GetPresentationName();
public bool TryShowSlideNavigation() => _inner.TryShowSlideNavigation();
public object GetCurrentActivePresentation() => _inner.GetCurrentActivePresentation();
#endregion
#region IDisposable
public void Dispose()
{
_inner?.Dispose();
}
#endregion
}
}
+161
View File
@@ -0,0 +1,161 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 提供多配置文件保存、切换与热重载支持。
/// 方案保存在 Configs/Profiles 目录下,当前生效的配置仍为 Configs/Settings.json。
/// </summary>
public static class ConfigProfileManager
{
private static readonly string ProfilesDir = Path.Combine(App.RootPath, "Configs", "Profiles");
private static readonly string SettingsFilePath = Path.Combine(App.RootPath, "Configs", "Settings.json");
private const string ProfileExtension = ".json";
/// <summary>将配置文件名称转为安全文件名(去掉非法字符)。</summary>
private static string ToSafeFileName(string profileName)
{
if (string.IsNullOrWhiteSpace(profileName)) return "未命名";
var invalid = Path.GetInvalidFileNameChars();
var name = string.Join("_", profileName.Trim().Split(invalid, StringSplitOptions.RemoveEmptyEntries));
return string.IsNullOrEmpty(name) ? "未命名" : name;
}
/// <summary>确保配置文件目录存在。</summary>
public static void EnsureProfilesDirectory()
{
try
{
if (!Directory.Exists(ProfilesDir))
{
ProcessProtectionManager.WithWriteAccess(ProfilesDir, () => Directory.CreateDirectory(ProfilesDir));
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"创建配置文件目录失败: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>获取所有配置文件名称(不含扩展名),按名称排序。</summary>
public static IReadOnlyList<string> ListProfileNames()
{
try
{
EnsureProfilesDirectory();
if (!Directory.Exists(ProfilesDir)) return Array.Empty<string>();
var files = Directory.GetFiles(ProfilesDir, "*" + ProfileExtension);
return files
.Select(f => Path.GetFileNameWithoutExtension(f))
.Where(n => !string.IsNullOrEmpty(n))
.OrderBy(n => n, StringComparer.OrdinalIgnoreCase)
.ToList();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"列举配置文件失败: {ex.Message}", LogHelper.LogType.Error);
return Array.Empty<string>();
}
}
/// <summary>获取某配置文件对应的文件路径。</summary>
public static string GetProfilePath(string profileName)
{
var safe = ToSafeFileName(profileName);
return Path.Combine(ProfilesDir, safe + ProfileExtension);
}
/// <summary>将当前配置的 JSON 内容保存为指定名称的配置文件。</summary>
/// <param name="profileName">配置文件显示名称(会转为安全文件名)。</param>
/// <param name="settingsJson">已序列化好的 Settings JSON 字符串。</param>
/// <returns>成功返回 true。</returns>
public static bool SaveAsProfile(string profileName, string settingsJson)
{
try
{
if (string.IsNullOrWhiteSpace(settingsJson))
{
LogHelper.WriteLogToFile("配置文件保存失败:内容为空", LogHelper.LogType.Warning);
return false;
}
EnsureProfilesDirectory();
var path = GetProfilePath(profileName);
ProcessProtectionManager.WithWriteAccess(path, () => File.WriteAllText(path, settingsJson));
LogHelper.WriteLogToFile($"配置文件已保存: {ToSafeFileName(profileName)}", LogHelper.LogType.Event);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存配置文件失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
/// <summary>将指定配置文件应用到当前配置(覆盖 Configs/Settings.json),供主窗口随后热重载。</summary>
/// <param name="profileName">配置文件名称(与 ListProfileNames 中一致,或与保存时使用的显示名一致)。</param>
/// <returns>成功返回 true;文件不存在或复制失败返回 false。</returns>
public static bool ApplyProfile(string profileName)
{
try
{
var path = GetProfilePath(profileName);
if (!File.Exists(path))
{
LogHelper.WriteLogToFile($"配置文件文件不存在: {path}", LogHelper.LogType.Warning);
return false;
}
var json = File.ReadAllText(path);
if (string.IsNullOrWhiteSpace(json))
{
LogHelper.WriteLogToFile("配置文件内容为空", LogHelper.LogType.Warning);
return false;
}
// 可选:校验是否为合法 Settings JSON
try
{
JsonConvert.DeserializeObject<Settings>(json);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"配置文件格式无效: {ex.Message}", LogHelper.LogType.Error);
return false;
}
var configsDir = Path.GetDirectoryName(SettingsFilePath);
if (!string.IsNullOrEmpty(configsDir) && !Directory.Exists(configsDir))
{
ProcessProtectionManager.WithWriteAccess(configsDir, () => Directory.CreateDirectory(configsDir));
}
ProcessProtectionManager.WithWriteAccess(SettingsFilePath, () => File.WriteAllText(SettingsFilePath, json));
LogHelper.WriteLogToFile($"已应用配置文件: {profileName}(请热重载以生效)", LogHelper.LogType.Event);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用配置文件失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
/// <summary>删除指定名称的配置文件。</summary>
public static bool DeleteProfile(string profileName)
{
try
{
var path = GetProfilePath(profileName);
if (!File.Exists(path)) return true;
ProcessProtectionManager.WithWriteAccess(path, () => File.Delete(path));
LogHelper.WriteLogToFile($"已删除配置文件: {profileName}", LogHelper.LogType.Event);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"删除配置文件失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
}
}
+17
View File
@@ -135,4 +135,21 @@ namespace Ink_Canvas.Converter
return Visibility.Visible;
}
}
public class RippleEffectTranslationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double d)
{
return -d / 2;
}
return 0.0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
+310 -163
View File
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OSVersionExtension;
using System;
using System.Collections.Generic;
using System.IO;
@@ -46,20 +47,40 @@ namespace Ink_Canvas.Helpers
{
try
{
// 1. 尝试从主文件读取设备ID
string deviceId = LoadDeviceIdFromFile(DeviceIdFilePath);
if (!string.IsNullOrEmpty(deviceId))
// 计算当前设备的硬件指纹
string currentHardwareFingerprint = GenerateHardwareFingerprint();
// 1. 尝试从主文件读取设备ID及其硬件指纹
var storedInfo = LoadDeviceIdFromFile(DeviceIdFilePath);
if (storedInfo != null && !string.IsNullOrEmpty(storedInfo.DeviceId) && IsValidDeviceId(storedInfo.DeviceId))
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 从主文件读取设备ID: {deviceId}");
return deviceId;
if (!string.IsNullOrEmpty(storedInfo.HardwareFingerprint))
{
if (storedInfo.HardwareFingerprint == currentHardwareFingerprint)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 从主文件读取设备ID且硬件信息一致: {storedInfo.DeviceId}");
return storedInfo.DeviceId;
}
LogHelper.WriteLogToFile("DeviceIdentifier | 检测到当前硬件信息与保存的设备ID不一致,将重新生成设备ID");
}
else
{
LogHelper.WriteLogToFile("DeviceIdentifier | 检测到旧格式设备ID文件(无硬件信息),将基于当前硬件重新生成设备ID并升级文件格式");
}
}
// 2. 生成新的设备ID
string newDeviceId = GenerateDeviceId();
// 2. 基于当前硬件指纹生成新的设备ID
string newDeviceId = GenerateDeviceIdFromFingerprint(currentHardwareFingerprint);
LogHelper.WriteLogToFile($"DeviceIdentifier | 生成新设备ID: {newDeviceId}");
// 3. 保存到主文件
SaveDeviceIdToFile(DeviceIdFilePath, newDeviceId);
// 3. 保存到主文件(包含硬件指纹)
var newInfo = new DeviceIdInfo
{
DeviceId = newDeviceId,
HardwareFingerprint = currentHardwareFingerprint
};
SaveDeviceIdToFile(DeviceIdFilePath, newInfo);
return newDeviceId;
}
@@ -79,143 +100,9 @@ namespace Ink_Canvas.Helpers
{
try
{
// 收集硬件信息
var hardwareInfo = new StringBuilder();
// 使用反射获取硬件信息,避免直接引用System.Management
try
{
// 尝试加载System.Management程序集
var assembly = Assembly.Load("System.Management");
if (assembly != null)
{
// CPU信息
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT ProcessorId FROM Win32_Processor");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var processorId = indexer.GetValue(obj, new object[] { "ProcessorId" });
hardwareInfo.Append(processorId?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch { }
// 主板序列号
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT SerialNumber FROM Win32_BaseBoard");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var serialNumber = indexer.GetValue(obj, new object[] { "SerialNumber" });
hardwareInfo.Append(serialNumber?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch { }
// BIOS序列号
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT SerialNumber FROM Win32_BIOS");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var serialNumber = indexer.GetValue(obj, new object[] { "SerialNumber" });
hardwareInfo.Append(serialNumber?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch { }
// 主硬盘序列号
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT SerialNumber FROM Win32_DiskDrive WHERE MediaType='Fixed hard disk media'");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var serialNumber = indexer.GetValue(obj, new object[] { "SerialNumber" });
hardwareInfo.Append(serialNumber?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch { }
}
}
catch { }
// 如果硬件信息不足,添加系统信息
if (hardwareInfo.Length < 10)
{
hardwareInfo.Append(Environment.MachineName);
hardwareInfo.Append(Environment.UserName);
hardwareInfo.Append(Environment.OSVersion);
}
// 生成哈希
using (var sha256 = SHA256.Create())
{
byte[] hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(hardwareInfo.ToString()));
string hashString = BitConverter.ToString(hashBytes).Replace("-", "");
// 取前25个字符,确保唯一性
string deviceId = hashString.Substring(0, 25);
// 添加校验位(第25位)
int checksum = 0;
for (int i = 0; i < 24; i++)
{
checksum += Convert.ToInt32(deviceId[i]);
}
checksum %= 36; // 0-9, A-Z
char checksumChar = checksum < 10 ? (char)(checksum + '0') : (char)(checksum - 10 + 'A');
return deviceId.Substring(0, 24) + checksumChar;
}
// 基于当前硬件指纹生成设备ID
string hardwareFingerprint = GenerateHardwareFingerprint();
return GenerateDeviceIdFromFingerprint(hardwareFingerprint);
}
catch (Exception ex)
{
@@ -224,6 +111,157 @@ namespace Ink_Canvas.Helpers
}
}
/// <summary>
/// 生成当前设备的硬件指纹字符串(用于生成和校验设备ID)
/// </summary>
private static string GenerateHardwareFingerprint()
{
// 收集硬件信息
var hardwareInfo = new StringBuilder();
try
{
var assembly = Assembly.Load("System.Management");
if (assembly != null)
{
// CPU信息
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT ProcessorId FROM Win32_Processor");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var processorId = indexer.GetValue(obj, new object[] { "ProcessorId" });
hardwareInfo.Append(processorId?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
// 主板序列号
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT SerialNumber FROM Win32_BaseBoard");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var serialNumber = indexer.GetValue(obj, new object[] { "SerialNumber" });
hardwareInfo.Append(serialNumber?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
// BIOS序列号
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT SerialNumber FROM Win32_BIOS");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var serialNumber = indexer.GetValue(obj, new object[] { "SerialNumber" });
hardwareInfo.Append(serialNumber?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
// 主硬盘序列号
try
{
var searcherType = assembly.GetType("System.Management.ManagementObjectSearcher");
var searcher = Activator.CreateInstance(searcherType, "SELECT SerialNumber FROM Win32_DiskDrive WHERE MediaType='Fixed hard disk media'");
var getMethod = searcherType.GetMethod("Get");
var enumerator = getMethod.Invoke(searcher, null);
var moveNextMethod = enumerator.GetType().GetMethod("MoveNext");
var currentProperty = enumerator.GetType().GetProperty("Current");
if ((bool)moveNextMethod.Invoke(enumerator, null))
{
var obj = currentProperty.GetValue(enumerator);
var indexer = obj.GetType().GetProperty("Item", new[] { typeof(string) });
var serialNumber = indexer.GetValue(obj, new object[] { "SerialNumber" });
hardwareInfo.Append(serialNumber?.ToString() ?? "");
}
var disposeMethod = searcher.GetType().GetMethod("Dispose");
disposeMethod?.Invoke(searcher, null);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
catch
{
}
if (hardwareInfo.Length < 10)
{
hardwareInfo.Append(Environment.MachineName);
hardwareInfo.Append(Environment.UserName);
hardwareInfo.Append(Environment.OSVersion);
}
return hardwareInfo.ToString();
}
/// <summary>
/// 基于硬件指纹生成25字符的设备ID
/// </summary>
private static string GenerateDeviceIdFromFingerprint(string hardwareFingerprint)
{
// 生成哈希
using (var sha256 = SHA256.Create())
{
byte[] hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(hardwareFingerprint ?? string.Empty));
string hashString = BitConverter.ToString(hashBytes).Replace("-", "");
// 取前25个字符,确保唯一性
string deviceId = hashString.Substring(0, 25);
// 添加校验位(第25位)
int checksum = 0;
for (int i = 0; i < 24; i++)
{
checksum += Convert.ToInt32(deviceId[i]);
}
checksum %= 36; // 0-9, A-Z
char checksumChar = checksum < 10 ? (char)(checksum + '0') : (char)(checksum - 10 + 'A');
return deviceId.Substring(0, 24) + checksumChar;
}
}
/// <summary>
/// 生成备用设备ID(基于时间戳)
/// </summary>
@@ -282,16 +320,33 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 从文件加载设备ID
/// </summary>
private static string LoadDeviceIdFromFile(string filePath)
private static DeviceIdInfo LoadDeviceIdFromFile(string filePath)
{
try
{
if (File.Exists(filePath))
{
string content = File.ReadAllText(filePath).Trim();
try
{
var info = JsonConvert.DeserializeObject<DeviceIdInfo>(content);
if (info != null && !string.IsNullOrEmpty(info.DeviceId) && IsValidDeviceId(info.DeviceId))
{
return info;
}
}
catch
{
}
if (IsValidDeviceId(content))
{
return content;
return new DeviceIdInfo
{
DeviceId = content,
HardwareFingerprint = null
};
}
}
}
@@ -305,7 +360,12 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 保存设备ID到文件
/// </summary>
private static void SaveDeviceIdToFile(string filePath, string deviceId)
/// <remarks>
/// 将设备标识信息以格式化的 JSON 写入指定文件,并确保目标目录存在;在失败时记录错误但不抛出异常。
/// </remarks>
/// <param name="filePath">目标文件的完整路径,用于保存设备标识信息。</param>
/// <param name="info">要保存的设备标识信息对象(包含 DeviceId 和 可选的硬件指纹)。</param>
private static void SaveDeviceIdToFile(string filePath, DeviceIdInfo info)
{
try
{
@@ -313,10 +373,11 @@ namespace Ink_Canvas.Helpers
var directory = Path.GetDirectoryName(filePath);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
ProcessProtectionManager.WithWriteAccess(directory, () => Directory.CreateDirectory(directory));
}
File.WriteAllText(filePath, deviceId);
string json = JsonConvert.SerializeObject(info, Formatting.Indented);
ProcessProtectionManager.WithWriteAccess(filePath, () => File.WriteAllText(filePath, json));
LogHelper.WriteLogToFile($"DeviceIdentifier | 设备ID已保存到: {filePath}");
}
@@ -326,6 +387,14 @@ namespace Ink_Canvas.Helpers
}
}
private class DeviceIdInfo
{
[JsonProperty("deviceId")]
public string DeviceId { get; set; }
[JsonProperty("hardwareFingerprint")]
public string HardwareFingerprint { get; set; }
}
/// <summary>
@@ -342,7 +411,9 @@ namespace Ink_Canvas.Helpers
[JsonProperty("launchCount")]
public int LaunchCount { get; set; }
// 新的秒级精度字段
[JsonProperty("systemVersion")]
public string SystemVersion { get; set; }
[JsonProperty("totalUsageSeconds")]
public long TotalUsageSeconds { get; set; }
@@ -363,6 +434,9 @@ namespace Ink_Canvas.Helpers
[JsonProperty("lastModified")]
public DateTime LastModified { get; set; }
[JsonProperty("updateChannel")]
public Ink_Canvas.UpdateChannel UpdateChannel { get; set; } = Ink_Canvas.UpdateChannel.Release;
// 每周统计数据(秒级精度)
[JsonProperty("weeklyLaunchCount")]
public int WeeklyLaunchCount { get; set; }
@@ -501,6 +575,20 @@ namespace Ink_Canvas.Helpers
// 记录每周启动次数
stats.RecordWeeklyLaunch();
try
{
var osName = OSVersion.GetOperatingSystem();
var osVersion = OSVersion.GetOSVersion();
string versionText = osVersion != null
? $"{osName} {osVersion.Version}"
: osName.ToString();
stats.SystemVersion = versionText;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 刷新系统版本信息失败: {ex.Message}", LogHelper.LogType.Warning);
}
// 计算使用频率
CalculateUsageFrequency(stats);
@@ -536,8 +624,6 @@ namespace Ink_Canvas.Helpers
// 更新秒级精度数据
stats.TotalUsageSeconds += sessionSeconds;
// 记录每周使用时长(秒级精度)
stats.RecordWeeklyUsage(sessionSeconds);
@@ -545,7 +631,6 @@ namespace Ink_Canvas.Helpers
if (stats.LaunchCount > 0)
{
stats.AverageSessionSeconds = (double)stats.TotalUsageSeconds / stats.LaunchCount;
}
}
@@ -565,6 +650,20 @@ namespace Ink_Canvas.Helpers
}
}
public static string GetSystemVersion()
{
try
{
var stats = LoadUsageStats();
return stats.SystemVersion;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 获取系统版本失败: {ex.Message}", LogHelper.LogType.Error);
return null;
}
}
/// <summary>
/// 计算使用频率和更新优先级(基于真实的每周统计数据)
/// 通过多维度评分系统确定用户类型:高频(≥80分)、中频(40-79分)、低频(<40分)
@@ -905,7 +1004,7 @@ namespace Ink_Canvas.Helpers
var directory = Path.GetDirectoryName(filePath);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
ProcessProtectionManager.WithWriteAccess(directory, () => Directory.CreateDirectory(directory));
}
string json = JsonConvert.SerializeObject(stats, Formatting.Indented);
@@ -929,7 +1028,7 @@ namespace Ink_Canvas.Helpers
checksum.CopyTo(finalData, 0);
encryptedData.CopyTo(finalData, checksum.Length);
File.WriteAllBytes(filePath, finalData);
ProcessProtectionManager.WithWriteAccess(filePath, () => File.WriteAllBytes(filePath, finalData));
LogHelper.WriteLogToFile($"DeviceIdentifier | 加密使用统计已保存到: {filePath}");
}
@@ -940,6 +1039,40 @@ namespace Ink_Canvas.Helpers
}
}
public static void UpdateUsageChannel(Ink_Canvas.UpdateChannel channel)
{
try
{
lock (fileLock)
{
var stats = LoadUsageStats();
if (stats == null)
{
stats = new UsageStats
{
DeviceId = DeviceId,
LastLaunchTime = DateTime.Now,
LaunchCount = 0,
TotalUsageSeconds = 0,
AverageSessionSeconds = 0,
LastUpdateCheck = DateTime.MinValue,
UpdatePriority = UpdatePriority.Medium,
UsageFrequency = UsageFrequency.Medium
};
}
stats.UpdateChannel = channel;
SaveUsageStats(stats);
LogHelper.WriteLogToFile($"DeviceIdentifier | 更新使用统计中的通道信息: {channel}");
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 更新通道信息到使用统计失败: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 记录更新检查时间
/// </summary>
@@ -960,6 +1093,23 @@ namespace Ink_Canvas.Helpers
}
}
/// <summary>
/// 获取上次更新检查时间
/// </summary>
public static DateTime GetLastUpdateCheck()
{
try
{
var stats = LoadUsageStats();
return stats.LastUpdateCheck;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 获取上次更新检查时间失败: {ex.Message}", LogHelper.LogType.Error);
return DateTime.MinValue;
}
}
/// <summary>
/// 从备份文件恢复使用统计数据
@@ -1092,15 +1242,13 @@ namespace Ink_Canvas.Helpers
int versionDiff = CalculateVersionGenerationDifference(localVersion, updateVersion);
LogHelper.WriteLogToFile($"DeviceIdentifier | 无法获取版本发布时间,使用版本号差异判断 - 本地版本: {localVersion}, 远程版本: {updateVersion}, 代数差异: {versionDiff}");
// 当版本号代数差异大于3时自动更新
if (versionDiff > 3)
if (versionDiff >= 1)
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 版本号代数差异({versionDiff})大于3,自动更新");
return true;
LogHelper.WriteLogToFile($"DeviceIdentifier | 版本号代数差异({versionDiff})>=1,允许更新");
}
else
{
LogHelper.WriteLogToFile($"DeviceIdentifier | 版本号代数差异({versionDiff})不大于3,暂不更新");
LogHelper.WriteLogToFile($"DeviceIdentifier | 版本号代数差异({versionDiff})<1,可能是相同版本或降级,暂不更新");
return false;
}
}
@@ -1476,4 +1624,3 @@ namespace Ink_Canvas.Helpers
}
}
}
+484
View File
@@ -0,0 +1,484 @@
using Newtonsoft.Json;
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// Dlass API 客户端,用于与服务端通信
/// </summary>
public class DlassApiClient : IDisposable
{
private const string DEFAULT_BASE_URL = "https://dlass.tech";
private readonly string _appId;
private readonly string _appSecret;
private readonly string _baseUrl;
private HttpClient _httpClient;
private string _accessToken;
private DateTime _tokenExpiresAt;
private string _userToken;
/// <summary>
/// 初始化 Dlass API 客户端
/// </summary>
/// <param name="appId">应用ID</param>
/// <param name="appSecret">应用密钥</param>
/// <param name="baseUrl">API基础URL,如果为空则使用默认URL</param>
/// <param name="userToken">用户Token,如果提供则优先使用用户token而不是App Secret</param>
public DlassApiClient(string appId, string appSecret, string baseUrl = null, string userToken = null)
{
_appId = appId ?? throw new ArgumentNullException(nameof(appId));
_appSecret = appSecret ?? throw new ArgumentNullException(nameof(appSecret));
_userToken = userToken;
_baseUrl = baseUrl ?? DEFAULT_BASE_URL;
_baseUrl = _baseUrl.TrimEnd('/');
if (!_baseUrl.StartsWith("http://") && !_baseUrl.StartsWith("https://"))
{
_baseUrl = "https://" + _baseUrl;
}
_httpClient = new HttpClient
{
BaseAddress = new Uri(_baseUrl),
Timeout = TimeSpan.FromSeconds(30)
};
_httpClient.DefaultRequestHeaders.Add("User-Agent", "InkCanvas/1.0");
}
/// <summary>
/// 获取访问令牌(Access Token
/// </summary>
/// <param name="cancellationToken">取消令牌</param>
public async Task<string> GetAccessTokenAsync(CancellationToken cancellationToken = default)
{
if (!string.IsNullOrEmpty(_userToken))
{
return _userToken;
}
if (!string.IsNullOrEmpty(_accessToken) && DateTime.Now < _tokenExpiresAt.AddMinutes(-5))
{
return _accessToken;
}
try
{
cancellationToken.ThrowIfCancellationRequested();
var requestData = new
{
app_id = _appId,
app_secret = _appSecret,
grant_type = "client_credentials"
};
var json = JsonConvert.SerializeObject(requestData);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("/oauth/token", content, cancellationToken);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var tokenResponse = JsonConvert.DeserializeObject<TokenResponse>(responseContent);
_accessToken = tokenResponse.AccessToken;
_tokenExpiresAt = DateTime.Now.AddSeconds(tokenResponse.ExpiresIn ?? 3600);
return _accessToken;
}
else
{
throw new Exception($"获取Access Token失败: {response.StatusCode}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (HttpRequestException httpEx)
{
throw new Exception($"获取Access Token时网络错误: {httpEx.Message}", httpEx);
}
catch (Exception ex)
{
throw new Exception($"获取Access Token时出错: {ex.Message}", ex);
}
}
/// <summary>
/// 发送GET请求
/// </summary>
/// <param name="endpoint">API端点</param>
/// <param name="requireAuth">是否需要认证</param>
/// <param name="cancellationToken">取消令牌</param>
public async Task<T> GetAsync<T>(string endpoint, bool requireAuth = true, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
string token = null;
if (requireAuth)
{
token = await GetAccessTokenAsync(cancellationToken);
}
var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
if (requireAuth && !string.IsNullOrEmpty(token))
{
if (!string.IsNullOrEmpty(_userToken))
{
request.Headers.Add("X-User-Token", token);
}
else
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
}
}
var response = await _httpClient.SendAsync(request, cancellationToken);
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (string.IsNullOrEmpty(content))
{
return default(T);
}
return JsonConvert.DeserializeObject<T>(content);
}
else
{
throw new Exception($"API请求失败: {response.StatusCode} - {content}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (HttpRequestException httpEx)
{
throw new Exception($"发送请求时出错: {httpEx.Message}", httpEx);
}
catch (Exception ex)
{
throw new Exception($"发送请求时出错: {ex.Message}", ex);
}
}
/// <summary>
/// 发送POST请求
/// </summary>
/// <param name="endpoint">API端点</param>
/// <param name="data">请求数据</param>
/// <param name="requireAuth">是否需要认证</param>
/// <param name="cancellationToken">取消令牌</param>
public async Task<T> PostAsync<T>(string endpoint, object data = null, bool requireAuth = true, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
string token = null;
if (requireAuth)
{
token = await GetAccessTokenAsync(cancellationToken);
}
var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
if (requireAuth && !string.IsNullOrEmpty(token))
{
if (!string.IsNullOrEmpty(_userToken))
{
request.Headers.Add("X-User-Token", token);
}
else
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
}
}
if (data != null)
{
var json = JsonConvert.SerializeObject(data);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
}
var response = await _httpClient.SendAsync(request, cancellationToken);
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (string.IsNullOrEmpty(content))
{
return default(T);
}
return JsonConvert.DeserializeObject<T>(content);
}
else
{
throw new Exception($"API请求失败: {response.StatusCode} - {content}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (HttpRequestException httpEx)
{
throw new Exception($"发送请求时出错: {httpEx.Message}", httpEx);
}
catch (Exception ex)
{
throw new Exception($"发送请求时出错: {ex.Message}", ex);
}
}
/// <summary>
/// 发送PUT请求
/// </summary>
/// <param name="endpoint">API端点</param>
/// <param name="data">请求数据</param>
/// <param name="requireAuth">是否需要认证</param>
/// <param name="cancellationToken">取消令牌</param>
public async Task<T> PutAsync<T>(string endpoint, object data = null, bool requireAuth = true, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
string token = null;
if (requireAuth)
{
token = await GetAccessTokenAsync(cancellationToken);
}
var request = new HttpRequestMessage(HttpMethod.Put, endpoint);
if (requireAuth && !string.IsNullOrEmpty(token))
{
// 如果是用户token,使用X-User-Token header
if (!string.IsNullOrEmpty(_userToken))
{
request.Headers.Add("X-User-Token", token);
}
else
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
}
}
if (data != null)
{
var json = JsonConvert.SerializeObject(data);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
}
var response = await _httpClient.SendAsync(request, cancellationToken);
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (string.IsNullOrEmpty(content))
{
return default(T);
}
return JsonConvert.DeserializeObject<T>(content);
}
else
{
throw new Exception($"API请求失败: {response.StatusCode} - {content}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (HttpRequestException httpEx)
{
throw new Exception($"发送请求时出错: {httpEx.Message}", httpEx);
}
catch (Exception ex)
{
throw new Exception($"发送请求时出错: {ex.Message}", ex);
}
}
/// <summary>
/// 发送DELETE请求
/// </summary>
/// <param name="endpoint">API端点</param>
/// <param name="requireAuth">是否需要认证</param>
/// <param name="cancellationToken">取消令牌</param>
public async Task<bool> DeleteAsync(string endpoint, bool requireAuth = true, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
string token = null;
if (requireAuth)
{
token = await GetAccessTokenAsync(cancellationToken);
}
var request = new HttpRequestMessage(HttpMethod.Delete, endpoint);
if (requireAuth && !string.IsNullOrEmpty(token))
{
// 如果是用户token,使用X-User-Token header
if (!string.IsNullOrEmpty(_userToken))
{
request.Headers.Add("X-User-Token", token);
}
else
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
}
}
var response = await _httpClient.SendAsync(request, cancellationToken);
if (response.IsSuccessStatusCode)
{
return true;
}
else
{
return false;
}
}
catch (OperationCanceledException)
{
throw;
}
catch (HttpRequestException)
{
return false;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// 上传笔记文件
/// </summary>
/// <param name="endpoint">上传端点</param>
/// <param name="filePath">文件路径</param>
/// <param name="boardId">白板ID</param>
/// <param name="secretKey">白板密钥</param>
/// <param name="title">笔记标题(可选)</param>
/// <param name="description">笔记描述(可选)</param>
/// <param name="tags">笔记标签(可选)</param>
/// <param name="cancellationToken">取消令牌</param>
public async Task<T> UploadNoteAsync<T>(string endpoint, string filePath, string boardId, string secretKey, string title = null, string description = null, string tags = null, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"文件不存在: {filePath}");
}
var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
// 设置白板认证头
request.Headers.Add("X-Board-ID", boardId);
request.Headers.Add("X-Secret-Key", secretKey);
// 创建multipart/form-data内容
var content = new MultipartFormDataContent();
// 添加文件
var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath));
var fileName = Path.GetFileName(filePath);
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
content.Add(fileContent, "file", fileName);
// 添加可选参数
if (!string.IsNullOrEmpty(title))
{
content.Add(new StringContent(title), "title");
}
if (!string.IsNullOrEmpty(description))
{
content.Add(new StringContent(description), "description");
}
if (!string.IsNullOrEmpty(tags))
{
content.Add(new StringContent(tags), "tags");
}
request.Content = content;
var response = await _httpClient.SendAsync(request, cancellationToken);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (string.IsNullOrEmpty(responseContent))
{
return default(T);
}
return JsonConvert.DeserializeObject<T>(responseContent);
}
else
{
throw new Exception($"上传文件失败: {response.StatusCode} - {responseContent}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (HttpRequestException httpEx)
{
throw new Exception($"上传文件时网络错误: {httpEx.Message}", httpEx);
}
catch (Exception ex)
{
throw new Exception($"上传文件时出错: {ex.Message}", ex);
}
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
_httpClient?.Dispose();
}
#region
/// <summary>
/// Token响应模型
/// </summary>
private class TokenResponse
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
[JsonProperty("expires_in")]
public int? ExpiresIn { get; set; }
[JsonProperty("token_type")]
public string TokenType { get; set; }
}
#endregion
}
}
+257
View File
@@ -0,0 +1,257 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// Dlass上传队列
/// </summary>
public class DlassUploadQueue : BaseUploadQueue
{
private const string APP_ID = "app_WkjocWqsrVY7T6zQV2CfiA";
private const string APP_SECRET = "o7dx5b5ASGUMcM72PCpmRQYAhSijqaOVHoGyBK0IxbA";
/// <summary>
/// 队列文件名
/// </summary>
protected override string QueueFileName => "DlassUploadQueue.json";
/// <summary>
/// 上传笔记响应模型
/// </summary>
public class UploadNoteResponse
{
[JsonProperty("success")]
public bool Success { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
[JsonProperty("note_id")]
public int? NoteId { get; set; }
[JsonProperty("filename")]
public string Filename { get; set; }
[JsonProperty("file_path")]
public string FilePath { get; set; }
[JsonProperty("file_url")]
public string FileUrl { get; set; }
}
/// <summary>
/// 白板信息模型(用于查找白板)
/// </summary>
private class WhiteboardInfo
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("board_id")]
public string BoardId { get; set; }
[JsonProperty("secret_key")]
public string SecretKey { get; set; }
[JsonProperty("class_name")]
public string ClassName { get; set; }
[JsonProperty("class_id")]
public int ClassId { get; set; }
}
/// <summary>
/// 认证响应模型
/// </summary>
private class AuthWithTokenResponse
{
[JsonProperty("success")]
public bool Success { get; set; }
[JsonProperty("whiteboards")]
public List<WhiteboardInfo> Whiteboards { get; set; }
}
/// <summary>
/// 检查上传是否启用
/// </summary>
protected override bool IsUploadEnabled()
{
return MainWindow.Settings?.Dlass?.IsAutoUploadNotes == true;
}
/// <summary>
/// 内部上传方法,执行实际上传操作
/// </summary>
protected override async Task<bool> UploadFileInternalAsync(string filePath, CancellationToken cancellationToken)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
// 再次检查文件是否存在(可能在队列等待时被删除)
if (!File.Exists(filePath))
{
return false;
}
// 获取白板信息
var whiteboard = await GetWhiteboardInfo(cancellationToken);
if (whiteboard == null)
{
return false;
}
// 获取API基础URL和用户Token
var apiBaseUrl = MainWindow.Settings?.Dlass?.ApiBaseUrl ?? "https://dlass.tech";
var userToken = MainWindow.Settings?.Dlass?.UserToken;
// 准备上传参数
var fileName = Path.GetFileNameWithoutExtension(filePath);
var fileExtension = Path.GetExtension(filePath).ToLower();
var title = fileName;
string fileType;
string tags;
if (fileExtension == ".zip")
{
fileType = "多页面墨迹压缩包";
tags = "自动上传,多页面,zip,压缩包";
}
else if (fileExtension == ".icstk")
{
fileType = "墨迹文件";
tags = "自动上传,墨迹,icstk";
}
else if (fileExtension == ".xml")
{
fileType = "XML文件";
tags = "自动上传,xml";
}
else
{
fileType = "笔记";
tags = "自动上传,笔记,png";
}
var description = $"自动上传的{fileType} - {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
// 创建API客户端并上传文件
var apiClient = new DlassApiClient(APP_ID, APP_SECRET, apiBaseUrl, userToken);
try
{
cancellationToken.ThrowIfCancellationRequested();
var uploadResult = await apiClient.UploadNoteAsync<UploadNoteResponse>(
"/api/whiteboard/upload_note",
filePath,
whiteboard.BoardId,
whiteboard.SecretKey,
title,
description,
tags,
cancellationToken);
if (uploadResult != null && uploadResult.Success)
{
return true;
}
else
{
return false;
}
}
finally
{
apiClient.Dispose();
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 获取白板信息
/// </summary>
private async Task<WhiteboardInfo> GetWhiteboardInfo(CancellationToken cancellationToken)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
var selectedClassName = MainWindow.Settings?.Dlass?.SelectedClassName;
if (string.IsNullOrEmpty(selectedClassName))
{
LogHelper.WriteLogToFile("[DlassUploadQueue] 上传失败:未选择班级", LogHelper.LogType.Error);
return null;
}
var userToken = MainWindow.Settings?.Dlass?.UserToken;
if (string.IsNullOrEmpty(userToken))
{
LogHelper.WriteLogToFile("[DlassUploadQueue] 上传失败:未设置用户Token", LogHelper.LogType.Error);
return null;
}
var apiBaseUrl = MainWindow.Settings?.Dlass?.ApiBaseUrl ?? "https://dlass.tech";
// 创建API客户端并获取白板信息
var apiClient = new DlassApiClient(APP_ID, APP_SECRET, apiBaseUrl, userToken);
try
{
var authData = new
{
app_id = APP_ID,
app_secret = APP_SECRET,
user_token = userToken
};
var authResult = await apiClient.PostAsync<AuthWithTokenResponse>("/api/whiteboard/framework/auth-with-token", authData, requireAuth: false, cancellationToken: cancellationToken);
if (authResult == null || !authResult.Success || authResult.Whiteboards == null)
{
LogHelper.WriteLogToFile("[DlassUploadQueue] 上传失败:无法获取白板信息", LogHelper.LogType.Error);
return null;
}
// 查找匹配班级的白板
var whiteboard = authResult.Whiteboards
.FirstOrDefault(w => !string.IsNullOrEmpty(w.ClassName) && w.ClassName == selectedClassName);
if (whiteboard == null || string.IsNullOrEmpty(whiteboard.BoardId) || string.IsNullOrEmpty(whiteboard.SecretKey))
{
LogHelper.WriteLogToFile($"[DlassUploadQueue] 上传失败:未找到班级'{selectedClassName}'对应的白板", LogHelper.LogType.Error);
return null;
}
return whiteboard;
}
finally
{
apiClient.Dispose();
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception)
{
return null;
}
}
}
}
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Ink_Canvas.Helpers
{
public static class ExternalCallerLauncher
{
private static readonly string[] ClassIslandProtocols =
{
"classisland://plugins/IslandCaller/Simple/1",
"classisland://plugins/IslandCaller/Simple",
"classisland://plugins/IslandCaller/Run"
};
public static string[] GetProtocolsByType(int externalCallerType)
{
switch (externalCallerType)
{
case 0:
return ClassIslandProtocols;
case 1:
return new[]
{
"secrandom://roll_call/quick_draw",
"secrandom://direct_extraction"
};
case 2:
return new[] { "namepicker://" };
default:
return ClassIslandProtocols;
}
}
public static string[] GetProtocolsByName(string externalCallerName)
{
switch (externalCallerName)
{
case "ClassIsland":
return ClassIslandProtocols;
case "SecRandom":
return new[]
{
"secrandom://roll_call/quick_draw",
"secrandom://direct_extraction"
};
case "NamePicker":
return new[] { "namepicker://" };
default:
return ClassIslandProtocols;
}
}
public static bool TryLaunch(IEnumerable<string> protocols, out Exception lastException)
{
lastException = null;
if (protocols == null) return false;
foreach (var protocol in protocols)
{
if (string.IsNullOrWhiteSpace(protocol)) continue;
try
{
Process.Start(new ProcessStartInfo
{
FileName = protocol,
UseShellExecute = true
});
return true;
}
catch (Exception ex)
{
lastException = ex;
}
}
return false;
}
}
}
+105 -3
View File
@@ -26,6 +26,7 @@ namespace Ink_Canvas.Helpers
private const string IpcFilePrefix = "InkCanvasFileAssociation_";
private const string IpcBoardModePrefix = "InkCanvasBoardMode_";
private const string IpcShowModePrefix = "InkCanvasShowMode_";
private const string IpcUriCommandPrefix = "InkCanvasUriCommand_";
private const int IpcTimeout = 5000; // 5秒超时
/// <summary>
@@ -361,6 +362,57 @@ namespace Ink_Canvas.Helpers
}
}
/// <summary>
/// 尝试通过IPC将URI命令发送给已运行的实例
/// </summary>
/// <param name="uri">URI命令</param>
/// <returns>是否成功发送</returns>
public static bool TrySendUriCommandToExistingInstance(string uri)
{
try
{
LogHelper.WriteLogToFile($"尝试通过IPC发送URI命令给已运行实例: {uri}", LogHelper.LogType.Event);
// 创建IPC文件
string tempDir = Path.GetTempPath();
string ipcFileName = IpcUriCommandPrefix + Guid.NewGuid().ToString("N") + ".tmp";
string ipcFilePath = Path.Combine(tempDir, ipcFileName);
// 写入URI命令到IPC文件
File.WriteAllText(ipcFilePath, uri, Encoding.UTF8);
// 创建事件通知已运行实例
using (EventWaitHandle ipcEvent = new EventWaitHandle(false, EventResetMode.ManualReset, IpcEventName))
{
ipcEvent.Set();
}
// 等待一段时间让已运行实例处理命令
Thread.Sleep(1000);
// 清理IPC文件
try
{
if (File.Exists(ipcFilePath))
{
File.Delete(ipcFilePath);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理IPC文件失败: {ex.Message}", LogHelper.LogType.Warning);
}
LogHelper.WriteLogToFile("IPC URI命令发送完成", LogHelper.LogType.Event);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"通过IPC发送URI命令失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
/// <summary>
/// 启动IPC监听器,等待其他实例发送文件路径
/// </summary>
@@ -467,7 +519,7 @@ namespace Ink_Canvas.Helpers
File.Delete(ipcFile);
}
}
catch { }
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
@@ -518,7 +570,7 @@ namespace Ink_Canvas.Helpers
File.Delete(ipcFile);
}
}
catch { }
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
@@ -573,7 +625,57 @@ namespace Ink_Canvas.Helpers
File.Delete(ipcFile);
}
}
catch { }
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
// 处理URI命令IPC文件
string[] uriCommandFiles = Directory.GetFiles(tempDir, IpcUriCommandPrefix + "*.tmp");
foreach (string ipcFile in uriCommandFiles)
{
try
{
// 读取命令内容
string uri = File.ReadAllText(ipcFile, Encoding.UTF8);
if (!string.IsNullOrEmpty(uri))
{
LogHelper.WriteLogToFile($"IPC接收到URI命令: {uri}", LogHelper.LogType.Event);
// 在UI线程中处理URI命令
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
// 获取主窗口并处理URI命令
if (Application.Current.MainWindow is MainWindow mainWindow)
{
mainWindow.HandleUriCommand(uri);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"IPC处理URI命令失败: {ex.Message}", LogHelper.LogType.Error);
}
}));
}
// 删除IPC文件
File.Delete(ipcFile);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"处理URI命令IPC文件失败: {ex.Message}", LogHelper.LogType.Warning);
// 尝试删除损坏的IPC文件
try
{
if (File.Exists(ipcFile))
{
File.Delete(ipcFile);
}
}
catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); }
}
}
}
+40 -4
View File
@@ -36,6 +36,24 @@ namespace Ink_Canvas.Helpers
public int Height => Bottom - Top;
}
[StructLayout(LayoutKind.Sequential)]
private struct MONITORINFO
{
public uint cbSize;
public RECT rcMonitor;
public RECT rcWork;
public uint dwFlags;
}
[DllImport("user32.dll")]
private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
[DllImport("user32.dll")]
private static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
[DllImport("user32.dll")]
private static extern IntPtr MonitorFromRect(ref RECT lprc, uint dwFlags);
public static string WindowTitle()
{
IntPtr foregroundWindowHandle = GetForegroundWindow();
@@ -106,10 +124,28 @@ namespace Ink_Canvas.Helpers
public static double GetTaskbarHeight(Screen screen, double dpiScaleY)
{
// 获取工作区和屏幕高度的差值
var workingArea = screen.WorkingArea;
var bounds = screen.Bounds;
int taskbarHeight = bounds.Height - workingArea.Height;
// 创建RECT结构体表示屏幕边界
RECT screenRect = new RECT
{
Left = screen.Bounds.Left,
Top = screen.Bounds.Top,
Right = screen.Bounds.Right,
Bottom = screen.Bounds.Bottom
};
// 获取屏幕句柄
const uint MONITOR_DEFAULTTONEAREST = 0x00000002;
IntPtr hMonitor = MonitorFromRect(ref screenRect, MONITOR_DEFAULTTONEAREST);
// 初始化MONITORINFO结构体
MONITORINFO monitorInfo = new MONITORINFO();
monitorInfo.cbSize = (uint)Marshal.SizeOf(typeof(MONITORINFO));
// 获取监视器信息
GetMonitorInfo(hMonitor, ref monitorInfo);
// 计算任务栏高度:monitorInfo.rcMonitor.bottom减去monitorInfo.rcWork.bottom的值
int taskbarHeight = monitorInfo.rcMonitor.Bottom - monitorInfo.rcWork.Bottom;
// 考虑 DPI 缩放
return taskbarHeight / dpiScaleY;
}
+40 -2
View File
@@ -78,6 +78,16 @@ namespace Ink_Canvas.Helpers
{
UnregisterHotkey(hotkeyName);
}
else
{
try
{
HotkeyManager.Current.Remove(hotkeyName);
}
catch
{
}
}
// 创建快捷键信息
var hotkeyInfo = new HotkeyInfo
@@ -112,9 +122,8 @@ namespace Ink_Canvas.Helpers
return true;
}
catch (Exception ex)
catch (Exception)
{
LogHelper.WriteLogToFile($"注册全局快捷键 {hotkeyName} 失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
@@ -276,6 +285,7 @@ namespace Ink_Canvas.Helpers
// 功能快捷键
RegisterHotkey("DrawLine", Key.L, ModifierKeys.Alt, () => _mainWindow.BtnDrawLine_Click(null, null));
RegisterHotkey("Screenshot", Key.C, ModifierKeys.Alt, () => _mainWindow.SaveScreenShotToDesktop());
RegisterHotkey("QuickDraw", Key.K, ModifierKeys.Alt, () => _mainWindow.OpenQuickDrawFromHotkey());
RegisterHotkey("Hide", Key.V, ModifierKeys.Alt, () => _mainWindow.SymbolIconEmoji_MouseUp(null, null));
// 退出快捷键
@@ -383,6 +393,13 @@ namespace Ink_Canvas.Helpers
}
else
{
if (_registeredHotkeys.Count == 0)
{
if (ShouldEnableHotkeysBasedOnContext())
{
LoadHotkeysFromSettings();
}
}
}
}
catch (Exception ex)
@@ -438,6 +455,11 @@ namespace Ink_Canvas.Helpers
{
// 如果设置允许,则在鼠标模式下也启用快捷键
EnableHotkeyRegistration();
if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0)
{
LoadHotkeysFromSettings();
}
}
else
{
@@ -449,6 +471,11 @@ namespace Ink_Canvas.Helpers
{
// 非鼠标模式下启用快捷键
EnableHotkeyRegistration();
if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0)
{
LoadHotkeysFromSettings();
}
}
}
catch (Exception ex)
@@ -1007,6 +1034,7 @@ namespace Ink_Canvas.Helpers
new HotkeyConfigItem { Name = "Pen5", Key = Key.D5, Modifiers = ModifierKeys.Alt },
new HotkeyConfigItem { Name = "DrawLine", Key = Key.L, Modifiers = ModifierKeys.Alt },
new HotkeyConfigItem { Name = "Screenshot", Key = Key.C, Modifiers = ModifierKeys.Alt },
new HotkeyConfigItem { Name = "QuickDraw", Key = Key.K, Modifiers = ModifierKeys.Alt },
new HotkeyConfigItem { Name = "Hide", Key = Key.V, Modifiers = ModifierKeys.Alt },
new HotkeyConfigItem { Name = "Exit", Key = Key.Escape, Modifiers = ModifierKeys.None }
});
@@ -1085,6 +1113,14 @@ namespace Ink_Canvas.Helpers
}
}
// 旧版 HotkeyConfig.json 无「快抽」项时补注册默认组合,避免升级后无快捷键
if (successCount > 0 && !IsHotkeyRegistered("QuickDraw"))
{
var quickDrawAction = GetActionByName("QuickDraw");
if (quickDrawAction != null && RegisterHotkey("QuickDraw", Key.K, ModifierKeys.Alt, quickDrawAction))
successCount++;
}
if (successCount > 0)
{
_hotkeysShouldBeRegistered = true;
@@ -1195,6 +1231,8 @@ namespace Ink_Canvas.Helpers
return () => _mainWindow.BtnDrawLine_Click(null, null);
case "Screenshot":
return () => _mainWindow.SaveScreenShotToDesktop();
case "QuickDraw":
return () => _mainWindow.OpenQuickDrawFromHotkey();
case "Hide":
return () => _mainWindow.SymbolIconEmoji_MouseUp(null, null);
case "Exit":
@@ -186,11 +186,11 @@ namespace Ink_Canvas.Helpers
}
/// <summary>
/// 释放GPU资源
/// 释放GPU相关资源标记
/// </summary>
public void Dispose()
{
_renderTarget?.Clear();
_isInitialized = false;
}
}
+35
View File
@@ -0,0 +1,35 @@
using System;
using System.Security.Cryptography;
using System.Text;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 哈希计算辅助类,用于路径/标识等短字符串的 MD5 前缀哈希。
/// </summary>
internal static class HashHelper
{
/// <summary>
/// 对给定路径字符串计算 MD5 哈希,返回前 8 位十六进制字符串。
/// </summary>
/// <param name="filePath">文件路径或任意字符串</param>
/// <returns>8 位十六进制字符串;异常或空输入时返回 "error" 或 "unknown"</returns>
public static string GetFileHash(string filePath)
{
try
{
if (string.IsNullOrEmpty(filePath)) return "unknown";
using (var md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(filePath));
return BitConverter.ToString(hash).Replace("-", "").Substring(0, 8);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"计算文件哈希失败: {ex}", LogHelper.LogType.Error);
return "error";
}
}
}
}
+63
View File
@@ -0,0 +1,63 @@
using System;
namespace Ink_Canvas.Helpers
{
public interface IPPTLinkManager : IDisposable
{
event Action<object> SlideShowBegin;
event Action<object> SlideShowNextSlide;
event Action<object> SlideShowEnd;
event Action<object> PresentationOpen;
event Action<object> PresentationClose;
event Action<bool> PPTConnectionChanged;
event Action<bool> SlideShowStateChanged;
bool IsConnected { get; }
bool IsInSlideShow { get; }
bool IsSupportWPS { get; set; }
bool SkipAnimationsWhenNavigating { get; set; }
int SlidesCount { get; }
object PPTApplication { get; }
/// <summary>
/// 开始监视与 PowerPoint 的连接以及幻灯片放映相关状态,并在状态变化时触发对应事件。
/// </summary>
void StartMonitoring();
/// <summary>
/// 停止监控 PowerPoint 的连接与事件,停止接收并处理与演示文稿和幻灯片放映相关的通知。
/// </summary>
void StopMonitoring();
/// <summary>
/// 重新加载或重建与 PowerPoint 的连接。
/// </summary>
/// <remarks>
/// 调用后实现应刷新内部连接与状态,必要时重建与 PowerPoint 的会话;此操作可能导致 IsConnected 变化并触发 PPTConnectionChanged 或其他相关事件(例如 SlideShowStateChanged)。
/// </remarks>
void ReloadConnection();
/// <summary>
/// 尝试启动当前演示文稿的放映模式。
/// </summary>
/// <returns><c>true</c> 如果放映已成功启动,<c>false</c> 否则。</returns>
bool TryStartSlideShow();
/// <summary>
/// 尝试结束当前正在进行的幻灯片放映。
/// </summary>
/// <returns><c>true</c> 如果放映已成功结束,<c>false</c> 否则。</returns>
bool TryEndSlideShow();
// 导航控制
bool TryNavigateToSlide(int slideNumber);
bool TryNavigateNext();
bool TryNavigatePrevious();
// 查询
int GetCurrentSlideNumber();
string GetPresentationName();
bool TryShowSlideNavigation();
object GetCurrentActivePresentation();
}
}
+1 -3
View File
@@ -264,7 +264,6 @@ namespace Ink_Canvas.Helpers
public void Enable()
{
IsEnabled = true;
LogHelper.WriteLogToFile("墨迹渐隐功能已启用");
}
/// <summary>
@@ -273,7 +272,6 @@ namespace Ink_Canvas.Helpers
public void Disable()
{
IsEnabled = false;
LogHelper.WriteLogToFile("墨迹渐隐功能已禁用");
}
#endregion
@@ -894,4 +892,4 @@ namespace Ink_Canvas.Helpers
}
#endregion
}
}
}
+257
View File
@@ -0,0 +1,257 @@
using System;
using System.Threading.Tasks;
using System.Windows.Ink;
namespace Ink_Canvas.Helpers
{
public sealed class InkRecognitionManager
{
private static InkRecognitionManager _instance;
private static readonly object _lock = new object();
private ModernInkProcessor _modernProcessor;
private ModernInkAnalyzer _modernAnalyzer;
private bool _isModernSystemAvailable;
private bool _isInitialized;
public static InkRecognitionManager Instance
{
get
{
if (_instance == null)
{
lock (_lock)
{
if (_instance == null)
_instance = new InkRecognitionManager();
}
}
return _instance;
}
}
private InkRecognitionManager()
{
Initialize();
}
private void Initialize()
{
try
{
var tryModern = WinRtInkShapeRecognizer.IsApiAvailable && Environment.Is64BitProcess;
_isModernSystemAvailable = false;
if (tryModern)
{
try
{
_modernProcessor = new ModernInkProcessor();
_modernAnalyzer = new ModernInkAnalyzer();
_isModernSystemAvailable = true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("WinRT 墨迹初始化失败: " + ex.Message, LogHelper.LogType.Warning);
_isModernSystemAvailable = false;
_modernProcessor = null;
_modernAnalyzer = null;
}
}
_isInitialized = true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("墨迹识别管理器初始化失败: " + ex.Message, LogHelper.LogType.Error);
_isInitialized = false;
}
}
public Task<InkShapeRecognitionResult> RecognizeShapeAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode)
{
if (!_isInitialized || strokes == null || strokes.Count == 0)
return Task.FromResult(InkShapeRecognitionResult.Empty);
try
{
if (ShapeRecognitionRouter.ResolveUseWinRt(mode)
&& WinRtInkShapeRecognizer.IsApiAvailable)
{
return RecognizeShapeWinRtOnDispatcherContext(strokes);
}
var legacy = InkRecognizeHelper.RecognizeShapeIACore(strokes);
return Task.FromResult(InkRecognizeHelper.FromIACoreOrEmpty(legacy));
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("墨迹形状识别失败: " + ex.Message, LogHelper.LogType.Error);
return Task.FromResult(InkShapeRecognitionResult.Empty);
}
}
private static async Task<InkShapeRecognitionResult> RecognizeShapeWinRtOnDispatcherContext(
StrokeCollection strokes)
{
return await WinRtInkShapeRecognizer.RecognizeShapeAsync(strokes).ConfigureAwait(true);
}
/// <param name="applyHandwritingBeautify">为 true 且走 WinRT 时,将识别成功的词替换为手写风格字体的轮廓墨迹(见设置中的字体列表)。</param>
/// <param name="handwritingFontFamilyList">逗号分隔的字体回退列表(WPF FontFamily);null 时使用内置默认。</param>
public Task<StrokeCollection> CorrectInkAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode,
bool applyHandwritingBeautify = false,
string handwritingFontFamilyList = null)
{
if (!_isInitialized)
{
LogHelper.WriteLogToFile("[手写体] CorrectInkAsync 跳过:InkRecognitionManager 未初始化。", LogHelper.LogType.Info);
return Task.FromResult(strokes);
}
if (strokes == null || strokes.Count == 0)
{
LogHelper.WriteLogToFile("[手写体] CorrectInkAsync 跳过:无笔画。", LogHelper.LogType.Info);
return Task.FromResult(strokes);
}
try
{
var useWinRt = ShapeRecognitionRouter.ResolveUseWinRt(mode);
if (!applyHandwritingBeautify)
{
LogHelper.WriteLogToFile(
"[手写体] CorrectInkAsync 跳过:未开启「识别转手写体字形」(applyHandwritingBeautify=false)。笔画数=" +
strokes.Count,
LogHelper.LogType.Info);
return Task.FromResult(strokes);
}
if (!useWinRt)
{
LogHelper.WriteLogToFile(
"[手写体] CorrectInkAsync 跳过:当前引擎非 WinRT(模式=" + mode + ")。笔画数=" + strokes.Count,
LogHelper.LogType.Info);
return Task.FromResult(strokes);
}
if (!Environment.Is64BitProcess)
{
LogHelper.WriteLogToFile(
"[手写体] CorrectInkAsync 跳过:非 64 位进程,WinRT 手写体替换不可用。笔画数=" + strokes.Count,
LogHelper.LogType.Info);
return Task.FromResult(strokes);
}
if (_modernAnalyzer == null)
{
LogHelper.WriteLogToFile(
"[手写体] CorrectInkAsync 跳过:ModernInkAnalyzer 未就绪(WinRT 初始化失败?)。笔画数=" +
strokes.Count,
LogHelper.LogType.Warning);
return Task.FromResult(strokes);
}
LogHelper.WriteLogToFile(
"[手写体] CorrectInkAsync 开始:笔画数=" + strokes.Count +
",字体=" + (string.IsNullOrWhiteSpace(handwritingFontFamilyList) ? "(默认)" : handwritingFontFamilyList.Trim()),
LogHelper.LogType.Info);
return _modernAnalyzer.AnalyzeAndCorrectAsync(strokes, handwritingFontFamilyList);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("墨迹纠正失败: " + ex.Message, LogHelper.LogType.Error);
return Task.FromResult(strokes);
}
}
/// <summary>
/// WinRT 手写体识别(需 64 位进程、Windows 10+ 及系统手写识别组件)。返回分词候选与包围框,供剪贴板或插件使用。
/// </summary>
public Task<HandwritingRecognitionResult> RecognizeHandwritingAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode)
{
if (!_isInitialized || strokes == null || strokes.Count == 0)
return Task.FromResult(HandwritingRecognitionResult.Empty);
try
{
if (!Environment.Is64BitProcess
|| !ShapeRecognitionRouter.ResolveUseWinRt(mode)
|| !WinRtHandwritingRecognizer.IsApiAvailable)
return Task.FromResult(HandwritingRecognitionResult.Empty);
return WinRtHandwritingRecognizer.RecognizeHandwritingAsync(strokes);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("手写识别失败: " + ex.Message, LogHelper.LogType.Error);
return Task.FromResult(HandwritingRecognitionResult.Empty);
}
}
public bool IsValidShapeType(string shapeName)
{
return !string.IsNullOrEmpty(shapeName)
&& (shapeName.Contains("Triangle") || shapeName.Contains("Circle")
|| shapeName.Contains("Rectangle") || shapeName.Contains("Diamond")
|| shapeName.Contains("Parallelogram") || shapeName.Contains("Square")
|| shapeName.Contains("Ellipse") || shapeName.Contains("Line")
|| shapeName.Contains("Arrow"));
}
public string GetSystemInfo()
{
return _isModernSystemAvailable
? $"现代化64位墨迹识别系统 (Windows Runtime API) - 进程架构: {Environment.Is64BitProcess}"
: $"传统墨迹识别系统 (IACore) - 进程架构: {Environment.Is64BitProcess}";
}
public void Dispose()
{
_modernProcessor?.Dispose();
_modernAnalyzer?.Dispose();
_isInitialized = false;
}
}
internal sealed class ModernInkProcessor : IDisposable
{
public ModernInkProcessor()
{
if (!WinRtInkShapeRecognizer.IsApiAvailable)
throw new InvalidOperationException("WinRT 墨迹分析需要 Windows 10 及以上。");
}
public Task<InkShapeRecognitionResult> RecognizeShapeAsync(StrokeCollection strokes)
{
return WinRtInkShapeRecognizer.RecognizeShapeAsync(strokes);
}
public void Dispose()
{
}
}
internal sealed class ModernInkAnalyzer : IDisposable
{
public Task<StrokeCollection> AnalyzeAndCorrectAsync(
StrokeCollection strokes,
string handwritingFontFamilyList)
{
return WinRtHandwritingRecognizer.ConvertRecognizedTextToHandwritingInkAsync(
strokes,
handwritingFontFamilyList);
}
public void Dispose()
{
}
}
}
+135 -10
View File
@@ -1,4 +1,5 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Media;
@@ -7,8 +8,8 @@ namespace Ink_Canvas.Helpers
{
public class InkRecognizeHelper
{
//识别形状
public static ShapeRecognizeResult RecognizeShape(StrokeCollection strokes)
/// <summary>IACore / IAWinFX 形状识别(典型用于 32 位进程)。</summary>
public static ShapeRecognizeResult RecognizeShapeIACore(StrokeCollection strokes)
{
if (strokes == null || strokes.Count == 0)
return default;
@@ -25,35 +26,159 @@ namespace Ink_Canvas.Helpers
var alternates = analyzer.GetAlternates();
if (alternates.Count > 0)
{
while ((!alternates[0].Strokes.Contains(strokes.Last()) ||
!IsContainShapeType(((InkDrawingNode)alternates[0].AlternateNodes[0]).GetShapeName()))
&& strokesCount >= 2)
while (strokesCount >= 2)
{
var alt0 = alternates[0];
if (alt0?.AlternateNodes == null || alt0.AlternateNodes.Count == 0)
break;
var drawNode = alt0.AlternateNodes[0] as InkDrawingNode;
if (drawNode == null)
break;
var shapeOk = IsContainShapeType(drawNode.GetShapeName());
if (alt0.Strokes.Contains(strokes.Last()) && shapeOk)
break;
analyzer.RemoveStroke(strokes[strokes.Count - strokesCount]);
strokesCount--;
sfsaf = analyzer.Analyze();
if (sfsaf.Successful)
{
alternates = analyzer.GetAlternates();
}
else
break;
if (alternates.Count == 0)
break;
}
if (alternates.Count > 0)
{
var altFinal = alternates[0];
if (altFinal?.AlternateNodes != null && altFinal.AlternateNodes.Count > 0)
analysisAlternate = altFinal;
}
analysisAlternate = alternates[0];
}
}
analyzer.Dispose();
if (analysisAlternate != null && analysisAlternate.AlternateNodes.Count > 0)
if (analysisAlternate != null && analysisAlternate.AlternateNodes != null && analysisAlternate.AlternateNodes.Count > 0)
{
var node = analysisAlternate.AlternateNodes[0] as InkDrawingNode;
if (node == null)
return default;
return new ShapeRecognizeResult(node.Centroid, node.HotPoints, analysisAlternate, node);
}
return default;
}
/// <summary>兼容旧调用:等价于 <see cref="RecognizeShapeIACore"/>。</summary>
public static ShapeRecognizeResult RecognizeShape(StrokeCollection strokes) =>
RecognizeShapeIACore(strokes);
/// <summary>按设置选择 WinRT<see cref="InkRecognitionManager"/>)或 IACoreWinRT 请用 <see cref="RecognizeShapeUnifiedAsync"/>。</summary>
public static InkShapeRecognitionResult RecognizeShapeUnified(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode)
{
if (strokes == null || strokes.Count == 0)
return InkShapeRecognitionResult.Empty;
if (ShapeRecognitionRouter.ResolveUseWinRt(mode))
return InkShapeRecognitionResult.Empty;
var legacy = RecognizeShapeIACore(strokes);
return FromIACoreOrEmpty(legacy);
}
/// <summary>与 CE 反编译版 <c>InkRecognitionManager.RecognizeShapeAsync</c> 对齐的统一入口。</summary>
public static Task<InkShapeRecognitionResult> RecognizeShapeUnifiedAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode)
{
if (strokes == null || strokes.Count == 0)
return Task.FromResult(InkShapeRecognitionResult.Empty);
return InkRecognitionManager.Instance.RecognizeShapeAsync(strokes, mode);
}
public static void WarmupShapeRecognition(ShapeRecognitionEngineMode mode)
{
try
{
_ = InkRecognitionManager.Instance;
if (ShapeRecognitionRouter.ResolveUseWinRt(mode))
{
WinRtInkShapeRecognizer.Warmup();
WinRtHandwritingRecognizer.Warmup();
}
else
RecognizeShapeIACore(new StrokeCollection());
}
catch
{
// 预热失败不影响启动
}
}
/// <summary>WinRT 手写识别(64 位 + Windows 10+)。</summary>
public static Task<HandwritingRecognitionResult> RecognizeHandwritingUnifiedAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode) =>
InkRecognitionManager.Instance.RecognizeHandwritingAsync(strokes, mode);
/// <summary>WinRT 下将识别成功的词替换为手写体字形墨迹;是否应用由设置「WinRT 识别转手写体字形」控制。</summary>
public static Task<StrokeCollection> CorrectHandwritingStrokesUnifiedAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode) =>
InkRecognitionManager.Instance.CorrectInkAsync(
strokes,
mode,
MainWindow.Settings?.InkToShape?.EnableWinRtHandwritingStrokeBeautify ?? false,
MainWindow.Settings?.InkToShape?.HandwritingCorrectionFontFamily);
/// <summary>显式指定是否应用手写体字形替换(忽略开关);字体仍从设置读取。</summary>
public static Task<StrokeCollection> CorrectHandwritingStrokesUnifiedAsync(
StrokeCollection strokes,
ShapeRecognitionEngineMode mode,
bool applyHandwritingBeautify) =>
InkRecognitionManager.Instance.CorrectInkAsync(
strokes,
mode,
applyHandwritingBeautify,
MainWindow.Settings?.InkToShape?.HandwritingCorrectionFontFamily);
internal static InkShapeRecognitionResult FromIACoreOrEmpty(ShapeRecognizeResult legacy)
{
if (legacy?.InkDrawingNode == null)
return InkShapeRecognitionResult.Empty;
var node = legacy.InkDrawingNode;
var shape = node.GetShape();
if (shape == null)
return InkShapeRecognitionResult.Empty;
var hot = ClonePointCollection(node.HotPoints);
return new InkShapeRecognitionResult(
node.GetShapeName(),
legacy.Centroid,
hot,
shape.Width,
shape.Height,
node.Strokes);
}
private static PointCollection ClonePointCollection(PointCollection src)
{
var dst = new PointCollection();
if (src == null) return dst;
foreach (System.Windows.Point p in src)
dst.Add(p);
return dst;
}
public static bool IsContainShapeType(string name)
{
if (string.IsNullOrEmpty(name))
return false;
if (name.Contains("Triangle") || name.Contains("Circle") ||
name.Contains("Rectangle") || name.Contains("Diamond") ||
name.Contains("Parallelogram") || name.Contains("Square")
+86
View File
@@ -0,0 +1,86 @@
using OSVersionExtension;
using System;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Media;
namespace Ink_Canvas.Helpers
{
/// <summary>墨迹形状识别后端:自动 / IACore / WinRT。</summary>
public enum ShapeRecognitionEngineMode
{
Auto = 0,
IACore = 1,
WinRT = 2,
}
public static class ShapeRecognitionRouter
{
/// <summary>
/// 自动模式:按当前进程位数选择——<c>64</c> 位进程用 WinRT<c>32</c> 位进程(含 x86 目标在 WOW64 下运行)用 IACore。
/// </summary>
public static bool ResolveUseWinRt(ShapeRecognitionEngineMode mode)
{
if (mode == ShapeRecognitionEngineMode.WinRT) return true;
if (mode == ShapeRecognitionEngineMode.IACore) return false;
return Environment.Is64BitProcess;
}
public static bool ShouldRunShapeRecognition(bool inkToShapeEnabled, ShapeRecognitionEngineMode mode)
{
if (!inkToShapeEnabled) return false;
if (ResolveUseWinRt(mode))
return OSVersion.GetOperatingSystem() >= OSVersionExtension.OperatingSystem.Windows10;
return !Environment.Is64BitProcess;
}
public static ShapeRecognitionEngineMode FromSettingsInt(int value)
{
if (value == (int)ShapeRecognitionEngineMode.IACore) return ShapeRecognitionEngineMode.IACore;
if (value == (int)ShapeRecognitionEngineMode.WinRT) return ShapeRecognitionEngineMode.WinRT;
return ShapeRecognitionEngineMode.Auto;
}
}
/// <summary>与具体识别后端无关的形状识别结果,供统一纠正模块消费。</summary>
public sealed class InkShapeRecognitionResult
{
public static readonly InkShapeRecognitionResult Empty = new InkShapeRecognitionResult();
private InkShapeRecognitionResult()
{
IsSuccess = false;
ShapeName = string.Empty;
Centroid = new Point();
HotPoints = new PointCollection();
StrokesToRemove = new StrokeCollection();
}
public InkShapeRecognitionResult(
string shapeName,
Point centroid,
PointCollection hotPoints,
double shapeWidth,
double shapeHeight,
StrokeCollection strokesToRemove)
{
ShapeName = shapeName ?? string.Empty;
Centroid = centroid;
HotPoints = hotPoints ?? new PointCollection();
ShapeWidth = shapeWidth;
ShapeHeight = shapeHeight;
StrokesToRemove = strokesToRemove ?? new StrokeCollection();
IsSuccess = StrokesToRemove.Count > 0
&& !string.IsNullOrEmpty(ShapeName)
&& ShapeName != "Drawing";
}
public bool IsSuccess { get; }
public string ShapeName { get; }
public Point Centroid { get; set; }
public PointCollection HotPoints { get; }
public double ShapeWidth { get; }
public double ShapeHeight { get; }
public StrokeCollection StrokesToRemove { get; }
}
}
+57
View File
@@ -0,0 +1,57 @@
using Ink_Canvas.Properties;
using System.Globalization;
using System.Threading;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// i18n 本地化辅助:设置/获取当前 UI 语言,便于后续从配置切换语言。
/// </summary>
public static class LocalizationHelper
{
/// <summary>
/// 当前 UI 语言(如 "zh-CN", "en-US")。未设置时使用系统当前 UI 语言。
/// </summary>
public static CultureInfo CurrentCulture
{
get => Thread.CurrentThread.CurrentUICulture;
set
{
if (value == null) return;
Thread.CurrentThread.CurrentUICulture = value;
Strings.Culture = value;
}
}
/// <summary>
/// 使用指定语言名称设置当前 UI 语言(如 "zh-CN", "en-US")。
/// 若名称无效则保持当前语言不变。
/// </summary>
public static bool TrySetCulture(string cultureName)
{
try
{
if (string.IsNullOrWhiteSpace(cultureName))
{
CurrentCulture = CultureInfo.InstalledUICulture;
return true;
}
var culture = CultureInfo.GetCultureInfo(cultureName);
CurrentCulture = culture;
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 获取本地化字符串。优先使用强类型属性,未知键时用此方法。
/// </summary>
public static string GetString(string key)
{
return Strings.GetString(key);
}
}
}
+43 -12
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
@@ -29,6 +29,11 @@ namespace Ink_Canvas.Helpers
WriteLogToFile(msg, LogType.Error);
}
/// <summary>
/// 将一条日志消息记录到应用的日志文件中(可能是单一日志文件或按启动时间存档的文件),同时在日志条目中包含时间戳、线程 ID 和调用者信息,并遵循应用的日志设置。
/// </summary>
/// <param name="str">要记录的日志文本消息。</param>
/// <param name="logType">日志的类型/等级,用于在日志条目中标识(例如 Info、Error、Warning 等)。</param>
public static void WriteLogToFile(string str, LogType logType = LogType.Info)
{
// 检查日志是否启用
@@ -62,7 +67,7 @@ namespace Ink_Canvas.Helpers
if (!Directory.Exists(App.RootPath))
{
Directory.CreateDirectory(App.RootPath);
ProcessProtectionManager.WithWriteAccess(App.RootPath, () => Directory.CreateDirectory(App.RootPath));
}
var threadId = Thread.CurrentThread.ManagedThreadId;
@@ -78,14 +83,30 @@ namespace Ink_Canvas.Helpers
}
}
string logLine = string.Format("{0} [T{1}] [{2}] [{3}] {4}", DateTime.Now.ToString("O"), threadId, strLogType, callerInfo, str);
using (StreamWriter sw = new StreamWriter(file, true))
ProcessProtectionManager.WithWriteAccess(file, () =>
{
sw.WriteLine(logLine);
}
using (StreamWriter sw = new StreamWriter(file, true))
{
sw.WriteLine(logLine);
}
});
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[LogHelper] WriteLogToFile failed: {ex.Message}");
}
catch { }
}
/// <summary>
/// 检查指定日志文件夹的总大小,并在超过 MaxLogsFolderSizeBytes 时删除该文件夹下的所有文件并记录清理日志。
/// </summary>
/// <param name="logsPath">要检查和清理的日志文件夹路径。</param>
/// <remarks>
/// - 如果目录不存在则直接返回。
/// - 当总大小超过 MaxLogsFolderSizeBytes 时,会尝试删除目录下的每个文件(单个删除失败将被忽略)。
/// - 清理完成后会向该目录下的 Log_{AppStartTime}.txt 写入一条带有时间戳和 [Cleanup] 标签的记录。
/// - 方法内部捕获并忽略所有异常以避免影响调用者流程。
/// </remarks>
private static void CheckAndCleanLogsFolder(string logsPath)
{
try
@@ -111,18 +132,28 @@ namespace Ink_Canvas.Helpers
{
file.Delete();
}
catch { }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[LogHelper] Delete log file failed: {ex.Message}");
}
}
// 记录清理操作
string cleanupMessage = $"Logs folder exceeded size limit ({totalSize / 1024.0 / 1024.0:F2} MB > {MaxLogsFolderSizeBytes / 1024.0 / 1024.0:F2} MB). Folder cleaned.";
using (StreamWriter sw = new StreamWriter(Path.Combine(logsPath, $"Log_{AppStartTime}.txt"), true))
var logFile = Path.Combine(logsPath, $"Log_{AppStartTime}.txt");
ProcessProtectionManager.WithWriteAccess(logFile, () =>
{
sw.WriteLine($"{DateTime.Now:O} [Cleanup] {cleanupMessage}");
}
using (StreamWriter sw = new StreamWriter(logFile, true))
{
sw.WriteLine($"{DateTime.Now:O} [Cleanup] {cleanupMessage}");
}
});
}
}
catch { }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[LogHelper] CheckAndCleanLogsFolder failed: {ex.Message}");
}
}
internal static void WriteLogToFile(string v, object warning)
@@ -139,4 +170,4 @@ namespace Ink_Canvas.Helpers
Warning
}
}
}
}
-813
View File
@@ -1,813 +0,0 @@
using Microsoft.Office.Interop.PowerPoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Ink;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 多PPT墨迹管理器 - 支持多个PPT窗口分别管理墨迹
/// </summary>
public class MultiPPTInkManager : IDisposable
{
#region Properties
public bool IsAutoSaveEnabled { get; set; } = true;
public string AutoSaveLocation { get; set; } = "";
public PPTManager PPTManager { get; set; }
#endregion
#region Private Fields
private readonly Dictionary<string, PPTInkManager> _presentationManagers;
private readonly Dictionary<string, PresentationInfo> _presentationInfos;
private readonly object _lockObject = new object();
private bool _disposed;
private string _currentActivePresentationId = "";
// 墨迹备份机制
private readonly Dictionary<string, Dictionary<int, StrokeCollection>> _strokeBackups;
private DateTime _lastBackupTime = DateTime.MinValue;
private const int BackupIntervalMinutes = 2; // 每2分钟备份一次
#endregion
#region Constructor
public MultiPPTInkManager()
{
_presentationManagers = new Dictionary<string, PPTInkManager>();
_presentationInfos = new Dictionary<string, PresentationInfo>();
_strokeBackups = new Dictionary<string, Dictionary<int, StrokeCollection>>();
}
#endregion
#region Public Methods
/// <summary>
/// 初始化新的演示文稿
/// </summary>
public void InitializePresentation(Presentation presentation)
{
if (presentation == null) return;
lock (_lockObject)
{
try
{
var presentationId = GeneratePresentationId(presentation);
// 如果已存在该演示文稿的管理器,先清理
if (_presentationManagers.ContainsKey(presentationId))
{
_presentationManagers[presentationId].Dispose();
_presentationManagers.Remove(presentationId);
}
// 创建新的墨迹管理器
var inkManager = new PPTInkManager();
inkManager.IsAutoSaveEnabled = IsAutoSaveEnabled;
inkManager.AutoSaveLocation = AutoSaveLocation;
inkManager.InitializePresentation(presentation);
// 保存管理器和演示文稿信息
_presentationManagers[presentationId] = inkManager;
_presentationInfos[presentationId] = new PresentationInfo
{
Id = presentationId,
Name = presentation.Name,
FullName = presentation.FullName,
SlideCount = presentation.Slides.Count,
CreatedTime = DateTime.Now,
LastAccessTime = DateTime.Now
};
// 设置为当前活跃的演示文稿
_currentActivePresentationId = presentationId;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"初始化多PPT墨迹管理失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 切换到指定的演示文稿
/// </summary>
public bool SwitchToPresentation(Presentation presentation)
{
if (presentation == null) return false;
lock (_lockObject)
{
try
{
var presentationId = GeneratePresentationId(presentation);
if (_presentationManagers.ContainsKey(presentationId))
{
// 如果切换的是不同的演示文稿,先保存当前活跃演示文稿的墨迹
if (!string.IsNullOrEmpty(_currentActivePresentationId) &&
_currentActivePresentationId != presentationId)
{
var currentManager = GetCurrentManager();
if (currentManager != null)
{
// 获取当前活跃的演示文稿并保存墨迹
var currentPresentation = GetCurrentActivePresentation();
if (currentPresentation != null)
{
try
{
currentManager.SaveAllStrokesToFile(currentPresentation);
LogHelper.WriteLogToFile($"已保存当前演示文稿墨迹: {currentPresentation.Name}", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存当前演示文稿墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
}
}
_currentActivePresentationId = presentationId;
// 更新最后访问时间
if (_presentationInfos.ContainsKey(presentationId))
{
_presentationInfos[presentationId].LastAccessTime = DateTime.Now;
}
if (_currentActivePresentationId != presentationId)
{
LogHelper.WriteLogToFile($"已切换到演示文稿: {presentation.Name}", LogHelper.LogType.Trace);
}
return true;
}
else
{
// 如果不存在,尝试初始化
InitializePresentation(presentation);
return true;
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换到演示文稿失败: {ex}", LogHelper.LogType.Error);
return false;
}
}
}
/// <summary>
/// 保存当前页面的墨迹
/// </summary>
public void SaveCurrentSlideStrokes(int slideIndex, StrokeCollection strokes)
{
if (slideIndex <= 0 || strokes == null) return;
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
// 保存到管理器
manager.SaveCurrentSlideStrokes(slideIndex, strokes);
// 只有在保存成功后才创建备份
if (!string.IsNullOrEmpty(_currentActivePresentationId))
{
CreateStrokeBackup(_currentActivePresentationId, slideIndex, strokes);
}
// 检查是否需要执行定期备份
CheckAndPerformBackup();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存当前页面墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 强制保存指定页面的墨迹(忽略锁定状态)
/// </summary>
public void ForceSaveSlideStrokes(int slideIndex, StrokeCollection strokes)
{
if (slideIndex <= 0 || strokes == null) return;
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
manager.ForceSaveSlideStrokes(slideIndex, strokes);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"强制保存页面墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 加载指定页面的墨迹
/// </summary>
public StrokeCollection LoadSlideStrokes(int slideIndex)
{
if (slideIndex <= 0) return new StrokeCollection();
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
var strokes = manager.LoadSlideStrokes(slideIndex);
// 如果从管理器加载失败,尝试从备份恢复
if (strokes == null || strokes.Count == 0)
{
if (!string.IsNullOrEmpty(_currentActivePresentationId))
{
strokes = RestoreStrokeFromBackup(_currentActivePresentationId, slideIndex);
}
}
return strokes ?? new StrokeCollection();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"加载页面墨迹失败: {ex}", LogHelper.LogType.Error);
// 尝试从备份恢复
if (!string.IsNullOrEmpty(_currentActivePresentationId))
{
return RestoreStrokeFromBackup(_currentActivePresentationId, slideIndex);
}
}
}
return new StrokeCollection();
}
/// <summary>
/// 切换到指定页面并加载墨迹
/// </summary>
public StrokeCollection SwitchToSlide(int slideIndex, StrokeCollection currentStrokes = null)
{
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
return manager.SwitchToSlide(slideIndex, currentStrokes);
}
else
{
LogHelper.WriteLogToFile($"无法获取当前墨迹管理器,页面切换失败: {slideIndex}", LogHelper.LogType.Warning);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换页面墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
return new StrokeCollection();
}
/// <summary>
/// 保存所有墨迹到文件
/// </summary>
public void SaveAllStrokesToFile(Presentation presentation)
{
if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation) || presentation == null) return;
lock (_lockObject)
{
try
{
var presentationId = GeneratePresentationId(presentation);
if (_presentationManagers.ContainsKey(presentationId))
{
_presentationManagers[presentationId].SaveAllStrokesToFile(presentation);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存所有墨迹到文件失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 从文件加载已保存的墨迹
/// </summary>
public void LoadSavedStrokes(Presentation presentation)
{
if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation) || presentation == null) return;
lock (_lockObject)
{
try
{
var presentationId = GeneratePresentationId(presentation);
if (_presentationManagers.ContainsKey(presentationId))
{
_presentationManagers[presentationId].LoadSavedStrokes();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"从文件加载墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 清除指定演示文稿的所有墨迹
/// </summary>
public void ClearPresentationStrokes(Presentation presentation)
{
if (presentation == null) return;
lock (_lockObject)
{
try
{
var presentationId = GeneratePresentationId(presentation);
if (_presentationManagers.ContainsKey(presentationId))
{
_presentationManagers[presentationId].ClearAllStrokes();
LogHelper.WriteLogToFile($"已清除演示文稿墨迹: {presentation.Name}", LogHelper.LogType.Trace);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清除演示文稿墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 清除所有演示文稿的墨迹
/// </summary>
public void ClearAllStrokes()
{
lock (_lockObject)
{
try
{
foreach (var manager in _presentationManagers.Values)
{
manager?.ClearAllStrokes();
}
LogHelper.WriteLogToFile("已清除所有演示文稿墨迹", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清除所有墨迹失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 翻页后锁定墨迹写入
/// </summary>
public void LockInkForSlide(int slideIndex)
{
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
manager.LockInkForSlide(slideIndex);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"锁定墨迹写入失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 检查是否可以写入墨迹
/// </summary>
public bool CanWriteInk(int currentSlideIndex)
{
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
return manager.CanWriteInk(currentSlideIndex);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"检查墨迹写入权限失败: {ex}", LogHelper.LogType.Error);
}
}
return false;
}
/// <summary>
/// 重置当前演示文稿的墨迹锁定状态
/// </summary>
public void ResetCurrentPresentationLockState()
{
lock (_lockObject)
{
try
{
var manager = GetCurrentManager();
if (manager != null)
{
manager.ResetLockState();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"重置墨迹锁定状态失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 移除演示文稿管理器
/// </summary>
public void RemovePresentation(Presentation presentation)
{
if (presentation == null) return;
lock (_lockObject)
{
try
{
var presentationId = GeneratePresentationId(presentation);
if (_presentationManagers.ContainsKey(presentationId))
{
// 保存墨迹到文件
_presentationManagers[presentationId].SaveAllStrokesToFile(presentation);
// 释放资源
_presentationManagers[presentationId].Dispose();
_presentationManagers.Remove(presentationId);
}
if (_presentationInfos.ContainsKey(presentationId))
{
_presentationInfos.Remove(presentationId);
}
// 如果移除的是当前活跃的演示文稿,重置活跃ID
if (_currentActivePresentationId == presentationId)
{
_currentActivePresentationId = "";
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005 || hr == 0x800706BA || hr == 0x800706BE || hr == 0x80048010)
{
}
}
catch (Exception)
{
}
}
}
/// <summary>
/// 获取当前管理的演示文稿数量
/// </summary>
public int GetPresentationCount()
{
lock (_lockObject)
{
return _presentationManagers.Count;
}
}
/// <summary>
/// 获取所有演示文稿信息
/// </summary>
public List<PresentationInfo> GetAllPresentationInfos()
{
lock (_lockObject)
{
return _presentationInfos.Values.ToList();
}
}
/// <summary>
/// 清理长时间未访问的演示文稿管理器
/// </summary>
public void CleanupInactivePresentations(TimeSpan inactiveThreshold)
{
lock (_lockObject)
{
try
{
var inactiveIds = new List<string>();
var cutoffTime = DateTime.Now - inactiveThreshold;
foreach (var info in _presentationInfos.Values)
{
if (info.LastAccessTime < cutoffTime && info.Id != _currentActivePresentationId)
{
inactiveIds.Add(info.Id);
}
}
foreach (var id in inactiveIds)
{
if (_presentationManagers.ContainsKey(id))
{
_presentationManagers[id].Dispose();
_presentationManagers.Remove(id);
}
_presentationInfos.Remove(id);
// 清理备份数据
if (_strokeBackups.ContainsKey(id))
{
_strokeBackups.Remove(id);
}
LogHelper.WriteLogToFile($"已清理非活跃演示文稿: {id}", LogHelper.LogType.Trace);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理非活跃演示文稿失败: {ex}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 创建墨迹备份
/// </summary>
private void CreateStrokeBackup(string presentationId, int slideIndex, StrokeCollection strokes)
{
try
{
if (strokes == null || strokes.Count == 0) return;
if (!_strokeBackups.ContainsKey(presentationId))
{
_strokeBackups[presentationId] = new Dictionary<int, StrokeCollection>();
}
// 释放旧的备份
if (_strokeBackups[presentationId].ContainsKey(slideIndex))
{
_strokeBackups[presentationId][slideIndex] = null;
}
// 创建新的备份
_strokeBackups[presentationId][slideIndex] = strokes.Clone();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"创建墨迹备份失败: {ex}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 从备份恢复墨迹
/// </summary>
private StrokeCollection RestoreStrokeFromBackup(string presentationId, int slideIndex)
{
try
{
if (_strokeBackups.ContainsKey(presentationId) &&
_strokeBackups[presentationId].ContainsKey(slideIndex))
{
var backup = _strokeBackups[presentationId][slideIndex];
if (backup != null)
{
LogHelper.WriteLogToFile($"从备份恢复第{slideIndex}页墨迹", LogHelper.LogType.Trace);
return backup.Clone();
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"从备份恢复墨迹失败: {ex}", LogHelper.LogType.Error);
}
return new StrokeCollection();
}
/// <summary>
/// 检查并执行定期备份
/// </summary>
private void CheckAndPerformBackup()
{
try
{
var now = DateTime.Now;
// 检查是否需要执行备份
if (now - _lastBackupTime < TimeSpan.FromMinutes(BackupIntervalMinutes))
{
return;
}
// 备份当前活跃演示文稿的所有墨迹
if (!string.IsNullOrEmpty(_currentActivePresentationId) &&
_presentationManagers.ContainsKey(_currentActivePresentationId))
{
var manager = _presentationManagers[_currentActivePresentationId];
if (manager != null)
{
// 这里可以添加更详细的备份逻辑
}
}
_lastBackupTime = now;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"定期备份检查失败: {ex}", LogHelper.LogType.Error);
}
}
#endregion
#region Private Methods
private PPTInkManager GetCurrentManager()
{
if (string.IsNullOrEmpty(_currentActivePresentationId) ||
!_presentationManagers.ContainsKey(_currentActivePresentationId))
{
return null;
}
return _presentationManagers[_currentActivePresentationId];
}
private Presentation GetCurrentActivePresentation()
{
try
{
// 通过PPTManager获取当前活跃的演示文稿
return PPTManager?.GetCurrentActivePresentation();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取当前活跃演示文稿失败: {ex}", LogHelper.LogType.Error);
return null;
}
}
private string GeneratePresentationId(Presentation presentation)
{
try
{
// 检查COM对象是否仍然有效
if (presentation == null)
{
return $"invalid_{DateTime.Now.Ticks}";
}
var presentationPath = presentation.FullName;
var fileHash = GetFileHash(presentationPath);
var processId = GetProcessId(presentation);
return $"{presentation.Name}_{presentation.Slides.Count}_{fileHash}_{processId}";
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005 || hr == 0x800706BA || hr == 0x800706BE || hr == 0x80048010)
{
return $"disconnected_{DateTime.Now.Ticks}";
}
return $"error_{DateTime.Now.Ticks}";
}
catch (Exception)
{
return $"unknown_{DateTime.Now.Ticks}";
}
}
private string GetFileHash(string filePath)
{
try
{
if (string.IsNullOrEmpty(filePath)) return "unknown";
using (var md5 = MD5.Create())
{
byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(filePath));
return BitConverter.ToString(hashBytes).Replace("-", "").Substring(0, 8);
}
}
catch (Exception)
{
// 所有异常都静默处理,避免日志噪音
return "error";
}
}
private string GetProcessId(Presentation presentation)
{
try
{
// 尝试获取PowerPoint应用程序的进程ID
if (presentation.Application != null)
{
// 通过COM对象获取进程信息
var hwnd = presentation.Application.HWND;
if (hwnd != 0)
{
return hwnd.ToString();
}
}
return "unknown";
}
catch (COMException comEx)
{
// COM对象已失效,这是正常情况,完全静默处理
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005 || hr == 0x800706BA || hr == 0x800706BE || hr == 0x80048010)
{
return "disconnected";
}
return "error";
}
catch (Exception)
{
return "error";
}
}
#endregion
#region Dispose
public void Dispose()
{
if (!_disposed)
{
lock (_lockObject)
{
// 释放所有管理器
foreach (var manager in _presentationManagers.Values)
{
manager?.Dispose();
}
_presentationManagers.Clear();
_presentationInfos.Clear();
// 清理备份数据
foreach (var backupDict in _strokeBackups.Values)
{
foreach (var backup in backupDict.Values)
{
backup?.Clear();
}
backupDict.Clear();
}
_strokeBackups.Clear();
}
_disposed = true;
}
}
#endregion
}
/// <summary>
/// 演示文稿信息
/// </summary>
public class PresentationInfo
{
public string Id { get; set; }
public string Name { get; set; }
public string FullName { get; set; }
public int SlideCount { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime LastAccessTime { get; set; }
}
}
+133 -35
View File
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Input;
@@ -8,30 +9,52 @@ namespace Ink_Canvas.Helpers
{
public class VisualCanvas : FrameworkElement
{
private readonly List<DrawingVisual> _visuals = new List<DrawingVisual>();
protected override Visual GetVisualChild(int index)
{
return Visual;
if (index < 0 || index >= _visuals.Count)
throw new ArgumentOutOfRangeException(nameof(index));
return _visuals[index];
}
protected override int VisualChildrenCount => 1;
protected override int VisualChildrenCount => _visuals.Count;
public VisualCanvas(DrawingVisual visual)
public VisualCanvas()
{
Visual = visual;
CacheMode = new BitmapCache();
RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality);
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
RenderOptions.SetCachingHint(this, CachingHint.Cache);
}
public void AddVisual(DrawingVisual visual)
{
if (visual == null) return;
_visuals.Add(visual);
AddVisualChild(visual);
}
public void Clear()
{
foreach (var visual in _visuals)
{
RemoveVisualChild(visual);
}
_visuals.Clear();
}
public DrawingVisual Visual { get; }
public IReadOnlyList<DrawingVisual> Visuals => _visuals;
}
/// <summary>
/// 用于显示笔迹的类
/// </summary>
public class StrokeVisual : DrawingVisual
public class StrokeVisual
{
private bool _needsRedraw = true;
private int _lastPointCount = 0;
private const int REDRAW_THRESHOLD = 3;
private int _lastDrawnPointCount = 0;
private const int INCREMENTAL_DRAW_THRESHOLD = 2;
private VisualCanvas _visualCanvas;
/// <summary>
/// 创建显示笔迹的类
@@ -47,17 +70,12 @@ namespace Ink_Canvas.Helpers
}
/// <summary>
/// 创建显示笔迹的类
/// 创建显示笔迹的类
/// </summary>
/// <param name="drawingAttributes"></param>
public StrokeVisual(DrawingAttributes drawingAttributes)
{
_drawingAttributes = drawingAttributes;
// 启用硬件加速
RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality);
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
RenderOptions.SetCachingHint(this, CachingHint.Cache);
}
/// <summary>
@@ -65,6 +83,14 @@ namespace Ink_Canvas.Helpers
/// </summary>
public Stroke Stroke { set; get; }
/// <summary>
/// 设置关联的VisualCanvas
/// </summary>
public void SetVisualCanvas(VisualCanvas visualCanvas)
{
_visualCanvas = visualCanvas;
}
/// <summary>
/// 在笔迹中添加点
/// </summary>
@@ -75,16 +101,75 @@ namespace Ink_Canvas.Helpers
{
var collection = new StylusPointCollection { point };
Stroke = new Stroke(collection) { DrawingAttributes = _drawingAttributes };
_lastPointCount = 1;
}
else
{
Stroke.StylusPoints.Add(point);
_lastPointCount++;
}
}
/// <summary>
/// 绘制点段到新的DrawingVisual
/// </summary>
private static double PressureToVisualScale(float pressureFactor, bool ignorePressure)
{
if (ignorePressure)
return 1.0;
// 与 WPF 墨迹观感接近:0.5 为标称,压低变细、抬高变粗(预览此前固定 Pen 宽,等同忽略压感)
return Math.Max(0.22, Math.Min(2.1, 0.42 + 1.16 * pressureFactor));
}
private void DrawSegmentToNewVisual(int startIndex, int endIndex)
{
if (Stroke == null || Stroke.StylusPoints.Count == 0 || _visualCanvas == null) return;
if (startIndex >= endIndex || startIndex < 0 || endIndex > Stroke.StylusPoints.Count) return;
var points = Stroke.StylusPoints;
var drawingAttributes = Stroke.DrawingAttributes;
var ignorePressure = drawingAttributes.IgnorePressure;
// 创建新的DrawingVisual用于绘制这个点段
var segmentVisual = new DrawingVisual();
RenderOptions.SetBitmapScalingMode(segmentVisual, BitmapScalingMode.HighQuality);
RenderOptions.SetEdgeMode(segmentVisual, EdgeMode.Aliased);
RenderOptions.SetCachingHint(segmentVisual, CachingHint.Cache);
using (var dc = segmentVisual.RenderOpen())
{
// 绘制指定范围内的点段
if (endIndex - startIndex >= 2)
{
// 多个点,绘制线段
for (int i = startIndex; i < endIndex - 1 && i < points.Count - 1; i++)
{
var startPoint = new Point(points[i].X, points[i].Y);
var endPoint = new Point(points[i + 1].X, points[i + 1].Y);
var s0 = PressureToVisualScale(points[i].PressureFactor, ignorePressure);
var s1 = PressureToVisualScale(points[i + 1].PressureFactor, ignorePressure);
var thickness = Math.Max(0.35, (drawingAttributes.Width * s0 + drawingAttributes.Width * s1) / 2.0);
var pen = new Pen(new SolidColorBrush(drawingAttributes.Color), thickness)
{
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round,
LineJoin = PenLineJoin.Round
};
dc.DrawLine(pen, startPoint, endPoint);
}
}
else if (endIndex - startIndex == 1 && startIndex < points.Count)
{
// 只有一个点,绘制圆点
var brush = new SolidColorBrush(drawingAttributes.Color);
var point = points[startIndex];
var s = PressureToVisualScale(point.PressureFactor, ignorePressure);
dc.DrawEllipse(brush, null, new Point(point.X, point.Y),
drawingAttributes.Width * s / 2, drawingAttributes.Height * s / 2);
}
}
// 标记需要重绘
_needsRedraw = true;
// 将新的DrawingVisual添加到VisualCanvas中
_visualCanvas.AddVisual(segmentVisual);
}
/// <summary>
@@ -92,22 +177,35 @@ namespace Ink_Canvas.Helpers
/// </summary>
public void Redraw()
{
if (!_needsRedraw || Stroke == null) return;
if (Stroke == null || _visualCanvas == null) return;
if (_lastPointCount % REDRAW_THRESHOLD != 0 && _lastPointCount > REDRAW_THRESHOLD)
{
return;
}
var currentPointCount = Stroke.StylusPoints.Count;
if (currentPointCount == 0) return;
try
// 计算新增的点数
int newPointCount = currentPointCount - _lastDrawnPointCount;
// 如果新增点数达到阈值,才进行增量绘制
if (newPointCount >= INCREMENTAL_DRAW_THRESHOLD || _lastDrawnPointCount == 0)
{
using (var dc = RenderOpen())
try
{
Stroke.Draw(dc);
if (_lastDrawnPointCount == 0)
{
// 首次绘制:绘制所有点
DrawSegmentToNewVisual(0, currentPointCount);
_lastDrawnPointCount = currentPointCount;
}
else
{
// 从上次绘制的最后一个点开始
int startIndex = Math.Max(0, _lastDrawnPointCount - 1);
DrawSegmentToNewVisual(startIndex, currentPointCount);
_lastDrawnPointCount = currentPointCount;
}
}
_needsRedraw = false;
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
catch { }
}
/// <summary>
@@ -115,15 +213,15 @@ namespace Ink_Canvas.Helpers
/// </summary>
public void ForceRedraw()
{
_needsRedraw = true;
if (_visualCanvas != null)
{
_visualCanvas.Clear();
}
_lastDrawnPointCount = 0;
Redraw();
}
private readonly DrawingAttributes _drawingAttributes;
public static implicit operator Stroke(StrokeVisual v)
{
throw new NotImplementedException();
}
}
}
+264 -319
View File
@@ -1,15 +1,13 @@
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Interop.PowerPoint;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Ink;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// PPT墨迹管理器 - 负责PPT中墨迹的保存、加载和同步
/// PPT墨迹管理器 - 负责按幻灯片保存/加载墨迹、自动保存与内存管理。
/// </summary>
public class PPTInkManager : IDisposable
{
@@ -21,7 +19,8 @@ namespace Ink_Canvas.Helpers
#region Private Fields
private MemoryStream[] _memoryStreams;
private int _maxSlides = 100;
private const int DefaultMaxSlides = 100;
private int _maxSlides = DefaultMaxSlides;
private string _currentPresentationId = "";
private readonly object _lockObject = new object();
private bool _disposed;
@@ -34,50 +33,70 @@ namespace Ink_Canvas.Helpers
// 添加快速切换保护机制
private DateTime _lastSwitchTime = DateTime.MinValue;
private int _lastSwitchSlideIndex = -1;
private const int MinSwitchIntervalMs = 100; // 最小切换间隔100毫秒
private const int MinSwitchIntervalMs = 100;
// 内存管理相关字段
private long _totalMemoryUsage = 0;
private const long MaxMemoryUsageBytes = 100 * 1024 * 1024; // 100MB限制
private long _totalMemoryUsage;
private const long MaxMemoryUsageBytes = 100 * 1024 * 1024; // 100MB
private DateTime _lastMemoryCleanup = DateTime.MinValue;
private const int MemoryCleanupIntervalMinutes = 5; // 5分钟清理一次
private const int MemoryCleanupIntervalMinutes = 5;
private const string StrokeFileExtension = ".icstk";
#endregion
#region Constructor
/// <summary>
/// 初始化 PPTInkManager 实例并为内部内存流分配初始容量以跟踪默认最大幻灯片数加上备用槽位。
/// </summary>
public PPTInkManager()
{
InitializeMemoryStreams();
InitializeMemoryStreams(DefaultMaxSlides + 2);
}
private void InitializeMemoryStreams()
/// <summary>
/// 根据指定容量初始化用于存储每页墨迹的内存流数组。
/// </summary>
/// <param name="capacity">期望的数组容量;如果小于 2,则会使用 2 作为最小容量。</param>
private void InitializeMemoryStreams(int capacity)
{
_memoryStreams = new MemoryStream[_maxSlides + 2];
if (_memoryStreams != null)
{
for (int i = 0; i < _memoryStreams.Length; i++)
{
try { _memoryStreams[i]?.Dispose(); } catch (Exception ex) { LogHelper.WriteLogToFile($"InitializeMemoryStreams 释放内存流 {i} 失败: {ex}", LogHelper.LogType.Warning); }
}
}
_memoryStreams = new MemoryStream[Math.Max(2, capacity)];
}
#endregion
#region Public Methods
/// <summary>
/// 初始化新的演示文稿
/// </summary>
/// <remarks>
/// 为新的或当前的演示文稿初始化墨迹管理器的内部状态。
/// 方法会清除所有内存中的笔迹数据,重置墨迹写入锁与快速切换追踪,并根据演示文稿的幻灯片数量分配内部内存缓冲区。
/// 如果已启用自动保存且设置了 <see cref="AutoSaveLocation"/>,则会尝试加载磁盘上的已保存墨迹文件。
/// </remarks>
/// <param name="presentation">要初始化的 PowerPoint Presentation 实例;为 null 时方法不执行任何操作并直接返回。</param>
public void InitializePresentation(Presentation presentation)
{
ThrowIfDisposed();
if (presentation == null) return;
lock (_lockObject)
{
try
{
// 完全清理之前的墨迹状态
ClearAllStrokes();
// 重置墨迹锁定状态
ClearAllStrokesInternal();
_inkLockUntil = DateTime.MinValue;
_lockedSlideIndex = -1;
_lastSwitchSlideIndex = -1;
_lastSwitchTime = DateTime.MinValue;
// 生成演示文稿唯一标识符
_currentPresentationId = GeneratePresentationId(presentation);
// 重新初始化内存流数组
int slideCount = 0;
try
{
@@ -85,21 +104,17 @@ namespace Ink_Canvas.Helpers
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x80048010)
{
return;
}
uint hr = (uint)comEx.HResult;
if (hr == 0x80048010) return;
throw;
}
_memoryStreams = new MemoryStream[slideCount + 2];
// 如果启用自动保存,尝试加载已保存的墨迹
int capacity = slideCount + 2;
_maxSlides = Math.Max(_maxSlides, slideCount);
_memoryStreams = new MemoryStream[capacity];
if (IsAutoSaveEnabled && !string.IsNullOrEmpty(AutoSaveLocation))
{
LoadSavedStrokes();
}
}
catch (Exception ex)
{
@@ -111,48 +126,25 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 保存当前页面的墨迹
/// </summary>
/// <remarks>
/// 将指定幻灯片的墨迹保存到内部内存缓存,并在必要时触发内存清理。
/// </remarks>
/// <param name="slideIndex">要保存的幻灯片索引(从 1 开始)。方法在索引小于或等于 0 时不执行任何操作。</param>
/// <param name="strokes">要保存的墨迹集合;为 null 时方法不执行任何操作。</param>
public void SaveCurrentSlideStrokes(int slideIndex, StrokeCollection strokes)
{
ThrowIfDisposed();
if (slideIndex <= 0 || strokes == null) return;
lock (_lockObject)
{
try
{
// 检查墨迹锁定
if (!CanWriteInk(slideIndex))
{
if (DateTime.Now < _inkLockUntil)
{
}
return;
}
if (!CanWriteInk(slideIndex)) return;
if (slideIndex >= _memoryStreams.Length) return;
if (slideIndex < _memoryStreams.Length)
{
// 先释放旧的内存流,防止内存泄漏
try
{
_memoryStreams[slideIndex]?.Dispose();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放旧内存流失败: {ex}", LogHelper.LogType.Warning);
}
// 创建新的内存流
var ms = new MemoryStream();
strokes.Save(ms);
ms.Position = 0;
_memoryStreams[slideIndex] = ms;
if (ms.Length > 0)
{
}
// 检查内存使用情况
CheckAndPerformMemoryCleanup();
}
ReplaceSlideStream(slideIndex, strokes);
CheckAndPerformMemoryCleanup();
}
catch (Exception ex)
{
@@ -162,36 +154,25 @@ namespace Ink_Canvas.Helpers
}
/// <summary>
/// 强制保存指定页面的墨迹
/// 强制保存指定页墨迹到内存(不受锁定限制)。用于放映结束前保存当前画布到当前页。
/// </summary>
/// <remarks>
/// 强制将指定幻灯片的墨迹保存到内部内存缓存,覆盖该幻灯片已有的墨迹数据。
/// </remarks>
/// <param name="slideIndex">要保存的幻灯片索引(从 1 开始)。</param>
/// <param name="strokes">要保存的墨迹集合,不能为空。</param>
public void ForceSaveSlideStrokes(int slideIndex, StrokeCollection strokes)
{
ThrowIfDisposed();
if (slideIndex <= 0 || strokes == null) return;
lock (_lockObject)
{
try
{
if (slideIndex < _memoryStreams.Length)
{
// 先释放旧的内存流,防止内存泄漏
try
{
_memoryStreams[slideIndex]?.Dispose();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放旧内存流失败: {ex}", LogHelper.LogType.Warning);
}
// 创建新的内存流
var ms = new MemoryStream();
strokes.Save(ms);
ms.Position = 0;
_memoryStreams[slideIndex] = ms;
LogHelper.WriteLogToFile($"已强制保存第{slideIndex}页墨迹,大小: {ms.Length} bytes", LogHelper.LogType.Trace);
}
if (slideIndex >= _memoryStreams.Length) return;
ReplaceSlideStream(slideIndex, strokes);
LogHelper.WriteLogToFile($"已强制保存第{slideIndex}页墨迹", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
@@ -203,8 +184,14 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 加载指定页面的墨迹
/// </summary>
/// <remarks>
/// 加载并返回指定幻灯片的墨迹集合。
/// </remarks>
/// <param name="slideIndex">要加载的幻灯片索引(从1开始)。</param>
/// <returns>包含指定幻灯片的墨迹的 StrokeCollection;如果该幻灯片没有已保存的墨迹或加载失败,则返回空的 StrokeCollection。</returns>
public StrokeCollection LoadSlideStrokes(int slideIndex)
{
ThrowIfDisposed();
if (slideIndex <= 0) return new StrokeCollection();
lock (_lockObject)
@@ -214,8 +201,7 @@ namespace Ink_Canvas.Helpers
if (slideIndex < _memoryStreams.Length && _memoryStreams[slideIndex] != null && _memoryStreams[slideIndex].Length > 0)
{
_memoryStreams[slideIndex].Position = 0;
var strokes = new StrokeCollection(_memoryStreams[slideIndex]);
return strokes;
return new StrokeCollection(_memoryStreams[slideIndex]);
}
}
catch (Exception ex)
@@ -230,36 +216,30 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 切换到指定页面并加载墨迹
/// </summary>
/// <remarks>
/// 切换到指定幻灯片并返回该幻灯片的已加载笔迹集合。
/// </remarks>
/// <param name="slideIndex">要切换到的幻灯片索引(从 1 开始)。</param>
/// <param name="currentStrokes">可选的当前笔迹集合,用于在切换时提供当前画面状态。</param>
/// <returns>`StrokeCollection`:指定幻灯片已加载的笔迹集合;若加载失败则返回一个空的 `StrokeCollection`。</returns>
public StrokeCollection SwitchToSlide(int slideIndex, StrokeCollection currentStrokes = null)
{
ThrowIfDisposed();
lock (_lockObject)
{
try
{
// 检查快速切换保护
var now = DateTime.Now;
if (now - _lastSwitchTime < TimeSpan.FromMilliseconds(MinSwitchIntervalMs) &&
_lastSwitchSlideIndex == slideIndex)
if (now - _lastSwitchTime < TimeSpan.FromMilliseconds(MinSwitchIntervalMs) && _lastSwitchSlideIndex == slideIndex)
{
LogHelper.WriteLogToFile($"快速切换保护:忽略重复的页面切换请求 {slideIndex}", LogHelper.LogType.Warning);
LogHelper.WriteLogToFile($"快速切换保护:忽略重复请求 {slideIndex}", LogHelper.LogType.Trace);
return LoadSlideStrokes(slideIndex);
}
// 设置墨迹锁定
LockInkForSlide(slideIndex);
// 加载新页面的墨迹
var newStrokes = LoadSlideStrokes(slideIndex);
// 更新切换记录
StrokeCollection newStrokes = LoadSlideStrokes(slideIndex);
_lastSwitchTime = now;
_lastSwitchSlideIndex = slideIndex;
if (newStrokes.Count > 0)
{
}
return newStrokes;
}
catch (Exception ex)
@@ -273,82 +253,66 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 保存所有墨迹到文件
/// </summary>
public void SaveAllStrokesToFile(Presentation presentation)
/// <remarks>
/// 将内存中当前演示文稿的每页墨迹保存到磁盘,并根据情况写入当前播放位置文件。
/// 仅在 IsAutoSaveEnabled 为真且 AutoSaveLocation 已设置时执行。会在演示文稿专属文件夹中写入按页编号的墨迹文件(带 `.icstk` 扩展名)和可选的 Position 文件。遇到特定 COM 错误(HRESULT 0x80048010)时会中止保存当前幻灯片计数读取而不抛出异常;单页保存失败会记录错误并继续处理其他页。
/// </remarks>
/// <param name="presentation">要保存墨迹的 PowerPoint 演示文稿对象。</param>
/// <param name="currentSlideIndex">当前播放的页码;如果大于 0 则以此值写入 Position 文件,否则使用当前被锁定的页码或最后切换的页码作为保存位置。</param>
public void SaveAllStrokesToFile(Presentation presentation, int currentSlideIndex = -1)
{
ThrowIfDisposed();
if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation) || presentation == null) return;
lock (_lockObject)
{
try
{
var folderPath = GetPresentationFolderPath();
string folderPath = GetPresentationFolderPath();
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
int positionToSave = currentSlideIndex > 0 ? currentSlideIndex : (_lockedSlideIndex > 0 ? _lockedSlideIndex : _lastSwitchSlideIndex);
if (positionToSave > 0)
{
try { File.WriteAllText(Path.Combine(folderPath, "Position"), positionToSave.ToString()); }
catch (Exception ex) { LogHelper.WriteLogToFile($"保存 Position 失败: {ex}", LogHelper.LogType.Warning); }
}
// 保存位置信息
try
{
File.WriteAllText(Path.Combine(folderPath, "Position"), _lockedSlideIndex.ToString());
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存位置信息失败: {ex}", LogHelper.LogType.Error);
}
// 保存所有页面的墨迹
int savedCount = 0;
int slideCount = 0;
try
{
slideCount = presentation.Slides.Count;
}
try { slideCount = presentation.Slides.Count; }
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x80048010)
{
return;
}
if ((uint)comEx.HResult == 0x80048010) return;
throw;
}
for (int i = 1; i <= slideCount && i < _memoryStreams.Length; i++)
{
if (_memoryStreams[i] != null)
if (_memoryStreams[i] == null) continue;
try
{
try
if (_memoryStreams[i].Length > 8)
{
if (_memoryStreams[i].Length > 8)
_memoryStreams[i].Position = 0;
byte[] buf = new byte[_memoryStreams[i].Length];
int read = _memoryStreams[i].Read(buf, 0, buf.Length);
if (read > 0)
{
var srcBuf = new byte[_memoryStreams[i].Length];
_memoryStreams[i].Position = 0;
var byteLength = _memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
File.WriteAllBytes(filePath, srcBuf);
savedCount++;
}
else
{
// 删除空的墨迹文件
var filePath = Path.Combine(folderPath, i.ToString("0000") + ".icstk");
if (File.Exists(filePath))
{
File.Delete(filePath);
}
string basePath = Path.Combine(folderPath, i.ToString("0000"));
File.WriteAllBytes(basePath + StrokeFileExtension, buf);
}
}
catch (Exception ex)
else
{
LogHelper.WriteLogToFile($"保存第{i}页墨迹失败: {ex}", LogHelper.LogType.Error);
TryDeleteStrokeFile(folderPath, i);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存第{i}页墨迹到文件失败: {ex}", LogHelper.LogType.Error);
}
}
}
catch (Exception ex)
{
@@ -360,41 +324,50 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 从文件加载已保存的墨迹
/// </summary>
/// <remarks>
/// 从自动保存目录加载已保存的幻灯片墨迹数据到内存流中,供后续显示和编辑使用。
/// 仅在启用自动保存且已设置 AutoSaveLocation 时执行。函数获取当前演示文稿的自动保存文件夹,遍历以 <c>.icstk</c> 为扩展名的文件,
/// 将文件名(去除扩展名)解析为幻灯片索引并在合法且文件大小大于 8 字节时加载到对应的内存流槽位。对单个文件的读取失败会记录错误并继续处理其他文件;
/// 若成功加载则会记录已加载页数。方法在内部使用锁以保证线程安全。
/// </remarks>
public void LoadSavedStrokes()
{
ThrowIfDisposed();
if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation)) return;
lock (_lockObject)
{
try
{
var folderPath = GetPresentationFolderPath();
string folderPath = GetPresentationFolderPath();
if (!Directory.Exists(folderPath)) return;
var files = new DirectoryInfo(folderPath).GetFiles("*.icstk");
var dir = new DirectoryInfo(folderPath);
int loadedCount = 0;
foreach (var file in files)
foreach (FileInfo file in dir.GetFiles("*" + StrokeFileExtension))
{
string nameWithoutExt = Path.GetFileNameWithoutExtension(file.Name);
if (!int.TryParse(nameWithoutExt, out int slideIndex) || slideIndex <= 0) continue;
if (slideIndex >= _memoryStreams.Length) continue;
try
{
if (int.TryParse(Path.GetFileNameWithoutExtension(file.Name), out int slideIndex))
byte[] bytes = File.ReadAllBytes(file.FullName);
if (bytes.Length > 8)
{
if (slideIndex > 0 && slideIndex < _memoryStreams.Length)
{
var fileBytes = File.ReadAllBytes(file.FullName);
_memoryStreams[slideIndex] = new MemoryStream(fileBytes);
_memoryStreams[slideIndex].Position = 0;
loadedCount++;
}
_memoryStreams[slideIndex] = new MemoryStream(bytes);
_memoryStreams[slideIndex].Position = 0;
loadedCount++;
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"加载墨迹文件{file.Name}失败: {ex}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"加载墨迹文件 {file.Name} 失败: {ex}", LogHelper.LogType.Error);
}
}
if (loadedCount > 0)
LogHelper.WriteLogToFile($"已从磁盘加载 {loadedCount} 页墨迹", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
@@ -406,87 +379,53 @@ namespace Ink_Canvas.Helpers
/// <summary>
/// 清除所有墨迹
/// </summary>
/// <remarks>
/// 清除并释放当前演示文稿所有幻灯片的墨迹数据和相关内存资源。
/// 该方法在内部加锁以保证线程安全;会处置并清空所有内部存储的墨迹流、重建内部流数组并清空 CurrentStrokes。
/// </remarks>
public void ClearAllStrokes()
{
ThrowIfDisposed();
lock (_lockObject)
{
try
{
// 安全释放所有内存流
if (_memoryStreams != null)
{
for (int i = 0; i < _memoryStreams.Length; i++)
{
try
{
_memoryStreams[i]?.Dispose();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"释放内存流{i}失败: {ex}", LogHelper.LogType.Warning);
}
finally
{
_memoryStreams[i] = null;
}
}
// 重新初始化数组
_memoryStreams = new MemoryStream[_maxSlides + 2];
}
CurrentStrokes?.Clear();
LogHelper.WriteLogToFile("已清除所有墨迹", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清除墨迹失败: {ex}", LogHelper.LogType.Error);
}
ClearAllStrokesInternal();
}
}
/// <summary>
/// 翻页后锁定墨迹写入
/// 为指定幻灯片设置短时墨迹写入锁,防止在该时间窗口内对其他幻灯片进行写入操作。
/// </summary>
/// <param name="slideIndex">要上锁的幻灯片索引(大于 0)。锁从调用时刻开始,持续 InkLockMilliseconds 毫秒。</param>
public void LockInkForSlide(int slideIndex)
{
ThrowIfDisposed();
_inkLockUntil = DateTime.Now.AddMilliseconds(InkLockMilliseconds);
_lockedSlideIndex = slideIndex;
}
/// <summary>
/// 检查是否可以写入墨迹
/// 确定在当前滑页上下文中是否允许写入墨迹(基于短期的墨迹写入锁与容差窗口)。
/// </summary>
/// <param name="currentSlideIndex">当前尝试写入墨迹的幻灯片索引(从 1 开始)。</param>
/// <returns>`true` 如果允许写入墨迹(锁已过期、目标为被锁定的幻灯片,或处于短暂的容差窗口内),`false` 否则。</returns>
public bool CanWriteInk(int currentSlideIndex)
{
// 如果锁定时间已过,允许写入
if (DateTime.Now >= _inkLockUntil)
{
return true;
}
// 如果当前页面与锁定页面相同,允许写入(用户在当前页面绘制)
if (currentSlideIndex == _lockedSlideIndex)
{
return true;
}
// 如果当前页面不是锁定页面,但锁定时间很短(小于50ms),允许写入
// 这样可以确保旧页面的墨迹能够及时保存
if (DateTime.Now - (_inkLockUntil.AddMilliseconds(-InkLockMilliseconds)) < TimeSpan.FromMilliseconds(50))
{
return true;
}
// 只有在快速切换且页面不同时才锁定
ThrowIfDisposed();
if (DateTime.Now >= _inkLockUntil) return true;
if (currentSlideIndex == _lockedSlideIndex) return true;
if (DateTime.Now - (_inkLockUntil.AddMilliseconds(-InkLockMilliseconds)) < TimeSpan.FromMilliseconds(50)) return true;
return false;
}
/// <summary>
/// 重置墨迹锁定状态
/// 重置墨迹书写和幻灯片切换相关的锁与跟踪状态为初始(未锁定)值。
/// </summary>
/// <remarks>
/// 将内部的墨迹写入到期时间、当前被锁定的幻灯片索引、上次切换时间和上次切换的幻灯片索引均恢复为默认未设置状态。
/// </remarks>
public void ResetLockState()
{
ThrowIfDisposed();
lock (_lockObject)
{
_inkLockUntil = DateTime.MinValue;
@@ -496,51 +435,90 @@ namespace Ink_Canvas.Helpers
}
}
#endregion
#region Private Helpers
/// <summary>
/// 检查并执行内存清理
/// 释放并清除类内用于存储各页墨迹的所有内存流,清空当前画笔集合,并重置内部内存流数组容量为 _maxSlides + 2。
/// </summary>
/// <remarks>
/// - 会逐个释放已存在的 MemoryStream(忽略释放过程中的异常),并将对应槽位设为 null。
/// - 会清空 CurrentStrokes 集合。
/// - 会记录一条跟踪日志,指示已完成清除操作。
/// </remarks>
private void ClearAllStrokesInternal()
{
if (_memoryStreams != null)
{
for (int i = 0; i < _memoryStreams.Length; i++)
{
try { _memoryStreams[i]?.Dispose(); }
catch (Exception ex) { LogHelper.WriteLogToFile($"释放内存流 {i} 失败: {ex}", LogHelper.LogType.Warning); }
finally { _memoryStreams[i] = null; }
}
_memoryStreams = new MemoryStream[_maxSlides + 2];
}
CurrentStrokes?.Clear();
LogHelper.WriteLogToFile("已清除所有墨迹", LogHelper.LogType.Trace);
}
/// <summary>
/// 用指定的笔迹集合替换内部存储中对应幻灯片索引的内存流:释放(并忽略释放错误)旧流,将 <paramref name="strokes"/> 序列化到新的 <see cref="MemoryStream"/> 并保存回内部数组。
/// </summary>
/// <param name="slideIndex">要替换的幻灯片索引(内部内存流数组的索引)。</param>
/// <param name="strokes">要序列化并保存到内存流的笔迹集合。</param>
private void ReplaceSlideStream(int slideIndex, StrokeCollection strokes)
{
try { _memoryStreams[slideIndex]?.Dispose(); } catch (Exception ex) { LogHelper.WriteLogToFile($"释放旧内存流失败: {ex}", LogHelper.LogType.Warning); }
var ms = new MemoryStream();
strokes.Save(ms);
ms.Position = 0;
_memoryStreams[slideIndex] = ms;
}
/// <summary>
/// 从指定文件夹删除对应幻灯片的笔迹文件(按四位索引命名);如果文件不存在或删除失败则静默忽略错误。
/// </summary>
/// <param name="folderPath">存放笔迹文件的文件夹路径。</param>
/// <param name="slideIndex">用于生成文件名的幻灯片索引(格式化为四位,例如 1 -> "0001")。</param>
private void TryDeleteStrokeFile(string folderPath, int slideIndex)
{
try
{
string path = Path.Combine(folderPath, slideIndex.ToString("0000") + StrokeFileExtension);
if (File.Exists(path)) File.Delete(path);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
/// <summary>
/// 检查当前墨迹内存使用状况并在超过阈值时触发清理操作。
/// </summary>
/// <remarks>
/// 会更新内部的内存使用统计并刷新上次清理时间;当总占用超过 MaxMemoryUsageBytes 时,会记录警告并调用 CleanupInactiveSlideStrokes 清理不活跃幻灯页的墨迹流。若检查或清理过程中发生异常,会记录错误日志。
/// </remarks>
private void CheckAndPerformMemoryCleanup()
{
try
{
var now = DateTime.Now;
if (now - _lastMemoryCleanup < TimeSpan.FromMinutes(MemoryCleanupIntervalMinutes)) return;
// 检查是否需要执行内存清理
if (now - _lastMemoryCleanup < TimeSpan.FromMinutes(MemoryCleanupIntervalMinutes))
{
return;
}
// 计算当前内存使用量
long currentMemoryUsage = 0;
if (_memoryStreams != null)
{
for (int i = 0; i < _memoryStreams.Length; i++)
{
if (_memoryStreams[i] != null)
{
currentMemoryUsage += _memoryStreams[i].Length;
}
}
if (_memoryStreams[i] != null) currentMemoryUsage += _memoryStreams[i].Length;
}
_totalMemoryUsage = currentMemoryUsage;
// 如果内存使用量超过限制,执行清理
if (currentMemoryUsage > MaxMemoryUsageBytes)
{
LogHelper.WriteLogToFile($"内存使用量超限 ({currentMemoryUsage / 1024 / 1024}MB)开始清理", LogHelper.LogType.Warning);
// 清理非当前页面的墨迹
LogHelper.WriteLogToFile($"墨迹内存超限 ({currentMemoryUsage / (1024 * 1024)}MB)执行清理", LogHelper.LogType.Warning);
CleanupInactiveSlideStrokes();
_lastMemoryCleanup = now;
LogHelper.WriteLogToFile($"内存清理完成,当前使用量: {_totalMemoryUsage / 1024 / 1024}MB", LogHelper.LogType.Trace);
}
else
{
_lastMemoryCleanup = now;
}
_lastMemoryCleanup = now;
}
catch (Exception ex)
{
@@ -549,111 +527,78 @@ namespace Ink_Canvas.Helpers
}
/// <summary>
/// 清理活跃页面的墨迹
/// 清理活跃幻灯片的内存化墨迹数据以回收内存空间。
/// </summary>
/// <remarks>
/// 将释放除当前锁定幻灯片与最近切换幻灯片之外的每页内存流(若存在),并将对应数组项设为 null;完成后若有释放,会记录已清理页数与释放的总大小(KB)。
/// </remarks>
private void CleanupInactiveSlideStrokes()
{
try
if (_memoryStreams == null) return;
int cleaned = 0;
long freed = 0;
for (int i = 0; i < _memoryStreams.Length; i++)
{
if (_memoryStreams == null) return;
int cleanedCount = 0;
long freedMemory = 0;
for (int i = 0; i < _memoryStreams.Length; i++)
if (i == _lockedSlideIndex || i == _lastSwitchSlideIndex) continue;
if (_memoryStreams[i] != null)
{
// 保留当前锁定页面和最近访问的页面
if (i == _lockedSlideIndex || i == _lastSwitchSlideIndex)
{
continue;
}
if (_memoryStreams[i] != null)
{
long memorySize = _memoryStreams[i].Length;
try
{
_memoryStreams[i].Dispose();
freedMemory += memorySize;
cleanedCount++;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理页面{i}墨迹失败: {ex}", LogHelper.LogType.Warning);
}
finally
{
_memoryStreams[i] = null;
}
}
}
if (cleanedCount > 0)
{
LogHelper.WriteLogToFile($"已清理{cleanedCount}个页面的墨迹,释放内存: {freedMemory / 1024}KB", LogHelper.LogType.Trace);
long len = _memoryStreams[i].Length;
try { _memoryStreams[i].Dispose(); freed += len; cleaned++; }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
finally { _memoryStreams[i] = null; }
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理非活跃页面墨迹失败: {ex}", LogHelper.LogType.Error);
}
if (cleaned > 0)
LogHelper.WriteLogToFile($"已清理 {cleaned} 页墨迹,释放 {freed / 1024}KB", LogHelper.LogType.Trace);
}
#endregion
#region Private Methods
/// <summary>
/// 生成基于演示文稿名称、幻灯片数量和路径哈希的标识符字符串。
/// </summary>
/// <returns>由 `名称_幻灯片数_路径哈希` 组成的标识符;若生成失败则返回形如 `unknown_{ticks}` 的回退标识符。</returns>
private string GeneratePresentationId(Presentation presentation)
{
try
{
var presentationPath = presentation.FullName;
var fileHash = GetFileHash(presentationPath);
return $"{presentation.Name}_{presentation.Slides.Count}_{fileHash}";
string path = presentation.FullName;
string hash = HashHelper.GetFileHash(path);
return $"{presentation.Name}_{presentation.Slides.Count}_{hash}";
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"生成演示文稿ID失败: {ex}", LogHelper.LogType.Error);
LogHelper.WriteLogToFile($"生成演示文稿 ID 失败: {ex}", LogHelper.LogType.Error);
return $"unknown_{DateTime.Now.Ticks}";
}
}
private string GetFileHash(string filePath)
{
try
{
if (string.IsNullOrEmpty(filePath)) return "unknown";
using (var md5 = MD5.Create())
{
byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(filePath));
return BitConverter.ToString(hashBytes).Replace("-", "").Substring(0, 8);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"计算文件哈希值失败: {ex}", LogHelper.LogType.Error);
return "error";
}
}
private string GetPresentationFolderPath()
{
return Path.Combine(AutoSaveLocation, "Auto Saved - Presentations", _currentPresentationId);
}
#endregion
#region Dispose
/// <summary>
/// 释放 PPTInkManager 持有的资源并清除所有内存中的笔迹数据。
/// </summary>
/// <remarks>
/// 调用后该实例将进入已释放状态,不应再被使用。方法为幂等且线程安全:如果已释放则立即返回,否则在同步区内清理资源并标记为已释放。
/// </remarks>
public void Dispose()
{
if (!_disposed)
{
lock (_lockObject)
{
ClearAllStrokes();
}
_disposed = true;
}
if (_disposed) return;
lock (_lockObject) { ClearAllStrokesInternal(); }
_disposed = true;
GC.SuppressFinalize(this);
}
private void ThrowIfDisposed()
{
if (_disposed) throw new ObjectDisposedException(nameof(PPTInkManager));
}
#endregion
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,522 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
namespace Ink_Canvas.Helpers
{
public static class PPTROTConnectionHelper
{
#region Win32 API Declarations
[DllImport("ole32.dll")]
private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);
[DllImport("ole32.dll")]
private static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
#endregion
#region Constants
private static readonly Guid PowerPointApplicationGuid = new Guid("91493441-5A91-11CF-8700-00AA0060263B");
private static readonly string[] PptLikeExtensions = new[]
{
".pptx", ".pptm", ".ppt",
".ppsx", ".ppsm", ".pps",
".potx", ".potm", ".pot",
".dps", ".dpt"
};
#endregion
#region Public Methods
public static Microsoft.Office.Interop.PowerPoint.Application TryConnectViaROT(bool isSupportWPS = false)
{
try
{
object bestApp = GetAnyActivePowerPoint(null, out int bestPriority, out _);
if (bestApp != null && bestPriority > 0)
{
try
{
Type appType = typeof(Microsoft.Office.Interop.PowerPoint.Application);
Microsoft.Office.Interop.PowerPoint.Application pptApp = null;
if (appType.IsInstanceOfType(bestApp))
{
pptApp = (Microsoft.Office.Interop.PowerPoint.Application)bestApp;
}
if (pptApp != null)
{
try
{
var nameObj = pptApp.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, pptApp, null);
SafeReleaseComObject(nameObj);
return pptApp;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"ROT 连接验证 Name 不可用(将依赖 SlideShowWindows: {ex.Message}", LogHelper.LogType.Warning);
return pptApp;
}
}
else
{
SafeReleaseComObject(bestApp);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"ROT 连接验证失败: {ex.Message}", LogHelper.LogType.Warning);
SafeReleaseComObject(bestApp);
}
}
else if (bestApp != null)
{
SafeReleaseComObject(bestApp);
}
try
{
var pptApp = (Microsoft.Office.Interop.PowerPoint.Application)Marshal.GetActiveObject("PowerPoint.Application");
if (pptApp != null && Marshal.IsComObject(pptApp))
{
try
{
var _ = pptApp.Name;
}
catch (COMException)
{
}
return pptApp;
}
}
catch (COMException) { }
catch (InvalidCastException) { }
if (isSupportWPS)
{
try
{
var wpsApp = (Microsoft.Office.Interop.PowerPoint.Application)Marshal.GetActiveObject("kwpp.Application");
if (wpsApp != null && Marshal.IsComObject(wpsApp))
{
try
{
var _ = wpsApp.Name;
}
catch (COMException)
{
}
return wpsApp;
}
}
catch (COMException) { }
catch (InvalidCastException) { }
}
return null;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"ROT 连接过程发生异常: {ex}", LogHelper.LogType.Error);
return null;
}
}
#endregion
#region Public Methods
/// <summary>
/// 在系统的运行对象表(ROT)中查找并返回最合适的正在运行的 PowerPoint 应用实例。
/// </summary>
/// <param name="targetApp">可选的目标 PowerPoint COM 对象,用于优先比较;传入 null 表示不指定目标。</param>
/// <param name="bestPriority">输出参数:返回找到的最佳实例的优先级(0 表示未找到或无活动演示)。</param>
/// <param name="targetPriority">输出参数:返回与 <paramref name="targetApp"/> 对应实例的优先级(如果未提供或未命中则为 0)。</param>
/// <returns>最合适的 PowerPoint 应用对象(通常为 COM Application 实例),若未找到则返回 null。</returns>
public static object GetAnyActivePowerPoint(object targetApp, out int bestPriority, out int targetPriority)
{
IRunningObjectTable rot = null;
IEnumMoniker enumMoniker = null;
object bestApp = null;
bestPriority = 0;
targetPriority = 0;
int highestPriority = 0;
List<object> foundAppObjects = new List<object>();
try
{
int hr = GetRunningObjectTable(0, out rot);
if (hr != 0 || rot == null)
{
LogHelper.WriteLogToFile("无法获取 Running Object Table", LogHelper.LogType.Warning);
return null;
}
rot.EnumRunning(out enumMoniker);
if (enumMoniker == null)
{
LogHelper.WriteLogToFile("无法枚举 ROT 中的对象", LogHelper.LogType.Warning);
return null;
}
IMoniker[] moniker = new IMoniker[1];
IntPtr fetched = IntPtr.Zero;
while (enumMoniker.Next(1, moniker, fetched) == 0)
{
IBindCtx bindCtx = null;
object comObject = null;
dynamic candidateApp = null;
string displayName = "Unknown";
dynamic activePres = null;
dynamic ssWindow = null;
bool keepAlive = false;
try
{
CreateBindCtx(0, out bindCtx);
moniker[0].GetDisplayName(bindCtx, null, out displayName);
if (LooksLikePresentationFile(displayName) || displayName == "!{91493441-5A91-11CF-8700-00AA0060263B}")
{
rot.GetObject(moniker[0], out comObject);
if (comObject != null)
{
try
{
object appObj = comObject.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, comObject, null);
candidateApp = appObj;
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
bool isDuplicate = false;
if (candidateApp != null)
{
foreach (var processedApp in foundAppObjects)
{
if (AreComObjectsEqual((object)candidateApp, processedApp))
{
isDuplicate = true;
break;
}
}
if (!isDuplicate)
{
foundAppObjects.Add(candidateApp);
keepAlive = true;
}
}
if (candidateApp != null && !isDuplicate)
{
int currentPriority = 0;
bool isTarget = false;
if (targetApp != null && AreComObjectsEqual((object)candidateApp, targetApp))
{
isTarget = true;
}
try
{
try
{
activePres = candidateApp.ActivePresentation;
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
if (activePres != null)
{
currentPriority = 1;
try
{
ssWindow = activePres.SlideShowWindow;
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
if (ssWindow != null)
{
currentPriority = 2;
try
{
bool isActive = false;
try
{
object val = ssWindow.Active;
if (val is int && (int)val == -1) isActive = true;
else if (val is bool && (bool)val == true) isActive = true;
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
if (isActive)
{
currentPriority = 3;
}
else
{
if (IsSlideShowWindowActive(ssWindow))
{
currentPriority = 3;
}
}
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"计算优先级时出错: {ex.Message}", LogHelper.LogType.Warning);
}
if (isTarget)
{
targetPriority = currentPriority;
}
if (currentPriority > 0)
{
if (currentPriority > highestPriority)
{
highestPriority = currentPriority;
SafeReleaseComObject(bestApp);
bestApp = candidateApp;
candidateApp = null;
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"ROT 枚举循环中出错: {ex.Message}", LogHelper.LogType.Warning);
}
finally
{
SafeReleaseComObject(ssWindow);
SafeReleaseComObject(activePres);
if (!keepAlive)
{
SafeReleaseComObject(candidateApp);
}
CleanUpLoopObjects(bindCtx, moniker[0], comObject);
}
}
bestPriority = highestPriority;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"ROT 扫描关键错误: {ex}", LogHelper.LogType.Error);
}
finally
{
if (foundAppObjects != null)
{
foreach (var cachedApp in foundAppObjects)
{
if (bestApp != null && ReferenceEquals(cachedApp, bestApp))
continue;
SafeReleaseComObject(cachedApp);
}
foundAppObjects.Clear();
}
if (enumMoniker != null) Marshal.ReleaseComObject(enumMoniker);
if (rot != null) Marshal.ReleaseComObject(rot);
}
return bestApp;
}
public static bool AreComObjectsEqual(object o1, object o2)
{
if (o1 == null || o2 == null) return false;
if (ReferenceEquals(o1, o2)) return true;
IntPtr pUnk1 = IntPtr.Zero;
IntPtr pUnk2 = IntPtr.Zero;
try
{
pUnk1 = Marshal.GetIUnknownForObject(o1);
pUnk2 = Marshal.GetIUnknownForObject(o2);
return pUnk1 == pUnk2;
}
catch { return false; }
finally
{
if (pUnk1 != IntPtr.Zero) Marshal.Release(pUnk1);
if (pUnk2 != IntPtr.Zero) Marshal.Release(pUnk2);
}
}
private static bool LooksLikePresentationFile(string displayName)
{
if (string.IsNullOrEmpty(displayName))
return false;
string lower = displayName.ToLowerInvariant();
foreach (var ext in PptLikeExtensions)
{
if (lower.Contains(ext))
return true;
}
return false;
}
public static bool IsSlideShowWindowActive(object sswObj)
{
try
{
dynamic ssw = sswObj;
IntPtr foregroundHwnd = GetForegroundWindow();
if (foregroundHwnd == IntPtr.Zero) return false;
uint fgPid;
GetWindowThreadProcessId(foregroundHwnd, out fgPid);
IntPtr sswHwnd = IntPtr.Zero;
try
{
sswHwnd = GetPptHwndFromSlideShowWindow(sswObj);
}
catch { return false; }
if (sswHwnd == IntPtr.Zero) return false;
uint sswPid;
GetWindowThreadProcessId(sswHwnd, out sswPid);
if (fgPid == sswPid) return true;
try
{
using (Process fgProc = Process.GetProcessById((int)fgPid))
using (Process appProc = Process.GetProcessById((int)sswPid))
{
string fgName = fgProc.ProcessName.ToLower();
string appName = appProc.ProcessName.ToLower();
if (fgName.StartsWith("wps") && appName.StartsWith("wpp"))
{
return true;
}
}
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return false;
}
catch
{
return false;
}
}
private static IntPtr GetPptHwndFromSlideShowWindow(object pptSlideShowWindowObj)
{
IntPtr hwnd = IntPtr.Zero;
if (pptSlideShowWindowObj == null) return IntPtr.Zero;
try
{
Microsoft.Office.Interop.PowerPoint.SlideShowWindow slideWindow = (Microsoft.Office.Interop.PowerPoint.SlideShowWindow)pptSlideShowWindowObj;
int hwndVal = slideWindow.HWND;
hwnd = new IntPtr(hwndVal);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return hwnd;
}
public static void SafeReleaseComObject(object comObj)
{
if (comObj == null) return;
if (Marshal.IsComObject(comObj))
{
try
{
Marshal.ReleaseComObject(comObj);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
private static void CleanUpLoopObjects(IBindCtx bindCtx, IMoniker moniker, object comObject)
{
if (comObject != null && Marshal.IsComObject(comObject))
Marshal.ReleaseComObject(comObject);
if (moniker != null)
Marshal.ReleaseComObject(moniker);
if (bindCtx != null)
Marshal.ReleaseComObject(bindCtx);
}
public static int GetSlideShowWindowsCount(Microsoft.Office.Interop.PowerPoint.Application pptApp)
{
try
{
if (pptApp == null) return 0;
return pptApp.SlideShowWindows.Count;
}
catch
{
return 0;
}
}
public static bool IsValidSlideShowWindow(object pptSlideShowWindow)
{
if (pptSlideShowWindow == null) return false;
try
{
dynamic ssw = pptSlideShowWindow;
var _ = ssw.Active;
return true;
}
catch
{
return false;
}
}
#endregion
}
}
+18 -8
View File
@@ -23,6 +23,10 @@ namespace Ink_Canvas.Helpers
public int PPTRBButtonPosition { get; set; } = 0;
public bool EnablePPTButtonPageClickable { get; set; } = true;
public bool EnablePPTButtonLongPressPageTurn { get; set; } = true;
public double PPTLSButtonOpacity { get; set; } = 0.5;
public double PPTRSButtonOpacity { get; set; } = 0.5;
public double PPTLBButtonOpacity { get; set; } = 0.5;
public double PPTRBButtonOpacity { get; set; } = 0.5;
#endregion
#region Private Fields
@@ -97,6 +101,8 @@ namespace Ink_Canvas.Helpers
UpdateNavigationPanelsVisibility();
UpdateNavigationButtonStyles();
_mainWindow.UpdatePPTTimeCapsuleVisibility();
_mainWindow.UpdatePPTQuickPanelVisibility();
if (MainWindow.Settings.Advanced.IsEnableAvoidFullScreenHelper)
{
// 设置为画板模式,允许全屏操作
@@ -107,6 +113,8 @@ namespace Ink_Canvas.Helpers
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
}), DispatcherPriority.ApplicationIdle);
_mainWindow.isFullScreenApplied = true; // 标记已应用全屏处理
}
}
else
@@ -114,6 +122,8 @@ namespace Ink_Canvas.Helpers
_mainWindow.BtnPPTSlideShow.Visibility = Visibility.Visible;
_mainWindow.BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
HideAllNavigationPanels();
_mainWindow.UpdatePPTTimeCapsuleVisibility();
_mainWindow.UpdatePPTQuickPanelVisibility();
if (MainWindow.Settings.Advanced.IsEnableAvoidFullScreenHelper)
{
// 恢复为非画板模式,重新启用全屏限制
@@ -127,6 +137,8 @@ namespace Ink_Canvas.Helpers
workingArea.X, workingArea.Y,
workingArea.Width, workingArea.Height, true);
}), DispatcherPriority.ApplicationIdle);
_mainWindow.isFullScreenApplied = false; // 标记全屏处理已还原
}
}
}
@@ -377,10 +389,9 @@ namespace Ink_Canvas.Helpers
_mainWindow.PPTLSPageButton.Visibility = pageButtonVisibility;
_mainWindow.PPTRSPageButton.Visibility = pageButtonVisibility;
// 透明度设置
var opacity = options[1] == '2' ? 0.5 : 1.0;
_mainWindow.PPTBtnLSBorder.Opacity = opacity;
_mainWindow.PPTBtnRSBorder.Opacity = opacity;
// 透明度设置 - 直接使用用户设置的透明度值
_mainWindow.PPTBtnLSBorder.Opacity = PPTLSButtonOpacity;
_mainWindow.PPTBtnRSBorder.Opacity = PPTRSButtonOpacity;
// 颜色主题
bool isDarkTheme = options[2] == '2';
@@ -406,10 +417,9 @@ namespace Ink_Canvas.Helpers
_mainWindow.PPTLBPageButton.Visibility = pageButtonVisibility;
_mainWindow.PPTRBPageButton.Visibility = pageButtonVisibility;
// 透明度设置
var opacity = options[1] == '2' ? 0.5 : 1.0;
_mainWindow.PPTBtnLBBorder.Opacity = opacity;
_mainWindow.PPTBtnRBBorder.Opacity = opacity;
// 透明度设置 - 直接使用用户设置的透明度值
_mainWindow.PPTBtnLBBorder.Opacity = PPTLBButtonOpacity;
_mainWindow.PPTBtnRBBorder.Opacity = PPTRBButtonOpacity;
// 颜色主题
bool isDarkTheme = options[2] == '2';
+79
View File
@@ -0,0 +1,79 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using Windows.Data.Pdf;
using Windows.Storage;
using Windows.Storage.Streams;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 使用 Windows.Data.PdfWinRT)将 PDF 页渲染为 WPF 可用的位图。
/// </summary>
internal static class PdfWinRtHelper
{
public static async Task<uint> GetPageCountAsync(string pdfPath)
{
if (string.IsNullOrWhiteSpace(pdfPath) || !File.Exists(pdfPath))
return 0;
var file = await StorageFile.GetFileFromPathAsync(pdfPath).AsTask();
var doc = await PdfDocument.LoadFromFileAsync(file).AsTask();
if (doc.IsPasswordProtected)
return 0;
return doc.PageCount;
}
public static async Task<BitmapSource> RenderPageToBitmapSourceAsync(string pdfPath, uint pageIndex)
{
if (string.IsNullOrWhiteSpace(pdfPath) || !File.Exists(pdfPath))
return null;
var file = await StorageFile.GetFileFromPathAsync(pdfPath).AsTask();
var doc = await PdfDocument.LoadFromFileAsync(file).AsTask();
if (doc.IsPasswordProtected)
return null;
if (pageIndex >= doc.PageCount)
return null;
var page = doc.GetPage(pageIndex);
try
{
using (var ras = new InMemoryRandomAccessStream())
{
await page.RenderToStreamAsync(ras).AsTask();
ras.Seek(0);
var ms = new MemoryStream();
using (var netStream = ras.AsStreamForRead())
netStream.CopyTo(ms);
ms.Position = 0;
try
{
return await Application.Current.Dispatcher.InvokeAsync(() =>
{
var bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.EndInit();
bi.Freeze();
return (BitmapSource)bi;
});
}
finally
{
ms.Dispose();
}
}
}
finally
{
(page as IDisposable)?.Dispose();
}
}
}
}
@@ -1,274 +0,0 @@
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
/// <summary>
/// 启动台按钮控件
/// </summary>
public class LauncherButton
{
/// <summary>
/// 父插件
/// </summary>
private readonly SuperLauncherPlugin _plugin;
/// <summary>
/// 实际按钮控件
/// </summary>
private readonly SimpleStackPanel _panel;
/// <summary>
/// 获取按钮UI元素
/// </summary>
public UIElement Element => _panel;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="plugin">父插件</param>
public LauncherButton(SuperLauncherPlugin plugin)
{
try
{
_plugin = plugin;
LogHelper.WriteLogToFile("开始创建启动台按钮");
// 创建SimpleStackPanel
_panel = new SimpleStackPanel
{
Name = "Launcher_Icon",
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Center,
Width = 28,
Margin = new Thickness(0, -2, 0, 0),
Background = Brushes.Transparent
};
LogHelper.WriteLogToFile("创建SimpleStackPanel完成");
// 添加图标
var image = CreateIconImage();
_panel.Children.Add(image);
// 添加文本
TextBlock textBlock = new TextBlock
{
Text = "启动台",
Foreground = Brushes.Black,
FontSize = 8,
Margin = new Thickness(0, 1, 0, 0),
TextAlignment = TextAlignment.Center
};
_panel.Children.Add(textBlock);
// 设置鼠标事件
_panel.MouseDown += Panel_MouseDown;
_panel.MouseUp += Panel_MouseUp;
_panel.MouseLeave += Panel_MouseLeave;
// 右键菜单支持
_panel.ContextMenu = CreateContextMenu();
// 设置工具提示
_panel.ToolTip = "启动台";
LogHelper.WriteLogToFile("启动台按钮创建完成");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"创建启动台按钮时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
/// <summary>
/// 创建右键菜单
/// </summary>
private ContextMenu CreateContextMenu()
{
try
{
// 创建菜单
ContextMenu menu = new ContextMenu();
// 创建位置切换菜单项
MenuItem positionMenuItem = new MenuItem();
positionMenuItem.Header = _plugin.Config.ButtonPosition == LauncherButtonPosition.Left ?
"移至右侧" : "移至左侧";
positionMenuItem.Click += (s, e) =>
{
// 切换位置
_plugin.Config.ButtonPosition = _plugin.Config.ButtonPosition == LauncherButtonPosition.Left ?
LauncherButtonPosition.Right : LauncherButtonPosition.Left;
// 更新按钮位置
_plugin.UpdateButtonPosition();
// 保存配置
_plugin.SaveConfig();
LogHelper.WriteLogToFile($"通过右键菜单切换启动台按钮位置为: {_plugin.Config.ButtonPosition}");
};
menu.Items.Add(positionMenuItem);
// 添加设置菜单项
MenuItem settingsMenuItem = new MenuItem();
settingsMenuItem.Header = "打开设置";
settingsMenuItem.Click += (s, e) =>
{
// 打开插件设置窗口
var mainWindow = Application.Current.MainWindow;
if (mainWindow != null)
{
try
{
// 使用反射调用主窗口的ShowPluginSettings方法
var method = mainWindow.GetType().GetMethod("ShowPluginSettings");
if (method != null)
{
method.Invoke(mainWindow, null);
LogHelper.WriteLogToFile("已打开插件设置窗口");
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"打开插件设置窗口失败: {ex.Message}", LogHelper.LogType.Error);
}
}
};
menu.Items.Add(settingsMenuItem);
return menu;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"创建右键菜单时出错: {ex.Message}", LogHelper.LogType.Error);
return null;
}
}
/// <summary>
/// 获取实际的UI元素
/// </summary>
[Obsolete("使用Element属性代替")]
public UIElement GetUIElement()
{
return _panel;
}
/// <summary>
/// 创建图标图像
/// </summary>
private Image CreateIconImage()
{
try
{
// 创建图像
Image image = new Image
{
Height = 17,
Margin = new Thickness(0, 3, 0, 0)
};
// 设置位图缩放模式
RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);
// 创建绘图图像
DrawingImage drawingImage = new DrawingImage();
DrawingGroup drawingGroup = new DrawingGroup();
drawingGroup.ClipGeometry = Geometry.Parse("M0,0 V24 H24 V0 H0 Z");
// 使用提供的应用网格图标
GeometryDrawing geometryDrawing = new GeometryDrawing
{
Brush = new SolidColorBrush(Color.FromRgb(0x1B, 0x1B, 0x1B)),
Geometry = Geometry.Parse("F0 M24,24z M0,0z M4.41721,4.29873C4.35178,4.29873,4.29873,4.35178,4.29873,4.41721L4.29873,9.15646C4.29873,9.22189,4.35178,9.27494,4.41721,9.27494L9.15646,9.27494C9.22189,9.27494,9.27494,9.22189,9.27494,9.15646L9.27494,4.41721C9.27494,4.35178,9.22189,4.29873,9.15646,4.29873L4.41721,4.29873z M2.64,4.41721C2.64,3.43569,3.43569,2.64,4.41721,2.64L9.15646,2.64C10.138,2.64,10.9337,3.43569,10.9337,4.41721L10.9337,9.15646C10.9337,10.138,10.138,10.9337,9.15646,10.9337L4.41721,10.9337C3.43569,10.9337,2.64,10.138,2.64,9.15646L2.64,4.41721z M14.8435,4.29873C14.7781,4.29873,14.7251,4.35178,14.7251,4.41721L14.7251,9.15646C14.7251,9.22189,14.7781,9.27494,14.8435,9.27494L19.5828,9.27494C19.6482,9.27494,19.7013,9.22189,19.7013,9.15646L19.7013,4.41721C19.7013,4.35178,19.6482,4.29873,19.5828,4.29873L14.8435,4.29873z M13.0663,4.41721C13.0663,3.43569,13.862,2.64,14.8435,2.64L19.5828,2.64C20.5643,2.64,21.36,3.43569,21.36,4.41721L21.36,9.15646C21.36,10.138,20.5643,10.9337,19.5828,10.9337L14.8435,10.9337C13.862,10.9337,13.0663,10.138,13.0663,9.15646L13.0663,4.41721z M14.8435,14.7251C14.7781,14.7251,14.7251,14.7781,14.7251,14.8435L14.7251,19.5828C14.7251,19.6482,14.7781,19.7013,14.8435,19.7013L19.5828,19.7013C19.6482,19.7013,19.7013,19.6482,19.7013,19.5828L19.7013,14.8435C19.7013,14.7781,19.6482,14.7251,19.5828,14.7251L14.8435,14.7251z M13.0663,14.8435C13.0663,13.862,13.862,13.0663,14.8435,13.0663L19.5828,13.0663C20.5643,13.0663,21.36,13.862,21.36,14.8435L21.36,19.5828C21.36,20.5643,20.5643,21.36,19.5828,21.36L14.8435,21.36C13.862,21.36,13.0663,20.5643,13.0663,19.5828L13.0663,14.8435z M4.41721,14.7251C4.35178,14.7251,4.29873,14.7781,4.29873,14.8435L4.29873,19.5828C4.29873,19.6482,4.35178,19.7013,4.41721,19.7013L9.15646,19.7013C9.22189,19.7013,9.27494,19.6482,9.27494,19.5828L9.27494,14.8435C9.27494,14.7781,9.22189,14.7251,9.15646,14.7251L4.41721,14.7251z M2.64,14.8435C2.64,13.862,3.43569,13.0663,4.41721,13.0663L9.15646,13.0663C10.138,13.0663,10.9337,13.862,10.9337,14.8435L10.9337,19.5828C10.9337,20.5643,10.138,21.36,9.15646,21.36L4.41721,21.36C3.43569,21.36,2.64,20.5643,2.64,19.5828L2.64,14.8435z")
};
drawingGroup.Children.Add(geometryDrawing);
// 设置图像源
drawingImage.Drawing = drawingGroup;
image.Source = drawingImage;
return image;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"创建图标图像时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
// 返回一个空图像
return new Image();
}
}
/// <summary>
/// 鼠标按下事件
/// </summary>
private void Panel_MouseDown(object sender, MouseButtonEventArgs e)
{
try
{
// 提供反馈
_panel.Background = new SolidColorBrush(Color.FromArgb(40, 0, 0, 0));
LogHelper.WriteLogToFile("启动台按钮鼠标按下");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动台按钮鼠标按下事件出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 鼠标抬起事件
/// </summary>
private void Panel_MouseUp(object sender, MouseButtonEventArgs e)
{
try
{
// 只有左键点击才显示启动台窗口
if (e.ChangedButton != MouseButton.Left)
{
return;
}
// 恢复背景
_panel.Background = Brushes.Transparent;
LogHelper.WriteLogToFile("启动台按钮鼠标抬起,准备显示启动台窗口");
// 获取按钮在屏幕上的位置
Point buttonPosition = _panel.PointToScreen(new Point(_panel.ActualWidth / 2, 0));
// 显示启动台窗口
_plugin.ShowLauncherWindow(buttonPosition);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动台按钮鼠标抬起事件出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
/// <summary>
/// 鼠标离开事件
/// </summary>
private void Panel_MouseLeave(object sender, MouseEventArgs e)
{
try
{
// 恢复背景
_panel.Background = Brushes.Transparent;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动台按钮鼠标离开事件出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
}
@@ -1,332 +0,0 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
/// <summary>
/// 启动台按钮位置
/// </summary>
public enum LauncherButtonPosition
{
/// <summary>
/// 左侧
/// </summary>
Left,
/// <summary>
/// 右侧
/// </summary>
Right
}
/// <summary>
/// 启动台配置
/// </summary>
public class LauncherConfig
{
/// <summary>
/// 启动台按钮位置
/// </summary>
public LauncherButtonPosition ButtonPosition { get; set; } = LauncherButtonPosition.Right;
/// <summary>
/// 启动台应用程序列表
/// </summary>
public List<LauncherItem> Items { get; set; } = new List<LauncherItem>();
}
/// <summary>
/// 启动台应用项
/// </summary>
public class LauncherItem
{
/// <summary>
/// 应用程序名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 应用程序路径
/// </summary>
public string Path { get; set; }
/// <summary>
/// 是否可见
/// </summary>
public bool IsVisible { get; set; } = true;
/// <summary>
/// 在启动台中的位置(0-39
/// </summary>
public int Position { get; set; } = -1;
/// <summary>
/// 是否已固定位置
/// </summary>
public bool IsPositionFixed { get; set; } = false;
/// <summary>
/// 图标缓存
/// </summary>
[JsonIgnore]
private ImageSource _iconCache;
/// <summary>
/// 获取应用程序图标
/// </summary>
[JsonIgnore]
public ImageSource Icon
{
get
{
if (_iconCache != null)
{
return _iconCache;
}
try
{
if (File.Exists(Path))
{
// 从文件中获取图标
Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(Path);
if (icon != null)
{
_iconCache = Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
icon.Dispose();
return _iconCache;
}
}
else
{
// 从注册表中获取文件类型关联图标
string extension = System.IO.Path.GetExtension(Path);
if (!string.IsNullOrEmpty(extension))
{
string fileType = Registry.ClassesRoot.OpenSubKey(extension)?.GetValue(string.Empty) as string;
if (!string.IsNullOrEmpty(fileType))
{
string iconPath = Registry.ClassesRoot.OpenSubKey(fileType + "\\DefaultIcon")?.GetValue(string.Empty) as string;
if (!string.IsNullOrEmpty(iconPath))
{
string[] parts = iconPath.Split(',');
string iconFile = parts[0].Trim('"');
int iconIndex = parts.Length > 1 ? Convert.ToInt32(parts[1]) : 0;
if (File.Exists(iconFile))
{
Icon icon = IconExtractor.Extract(iconFile, iconIndex, true);
if (icon != null)
{
_iconCache = Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
icon.Dispose();
return _iconCache;
}
}
}
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取应用图标时出错: {ex.Message}", LogHelper.LogType.Error);
}
// 返回默认图标
return GetDefaultIcon();
}
}
/// <summary>
/// 获取默认图标
/// </summary>
private ImageSource GetDefaultIcon()
{
try
{
// 对于资源管理器,使用特定图标
if (Path.EndsWith("explorer.exe", StringComparison.OrdinalIgnoreCase))
{
try
{
// 直接从C:\Windows\explorer.exe获取图标
string explorerPath = @"C:\Windows\explorer.exe";
if (File.Exists(explorerPath))
{
Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(explorerPath);
if (icon != null)
{
_iconCache = Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
icon.Dispose();
return _iconCache;
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取资源管理器图标时出错: {ex.Message}", LogHelper.LogType.Warning);
// 如果获取Windows图标失败,回退到默认图标
}
// 回退到备用图标
string explorerIconPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Icons-Fluent", "ic_fluent_folder_24_regular.png");
if (File.Exists(explorerIconPath))
{
Uri uri = new Uri(explorerIconPath);
BitmapImage image = new BitmapImage(uri);
_iconCache = image;
return _iconCache;
}
}
// 返回一个简单的默认图标
string iconPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Icons-png", "icc.png");
if (File.Exists(iconPath))
{
Uri uri = new Uri(iconPath);
BitmapImage image = new BitmapImage(uri);
_iconCache = image;
return _iconCache;
}
// 如果还是没有找到,尝试使用应用程序图标
string appIconPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Icons-Fluent", "ic_fluent_apps_24_regular.png");
if (File.Exists(appIconPath))
{
Uri uri = new Uri(appIconPath);
BitmapImage image = new BitmapImage(uri);
_iconCache = image;
return _iconCache;
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取默认图标时出错: {ex.Message}", LogHelper.LogType.Error);
}
return null;
}
/// <summary>
/// 启动应用程序
/// </summary>
public void Launch()
{
try
{
if (string.IsNullOrEmpty(Path))
{
LogHelper.WriteLogToFile("无法启动应用程序:路径为空", LogHelper.LogType.Error);
return;
}
// 检查文件是否存在
if (!File.Exists(Path) && !Path.Contains(":\\"))
{
// 可能是系统命令,如explorer.exe
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = Path,
UseShellExecute = true
};
Process.Start(psi);
}
else
{
// 使用Process.Start启动应用程序
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = Path,
UseShellExecute = true
};
Process.Start(psi);
}
LogHelper.WriteLogToFile($"已启动应用程序: {Path}");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动应用程序时出错: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"启动应用程序时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
/// <summary>
/// 图标提取工具类
/// </summary>
public static class IconExtractor
{
/// <summary>
/// 从文件中提取图标
/// </summary>
/// <param name="file">文件路径</param>
/// <param name="index">图标索引</param>
/// <param name="largeIcon">是否提取大图标</param>
/// <returns>提取的图标</returns>
public static Icon Extract(string file, int index, bool largeIcon)
{
try
{
IntPtr large;
IntPtr small;
ExtractIconEx(file, index, out large, out small, 1);
try
{
return Icon.FromHandle(largeIcon ? large : small);
}
catch
{
return null;
}
finally
{
if (large != IntPtr.Zero)
DestroyIcon(large);
if (small != IntPtr.Zero)
DestroyIcon(small);
}
}
catch
{
return null;
}
}
[DllImport("Shell32.dll", EntryPoint = "ExtractIconEx")]
private static extern int ExtractIconEx(
[MarshalAs(UnmanagedType.LPStr)] string lpszFile,
int nIconIndex,
out IntPtr phiconLarge,
out IntPtr phiconSmall,
int nIcons);
[DllImport("User32.dll")]
private static extern int DestroyIcon(IntPtr hIcon);
}
}
@@ -1,143 +0,0 @@
<UserControl x:Class="Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher.LauncherSettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="600">
<UserControl.Resources>
<!-- 自定义按钮样式 -->
<Style x:Key="DefaultButtonStyle" TargetType="Button">
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
TextElement.Foreground="{TemplateBinding Foreground}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Opacity" Value="0.8"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="270" ShadowDepth="2" Opacity="0.3" BlurRadius="4"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="border" Property="Opacity" Value="0.6"/>
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.95" ScaleY="0.95"/>
</Setter.Value>
</Setter>
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.4"/>
<Setter Property="Cursor" Value="Arrow"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 标题 -->
<TextBlock Grid.Row="0" Text="超级启动台设置" FontSize="16" FontWeight="Bold" Margin="0,0,0,15" Foreground="Black"/>
<!-- 基本设置 -->
<StackPanel Grid.Row="1" Margin="0,0,0,15">
<TextBlock Text="基本设置" FontSize="14" FontWeight="SemiBold" Margin="0,0,0,10" Foreground="Black"/>
<Grid Margin="10,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 按钮位置 -->
<TextBlock Grid.Row="0" Grid.Column="0" Text="按钮位置:" VerticalAlignment="Center" Foreground="Black"/>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Margin="0,5">
<RadioButton x:Name="RbtnLeft" Content="浮动栏左侧" Margin="0,0,20,0" Checked="RbtnPosition_Checked" Foreground="Black"/>
<RadioButton x:Name="RbtnRight" Content="浮动栏右侧" IsChecked="True" Checked="RbtnPosition_Checked" Foreground="Black"/>
</StackPanel>
</Grid>
</StackPanel>
<!-- 应用管理 -->
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="应用管理" FontSize="14" FontWeight="SemiBold" Margin="0,0,0,10" Foreground="Black"/>
<Border Grid.Row="1" BorderThickness="1" BorderBrush="#CCCCCC" CornerRadius="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 应用列表 -->
<DataGrid Grid.Row="0" x:Name="DgApps" AutoGenerateColumns="False" Margin="5"
CanUserAddRows="False" CanUserDeleteRows="False"
HeadersVisibility="Column" SelectionMode="Single"
SelectionChanged="DgApps_SelectionChanged">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="显示" Binding="{Binding IsVisible}" Width="50"/>
<DataGridTextColumn Header="名称" Binding="{Binding Name}" Width="150"/>
<DataGridTextColumn Header="路径" Binding="{Binding Path}" Width="*"/>
<DataGridTextColumn Header="位置" Binding="{Binding Position}" Width="50"/>
</DataGrid.Columns>
</DataGrid>
<!-- 操作按钮 -->
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="5">
<Button x:Name="BtnAdd" Content="添加" Padding="10,5" Margin="0,5,5,5" Click="BtnAdd_Click"
Background="#FF007ACC" Foreground="White" BorderBrush="#FF005A9B" BorderThickness="1"
Style="{StaticResource DefaultButtonStyle}"/>
<Button x:Name="BtnEdit" Content="编辑" Padding="10,5" Margin="5" Click="BtnEdit_Click"
Background="#FF6C757D" Foreground="White" BorderBrush="#FF5A6268" BorderThickness="1"
Style="{StaticResource DefaultButtonStyle}"/>
<Button x:Name="BtnDelete" Content="删除" Padding="10,5" Margin="5" Click="BtnDelete_Click"
Background="#FFDC3545" Foreground="White" BorderBrush="#FFBD2130" BorderThickness="1"
Style="{StaticResource DefaultButtonStyle}"/>
</StackPanel>
</Grid>
</Border>
</Grid>
<!-- 底部按钮 -->
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,15,0,0">
<Button x:Name="BtnSave" Content="保存设置" Padding="15,5" Click="BtnSave_Click"
Background="#FF28A745" Foreground="White" BorderBrush="#FF1E7E34" BorderThickness="1"
Style="{StaticResource DefaultButtonStyle}"/>
</StackPanel>
</Grid>
</UserControl>
@@ -1,396 +0,0 @@
using Ink_Canvas.Windows;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
/// <summary>
/// LauncherSettingsControl.xaml 的交互逻辑
/// </summary>
public partial class LauncherSettingsControl : UserControl
{
/// <summary>
/// 父插件
/// </summary>
private readonly SuperLauncherPlugin _plugin;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="plugin">父插件</param>
public LauncherSettingsControl(SuperLauncherPlugin plugin)
{
InitializeComponent();
_plugin = plugin;
// 设置按钮位置
RbtnLeft.IsChecked = _plugin.Config.ButtonPosition == LauncherButtonPosition.Left;
RbtnRight.IsChecked = _plugin.Config.ButtonPosition == LauncherButtonPosition.Right;
// 绑定应用列表
DgApps.ItemsSource = _plugin.LauncherItems;
// 初始化按钮状态
UpdateButtonStates();
}
/// <summary>
/// 更新按钮状态
/// </summary>
private void UpdateButtonStates()
{
bool hasSelection = DgApps.SelectedItem != null;
BtnEdit.IsEnabled = hasSelection;
BtnDelete.IsEnabled = hasSelection;
}
/// <summary>
/// 位置单选按钮选择事件
/// </summary>
private void RbtnPosition_Checked(object sender, RoutedEventArgs e)
{
if (!IsLoaded) return;
LauncherButtonPosition oldPosition = _plugin.Config.ButtonPosition;
if (sender == RbtnLeft)
{
_plugin.Config.ButtonPosition = LauncherButtonPosition.Left;
}
else if (sender == RbtnRight)
{
_plugin.Config.ButtonPosition = LauncherButtonPosition.Right;
}
// 如果位置发生变化,更新按钮位置
if (oldPosition != _plugin.Config.ButtonPosition)
{
try
{
// 更新按钮位置
_plugin.UpdateButtonPosition();
// 保存配置
_plugin.SaveConfig();
LogHelper.WriteLogToFile($"启动台按钮位置已更改为: {_plugin.Config.ButtonPosition}");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"更新启动台按钮位置时出错: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"更新启动台按钮位置时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
/// <summary>
/// 添加按钮点击事件
/// </summary>
private void BtnAdd_Click(object sender, RoutedEventArgs e)
{
try
{
// 创建新的启动项
LauncherItem item = new LauncherItem
{
Name = "",
Path = "",
IsVisible = true,
Position = -1 // 让插件管理器分配位置
};
// 直接显示编辑对话框
EditLauncherItem(item, true);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"添加启动项时出错: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"添加启动项时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary>
/// 编辑应用按钮点击事件
/// </summary>
private void BtnEdit_Click(object sender, RoutedEventArgs e)
{
if (DgApps.SelectedItem is LauncherItem item)
{
EditLauncherItem(item, false);
}
}
/// <summary>
/// 删除应用按钮点击事件
/// </summary>
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
if (DgApps.SelectedItem is LauncherItem item)
{
// 确认删除
MessageBoxResult result = MessageBox.Show(
$"确定要删除 {item.Name} 吗?",
"删除确认",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
// 从集合中移除
_plugin.LauncherItems.Remove(item);
// 保存配置
_plugin.SaveConfig();
}
}
}
/// <summary>
/// 保存设置按钮点击事件
/// </summary>
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
try
{
// 保存配置
_plugin.SaveConfig();
// 如果插件已启用,重新加载启动台按钮
if (_plugin.IsEnabled)
{
_plugin.Disable();
_plugin.Enable();
}
else
{
// 如果插件未启用,则启用它
_plugin.Enable();
// 通知PluginSettingsWindow刷新插件列表
var window = Window.GetWindow(this);
if (window is PluginSettingsWindow pluginSettingsWindow)
{
// 触发刷新
pluginSettingsWindow.RefreshPluginList();
}
}
MessageBox.Show("设置已保存并应用!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存设置时出错: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"保存设置时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary>
/// 应用项选择变更事件
/// </summary>
private void DgApps_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
UpdateButtonStates();
}
/// <summary>
/// 编辑启动项
/// </summary>
/// <param name="item">启动项</param>
/// <param name="isNew">是否为新建</param>
private void EditLauncherItem(LauncherItem item, bool isNew)
{
// 创建简单的编辑窗口
Window editWindow = new Window
{
Title = isNew ? "添加" : "编辑应用",
Width = 400,
Height = 200,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
ResizeMode = ResizeMode.NoResize
};
// 创建编辑表单
Grid grid = new Grid
{
Margin = new Thickness(20)
};
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(80) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
// 名称输入框
TextBlock nameLabel = new TextBlock
{
Text = "名称:",
VerticalAlignment = VerticalAlignment.Center
};
TextBox nameTextBox = new TextBox
{
Text = item.Name,
Margin = new Thickness(0, 5, 0, 5)
};
Grid.SetRow(nameLabel, 0);
Grid.SetColumn(nameLabel, 0);
Grid.SetRow(nameTextBox, 0);
Grid.SetColumn(nameTextBox, 1);
grid.Children.Add(nameLabel);
grid.Children.Add(nameTextBox);
// 路径输入框
TextBlock pathLabel = new TextBlock
{
Text = "路径:",
VerticalAlignment = VerticalAlignment.Center
};
Grid pathGrid = new Grid();
pathGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
pathGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength() });
TextBox pathTextBox = new TextBox
{
Text = item.Path,
Margin = new Thickness(0, 5, 5, 5)
};
Button browseButton = new Button
{
Content = "浏览",
Padding = new Thickness(5, 0, 5, 0),
Margin = new Thickness(0, 5, 0, 5)
};
browseButton.Click += (s, e) =>
{
OpenFileDialog dialog = new OpenFileDialog
{
Title = "选择应用程序",
Filter = "应用程序 (*.exe)|*.exe|所有文件 (*.*)|*.*",
Multiselect = false,
FileName = pathTextBox.Text
};
if (dialog.ShowDialog() == true)
{
pathTextBox.Text = dialog.FileName;
// 如果选择的是.exe文件,自动获取文件名填入名称字段
if (Path.GetExtension(dialog.FileName).ToLower() == ".exe")
{
string fileName = Path.GetFileNameWithoutExtension(dialog.FileName);
// 只有在名称字段为空或者是新建项目时才自动填入
if (string.IsNullOrWhiteSpace(nameTextBox.Text) || isNew)
{
nameTextBox.Text = fileName;
}
}
}
};
Grid.SetColumn(pathTextBox, 0);
Grid.SetColumn(browseButton, 1);
pathGrid.Children.Add(pathTextBox);
pathGrid.Children.Add(browseButton);
Grid.SetRow(pathLabel, 1);
Grid.SetColumn(pathLabel, 0);
Grid.SetRow(pathGrid, 1);
Grid.SetColumn(pathGrid, 1);
grid.Children.Add(pathLabel);
grid.Children.Add(pathGrid);
// 确认和取消按钮
StackPanel buttonPanel = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Margin = new Thickness(0, 10, 0, 0)
};
Button okButton = new Button
{
Content = "确定",
Padding = new Thickness(15, 5, 15, 5),
Margin = new Thickness(0, 0, 10, 0),
IsDefault = true
};
Button cancelButton = new Button
{
Content = "取消",
Padding = new Thickness(15, 5, 15, 5),
IsCancel = true
};
okButton.Click += (s, e) =>
{
// 验证输入
if (string.IsNullOrWhiteSpace(nameTextBox.Text))
{
MessageBox.Show("请输入应用名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (string.IsNullOrWhiteSpace(pathTextBox.Text))
{
MessageBox.Show("请输入应用路径!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// 更新项目
item.Name = nameTextBox.Text;
item.Path = pathTextBox.Text;
// 如果是新建,添加到集合
if (isNew)
{
_plugin.AddLauncherItem(item);
}
else
{
// 触发属性变更通知,刷新DataGrid
if (DgApps.ItemsSource is ICollectionView view)
{
view.Refresh();
}
// 保存配置
_plugin.SaveConfig();
}
editWindow.DialogResult = true;
editWindow.Close();
};
cancelButton.Click += (s, e) =>
{
editWindow.DialogResult = false;
editWindow.Close();
};
buttonPanel.Children.Add(okButton);
buttonPanel.Children.Add(cancelButton);
Grid.SetRow(buttonPanel, 2);
Grid.SetColumnSpan(buttonPanel, 2);
grid.Children.Add(buttonPanel);
// 设置窗口内容
editWindow.Content = grid;
// 显示窗口
editWindow.ShowDialog();
}
}
}
@@ -1,91 +0,0 @@
<Window x:Class="Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher.LauncherWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher"
mc:Ignorable="d"
Title="启动台"
Width="400"
Height="300"
WindowStyle="None"
AllowsTransparency="True"
Background="#80000000"
ResizeMode="NoResize"
Topmost="True"
Deactivated="Window_Deactivated"
ShowInTaskbar="False">
<Window.Resources>
<!-- 应用项样式 -->
<Style x:Key="LauncherItemStyle" TargetType="Button">
<Setter Property="Width" Value="80"/>
<Setter Property="Height" Value="80"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Background" Value="#40FFFFFF"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding Icon}" Width="32" Height="32" Margin="0,10,0,5"/>
<TextBlock Grid.Row="1" Text="{Binding Name}" TextWrapping="Wrap" TextAlignment="Center"
Margin="2,0,2,8" FontSize="11" Foreground="White"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#80FFFFFF"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#C0FFFFFF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Border CornerRadius="15" Background="#80000000" BorderThickness="1" BorderBrush="#40FFFFFF">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- 标题栏 -->
<Grid Grid.Row="0" Height="40">
<TextBlock Text="启动台" Foreground="White" FontSize="18" FontWeight="Bold"
VerticalAlignment="Center" Margin="15,0,0,0"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,10,0">
<Button x:Name="BtnFixMode" Click="BtnFixMode_Click" Width="30" Height="30"
Margin="5,0" Background="Transparent" BorderThickness="0"
ToolTip="切换固定模式">
<Path x:Name="FixModeIcon" Data="M7,2V13H10V22L17,10H13L17,2H7Z" Fill="White" Stretch="Uniform" Width="16" Height="16"/>
</Button>
<Button x:Name="BtnClose" Click="BtnClose_Click" Width="30" Height="30"
Background="Transparent" BorderThickness="0"
ToolTip="关闭">
<Path Data="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"
Fill="White" Stretch="Uniform" Width="16" Height="16"/>
</Button>
</StackPanel>
</Grid>
<!-- 应用网格 -->
<ScrollViewer Grid.Row="1" Margin="10" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<WrapPanel x:Name="AppPanel" Orientation="Horizontal" HorizontalAlignment="Center"/>
</ScrollViewer>
</Grid>
</Border>
</Window>
@@ -1,466 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
{
/// <summary>
/// LauncherWindow.xaml 的交互逻辑
/// </summary>
public partial class LauncherWindow : Window
{
/// <summary>
/// 父插件
/// </summary>
private readonly SuperLauncherPlugin _plugin;
/// <summary>
/// 是否处于固定模式
/// </summary>
private bool _isFixMode;
/// <summary>
/// 应用项按钮列表
/// </summary>
private readonly Dictionary<Button, LauncherItem> _appButtons = new Dictionary<Button, LauncherItem>();
/// <summary>
/// 拖拽中的按钮
/// </summary>
private Button _draggingButton;
/// <summary>
/// 拖拽开始位置
/// </summary>
private Point _dragStartPoint;
/// <summary>
/// 构造函数
/// </summary>
public LauncherWindow(SuperLauncherPlugin plugin)
{
InitializeComponent();
_plugin = plugin;
// 加载应用项
LoadLauncherItems();
// 添加鼠标按下事件(用于拖动窗口)
MouseDown += (s, e) =>
{
if (e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed)
{
DragMove();
}
};
// 根据应用数量调整窗口大小
AdjustWindowSize();
}
/// <summary>
/// 加载启动台应用项
/// </summary>
private void LoadLauncherItems()
{
// 清空现有应用项
AppPanel.Children.Clear();
_appButtons.Clear();
// 获取显示的应用项
var visibleItems = _plugin.LauncherItems
.Where(item => item.IsVisible)
.OrderBy(item => item.Position)
.ToList();
foreach (var item in visibleItems)
{
// 创建应用按钮
Button appButton = new Button
{
Style = (Style)FindResource("LauncherItemStyle"),
DataContext = item,
Tag = item.Position
};
// 添加点击事件
appButton.Click += AppButton_Click;
// 在固定模式下,添加拖拽事件
appButton.PreviewMouseDown += AppButton_PreviewMouseDown;
appButton.PreviewMouseMove += AppButton_PreviewMouseMove;
appButton.PreviewMouseUp += AppButton_PreviewMouseUp;
// 记录按钮和项目的对应关系
_appButtons.Add(appButton, item);
// 添加到面板
AppPanel.Children.Add(appButton);
}
}
/// <summary>
/// 根据应用数量调整窗口大小
/// </summary>
private void AdjustWindowSize()
{
try
{
// 每行最多显示4个应用
const int appsPerRow = 4;
// 计算行数
int visibleCount = _appButtons.Count;
int rowCount = (int)Math.Ceiling(visibleCount / (double)appsPerRow);
// 设置窗口宽度(每个应用90像素宽 = 80 + 5*2
Width = Math.Min(appsPerRow * 90 + 40, 400); // 最大宽度400
// 设置窗口高度(每个应用90像素高 = 80 + 5*2
Height = Math.Min(rowCount * 90 + 60, 600); // 最大高度600,标题栏40 + 边距20
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"调整启动台窗口大小时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 应用按钮点击事件
/// </summary>
private void AppButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (_isFixMode) return; // 在固定模式下,不响应点击事件
if (sender is Button button && _appButtons.TryGetValue(button, out LauncherItem item))
{
// 获取应用路径和名称,用于后续启动
string appPath = item.Path;
string appName = item.Name;
LogHelper.WriteLogToFile($"点击启动应用: {appName}, 路径: {appPath}");
// 首先标记窗口正在关闭
IsClosing = true;
// 创建一个应用启动任务
var launchTask = new Task(() =>
{
try
{
// 等待一段时间,确保窗口关闭流程已经开始
Thread.Sleep(200);
// 使用UI线程启动应用
Application.Current.Dispatcher.Invoke(() =>
{
try
{
// 检查应用路径是否存在
if (File.Exists(appPath) || !appPath.Contains(":\\"))
{
// 创建进程启动信息
var psi = new ProcessStartInfo
{
FileName = appPath,
UseShellExecute = true,
};
// 启动应用程序
var process = Process.Start(psi);
LogHelper.WriteLogToFile($"应用程序 {appName} 已启动");
}
else
{
LogHelper.WriteLogToFile($"应用路径不存在: {appPath}", LogHelper.LogType.Error);
MessageBox.Show($"找不到应用程序: {appPath}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动应用程序失败: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"启动应用程序失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
});
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用启动任务出错: {ex.Message}", LogHelper.LogType.Error);
}
});
// 关闭窗口
try
{
Dispatcher.BeginInvoke(new Action(() =>
{
try { Close(); } catch { }
// 启动应用程序任务
launchTask.Start();
}), DispatcherPriority.Background);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"关闭窗口或启动任务时出错: {ex.Message}", LogHelper.LogType.Error);
// 如果无法通过UI关闭窗口,直接启动任务
launchTask.Start();
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用按钮点击事件出错: {ex.Message}", LogHelper.LogType.Error);
try { IsClosing = true; Close(); } catch { }
}
}
#region
/// <summary>
/// 应用按钮鼠标按下事件
/// </summary>
private void AppButton_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (!_isFixMode) return;
if (e.ChangedButton == MouseButton.Left && sender is Button button)
{
_draggingButton = button;
_dragStartPoint = e.GetPosition(AppPanel);
button.CaptureMouse();
button.Opacity = 0.7;
// 阻止事件冒泡,以避免触发按钮点击
e.Handled = true;
}
}
/// <summary>
/// 应用按钮鼠标移动事件
/// </summary>
private void AppButton_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (!_isFixMode || _draggingButton == null) return;
if (e.LeftButton == MouseButtonState.Pressed)
{
Point currentPosition = e.GetPosition(AppPanel);
// 移动按钮
System.Windows.Controls.Canvas.SetLeft(_draggingButton, currentPosition.X - _draggingButton.ActualWidth / 2);
System.Windows.Controls.Canvas.SetTop(_draggingButton, currentPosition.Y - _draggingButton.ActualHeight / 2);
// 将按钮移到最上层
Panel.SetZIndex(_draggingButton, 100);
// 阻止事件冒泡
e.Handled = true;
}
}
/// <summary>
/// 应用按钮鼠标释放事件
/// </summary>
private void AppButton_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (!_isFixMode || _draggingButton == null) return;
// 释放鼠标捕获
_draggingButton.ReleaseMouseCapture();
// 计算新位置
Point releasePoint = e.GetPosition(AppPanel);
int newPosition = CalculateGridPosition(releasePoint);
// 获取当前项目
LauncherItem currentItem = _appButtons[_draggingButton];
// 重新排序
ReorderItems(currentItem, newPosition);
// 重新加载应用项
LoadLauncherItems();
// 保存配置
_plugin.SaveConfig();
// 清除拖拽状态
_draggingButton.Opacity = 1;
Panel.SetZIndex(_draggingButton, 0);
_draggingButton = null;
// 阻止事件冒泡
e.Handled = true;
}
/// <summary>
/// 计算网格位置
/// </summary>
private int CalculateGridPosition(Point point)
{
// 计算行和列
int columnCount = 4; // 每行最多4个应用
int columnWidth = 90; // 应用宽度(包括边距)
int rowHeight = 90; // 应用高度(包括边距)
int column = (int)(point.X / columnWidth);
int row = (int)(point.Y / rowHeight);
// 确保在有效范围内
column = Math.Max(0, Math.Min(column, columnCount - 1));
row = Math.Max(0, row);
// 计算位置索引
return row * columnCount + column;
}
/// <summary>
/// 重新排序应用项
/// </summary>
private void ReorderItems(LauncherItem item, int newPosition)
{
try
{
// 设置项目为固定位置
item.IsPositionFixed = true;
// 如果位置相同,无需调整
if (item.Position == newPosition)
{
return;
}
// 获取所有可见项目
var visibleItems = _plugin.LauncherItems
.Where(i => i.IsVisible)
.OrderBy(i => i.Position)
.ToList();
// 移除当前项目
visibleItems.Remove(item);
// 查找插入位置
int insertIndex = 0;
for (int i = 0; i < visibleItems.Count; i++)
{
if (visibleItems[i].Position >= newPosition)
{
insertIndex = i;
break;
}
insertIndex = i + 1;
}
// 插入项目
visibleItems.Insert(insertIndex, item);
// 重新分配位置
for (int i = 0; i < visibleItems.Count; i++)
{
visibleItems[i].Position = i;
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"重新排序应用项时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#endregion
#region
/// <summary>
/// 窗口失去焦点事件
/// </summary>
private void Window_Deactivated(object sender, EventArgs e)
{
try
{
// 只有在非固定模式、窗口已加载、未处于关闭状态且IsLoaded=true时关闭窗口
if (!_isFixMode && IsLoaded && !IsClosing)
{
// 标记为正在关闭
IsClosing = true;
// 使用Dispatcher.BeginInvoke而不是直接调用Close,避免冲突
Dispatcher.BeginInvoke(new Action(() =>
{
try
{
// 再次检查窗口状态
if (IsLoaded && !IsClosing)
{
Close();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"延迟关闭窗口时出错: {ex.Message}", LogHelper.LogType.Error);
}
}), DispatcherPriority.Background);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"窗口失去焦点关闭时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 窗口是否正在关闭
/// </summary>
private bool IsClosing { get; set; }
/// <summary>
/// 重写OnClosing方法,标记窗口正在关闭
/// </summary>
protected override void OnClosing(CancelEventArgs e)
{
IsClosing = true;
base.OnClosing(e);
}
/// <summary>
/// 关闭按钮点击事件
/// </summary>
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
Close();
}
/// <summary>
/// 固定模式按钮点击事件
/// </summary>
private void BtnFixMode_Click(object sender, RoutedEventArgs e)
{
// 切换固定模式
_isFixMode = !_isFixMode;
// 更新固定模式按钮图标颜色
FixModeIcon.Fill = _isFixMode ? Brushes.Yellow : Brushes.White;
// 显示提示
if (_isFixMode)
{
MessageBox.Show("已进入固定模式,您可以拖动应用图标调整位置。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
#endregion
}
}
@@ -1,589 +0,0 @@
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Ink_Canvas.Helpers.Plugins.BuiltIn
{
/// <summary>
/// 超级启动台插件
/// </summary>
public class SuperLauncherPlugin : PluginBase
{
#region
public override string Name => "超级启动台";
public override string Description => "在浮动栏添加一个启动台按钮,可快速启动常用应用程序。";
public override Version Version => new Version(1, 0, 1);
public override string Author => "ICC CE 团队";
public override bool IsBuiltIn => true;
#endregion
#region
/// <summary>
/// 启动台配置
/// </summary>
public LauncherConfig Config { get; private set; }
/// <summary>
/// 启动台应用程序列表
/// </summary>
public ObservableCollection<LauncherItem> LauncherItems { get; private set; }
/// <summary>
/// 启动台按钮
/// </summary>
private LauncherButton _launcherButton;
/// <summary>
/// 启动台窗口
/// </summary>
private LauncherWindow _launcherWindow;
/// <summary>
/// 配置文件路径
/// </summary>
private readonly string _configPath = Path.Combine(App.RootPath, "PluginConfigs", "SuperLauncher.json");
/// <summary>
/// 标记是否已添加到浮动栏
/// </summary>
private bool _isAddedToFloatingBar;
#endregion
#region
public override void Initialize()
{
try
{
base.Initialize();
// 创建配置目录
string configDir = Path.Combine(App.RootPath, "PluginConfigs");
if (!Directory.Exists(configDir))
{
Directory.CreateDirectory(configDir);
}
// 加载配置
LoadConfig();
LogHelper.WriteLogToFile("超级启动台插件已初始化");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"初始化超级启动台插件时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
public override void Enable()
{
try
{
if (IsEnabled) return; // 防止重复启用
// 创建启动台按钮
if (_launcherButton == null)
{
_launcherButton = new LauncherButton(this);
LogHelper.WriteLogToFile("超级启动台按钮已创建");
}
// 添加启动台按钮到浮动栏
AddLauncherButtonToFloatingBar();
// 设置启用状态
base.Enable();
// 保存插件配置
SavePluginSettings();
LogHelper.WriteLogToFile("超级启动台插件已启用");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启用超级启动台插件时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
public override void Disable()
{
try
{
if (!IsEnabled) return; // 防止重复禁用
// 从浮动栏移除启动台按钮
RemoveLauncherButtonFromFloatingBar();
// 如果启动台窗口打开,则关闭
if (_launcherWindow != null && _launcherWindow.IsVisible)
{
_launcherWindow.Close();
_launcherWindow = null;
}
// 设置禁用状态
base.Disable();
// 保存插件配置
SavePluginSettings();
LogHelper.WriteLogToFile("超级启动台插件已禁用");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"禁用超级启动台插件时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
public override UserControl GetSettingsView()
{
return new LauncherSettingsControl(this);
}
public override void Cleanup()
{
// 保存配置
SaveConfig();
// 从浮动栏移除启动台按钮
RemoveLauncherButtonFromFloatingBar();
// 如果启动台窗口打开,则关闭
if (_launcherWindow != null && _launcherWindow.IsVisible)
{
_launcherWindow.Close();
_launcherWindow = null;
}
base.Cleanup();
}
/// <summary>
/// 保存插件设置
/// </summary>
public override void SavePluginSettings()
{
try
{
// 确保配置已加载
if (Config == null)
{
LoadConfig();
}
// 更新其他设置,但不更改插件启用状态
// 保存配置
SaveConfig();
LogHelper.WriteLogToFile("超级启动台插件设置已保存");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存超级启动台插件设置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#endregion
#region
/// <summary>
/// 加载配置
/// </summary>
private void LoadConfig()
{
try
{
if (File.Exists(_configPath))
{
string json = File.ReadAllText(_configPath);
Config = JsonConvert.DeserializeObject<LauncherConfig>(json) ?? CreateDefaultConfig();
LauncherItems = new ObservableCollection<LauncherItem>(Config.Items ?? new List<LauncherItem>());
// 注意:不再根据配置更改插件启用状态
// 插件状态由PluginManager统一管理
}
else
{
Config = CreateDefaultConfig();
LauncherItems = new ObservableCollection<LauncherItem>(Config.Items);
SaveConfig();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"加载超级启动台配置时出错: {ex.Message}", LogHelper.LogType.Error);
Config = CreateDefaultConfig();
LauncherItems = new ObservableCollection<LauncherItem>(Config.Items);
}
}
/// <summary>
/// 保存配置
/// </summary>
public void SaveConfig()
{
try
{
// 同步LauncherItems到Config
Config.Items = new List<LauncherItem>(LauncherItems);
// 序列化并保存配置
string json = JsonConvert.SerializeObject(Config, Formatting.Indented);
File.WriteAllText(_configPath, json);
LogHelper.WriteLogToFile("超级启动台配置已保存");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存超级启动台配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 创建默认配置
/// </summary>
private LauncherConfig CreateDefaultConfig()
{
var config = new LauncherConfig
{
ButtonPosition = LauncherButtonPosition.Right,
// 不再使用IsEnabled,插件状态由PluginManager管理
Items = new List<LauncherItem>
{
new LauncherItem
{
Name = "资源管理器",
Path = @"C:\Windows\explorer.exe",
IsVisible = true,
Position = 0
}
}
};
return config;
}
#endregion
#region
/// <summary>
/// 将启动台按钮添加到浮动栏
/// </summary>
private void AddLauncherButtonToFloatingBar()
{
try
{
// 如果已经添加,先移除
if (_isAddedToFloatingBar)
{
RemoveLauncherButtonFromFloatingBar();
_isAddedToFloatingBar = false;
}
// 获取主窗口实例
var mainWindow = Application.Current.MainWindow;
if (mainWindow == null)
{
LogHelper.WriteLogToFile("未找到主窗口实例,无法添加启动台按钮", LogHelper.LogType.Error);
return;
}
// 创建启动台按钮
_launcherButton = new LauncherButton(this);
var buttonElement = _launcherButton.Element;
// 查找浮动栏
var floatingBar = mainWindow.FindName("StackPanelFloatingBar") as Panel;
if (floatingBar == null)
{
// 如果直接查找失败,则尝试遍历可视树查找
Panel floatingBarPanelFromTree = null;
FindStackPanelFloatingBar(mainWindow, ref floatingBarPanelFromTree);
floatingBar = floatingBarPanelFromTree;
}
if (floatingBar == null)
{
LogHelper.WriteLogToFile("未找到浮动栏,无法添加启动台按钮", LogHelper.LogType.Error);
return;
}
// 添加启动台按钮到浮动栏
if (Config.ButtonPosition == LauncherButtonPosition.Left)
{
floatingBar.Children.Insert(0, buttonElement);
LogHelper.WriteLogToFile("启动台按钮已添加到浮动栏左侧");
}
else
{
floatingBar.Children.Add(buttonElement);
LogHelper.WriteLogToFile("启动台按钮已添加到浮动栏右侧");
}
_isAddedToFloatingBar = true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"添加启动台按钮到浮动栏时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
/// <summary>
/// 递归查找StackPanelFloatingBar
/// </summary>
private void FindStackPanelFloatingBar(DependencyObject parent, ref Panel result)
{
if (parent == null || result != null) return;
try
{
// 检查当前对象是否为我们要找的面板
if (parent is Panel panel && panel.Name == "StackPanelFloatingBar")
{
result = panel;
return;
}
// 获取子元素数量
int childCount = VisualTreeHelper.GetChildrenCount(parent);
// 遍历所有子元素
for (int i = 0; i < childCount; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
FindStackPanelFloatingBar(child, ref result);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"查找StackPanelFloatingBar时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 从浮动栏移除启动台按钮
/// </summary>
private void RemoveLauncherButtonFromFloatingBar()
{
try
{
if (!_isAddedToFloatingBar || _launcherButton == null)
{
return;
}
// 获取主窗口实例
var mainWindow = Application.Current.MainWindow;
if (mainWindow == null)
{
LogHelper.WriteLogToFile("未找到主窗口实例,无法移除启动台按钮", LogHelper.LogType.Error);
return;
}
// 获取按钮元素
var buttonElement = _launcherButton.Element;
// 查找浮动栏
var floatingBar = mainWindow.FindName("StackPanelFloatingBar") as Panel;
if (floatingBar == null)
{
// 如果直接查找失败,则尝试遍历可视树查找
Panel floatingBarPanelFromTree = null;
FindStackPanelFloatingBar(mainWindow, ref floatingBarPanelFromTree);
floatingBar = floatingBarPanelFromTree;
}
if (floatingBar == null)
{
LogHelper.WriteLogToFile("未找到浮动栏,无法移除启动台按钮", LogHelper.LogType.Error);
return;
}
// 从浮动栏移除启动台按钮
if (floatingBar.Children.Contains(buttonElement))
{
floatingBar.Children.Remove(buttonElement);
LogHelper.WriteLogToFile("启动台按钮已从浮动栏移除");
}
_isAddedToFloatingBar = false;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"移除启动台按钮时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
/// <summary>
/// 更新启动台按钮位置
/// </summary>
public void UpdateButtonPosition()
{
try
{
// 如果按钮已添加到浮动栏,重新添加以更新位置
if (_isAddedToFloatingBar)
{
RemoveLauncherButtonFromFloatingBar();
AddLauncherButtonToFloatingBar();
LogHelper.WriteLogToFile($"启动台按钮位置已更新为: {Config.ButtonPosition}");
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"更新启动台按钮位置时出错: {ex.Message}", LogHelper.LogType.Error);
LogHelper.NewLog(ex);
}
}
#endregion
#region
/// <summary>
/// 显示启动台窗口
/// </summary>
/// <param name="buttonPosition">按钮在屏幕上的位置</param>
public void ShowLauncherWindow(Point buttonPosition)
{
try
{
// 如果窗口已存在,关闭它
if (_launcherWindow != null && _launcherWindow.IsVisible)
{
_launcherWindow.Close();
_launcherWindow = null;
return;
}
// 创建新的启动台窗口
_launcherWindow = new LauncherWindow(this);
// 计算窗口位置,使其位于按钮上方
PositionLauncherWindow(_launcherWindow, buttonPosition);
// 显示窗口
_launcherWindow.Show();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"显示启动台窗口时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 设置启动台窗口位置
/// </summary>
/// <param name="window">启动台窗口</param>
/// <param name="buttonPosition">按钮在屏幕上的位置</param>
private void PositionLauncherWindow(LauncherWindow window, Point buttonPosition)
{
// 确保窗口已加载
if (window.ActualWidth == 0 || window.ActualHeight == 0)
{
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
// 设置窗口加载完成后的位置
window.Loaded += (s, e) =>
{
// 窗口位于按钮上方居中
double left = buttonPosition.X - (window.ActualWidth / 2);
double top = buttonPosition.Y - window.ActualHeight - 10; // 在按钮上方留出一些间距
// 确保窗口在屏幕内
left = Math.Max(0, Math.Min(left, SystemParameters.WorkArea.Width - window.ActualWidth));
top = Math.Max(0, Math.Min(top, SystemParameters.WorkArea.Height - window.ActualHeight));
window.Left = left;
window.Top = top;
};
}
else
{
// 窗口位于按钮上方居中
double left = buttonPosition.X - (window.ActualWidth / 2);
double top = buttonPosition.Y - window.ActualHeight - 10; // 在按钮上方留出一些间距
// 确保窗口在屏幕内
left = Math.Max(0, Math.Min(left, SystemParameters.WorkArea.Width - window.ActualWidth));
top = Math.Max(0, Math.Min(top, SystemParameters.WorkArea.Height - window.ActualHeight));
window.Left = left;
window.Top = top;
}
}
/// <summary>
/// 添加应用到启动台
/// </summary>
/// <param name="item">启动台项</param>
public void AddLauncherItem(LauncherItem item)
{
// 如果项目数量已达上限,则不添加
if (LauncherItems.Count >= 40)
{
MessageBox.Show("启动台项目数量已达上限(40个)!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 寻找合适的位置
if (item.Position < 0)
{
item.Position = FindNextAvailablePosition();
}
// 添加项目并保存配置
LauncherItems.Add(item);
SaveConfig();
}
/// <summary>
/// 查找下一个可用位置
/// </summary>
private int FindNextAvailablePosition()
{
// 获取已使用的位置列表
var usedPositions = new HashSet<int>();
foreach (var item in LauncherItems)
{
usedPositions.Add(item.Position);
}
// 查找第一个可用位置
for (int i = 0; i < 40; i++)
{
if (!usedPositions.Contains(i))
{
return i;
}
}
// 如果所有位置都已使用,则返回0
return 0;
}
#endregion
}
}
@@ -1,92 +0,0 @@
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 增强的插件基类,提供对插件服务的访问和基本实现
/// </summary>
public abstract class EnhancedPluginBase : PluginBase, IEnhancedPlugin
{
/// <summary>
/// 插件服务实例
/// </summary>
public IPluginService PluginService { get; private set; }
/// <summary>
/// 构造函数
/// </summary>
protected EnhancedPluginBase()
{
PluginService = PluginServiceManager.Instance;
}
/// <summary>
/// 插件启动时调用,在Initialize之后
/// </summary>
public virtual void OnStartup()
{
LogHelper.WriteLogToFile($"插件 {Name} 已启动");
}
/// <summary>
/// 插件关闭时调用,在Cleanup之前
/// </summary>
public virtual void OnShutdown()
{
LogHelper.WriteLogToFile($"插件 {Name} 正在关闭");
}
/// <summary>
/// 获取插件的菜单项
/// </summary>
/// <returns>菜单项集合</returns>
public virtual MenuItem[] GetMenuItems()
{
return new MenuItem[0];
}
/// <summary>
/// 获取插件的工具栏按钮
/// </summary>
/// <returns>工具栏按钮集合</returns>
public virtual Button[] GetToolbarButtons()
{
return new Button[0];
}
/// <summary>
/// 获取插件的状态栏信息
/// </summary>
/// <returns>状态栏信息</returns>
public virtual string GetStatusBarInfo()
{
return $"{Name} v{Version} - {(IsEnabled ? "" : "")}";
}
/// <summary>
/// 插件配置变更时调用
/// </summary>
public virtual void OnConfigurationChanged()
{
LogHelper.WriteLogToFile($"插件 {Name} 配置已变更");
}
/// <summary>
/// 重写初始化方法,调用OnStartup
/// </summary>
public override void Initialize()
{
base.Initialize();
OnStartup();
}
/// <summary>
/// 重写清理方法,调用OnShutdown
/// </summary>
public override void Cleanup()
{
OnShutdown();
base.Cleanup();
}
}
}
@@ -1,241 +0,0 @@
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 增强的插件基类 V2,提供对三个专门服务接口的访问
/// 插件开发者可以根据需要选择性地使用这些服务
/// </summary>
public abstract class EnhancedPluginBaseV2 : PluginBase, IEnhancedPlugin
{
/// <summary>
/// 获取服务实例
/// </summary>
public IGetService GetService { get; private set; }
/// <summary>
/// 窗口服务实例
/// </summary>
public IWindowService WindowService { get; private set; }
/// <summary>
/// 操作服务实例
/// </summary>
public IActionService ActionService { get; private set; }
/// <summary>
/// 插件服务实例(兼容性)
/// </summary>
public IPluginService PluginService { get; private set; }
/// <summary>
/// 构造函数
/// </summary>
protected EnhancedPluginBaseV2()
{
// 初始化所有服务实例
PluginService = PluginServiceManager.Instance;
GetService = PluginServiceManager.Instance;
WindowService = PluginServiceManager.Instance;
ActionService = PluginServiceManager.Instance;
}
/// <summary>
/// 插件启动时调用,在Initialize之后
/// </summary>
public virtual void OnStartup()
{
LogHelper.WriteLogToFile($"插件 {Name} 已启动");
}
/// <summary>
/// 插件关闭时调用,在Cleanup之前
/// </summary>
public virtual void OnShutdown()
{
LogHelper.WriteLogToFile($"插件 {Name} 正在关闭");
}
/// <summary>
/// 获取插件的菜单项
/// </summary>
/// <returns>菜单项集合</returns>
public virtual MenuItem[] GetMenuItems()
{
return new MenuItem[0];
}
/// <summary>
/// 获取插件的工具栏按钮
/// </summary>
/// <returns>工具栏按钮集合</returns>
public virtual Button[] GetToolbarButtons()
{
return new Button[0];
}
/// <summary>
/// 获取插件的状态栏信息
/// </summary>
/// <returns>状态栏信息</returns>
public virtual string GetStatusBarInfo()
{
return $"{Name} v{Version} - {(IsEnabled ? "" : "")}";
}
/// <summary>
/// 插件配置变更时调用
/// </summary>
public virtual void OnConfigurationChanged()
{
LogHelper.WriteLogToFile($"插件 {Name} 配置已变更");
}
#region 便
/// <summary>
/// 显示通知消息
/// </summary>
/// <param name="message">消息内容</param>
/// <param name="type">消息类型</param>
protected void ShowNotification(string message, NotificationType type = NotificationType.Info)
{
WindowService.ShowNotification(message, type);
}
/// <summary>
/// 显示确认对话框
/// </summary>
/// <param name="message">消息内容</param>
/// <param name="title">标题</param>
/// <returns>用户选择结果</returns>
protected bool ShowConfirmDialog(string message, string title = "确认")
{
return WindowService.ShowConfirmDialog(message, title);
}
/// <summary>
/// 显示输入对话框
/// </summary>
/// <param name="message">提示消息</param>
/// <param name="title">标题</param>
/// <param name="defaultValue">默认值</param>
/// <returns>用户输入内容</returns>
protected string ShowInputDialog(string message, string title = "输入", string defaultValue = "")
{
return WindowService.ShowInputDialog(message, title, defaultValue);
}
/// <summary>
/// 获取系统设置
/// </summary>
/// <typeparam name="T">设置类型</typeparam>
/// <param name="key">设置键</param>
/// <param name="defaultValue">默认值</param>
/// <returns>设置值</returns>
protected T GetSetting<T>(string key, T defaultValue = default(T))
{
return GetService.GetSetting(key, defaultValue);
}
/// <summary>
/// 设置系统设置
/// </summary>
/// <typeparam name="T">设置类型</typeparam>
/// <param name="key">设置键</param>
/// <param name="value">设置值</param>
protected void SetSetting<T>(string key, T value)
{
ActionService.SetSetting(key, value);
}
/// <summary>
/// 保存设置
/// </summary>
protected void SaveSettings()
{
ActionService.SaveSettings();
}
/// <summary>
/// 清除当前画布
/// </summary>
protected void ClearCanvas()
{
ActionService.ClearCanvas();
}
/// <summary>
/// 撤销操作
/// </summary>
protected void Undo()
{
ActionService.Undo();
}
/// <summary>
/// 重做操作
/// </summary>
protected void Redo()
{
ActionService.Redo();
}
/// <summary>
/// 检查是否可以撤销
/// </summary>
protected bool CanUndo => GetService.CanUndo;
/// <summary>
/// 检查是否可以重做
/// </summary>
protected bool CanRedo => GetService.CanRedo;
/// <summary>
/// 获取当前绘制模式
/// </summary>
protected int CurrentDrawingMode => GetService.CurrentDrawingMode;
/// <summary>
/// 设置绘制模式
/// </summary>
/// <param name="mode">绘制模式</param>
protected void SetDrawingMode(int mode)
{
ActionService.SetDrawingMode(mode);
}
/// <summary>
/// 注册事件处理器
/// </summary>
/// <param name="eventName">事件名称</param>
/// <param name="handler">事件处理器</param>
protected void RegisterEventHandler(string eventName, System.EventHandler handler)
{
ActionService.RegisterEventHandler(eventName, handler);
}
/// <summary>
/// 注销事件处理器
/// </summary>
/// <param name="eventName">事件名称</param>
/// <param name="handler">事件处理器</param>
protected void UnregisterEventHandler(string eventName, System.EventHandler handler)
{
ActionService.UnregisterEventHandler(eventName, handler);
}
/// <summary>
/// 触发事件
/// </summary>
/// <param name="eventName">事件名称</param>
/// <param name="sender">事件发送者</param>
/// <param name="args">事件参数</param>
protected void TriggerEvent(string eventName, object sender, System.EventArgs args)
{
ActionService.TriggerEvent(eventName, sender, args);
}
#endregion
}
}
@@ -1,296 +0,0 @@
using System;
using System.Windows.Media;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 操作服务接口,统一所有执行操作相关的方法
/// </summary>
public interface IActionService
{
#region
/// <summary>
/// 清除当前画布
/// </summary>
void ClearCanvas();
/// <summary>
/// 清除所有画布
/// </summary>
void ClearAllCanvases();
/// <summary>
/// 添加新页面
/// </summary>
void AddNewPage();
/// <summary>
/// 删除当前页面
/// </summary>
void DeleteCurrentPage();
/// <summary>
/// 切换到指定页面
/// </summary>
/// <param name="pageIndex">页面索引</param>
void SwitchToPage(int pageIndex);
/// <summary>
/// 切换到下一页
/// </summary>
void NextPage();
/// <summary>
/// 切换到上一页
/// </summary>
void PreviousPage();
#endregion
#region
/// <summary>
/// 设置绘制模式
/// </summary>
/// <param name="mode">绘制模式</param>
void SetDrawingMode(int mode);
/// <summary>
/// 设置笔触宽度
/// </summary>
/// <param name="width">宽度</param>
void SetInkWidth(double width);
/// <summary>
/// 设置笔触颜色
/// </summary>
/// <param name="color">颜色</param>
void SetInkColor(Color color);
/// <summary>
/// 设置高亮笔宽度
/// </summary>
/// <param name="width">宽度</param>
void SetHighlighterWidth(double width);
/// <summary>
/// 设置橡皮擦大小
/// </summary>
/// <param name="size">大小</param>
void SetEraserSize(int size);
/// <summary>
/// 设置橡皮擦类型
/// </summary>
/// <param name="type">类型</param>
void SetEraserType(int type);
/// <summary>
/// 设置橡皮擦形状
/// </summary>
/// <param name="shape">形状</param>
void SetEraserShape(int shape);
/// <summary>
/// 设置笔触透明度
/// </summary>
/// <param name="alpha">透明度</param>
void SetInkAlpha(double alpha);
/// <summary>
/// 设置笔触样式
/// </summary>
/// <param name="style">样式</param>
void SetInkStyle(int style);
/// <summary>
/// 设置背景颜色
/// </summary>
/// <param name="color">颜色</param>
void SetBackgroundColor(string color);
#endregion
#region
/// <summary>
/// 保存画布内容
/// </summary>
/// <param name="filePath">文件路径</param>
void SaveCanvas(string filePath);
/// <summary>
/// 加载画布内容
/// </summary>
/// <param name="filePath">文件路径</param>
void LoadCanvas(string filePath);
/// <summary>
/// 导出为图片
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="format">图片格式</param>
void ExportAsImage(string filePath, string format);
/// <summary>
/// 导出为PDF
/// </summary>
/// <param name="filePath">文件路径</param>
void ExportAsPDF(string filePath);
#endregion
#region
/// <summary>
/// 撤销操作
/// </summary>
void Undo();
/// <summary>
/// 重做操作
/// </summary>
void Redo();
#endregion
#region
/// <summary>
/// 全选
/// </summary>
void SelectAll();
/// <summary>
/// 取消选择
/// </summary>
void DeselectAll();
/// <summary>
/// 删除选中内容
/// </summary>
void DeleteSelected();
/// <summary>
/// 复制选中内容
/// </summary>
void CopySelected();
/// <summary>
/// 剪切选中内容
/// </summary>
void CutSelected();
/// <summary>
/// 粘贴内容
/// </summary>
void Paste();
#endregion
#region
/// <summary>
/// 设置系统设置
/// </summary>
/// <typeparam name="T">设置类型</typeparam>
/// <param name="key">设置键</param>
/// <param name="value">设置值</param>
void SetSetting<T>(string key, T value);
/// <summary>
/// 保存设置到文件
/// </summary>
void SaveSettings();
/// <summary>
/// 从文件加载设置
/// </summary>
void LoadSettings();
/// <summary>
/// 重置设置为默认值
/// </summary>
void ResetSettings();
#endregion
#region
/// <summary>
/// 启用插件
/// </summary>
/// <param name="pluginName">插件名称</param>
void EnablePlugin(string pluginName);
/// <summary>
/// 禁用插件
/// </summary>
/// <param name="pluginName">插件名称</param>
void DisablePlugin(string pluginName);
/// <summary>
/// 卸载插件
/// </summary>
/// <param name="pluginName">插件名称</param>
void UnloadPlugin(string pluginName);
#endregion
#region
/// <summary>
/// 注册事件处理器
/// </summary>
/// <param name="eventName">事件名称</param>
/// <param name="handler">事件处理器</param>
void RegisterEventHandler(string eventName, EventHandler handler);
/// <summary>
/// 注销事件处理器
/// </summary>
/// <param name="eventName">事件名称</param>
/// <param name="handler">事件处理器</param>
void UnregisterEventHandler(string eventName, EventHandler handler);
/// <summary>
/// 触发事件
/// </summary>
/// <param name="eventName">事件名称</param>
/// <param name="sender">事件发送者</param>
/// <param name="args">事件参数</param>
void TriggerEvent(string eventName, object sender, EventArgs args);
#endregion
#region
/// <summary>
/// 重启应用程序
/// </summary>
void RestartApplication();
/// <summary>
/// 退出应用程序
/// </summary>
void ExitApplication();
/// <summary>
/// 检查更新
/// </summary>
void CheckForUpdates();
/// <summary>
/// 打开帮助文档
/// </summary>
void OpenHelpDocument();
/// <summary>
/// 打开关于页面
/// </summary>
void OpenAboutPage();
#endregion
}
}
@@ -1,178 +0,0 @@
using System;
using System.IO;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// ICCPP 插件适配器,用于加载和管理 .iccpp 格式的插件
/// </summary>
public class ICCPPPluginAdapter : PluginBase
{
private readonly byte[] _pluginData;
private readonly string _pluginPath;
private readonly string _pluginName;
private readonly Version _pluginVersion;
private bool _isInitialized;
/// <summary>
/// 创建 ICCPP 插件适配器
/// </summary>
/// <param name="pluginPath">插件文件路径</param>
/// <param name="pluginData">插件文件数据</param>
public ICCPPPluginAdapter(string pluginPath, byte[] pluginData)
{
_pluginPath = pluginPath;
_pluginData = pluginData;
PluginPath = pluginPath;
// 从文件名获取插件名称
_pluginName = Path.GetFileNameWithoutExtension(pluginPath);
_pluginVersion = new Version(1, 0, 0); // 默认版本
// 尝试从插件数据中读取更多信息
TryReadPluginMetadata();
}
public ICCPPPluginAdapter()
{
_pluginPath = string.Empty;
_pluginData = new byte[0];
PluginPath = string.Empty;
_pluginName = "ICCPPPlugin";
_pluginVersion = new Version(1, 0, 0);
// 可选:初始化其他字段
}
/// <summary>
/// 尝试从插件数据中读取元数据
/// </summary>
private void TryReadPluginMetadata()
{
try
{
// 这里可以根据 .iccpp 文件的实际格式解析元数据
// 例如,如果文件有特定的头部结构,可以在这里解析
// 示例:如果前100字节包含元数据
if (_pluginData.Length > 100)
{
// 解析元数据的代码...
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"解析插件 {_pluginName} 元数据时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#region IPlugin
/// <summary>
/// 插件名称
/// </summary>
public override string Name => _pluginName;
/// <summary>
/// 插件描述
/// </summary>
public override string Description => $"{_pluginName} (ICCPP 格式插件)";
/// <summary>
/// 插件版本
/// </summary>
public override Version Version => _pluginVersion;
/// <summary>
/// 插件作者
/// </summary>
public override string Author => "未知";
/// <summary>
/// 是否为内置插件
/// </summary>
public override bool IsBuiltIn => false;
/// <summary>
/// 初始化插件
/// </summary>
public override void Initialize()
{
if (_isInitialized) return;
try
{
// 这里可以添加 .iccpp 插件的初始化逻辑
// 例如,根据文件格式加载特定资源
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已初始化");
_isInitialized = true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"初始化 ICCPP 插件 {Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 启用插件
/// </summary>
public override void Enable()
{
if (IsEnabled) return;
try
{
// 这里可以添加 .iccpp 插件的启用逻辑
// 例如,加载动态库、注册事件等
base.Enable(); // 设置启用状态并触发事件
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已启用");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启用 ICCPP 插件 {Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 禁用插件
/// </summary>
public override void Disable()
{
if (!IsEnabled) return;
try
{
// 这里可以添加 .iccpp 插件的禁用逻辑
// 例如,卸载动态库、注销事件等
base.Disable(); // 设置禁用状态并触发事件
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已禁用");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"禁用 ICCPP 插件 {Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 清理插件资源
/// </summary>
public override void Cleanup()
{
try
{
// 这里可以添加 .iccpp 插件的清理逻辑
// 例如,释放资源等
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已清理资源");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清理 ICCPP 插件 {Name} 资源时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#endregion
}
}
@@ -1,48 +0,0 @@
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 增强的插件接口,提供对插件服务的访问
/// </summary>
public interface IEnhancedPlugin : IPlugin
{
/// <summary>
/// 获取插件服务实例
/// </summary>
IPluginService PluginService { get; }
/// <summary>
/// 插件启动时调用,在Initialize之后
/// </summary>
void OnStartup();
/// <summary>
/// 插件关闭时调用,在Cleanup之前
/// </summary>
void OnShutdown();
/// <summary>
/// 获取插件的菜单项
/// </summary>
/// <returns>菜单项集合</returns>
MenuItem[] GetMenuItems();
/// <summary>
/// 获取插件的工具栏按钮
/// </summary>
/// <returns>工具栏按钮集合</returns>
Button[] GetToolbarButtons();
/// <summary>
/// 获取插件的状态栏信息
/// </summary>
/// <returns>状态栏信息</returns>
string GetStatusBarInfo();
/// <summary>
/// 插件配置变更时调用
/// </summary>
void OnConfigurationChanged();
}
}
-214
View File
@@ -1,214 +0,0 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 获取服务接口,统一所有获取类的方法
/// </summary>
public interface IGetService
{
#region UI获取
/// <summary>
/// 获取主窗口引用
/// </summary>
Window MainWindow { get; }
/// <summary>
/// 获取当前画布
/// </summary>
InkCanvas CurrentCanvas { get; }
/// <summary>
/// 获取所有画布页面
/// </summary>
List<Canvas> AllCanvasPages { get; }
/// <summary>
/// 获取当前页面索引
/// </summary>
int CurrentPageIndex { get; }
/// <summary>
/// 获取当前页面数量
/// </summary>
int TotalPageCount { get; }
/// <summary>
/// 获取浮动工具栏
/// </summary>
FrameworkElement FloatingToolBar { get; }
/// <summary>
/// 获取左侧面板
/// </summary>
FrameworkElement LeftPanel { get; }
/// <summary>
/// 获取右侧面板
/// </summary>
FrameworkElement RightPanel { get; }
/// <summary>
/// 获取顶部面板
/// </summary>
FrameworkElement TopPanel { get; }
/// <summary>
/// 获取底部面板
/// </summary>
FrameworkElement BottomPanel { get; }
#endregion
#region
/// <summary>
/// 获取当前绘制模式
/// </summary>
int CurrentDrawingMode { get; }
/// <summary>
/// 获取当前笔触宽度
/// </summary>
double CurrentInkWidth { get; }
/// <summary>
/// 获取当前笔触颜色
/// </summary>
Color CurrentInkColor { get; }
/// <summary>
/// 获取当前高亮笔宽度
/// </summary>
double CurrentHighlighterWidth { get; }
/// <summary>
/// 获取当前橡皮擦大小
/// </summary>
int CurrentEraserSize { get; }
/// <summary>
/// 获取当前橡皮擦类型
/// </summary>
int CurrentEraserType { get; }
/// <summary>
/// 获取当前橡皮擦形状
/// </summary>
int CurrentEraserShape { get; }
/// <summary>
/// 获取当前笔触透明度
/// </summary>
double CurrentInkAlpha { get; }
/// <summary>
/// 获取当前笔触样式
/// </summary>
int CurrentInkStyle { get; }
/// <summary>
/// 获取当前背景颜色
/// </summary>
string CurrentBackgroundColor { get; }
#endregion
#region
/// <summary>
/// 获取当前主题模式
/// </summary>
bool IsDarkTheme { get; }
/// <summary>
/// 获取当前是否为白板模式
/// </summary>
bool IsWhiteboardMode { get; }
/// <summary>
/// 获取当前是否为PPT模式
/// </summary>
bool IsPPTMode { get; }
/// <summary>
/// 获取当前是否为全屏模式
/// </summary>
bool IsFullScreenMode { get; }
/// <summary>
/// 获取当前是否为画板模式
/// </summary>
bool IsCanvasMode { get; }
/// <summary>
/// 获取当前是否为选择模式
/// </summary>
bool IsSelectionMode { get; }
/// <summary>
/// 获取当前是否为擦除模式
/// </summary>
bool IsEraserMode { get; }
/// <summary>
/// 获取当前是否为形状绘制模式
/// </summary>
bool IsShapeDrawingMode { get; }
/// <summary>
/// 获取当前是否为高亮模式
/// </summary>
bool IsHighlighterMode { get; }
#endregion
#region
/// <summary>
/// 获取是否可以撤销
/// </summary>
bool CanUndo { get; }
/// <summary>
/// 获取是否可以重做
/// </summary>
bool CanRedo { get; }
#endregion
#region
/// <summary>
/// 获取系统设置
/// </summary>
/// <typeparam name="T">设置类型</typeparam>
/// <param name="key">设置键</param>
/// <param name="defaultValue">默认值</param>
/// <returns>设置值</returns>
T GetSetting<T>(string key, T defaultValue = default(T));
#endregion
#region
/// <summary>
/// 获取所有已加载的插件
/// </summary>
/// <returns>插件列表</returns>
List<IPlugin> GetAllPlugins();
/// <summary>
/// 获取指定插件
/// </summary>
/// <param name="pluginName">插件名称</param>
/// <returns>插件实例</returns>
IPlugin GetPlugin(string pluginName);
#endregion
}
}
-67
View File
@@ -1,67 +0,0 @@
using System;
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 定义插件的基本接口
/// </summary>
public interface IPlugin
{
/// <summary>
/// 插件名称
/// </summary>
string Name { get; }
/// <summary>
/// 插件描述
/// </summary>
string Description { get; }
/// <summary>
/// 插件版本
/// </summary>
Version Version { get; }
/// <summary>
/// 插件作者
/// </summary>
string Author { get; }
/// <summary>
/// 是否为内置插件
/// </summary>
bool IsBuiltIn { get; }
/// <summary>
/// 初始化插件
/// 此方法在插件加载时被调用,用于执行一些初始化工作
/// </summary>
void Initialize();
/// <summary>
/// 启用插件
/// 此方法在插件被用户或系统启用时调用,激活插件功能
/// </summary>
void Enable();
/// <summary>
/// 禁用插件
/// 此方法在插件被用户或系统禁用时调用,停用插件功能
/// </summary>
void Disable();
/// <summary>
/// 获取插件设置界面
/// 此方法返回插件的设置界面控件,用于展示在设置窗口
/// </summary>
/// <returns>插件设置界面</returns>
UserControl GetSettingsView();
/// <summary>
/// 插件卸载时的清理工作
/// 此方法在插件被卸载前调用,用于释放资源和执行清理
/// </summary>
void Cleanup();
}
}
@@ -1,38 +0,0 @@
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 插件服务接口,提供对软件内部功能的访问
/// 继承自三个专门的服务接口:获取服务、窗口服务、操作服务
/// </summary>
public interface IPluginService : IGetService, IWindowService, IActionService
{
// 这个接口现在继承自三个专门的服务接口
// 所有方法都在子接口中定义,这里不需要重复定义
}
/// <summary>
/// 通知类型枚举
/// </summary>
public enum NotificationType
{
/// <summary>
/// 信息
/// </summary>
Info,
/// <summary>
/// 成功
/// </summary>
Success,
/// <summary>
/// 警告
/// </summary>
Warning,
/// <summary>
/// 错误
/// </summary>
Error
}
}
@@ -1,152 +0,0 @@
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 窗口服务接口,统一所有窗口操作相关的方法
/// </summary>
public interface IWindowService
{
#region
/// <summary>
/// 显示设置窗口
/// </summary>
void ShowSettingsWindow();
/// <summary>
/// 隐藏设置窗口
/// </summary>
void HideSettingsWindow();
/// <summary>
/// 显示插件设置窗口
/// </summary>
void ShowPluginSettingsWindow();
/// <summary>
/// 隐藏插件设置窗口
/// </summary>
void HidePluginSettingsWindow();
/// <summary>
/// 显示帮助窗口
/// </summary>
void ShowHelpWindow();
/// <summary>
/// 隐藏帮助窗口
/// </summary>
void HideHelpWindow();
/// <summary>
/// 显示关于窗口
/// </summary>
void ShowAboutWindow();
/// <summary>
/// 隐藏关于窗口
/// </summary>
void HideAboutWindow();
#endregion
#region
/// <summary>
/// 显示通知消息
/// </summary>
/// <param name="message">消息内容</param>
/// <param name="type">消息类型</param>
void ShowNotification(string message, NotificationType type = NotificationType.Info);
/// <summary>
/// 显示确认对话框
/// </summary>
/// <param name="message">消息内容</param>
/// <param name="title">标题</param>
/// <returns>用户选择结果</returns>
bool ShowConfirmDialog(string message, string title = "确认");
/// <summary>
/// 显示输入对话框
/// </summary>
/// <param name="message">提示消息</param>
/// <param name="title">标题</param>
/// <param name="defaultValue">默认值</param>
/// <returns>用户输入内容</returns>
string ShowInputDialog(string message, string title = "输入", string defaultValue = "");
#endregion
#region
/// <summary>
/// 设置窗口全屏状态
/// </summary>
/// <param name="isFullScreen">是否全屏</param>
void SetFullScreen(bool isFullScreen);
/// <summary>
/// 设置窗口置顶状态
/// </summary>
/// <param name="isTopMost">是否置顶</param>
void SetTopMost(bool isTopMost);
/// <summary>
/// 设置窗口可见性
/// </summary>
/// <param name="isVisible">是否可见</param>
void SetWindowVisibility(bool isVisible);
/// <summary>
/// 最小化窗口
/// </summary>
void MinimizeWindow();
/// <summary>
/// 最大化窗口
/// </summary>
void MaximizeWindow();
/// <summary>
/// 恢复窗口
/// </summary>
void RestoreWindow();
/// <summary>
/// 关闭窗口
/// </summary>
void CloseWindow();
#endregion
#region
/// <summary>
/// 设置窗口位置
/// </summary>
/// <param name="x">X坐标</param>
/// <param name="y">Y坐标</param>
void SetWindowPosition(double x, double y);
/// <summary>
/// 设置窗口大小
/// </summary>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
void SetWindowSize(double width, double height);
/// <summary>
/// 获取窗口位置
/// </summary>
/// <returns>窗口位置</returns>
(double x, double y) GetWindowPosition();
/// <summary>
/// 获取窗口大小
/// </summary>
/// <returns>窗口大小</returns>
(double width, double height) GetWindowSize();
#endregion
}
}
-161
View File
@@ -1,161 +0,0 @@
using System;
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 插件基类,提供基本实现
/// </summary>
public abstract class PluginBase : IPlugin
{
/// <summary>
/// 插件状态(私有字段)
/// </summary>
private bool _isEnabled;
/// <summary>
/// 插件状态(公共属性)
/// </summary>
public bool IsEnabled
{
get => _isEnabled;
protected set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnEnabledStateChanged(value);
}
}
}
/// <summary>
/// 插件ID
/// </summary>
public string Id { get; protected set; }
/// <summary>
/// 插件路径
/// </summary>
public string PluginPath { get; set; }
/// <summary>
/// 插件名称
/// </summary>
public abstract string Name { get; }
/// <summary>
/// 插件描述
/// </summary>
public abstract string Description { get; }
/// <summary>
/// 插件版本
/// </summary>
public abstract Version Version { get; }
/// <summary>
/// 插件作者
/// </summary>
public abstract string Author { get; }
/// <summary>
/// 是否为内置插件
/// </summary>
public virtual bool IsBuiltIn => false;
/// <summary>
/// 状态变更事件
/// </summary>
public event EventHandler<bool> EnabledStateChanged;
/// <summary>
/// 初始化插件
/// </summary>
public virtual void Initialize()
{
Id = GetType().FullName;
// 添加日志,记录插件名称
try
{
string name = Name;
LogHelper.WriteLogToFile($"初始化插件: ID={Id}, 名称={name ?? ""}");
if (string.IsNullOrEmpty(name))
{
LogHelper.WriteLogToFile($"警告: 插件 {Id} 的名称为空", LogHelper.LogType.Warning);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取插件名称时出错: {ex.Message}", LogHelper.LogType.Error);
}
LogHelper.WriteLogToFile($"插件 {Name} 已初始化");
}
/// <summary>
/// 启用插件
/// </summary>
public virtual void Enable()
{
if (!IsEnabled)
{
IsEnabled = true;
LogHelper.WriteLogToFile($"插件 {Name} 已启用");
}
}
/// <summary>
/// 禁用插件
/// </summary>
public virtual void Disable()
{
if (IsEnabled)
{
IsEnabled = false;
LogHelper.WriteLogToFile($"插件 {Name} 已禁用");
}
}
/// <summary>
/// 获取插件设置界面
/// </summary>
/// <returns>插件设置界面</returns>
public virtual UserControl GetSettingsView()
{
// 默认返回空设置页面
return new UserControl();
}
/// <summary>
/// 插件卸载时的清理工作
/// </summary>
public virtual void Cleanup()
{
LogHelper.WriteLogToFile($"插件 {Name} 已卸载");
}
/// <summary>
/// 保存插件自身的设置
/// 注意:此方法仅用于保存插件的特定设置,不应影响插件启用/禁用状态
/// 插件启用状态由PluginManager统一管理
/// </summary>
public virtual void SavePluginSettings()
{
// 默认实现不做任何事情
// 子类可以重写此方法,将自身设置保存到配置文件中
LogHelper.WriteLogToFile($"插件 {Name} 设置已保存", LogHelper.LogType.Event);
}
/// <summary>
/// 触发状态变更事件
/// </summary>
/// <param name="isEnabled">是否启用</param>
protected virtual void OnEnabledStateChanged(bool isEnabled)
{
EnabledStateChanged?.Invoke(this, isEnabled);
}
}
}
@@ -1,273 +0,0 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 插件配置管理器,允许插件管理自己的配置
/// </summary>
public class PluginConfigurationManager
{
private static readonly string PluginConfigDirectory = Path.Combine(App.RootPath, "PluginConfigs");
private static readonly Dictionary<string, Dictionary<string, object>> _pluginConfigs = new Dictionary<string, Dictionary<string, object>>();
private static readonly object _lockObject = new object();
static PluginConfigurationManager()
{
// 确保配置目录存在
if (!Directory.Exists(PluginConfigDirectory))
{
Directory.CreateDirectory(PluginConfigDirectory);
}
}
/// <summary>
/// 获取插件配置值
/// </summary>
/// <typeparam name="T">配置值类型</typeparam>
/// <param name="pluginName">插件名称</param>
/// <param name="key">配置键</param>
/// <param name="defaultValue">默认值</param>
/// <returns>配置值</returns>
public static T GetConfiguration<T>(string pluginName, string key, T defaultValue = default(T))
{
lock (_lockObject)
{
try
{
if (_pluginConfigs.TryGetValue(pluginName, out var pluginConfig))
{
if (pluginConfig.TryGetValue(key, out var value))
{
if (value is T typedValue)
{
return typedValue;
}
// 尝试类型转换
try
{
return (T)Convert.ChangeType(value, typeof(T));
}
catch
{
return defaultValue;
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取插件 {pluginName} 配置 {key} 时出错: {ex.Message}", LogHelper.LogType.Error);
}
return defaultValue;
}
}
/// <summary>
/// 设置插件配置值
/// </summary>
/// <typeparam name="T">配置值类型</typeparam>
/// <param name="pluginName">插件名称</param>
/// <param name="key">配置键</param>
/// <param name="value">配置值</param>
public static void SetConfiguration<T>(string pluginName, string key, T value)
{
lock (_lockObject)
{
try
{
if (!_pluginConfigs.ContainsKey(pluginName))
{
_pluginConfigs[pluginName] = new Dictionary<string, object>();
}
_pluginConfigs[pluginName][key] = value;
// 异步保存配置
Task.Run(() => SavePluginConfiguration(pluginName));
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"设置插件 {pluginName} 配置 {key} 时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 删除插件配置
/// </summary>
/// <param name="pluginName">插件名称</param>
/// <param name="key">配置键</param>
public static void RemoveConfiguration(string pluginName, string key)
{
lock (_lockObject)
{
try
{
if (_pluginConfigs.TryGetValue(pluginName, out var pluginConfig))
{
if (pluginConfig.Remove(key))
{
// 异步保存配置
Task.Run(() => SavePluginConfiguration(pluginName));
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"删除插件 {pluginName} 配置 {key} 时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 获取插件的所有配置
/// </summary>
/// <param name="pluginName">插件名称</param>
/// <returns>配置字典</returns>
public static Dictionary<string, object> GetAllConfigurations(string pluginName)
{
lock (_lockObject)
{
if (_pluginConfigs.TryGetValue(pluginName, out var pluginConfig))
{
return new Dictionary<string, object>(pluginConfig);
}
return new Dictionary<string, object>();
}
}
/// <summary>
/// 清除插件的所有配置
/// </summary>
/// <param name="pluginName">插件名称</param>
public static void ClearAllConfigurations(string pluginName)
{
lock (_lockObject)
{
try
{
if (_pluginConfigs.Remove(pluginName))
{
// 删除配置文件
string configFile = Path.Combine(PluginConfigDirectory, $"{pluginName}.json");
if (File.Exists(configFile))
{
File.Delete(configFile);
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"清除插件 {pluginName} 所有配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
/// <summary>
/// 加载插件配置
/// </summary>
/// <param name="pluginName">插件名称</param>
public static void LoadPluginConfiguration(string pluginName)
{
try
{
string configFile = Path.Combine(PluginConfigDirectory, $"{pluginName}.json");
if (File.Exists(configFile))
{
string json = File.ReadAllText(configFile);
var config = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
lock (_lockObject)
{
_pluginConfigs[pluginName] = config ?? new Dictionary<string, object>();
}
LogHelper.WriteLogToFile($"已加载插件 {pluginName} 的配置");
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"加载插件 {pluginName} 配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 保存插件配置
/// </summary>
/// <param name="pluginName">插件名称</param>
private static void SavePluginConfiguration(string pluginName)
{
try
{
Dictionary<string, object> pluginConfig;
lock (_lockObject)
{
if (!_pluginConfigs.TryGetValue(pluginName, out pluginConfig))
{
return;
}
}
string configFile = Path.Combine(PluginConfigDirectory, $"{pluginName}.json");
string json = JsonConvert.SerializeObject(pluginConfig, Formatting.Indented);
File.WriteAllText(configFile, json);
LogHelper.WriteLogToFile($"已保存插件 {pluginName} 的配置");
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存插件 {pluginName} 配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 加载所有插件的配置
/// </summary>
public static void LoadAllPluginConfigurations()
{
try
{
if (Directory.Exists(PluginConfigDirectory))
{
string[] configFiles = Directory.GetFiles(PluginConfigDirectory, "*.json");
foreach (string configFile in configFiles)
{
string pluginName = Path.GetFileNameWithoutExtension(configFile);
LoadPluginConfiguration(pluginName);
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"加载所有插件配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 保存所有插件的配置
/// </summary>
public static void SaveAllPluginConfigurations()
{
try
{
lock (_lockObject)
{
foreach (string pluginName in _pluginConfigs.Keys)
{
SavePluginConfiguration(pluginName);
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存所有插件配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,509 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 插件服务管理器,实现IPluginService接口,提供对软件内部功能的访问
/// </summary>
public class PluginServiceManager : IPluginService
{
private static PluginServiceManager _instance;
private MainWindow _mainWindow;
private Dictionary<string, EventHandler> _eventHandlers;
/// <summary>
/// 单例实例
/// </summary>
public static PluginServiceManager Instance
{
get
{
if (_instance == null)
{
_instance = new PluginServiceManager();
}
return _instance;
}
}
private PluginServiceManager()
{
_eventHandlers = new Dictionary<string, EventHandler>();
}
/// <summary>
/// 设置主窗口引用
/// </summary>
/// <param name="mainWindow">主窗口实例</param>
public void SetMainWindow(MainWindow mainWindow)
{
_mainWindow = mainWindow;
}
#region UI访问
public Window MainWindow => _mainWindow;
public InkCanvas CurrentCanvas => null; // 暂时返回null,避免访问权限问题
public List<Canvas> AllCanvasPages => new List<Canvas>(); // 暂时返回空列表
public int CurrentPageIndex => 0; // 暂时返回0
public int TotalPageCount => 0; // 暂时返回0
public FrameworkElement FloatingToolBar => _mainWindow?.ViewboxFloatingBar;
public FrameworkElement LeftPanel => _mainWindow?.BlackboardLeftSide;
public FrameworkElement RightPanel => _mainWindow?.BlackboardRightSide;
public FrameworkElement TopPanel => _mainWindow?.BorderTools;
public FrameworkElement BottomPanel => _mainWindow?.BorderSettings;
#endregion
#region
public int CurrentDrawingMode => 0; // 暂时返回0
public double CurrentInkWidth => 2.5; // 暂时返回默认值
public Color CurrentInkColor => Colors.Black; // 暂时返回默认值
public double CurrentHighlighterWidth => 20.0; // 暂时返回默认值
public int CurrentEraserSize => 2; // 暂时返回默认值
public int CurrentEraserType => 0; // 暂时返回默认值
public int CurrentEraserShape => 0; // 暂时返回默认值
public double CurrentInkAlpha => 255.0; // 暂时返回默认值
public int CurrentInkStyle => 0; // 暂时返回默认值
public string CurrentBackgroundColor => "#162924"; // 暂时返回默认值
#endregion
#region
public bool IsDarkTheme => false; // 暂时返回默认值
public bool IsWhiteboardMode => false; // 暂时返回默认值
public bool IsPPTMode => false; // 暂时返回默认值
public bool IsFullScreenMode => false; // 暂时返回默认值
public bool IsCanvasMode => true; // 暂时返回默认值
public bool IsSelectionMode => false; // 暂时返回默认值
public bool IsEraserMode => false; // 暂时返回默认值
public bool IsShapeDrawingMode => false; // 暂时返回默认值
public bool IsHighlighterMode => false; // 暂时返回默认值
#endregion
#region IGetService
public bool CanUndo => false; // 暂时返回默认值
public bool CanRedo => false; // 暂时返回默认值
public T GetSetting<T>(string key, T defaultValue = default(T))
{
// 暂时不实现,避免访问权限问题
return defaultValue;
}
public List<IPlugin> GetAllPlugins()
{
return new List<IPlugin>(PluginManager.Instance.Plugins);
}
public IPlugin GetPlugin(string pluginName)
{
return PluginManager.Instance.Plugins.FirstOrDefault(p => p.Name == pluginName);
}
#endregion
#region IWindowService
public void ShowSettingsWindow()
{
// 暂时不实现,避免访问权限问题
}
public void HideSettingsWindow()
{
// 暂时不实现,避免访问权限问题
}
public void ShowPluginSettingsWindow()
{
// 暂时不实现,避免访问权限问题
}
public void HidePluginSettingsWindow()
{
// 暂时不实现,避免访问权限问题
}
public void ShowHelpWindow()
{
// 暂时不实现,避免访问权限问题
}
public void HideHelpWindow()
{
// 暂时不实现,避免访问权限问题
}
public void ShowAboutWindow()
{
// 暂时不实现,避免访问权限问题
}
public void HideAboutWindow()
{
// 暂时不实现,避免访问权限问题
}
public void ShowNotification(string message, NotificationType type = NotificationType.Info)
{
// 暂时不实现,避免访问权限问题
}
public bool ShowConfirmDialog(string message, string title = "确认")
{
// 暂时不实现,避免访问权限问题
return false;
}
public string ShowInputDialog(string message, string title = "输入", string defaultValue = "")
{
// 暂时不实现,避免访问权限问题
return defaultValue;
}
public void SetFullScreen(bool isFullScreen)
{
// 暂时不实现,避免访问权限问题
}
public void SetTopMost(bool isTopMost)
{
// 暂时不实现,避免访问权限问题
}
public void SetWindowVisibility(bool isVisible)
{
// 暂时不实现,避免访问权限问题
}
public void MinimizeWindow()
{
// 暂时不实现,避免访问权限问题
}
public void MaximizeWindow()
{
// 暂时不实现,避免访问权限问题
}
public void RestoreWindow()
{
// 暂时不实现,避免访问权限问题
}
public void CloseWindow()
{
// 暂时不实现,避免访问权限问题
}
public void SetWindowPosition(double x, double y)
{
// 暂时不实现,避免访问权限问题
}
public void SetWindowSize(double width, double height)
{
// 暂时不实现,避免访问权限问题
}
public (double x, double y) GetWindowPosition()
{
// 暂时不实现,避免访问权限问题
return (0, 0);
}
public (double width, double height) GetWindowSize()
{
// 暂时不实现,避免访问权限问题
return (800, 600);
}
#endregion
#region IActionService
public void ClearCanvas()
{
// 暂时不实现,避免访问权限问题
}
public void ClearAllCanvases()
{
// 暂时不实现,避免访问权限问题
}
public void AddNewPage()
{
// 暂时不实现,避免访问权限问题
}
public void DeleteCurrentPage()
{
// 暂时不实现,避免访问权限问题
}
public void SwitchToPage(int pageIndex)
{
// 暂时不实现,避免访问权限问题
}
public void NextPage()
{
// 暂时不实现,避免访问权限问题
}
public void PreviousPage()
{
// 暂时不实现,避免访问权限问题
}
public void SetDrawingMode(int mode)
{
// 暂时不实现,避免访问权限问题
}
public void SetInkWidth(double width)
{
// 暂时不实现,避免访问权限问题
}
public void SetInkColor(Color color)
{
// 暂时不实现,避免访问权限问题
}
public void SetHighlighterWidth(double width)
{
// 暂时不实现,避免访问权限问题
}
public void SetEraserSize(int size)
{
// 暂时不实现,避免访问权限问题
}
public void SetEraserType(int type)
{
// 暂时不实现,避免访问权限问题
}
public void SetEraserShape(int shape)
{
// 暂时不实现,避免访问权限问题
}
public void SetInkAlpha(double alpha)
{
// 暂时不实现,避免访问权限问题
}
public void SetInkStyle(int style)
{
// 暂时不实现,避免访问权限问题
}
public void SetBackgroundColor(string color)
{
// 暂时不实现,避免访问权限问题
}
public void SaveCanvas(string filePath)
{
// 暂时不实现,避免访问权限问题
}
public void LoadCanvas(string filePath)
{
// 暂时不实现,避免访问权限问题
}
public void ExportAsImage(string filePath, string format)
{
// 暂时不实现,避免访问权限问题
}
public void ExportAsPDF(string filePath)
{
// 暂时不实现,避免访问权限问题
}
public void Undo()
{
// 暂时不实现,避免访问权限问题
}
public void Redo()
{
// 暂时不实现,避免访问权限问题
}
public void SelectAll()
{
// 暂时不实现,避免访问权限问题
}
public void DeselectAll()
{
// 暂时不实现,避免访问权限问题
}
public void DeleteSelected()
{
// 暂时不实现,避免访问权限问题
}
public void CopySelected()
{
// 暂时不实现,避免访问权限问题
}
public void CutSelected()
{
// 暂时不实现,避免访问权限问题
}
public void Paste()
{
// 暂时不实现,避免访问权限问题
}
public void SetSetting<T>(string key, T value)
{
// 暂时不实现,避免访问权限问题
}
public void SaveSettings()
{
// 暂时不实现,避免访问权限问题
}
public void LoadSettings()
{
// 暂时不实现,避免访问权限问题
}
public void ResetSettings()
{
// 暂时不实现,避免访问权限问题
}
public void EnablePlugin(string pluginName)
{
var plugin = GetPlugin(pluginName);
if (plugin != null)
{
PluginManager.Instance.TogglePlugin(plugin, true);
}
}
public void DisablePlugin(string pluginName)
{
var plugin = GetPlugin(pluginName);
if (plugin != null)
{
PluginManager.Instance.TogglePlugin(plugin, false);
}
}
public void UnloadPlugin(string pluginName)
{
var plugin = GetPlugin(pluginName);
if (plugin != null)
{
PluginManager.Instance.UnloadPlugin(plugin);
}
}
public void RegisterEventHandler(string eventName, EventHandler handler)
{
if (!_eventHandlers.ContainsKey(eventName))
{
_eventHandlers[eventName] = handler;
}
else
{
_eventHandlers[eventName] += handler;
}
}
public void UnregisterEventHandler(string eventName, EventHandler handler)
{
if (_eventHandlers.ContainsKey(eventName))
{
_eventHandlers[eventName] -= handler;
}
}
public void TriggerEvent(string eventName, object sender, EventArgs args)
{
if (_eventHandlers.ContainsKey(eventName))
{
_eventHandlers[eventName]?.Invoke(sender, args);
}
}
public void RestartApplication()
{
// 暂时不实现,避免访问权限问题
}
public void ExitApplication()
{
// 暂时不实现,避免访问权限问题
}
public void CheckForUpdates()
{
// 暂时不实现,避免访问权限问题
}
public void OpenHelpDocument()
{
// 暂时不实现,避免访问权限问题
}
public void OpenAboutPage()
{
// 暂时不实现,避免访问权限问题
}
#endregion
}
}
@@ -1,276 +0,0 @@
using System;
using System.Windows;
using System.Windows.Controls;
namespace Ink_Canvas.Helpers.Plugins
{
/// <summary>
/// 插件模板,用于开发者参考
/// 注意:实际开发时,请将此类移到单独的程序集中
/// </summary>
public class PluginTemplate : PluginBase
{
#region
/// <summary>
/// 插件名称
/// </summary>
public override string Name => "插件模板";
/// <summary>
/// 插件描述
/// </summary>
public override string Description => "这是一个插件开发模板,用于开发者参考。";
/// <summary>
/// 插件版本
/// </summary>
public override Version Version => new Version(1, 0, 0);
/// <summary>
/// 插件作者
/// </summary>
public override string Author => "Your Name";
/// <summary>
/// 是否为内置插件(外部插件请返回false)
/// </summary>
public override bool IsBuiltIn => false;
#endregion
#region
/// <summary>
/// 插件初始化
/// 在这里进行插件的初始化工作,如加载配置、注册事件等
/// </summary>
public override void Initialize()
{
// 先调用基类方法,这样会设置插件ID和记录日志
base.Initialize();
// TODO: 在这里进行插件初始化工作
// 示例:记录初始化信息
LogHelper.WriteLogToFile($"插件 {Name} 开始初始化");
// 示例:加载配置
LoadConfig();
// 示例:注册自定义事件
// MainWindow.Instance.SomeEvent += OnSomeEvent;
LogHelper.WriteLogToFile($"插件 {Name} 初始化完成");
}
/// <summary>
/// 启用插件
/// 在这里激活插件功能
/// </summary>
public override void Enable()
{
// 先调用基类方法,这样会设置插件状态和记录日志
base.Enable();
// TODO: 在这里启用插件功能
LogHelper.WriteLogToFile($"插件 {Name} 已启用");
}
/// <summary>
/// 禁用插件
/// 在这里停用插件功能
/// </summary>
public override void Disable()
{
// 先调用基类方法,这样会设置插件状态和记录日志
base.Disable();
// TODO: 在这里禁用插件功能
LogHelper.WriteLogToFile($"插件 {Name} 已禁用");
}
/// <summary>
/// 清理资源
/// 在插件卸载时调用,清理资源
/// </summary>
public override void Cleanup()
{
// TODO: 在这里清理插件资源
// 示例:取消注册事件
// MainWindow.Instance.SomeEvent -= OnSomeEvent;
// 示例:保存配置
SaveConfig();
// 最后调用基类方法
base.Cleanup();
}
#endregion
#region
/// <summary>
/// 加载插件配置
/// </summary>
private void LoadConfig()
{
try
{
// TODO: 从文件或其他位置加载配置
// 示例:
// string configPath = Path.Combine(App.RootPath, "PluginConfigs", "YourPluginName.json");
// if (File.Exists(configPath))
// {
// string json = File.ReadAllText(configPath);
// YourConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<YourConfigClass>(json);
// }
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"加载插件配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 保存插件配置
/// </summary>
private void SaveConfig()
{
try
{
// TODO: 保存配置到文件或其他位置
// 示例:
// string configDir = Path.Combine(App.RootPath, "PluginConfigs");
// if (!Directory.Exists(configDir))
// {
// Directory.CreateDirectory(configDir);
// }
// string configPath = Path.Combine(configDir, "YourPluginName.json");
// string json = Newtonsoft.Json.JsonConvert.SerializeObject(YourConfig, Newtonsoft.Json.Formatting.Indented);
// File.WriteAllText(configPath, json);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"保存插件配置时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#endregion
#region
/// <summary>
/// 获取插件设置界面
/// </summary>
/// <returns>插件设置界面</returns>
public override UserControl GetSettingsView()
{
// 创建插件设置界面
return new PluginTemplateSettingsControl();
}
#endregion
#region
// TODO: 在这里添加插件的具体功能方法
/// <summary>
/// 示例方法:执行一些功能
/// </summary>
public void DoSomething()
{
if (!IsEnabled) return;
try
{
// TODO: 实现你的功能
MessageBox.Show("插件功能执行示例", "插件模板", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"执行插件功能时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#endregion
}
/// <summary>
/// 插件设置控件
/// </summary>
public class PluginTemplateSettingsControl : UserControl
{
public PluginTemplateSettingsControl()
{
// 创建设置界面布局
var panel = new StackPanel
{
Margin = new Thickness(10)
};
// 添加标题
panel.Children.Add(new TextBlock
{
Text = "插件模板设置",
FontSize = 16,
FontWeight = FontWeights.Bold,
Margin = new Thickness(0, 0, 0, 10)
});
// 添加说明文字
panel.Children.Add(new TextBlock
{
Text = "这是一个示例设置界面,你可以在这里添加自己的设置控件。",
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0, 0, 0, 15)
});
// 添加示例设置选项
var checkBox = new CheckBox
{
Content = "启用某项功能",
Margin = new Thickness(0, 0, 0, 10)
};
panel.Children.Add(checkBox);
// 添加文本输入框
panel.Children.Add(new TextBlock
{
Text = "设置项:",
Margin = new Thickness(0, 5, 0, 5)
});
panel.Children.Add(new TextBox
{
Margin = new Thickness(0, 0, 0, 10),
Width = 200,
HorizontalAlignment = HorizontalAlignment.Left
});
// 添加按钮
var button = new Button
{
Content = "保存设置",
Padding = new Thickness(10, 5, 10, 5),
Margin = new Thickness(0, 10, 0, 0),
HorizontalAlignment = HorizontalAlignment.Left
};
button.Click += (sender, e) =>
{
MessageBox.Show("设置已保存!", "插件模板", MessageBoxButton.OK, MessageBoxImage.Information);
};
panel.Children.Add(button);
// 设置控件内容
Content = panel;
}
}
}
@@ -0,0 +1,561 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace Ink_Canvas.Helpers
{
internal static class ProcessProtectionManager
{
private static readonly object _lock = new object();
private static readonly Dictionary<string, FileStream> _lockedFiles = new Dictionary<string, FileStream>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, SafeFileHandle> _lockedDirs = new Dictionary<string, SafeFileHandle>(StringComparer.OrdinalIgnoreCase);
private static bool _enabled;
private static int _writeGate;
private static readonly string[] _excludedSubDirectories = new[]
{
"Configs",
"Saves",
"Backups",
"Logs",
"AutoUpdate"
};
public static bool Enabled
{
get { lock (_lock) return _enabled; }
}
/// <summary>
/// 从应用设置读取 EnableProcessProtection 并相应地启用或禁用进程保护。
/// </summary>
public static void ApplyFromSettings()
{
try
{
var settings = MainWindow.Settings;
var enabled = settings?.Security != null && settings.Security.EnableProcessProtection;
SetEnabled(enabled);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"ProcessProtectionManager.ApplyFromSettings 失败: {ex.Message}", LogHelper.LogType.Warning);
}
}
/// <summary>
/// 切换进程保护的启用状态;在状态发生变化时触发相应的启用或禁用操作并保证线程安全。
/// </summary>
/// <param name="enabled">为 `true` 时启用进程保护,为 `false` 时禁用进程保护。</param>
public static void SetEnabled(bool enabled)
{
lock (_lock)
{
if (_enabled == enabled) return;
_enabled = enabled;
}
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
if (enabled) Enable();
else Disable();
}
catch (Exception ex)
{
try
{
LogHelper.WriteLogToFile($"ProcessProtectionManager.SetEnabled 后台执行失败: {ex.Message}", LogHelper.LogType.Warning);
}
catch { }
}
});
}
/// <summary>
/// 在受进程保护的上下文中执行对指定目标的写入操作;在执行时会在必要情况下临时释放针对目标路径及其父目录的锁,执行完成后恢复这些锁。
/// </summary>
/// <param name="targetPath">目标文件或目录的路径,用于确定需要临时释放和随后恢复的锁。</param>
/// <param name="action">执行写入的操作委托,不能为空。</param>
/// <remarks>
/// 如果 ProcessProtectionManager.Enabled 为 false,会直接执行 <paramref name="action"/>
/// 若在有限时间内无法获取写入门闩,会记录警告并降级为直接执行 <paramref name="action"/>。方法在内部处理异常,不会抛出异常给调用者。
/// </remarks>
public static void WithWriteAccess(string targetPath, Action action)
{
if (action == null) return;
if (!Enabled)
{
action();
return;
}
const int gateTimeoutMs = 10_000;
if (!TryEnterWriteGate(gateTimeoutMs))
{
try
{
LogHelper.WriteLogToFile($"ProcessProtectionManager.WithWriteAccess: 获取写入门闩超时({gateTimeoutMs}ms),将降级释放目标路径锁后执行写入。目标: {targetPath}",
LogHelper.LogType.Warning);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[ProcessProtectionManager] 写日志失败: {ex.Message}");
}
var normPath = NormalizePath(targetPath);
var dirsChain = GetDirChainToRoot(normPath);
Dictionary<string, SafeFileHandle> fallbackDirs = null;
Dictionary<string, FileStream> fallbackFiles = null;
try
{
lock (_lock)
{
fallbackDirs = new Dictionary<string, SafeFileHandle>(StringComparer.OrdinalIgnoreCase);
fallbackFiles = new Dictionary<string, FileStream>(StringComparer.OrdinalIgnoreCase);
foreach (var dir in dirsChain)
{
if (_lockedDirs.TryGetValue(dir, out var handle))
{
_lockedDirs.Remove(dir);
fallbackDirs[dir] = handle;
}
}
if (!string.IsNullOrWhiteSpace(normPath) && File.Exists(normPath) && _lockedFiles.TryGetValue(normPath, out var fs))
{
_lockedFiles.Remove(normPath);
fallbackFiles[normPath] = fs;
}
}
if (fallbackFiles != null)
{
foreach (var kv in fallbackFiles)
{
try { kv.Value.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
if (fallbackDirs != null)
{
foreach (var kv in fallbackDirs)
{
try { kv.Value.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
action();
}
finally
{
try
{
if (Enabled)
{
Enable(rescanRoot: false, rescanDirs: dirsChain);
}
}
catch { }
}
return;
}
var normalized = NormalizePath(targetPath);
var dirsToToggle = GetDirChainToRoot(normalized);
Dictionary<string, SafeFileHandle> releasedDirs = null;
Dictionary<string, FileStream> releasedFiles = null;
try
{
lock (_lock)
{
releasedDirs = new Dictionary<string, SafeFileHandle>(StringComparer.OrdinalIgnoreCase);
releasedFiles = new Dictionary<string, FileStream>(StringComparer.OrdinalIgnoreCase);
foreach (var dir in dirsToToggle)
{
if (_lockedDirs.TryGetValue(dir, out var handle))
{
_lockedDirs.Remove(dir);
releasedDirs[dir] = handle;
}
}
if (!string.IsNullOrWhiteSpace(normalized) && File.Exists(normalized) && _lockedFiles.TryGetValue(normalized, out var fs))
{
_lockedFiles.Remove(normalized);
releasedFiles[normalized] = fs;
}
}
if (releasedFiles != null)
{
foreach (var kv in releasedFiles)
{
try { kv.Value.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
if (releasedDirs != null)
{
foreach (var kv in releasedDirs)
{
try { kv.Value.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
action();
}
finally
{
try
{
if (Enabled)
{
Enable(rescanRoot: false, rescanDirs: dirsToToggle);
}
}
catch
{
}
Interlocked.Exchange(ref _writeGate, 0);
}
}
/// <summary>
/// 尝试在指定的毫秒数内获取写入门控(write gate)。
/// </summary>
/// <param name="timeoutMs">等待超时时间(毫秒)。小于或等于 0 时视为 1 毫秒。</param>
/// <returns>`true` 如果在指定时间内成功获取到写入门控,`false` 否则。</returns>
private static bool TryEnterWriteGate(int timeoutMs)
{
if (timeoutMs <= 0) timeoutMs = 1;
var start = Environment.TickCount;
while (Interlocked.CompareExchange(ref _writeGate, 1, 0) != 0)
{
var elapsed = unchecked(Environment.TickCount - start);
if (elapsed >= timeoutMs) return false;
if (elapsed < 2000) Thread.Sleep(10);
else Thread.Sleep(50);
}
return true;
}
/// <summary>
/// 启用进程保护并对应用根路径进行完整重扫描以锁定需要保护的目录和文件。
/// </summary>
private static void Enable()
{
Enable(rescanRoot: true, rescanDirs: null);
}
/// <summary>
/// 在应用根目录或提供的路径集合上建立目录句柄和文件读取锁以启用进程保护。
/// </summary>
/// <param name="rescanRoot">为 true 时对 App.RootPath 进行递归扫描并锁定其下的目录与文件;为 false 时仅处理 <paramref name="rescanDirs"/> 指定的路径(若为 null 则不处理)。</param>
/// <param name="rescanDirs">当 <paramref name="rescanRoot"/> 为 false 时,按项对存在的目录建立目录锁,对存在的文件建立文件锁;可为 null。</param>
private static void Enable(bool rescanRoot, IEnumerable<string> rescanDirs)
{
try
{
var root = App.RootPath;
if (string.IsNullOrWhiteSpace(root) || !Directory.Exists(root)) return;
root = NormalizePath(root);
if (rescanRoot)
{
LockDirectoryRecursive(root);
}
else if (rescanDirs != null)
{
foreach (var d in rescanDirs)
{
if (Directory.Exists(d))
{
LockDirectory(d);
}
}
}
if (rescanRoot)
{
LockFilesRecursive(root);
}
else if (rescanDirs != null)
{
foreach (var d in rescanDirs)
{
if (Directory.Exists(d))
{
LockFilesRecursive(d);
}
else if (File.Exists(d))
{
LockFile(d);
}
}
}
}
catch
{
}
}
/// <summary>
/// 释放并清除当前进程持有的所有文件和目录锁定句柄与流资源。
/// </summary>
/// <remarks>
/// 在内部同步锁定下逐一 Dispose 已记录的 FileStream 和 SafeFileHandle,并清空对应的缓存字典;
/// 释放过程中发生的异常会被忽略(吞掉)。
/// </remarks>
private static void Disable()
{
lock (_lock)
{
foreach (var kv in _lockedFiles)
{
try { kv.Value.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
_lockedFiles.Clear();
foreach (var kv in _lockedDirs)
{
try { kv.Value.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
_lockedDirs.Clear();
}
}
/// <summary>
/// 递归地尝试为指定目录及其所有子目录建立并保持目录句柄锁定,跳过配置的排除目录。
/// </summary>
/// <param name="root">起始目录的路径;从此路径开始遍历并对符合条件的子目录尝试建立锁定。</param>
/// <remarks>遇到的异常会被捕获并忽略,不会向调用方抛出。</remarks>
private static void LockDirectoryRecursive(string root)
{
try
{
if (!IsExcludedPath(root))
{
LockDirectory(root);
}
foreach (var dir in Directory.GetDirectories(root, "*", SearchOption.AllDirectories))
{
if (!IsExcludedPath(dir))
{
LockDirectory(dir);
}
}
}
catch
{
}
}
/// <summary>
/// 递归扫描指定根目录下的所有文件,并为具有特定扩展名的文件建立读取锁定以防止被进程修改或替换。
/// </summary>
/// <param name="root">要开始扫描的根目录路径。</param>
/// <remarks>
/// 仅处理扩展名为 `.exe`, `.dll`, `.config`, `.manifest`, `.dat`, `.enc` 的文件,以及应用根目录下的点名名单 `Names.txt`
/// 会跳过被 IsExcludedPath 判定为排除的路径。遇到任何 I/O 或访问错误时会静默忽略,不会抛出异常。</remarks>
private static void LockFilesRecursive(string root)
{
try
{
var rollCallNamesPath = NormalizePath(Path.Combine(root, "Names.txt"));
foreach (var file in Directory.GetFiles(root, "*", SearchOption.AllDirectories))
{
if (!IsExcludedPath(file))
{
var ext = Path.GetExtension(file);
var normFile = NormalizePath(file);
if (string.Equals(normFile, rollCallNamesPath, StringComparison.OrdinalIgnoreCase) ||
string.Equals(ext, ".exe", StringComparison.OrdinalIgnoreCase) ||
string.Equals(ext, ".dll", StringComparison.OrdinalIgnoreCase) ||
string.Equals(ext, ".config", StringComparison.OrdinalIgnoreCase) ||
string.Equals(ext, ".manifest", StringComparison.OrdinalIgnoreCase) ||
string.Equals(ext, ".dat", StringComparison.OrdinalIgnoreCase) ||
string.Equals(ext, ".enc", StringComparison.OrdinalIgnoreCase))
{
LockFile(file);
}
}
}
}
catch
{
}
}
/// <summary>
/// 以只读方式打开并保留指定文件的句柄,将其加入内部锁定缓存以减少该文件被外部修改或删除的可能性。
/// </summary>
/// <param name="filePath">要锁定的文件的路径(会被规范化为完整路径)。</param>
private static void LockFile(string filePath)
{
filePath = NormalizePath(filePath);
lock (_lock)
{
if (_lockedFiles.ContainsKey(filePath)) return;
try
{
var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
_lockedFiles[filePath] = fs;
}
catch
{
}
}
}
/// <summary>
/// 尝试为指定目录获取一个用于保持目录打开的句柄并将其保存为内部锁定记录;若目录已被记录则不作任何操作,发生错误时静默忽略。
/// </summary>
/// <param name="dirPath">要锁定的目录路径;调用时会对路径进行规范化(转换为完整路径并移除多余分隔符)。</param>
private static void LockDirectory(string dirPath)
{
dirPath = NormalizePath(dirPath);
lock (_lock)
{
if (_lockedDirs.ContainsKey(dirPath)) return;
try
{
var handle = CreateDirectoryHandle(dirPath);
if (handle != null && !handle.IsInvalid)
{
_lockedDirs[dirPath] = handle;
}
}
catch
{
}
}
}
/// <summary>
/// 将路径标准化为不含末尾路径分隔符的绝对路径。
/// </summary>
/// <param name="p">要规范化的路径;如果为 null、空或仅空白,则返回原值。</param>
/// <returns>规范化后的路径:在解析成功时返回去除末尾分隔符的绝对路径;在解析失败时返回原始输入。</returns>
private static string NormalizePath(string p)
{
try
{
if (string.IsNullOrWhiteSpace(p)) return p;
return Path.GetFullPath(p.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
}
catch
{
return p;
}
}
/// <summary>
/// 构建从指定路径向上直到应用根目录(App.RootPath)的目录链,并按从下到上的顺序返回已规范化的目录路径。
/// </summary>
/// <param name="path">起始路径,既可为文件路径也可为目录路径;若为文件则使用其所在目录作为起点。</param>
/// <returns>包含起始目录及其各级父目录直到并包含应用根目录的列表;当根路径无效或未能匹配到根目录时返回空列表。</returns>
private static List<string> GetDirChainToRoot(string path)
{
var list = new List<string>();
try
{
var root = NormalizePath(App.RootPath);
if (string.IsNullOrWhiteSpace(root)) return list;
string dir = Directory.Exists(path) ? NormalizePath(path) : NormalizePath(Path.GetDirectoryName(path));
while (!string.IsNullOrWhiteSpace(dir))
{
if (!dir.StartsWith(root, StringComparison.OrdinalIgnoreCase)) break;
list.Add(dir);
if (string.Equals(dir, root, StringComparison.OrdinalIgnoreCase)) break;
dir = NormalizePath(Path.GetDirectoryName(dir));
}
}
catch
{
}
return list;
}
/// <summary>
/// 检查给定路径是否位于应用根目录下的受排除子目录之一。
/// </summary>
/// <param name="path">要检查的文件或目录路径。</param>
/// <returns>`true` 如果路径位于任何配置为排除的子目录下,`false` 否则。</returns>
private static bool IsExcludedPath(string path)
{
try
{
var root = NormalizePath(App.RootPath);
if (string.IsNullOrWhiteSpace(root)) return false;
path = NormalizePath(path);
foreach (var name in _excludedSubDirectories)
{
var prefix = Path.Combine(root, name);
if (path.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
}
catch
{
}
return false;
}
/// <summary>
/// 为指定目录打开一个文件句柄,便于对该目录进行锁定或访问其元数据。
/// </summary>
/// <param name="dirPath">目标目录的完整路径。</param>
/// <returns>表示已打开目录的 <see cref="SafeFileHandle"/>;若无法打开则返回无效的句柄,调用方应检查句柄有效性。</returns>
private static SafeFileHandle CreateDirectoryHandle(string dirPath)
{
const uint GENERIC_READ = 0x80000000;
const uint FILE_SHARE_READ = 0x00000001;
const uint OPEN_EXISTING = 3;
const uint FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
return CreateFile(
dirPath,
GENERIC_READ,
FILE_SHARE_READ,
IntPtr.Zero,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
IntPtr.Zero);
}
/// <summary>
/// 使用原生 CreateFile API 打开或创建一个文件/目录并返回底层句柄的包装函数声明。
/// </summary>
/// <param name="lpFileName">要打开或创建的文件或目录的完整路径(UTF-16 编码)。</param>
/// <param name="dwDesiredAccess">请求的访问权限位掩码(例如读取或写入访问)。</param>
/// <param name="dwShareMode">共享模式位掩码,指定其他进程可以如何共享此文件句柄。</param>
/// <param name="lpSecurityAttributes">指向安全属性结构的指针,或为 <see cref="IntPtr.Zero"/> 表示默认安全性。</param>
/// <param name="dwCreationDisposition">指定如何处理已存在或不存在的文件(例如打开、创建或截断)。</param>
/// <param name="dwFlagsAndAttributes">文件属性和标志位,用于控制文件或目录的特殊行为(例如备份语义)。</param>
/// <param name="hTemplateFile">用于创建新文件时的模板句柄,通常为 <see cref="IntPtr.Zero"/>。</param>
/// <returns>表示文件或目录句柄的 <see cref="Microsoft.Win32.SafeHandles.SafeFileHandle"/>;调用失败时返回无效的句柄(可通过检查句柄或调用 <see cref="System.Runtime.InteropServices.Marshal.GetLastWin32Error"/> 获取错误码)。</returns>
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern SafeFileHandle CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);
}
}
File diff suppressed because it is too large Load Diff
+75
View File
@@ -0,0 +1,75 @@
using System;
using System.IO;
using System.IO.Compression;
namespace Ink_Canvas.Helpers
{
public static class SafeZipExtractor
{
/// <param name="zipFilePath">ZIP 文件路径</param>
/// <param name="extractPath">解压目标目录</param>
/// <param name="overwrite">是否覆盖已存在文件</param>
public static void ExtractZipSafely(string zipFilePath, string extractPath, bool overwrite = true)
{
if (string.IsNullOrWhiteSpace(zipFilePath))
throw new ArgumentNullException(nameof(zipFilePath));
if (string.IsNullOrWhiteSpace(extractPath))
throw new ArgumentNullException(nameof(extractPath));
var fullExtractPath = Path.GetFullPath(extractPath);
Directory.CreateDirectory(fullExtractPath);
using (var zip = ZipFile.OpenRead(zipFilePath))
{
foreach (var entry in zip.Entries)
{
// 跳过空条目
if (string.IsNullOrEmpty(entry.FullName))
continue;
// 防止绝对路径和盘符前缀
if (Path.IsPathRooted(entry.FullName))
continue;
// 统一路径分隔符
var normalized = entry.FullName.Replace('/', Path.DirectorySeparatorChar);
// 拒绝包含 .. 的路径,防止目录穿越
if (normalized.Contains(".." + Path.DirectorySeparatorChar) ||
normalized.StartsWith(".." + Path.DirectorySeparatorChar, StringComparison.Ordinal))
{
continue;
}
var destinationPath = Path.GetFullPath(
Path.Combine(fullExtractPath, normalized));
// 再次确认仍然在目标目录下
if (!destinationPath.StartsWith(fullExtractPath, StringComparison.OrdinalIgnoreCase))
continue;
// 目录条目
if (entry.FullName.EndsWith("/", StringComparison.Ordinal) ||
entry.FullName.EndsWith("\\", StringComparison.Ordinal))
{
Directory.CreateDirectory(destinationPath);
continue;
}
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath) ?? fullExtractPath);
if (!overwrite && File.Exists(destinationPath))
continue;
using (var input = entry.Open())
using (var output = File.Create(destinationPath))
{
input.CopyTo(output);
}
}
}
}
}
}
+330
View File
@@ -0,0 +1,330 @@
using iNKORE.UI.WPF.Controls;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Security.Cryptography;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
namespace Ink_Canvas.Helpers
{
internal static class SecurityManager
{
private const int Pbkdf2Iterations = 120_000;
private const int SaltSizeBytes = 16;
private const int HashSizeBytes = 32;
/// <summary>
/// 检查设置中是否启用了密码安全功能。
/// </summary>
/// <param name="settings">应用程序设置对象(可能为 null)。</param>
/// <returns>`true` 当 settings 非 null 且其 Security 部分存在且已启用密码功能;`false` 否则。</returns>
public static bool IsPasswordFeatureEnabled(Settings settings)
=> settings?.Security != null && settings.Security.PasswordEnabled;
/// <summary>
/// 确定给定设置中是否已配置密码(存在非空的密码盐和密码哈希)。
/// </summary>
/// <param name="settings">应用的设置;为 null 或未包含 Security 部分时视为未配置密码。</param>
/// <returns>`true` 如果设置包含非空的 PasswordSalt 和 PasswordHash,否则 `false`。</returns>
public static bool HasPasswordConfigured(Settings settings)
=> settings?.Security != null
&& !string.IsNullOrWhiteSpace(settings.Security.PasswordSalt)
&& !string.IsNullOrWhiteSpace(settings.Security.PasswordHash);
/// <summary>
/// 确定在退出应用时是否需要输入密码。
/// </summary>
/// <param name="settings">应用配置;如果为 null,则视为未启用或未配置密码。</param>
/// <returns>`true` 当密码功能已启用、已配置密码且设置要求在退出时需要密码,`false` 否则。</returns>
public static bool IsPasswordRequiredForExit(Settings settings)
=> IsPasswordFeatureEnabled(settings) && HasPasswordConfigured(settings) && settings.Security.RequirePasswordOnExit;
/// <summary>
/// 确定在进入设置界面时是否需要输入密码。
/// </summary>
/// <param name="settings">应用配置;为 null 或未启用密码功能时视为未配置密码。</param>
/// <returns>`true` 如果已启用密码功能、已配置密码且已设置为在进入设置时要求密码,`false` 否则。</returns>
public static bool IsPasswordRequiredForEnterSettings(Settings settings)
=> IsPasswordFeatureEnabled(settings) && HasPasswordConfigured(settings) && settings.Security.RequirePasswordOnEnterSettings;
/// <summary>
/// 指示在重置配置时是否需要输入密码。
/// </summary>
/// <param name="settings">应用设置对象;如果为 null 或未启用密码功能,则视为不需要密码。</param>
/// <returns>`true` 如果已启用密码功能、已有配置的密码且设置要求在重置配置时进行密码验证;`false` 否则。</returns>
public static bool IsPasswordRequiredForResetConfig(Settings settings)
=> IsPasswordFeatureEnabled(settings) && HasPasswordConfigured(settings) && settings.Security.RequirePasswordOnResetConfig;
/// <summary>
/// 指示在修改或清空点名名单前是否需要输入安全密码。
/// </summary>
/// <param name="settings">应用设置对象。</param>
/// <returns>当已启用密码功能、已配置密码且开启了对应开关时返回 true;否则返回 false。</returns>
public static bool IsPasswordRequiredForModifyOrClearNameList(Settings settings)
=> IsPasswordFeatureEnabled(settings)
&& HasPasswordConfigured(settings)
&& settings.Security.RequirePasswordOnModifyOrClearNameList;
/// <summary>
/// 将提供的明文密码与 Settings 中存储的密码散列进行比对以验证密码是否正确。
/// </summary>
/// <param name="settings">包含存储的密码盐和哈希的设置对象(使用 Base64 编码的 PasswordSalt 和 PasswordHash)。</param>
/// <param name="password">要验证的明文密码。</param>
/// <returns>`true` 如果密码与存储的哈希匹配,`false` 否则(包括未配置密码、password 为 null 或在解析/派生过程中发生错误)。</returns>
public static bool VerifyPassword(Settings settings, string password)
{
if (!HasPasswordConfigured(settings)) return false;
if (password == null) return false;
try
{
var salt = Convert.FromBase64String(settings.Security.PasswordSalt);
var expected = Convert.FromBase64String(settings.Security.PasswordHash);
var actual = DeriveKey(password, salt, expected.Length);
return FixedTimeEquals(actual, expected);
}
catch
{
return false;
}
}
/// <summary>
/// 如果已配置密码,显示一个对话框提示用户输入密码并验证;如果未配置密码则直接允许通过。
/// </summary>
/// <returns>`true` 如果未配置密码或用户确认并输入了正确的密码,`false` 如果用户取消或验证失败。</returns>
public static async Task<bool> PromptAndVerifyAsync(Settings settings, Window owner, string title, string message)
{
if (!HasPasswordConfigured(settings)) return true;
var dialog = new ContentDialog
{
Title = title,
PrimaryButtonText = "确定",
SecondaryButtonText = "取消"
};
var panel = new SimpleStackPanel
{
Spacing = 12,
Margin = new Thickness(0, 10, 0, 0)
};
var textBlock = new TextBlock
{
Text = message,
TextWrapping = TextWrapping.Wrap
};
var passwordBox = new PasswordBox
{
Height = 32
};
panel.Children.Add(textBlock);
panel.Children.Add(passwordBox);
dialog.Content = panel;
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary) return false;
return VerifyPassword(settings, passwordBox.Password);
}
/// <summary>
/// 显示一个对话框让用户输入并确认新密码,成功时返回该密码。
/// </summary>
/// <param name="owner">对话框的所属窗口(用于指定父窗口)。</param>
/// <returns>用户输入的新密码;如果用户取消或输入无效(长度不足或两次不匹配),则返回 <c>null</c>。</returns>
public static async Task<string> PromptSetNewPasswordAsync(Window owner)
{
var dialog = new ContentDialog
{
Title = "设置安全密码",
PrimaryButtonText = "确定",
SecondaryButtonText = "取消"
};
var panel = new SimpleStackPanel
{
Spacing = 12,
Margin = new Thickness(0, 10, 0, 0)
};
var tipText = new TextBlock
{
Text = "请输入新密码",
TextWrapping = TextWrapping.Wrap
};
var newPwdBox = new PasswordBox { Height = 32, Margin = new Thickness(0, 4, 0, 0) };
var confirmPwdBox = new PasswordBox { Height = 32, Margin = new Thickness(0, 4, 0, 0) };
panel.Children.Add(tipText);
panel.Children.Add(new TextBlock { Text = "新密码", Margin = new Thickness(0, 4, 0, 0) });
panel.Children.Add(newPwdBox);
panel.Children.Add(new TextBlock { Text = "确认新密码", Margin = new Thickness(0, 8, 0, 0) });
panel.Children.Add(confirmPwdBox);
dialog.Content = panel;
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary) return null;
var pwd = newPwdBox.Password ?? "";
var confirm = confirmPwdBox.Password ?? "";
if (string.IsNullOrWhiteSpace(pwd) || pwd.Length < 4)
{
MessageBox.Show("密码长度过短。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return null;
}
if (!string.Equals(pwd, confirm, StringComparison.Ordinal))
{
MessageBox.Show("两次输入的密码不一致。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return null;
}
return pwd;
}
/// <summary>
/// 弹出对话框以更改已配置的安全密码;如果尚未配置密码则转而提示设置新密码。
/// </summary>
/// <param name="settings">应用配置对象,包含当前存储的密码信息。</param>
/// <param name="owner">对话框的父窗口(用于定位/所有权)。</param>
/// <returns>用户成功更改后返回新的密码字符串;当用户取消、验证失败或校验不通过时返回 <c>null</c>。</returns>
public static async Task<string> PromptChangePasswordAsync(Settings settings, Window owner)
{
if (!HasPasswordConfigured(settings))
{
return await PromptSetNewPasswordAsync(owner);
}
var dialog = new ContentDialog
{
Title = "修改安全密码",
PrimaryButtonText = "确定",
SecondaryButtonText = "取消"
};
var panel = new SimpleStackPanel
{
Spacing = 12,
Margin = new Thickness(0, 10, 0, 0)
};
var tipText = new TextBlock
{
Text = "请输入当前密码,并设置新密码。",
TextWrapping = TextWrapping.Wrap
};
var currentBox = new PasswordBox { Height = 32, Margin = new Thickness(0, 4, 0, 0) };
var newPwdBox = new PasswordBox { Height = 32, Margin = new Thickness(0, 4, 0, 0) };
var confirmPwdBox = new PasswordBox { Height = 32, Margin = new Thickness(0, 4, 0, 0) };
panel.Children.Add(tipText);
panel.Children.Add(new TextBlock { Text = "当前密码", Margin = new Thickness(0, 4, 0, 0) });
panel.Children.Add(currentBox);
panel.Children.Add(new TextBlock { Text = "新密码", Margin = new Thickness(0, 8, 0, 0) });
panel.Children.Add(newPwdBox);
panel.Children.Add(new TextBlock { Text = "确认新密码", Margin = new Thickness(0, 8, 0, 0) });
panel.Children.Add(confirmPwdBox);
dialog.Content = panel;
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary) return null;
var current = currentBox.Password ?? "";
var newPwd = newPwdBox.Password ?? "";
var confirm = confirmPwdBox.Password ?? "";
if (!VerifyPassword(settings, current))
{
MessageBox.Show("当前密码错误。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return null;
}
if (string.IsNullOrWhiteSpace(newPwd) || newPwd.Length < 4)
{
MessageBox.Show("新密码长度过短。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return null;
}
if (!string.Equals(newPwd, confirm, StringComparison.Ordinal))
{
MessageBox.Show("两次输入的新密码不一致。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return null;
}
return newPwd;
}
/// <summary>
/// 为指定 Settings 生成并存储新的密码盐与哈希到 settings.Security 中。
/// </summary>
/// <param name="settings">要更新的设置对象;如果为 null 或其 Security 为 null 则不执行任何操作。</param>
/// <param name="password">用于派生哈希的原始密码字符串。</param>
public static void SetPassword(Settings settings, string password)
{
if (settings?.Security == null) return;
var salt = new byte[SaltSizeBytes];
using (var rng = RandomNumberGenerator.Create())
{
rng.GetBytes(salt);
}
var hash = DeriveKey(password, salt, HashSizeBytes);
settings.Security.PasswordSalt = Convert.ToBase64String(salt);
settings.Security.PasswordHash = Convert.ToBase64String(hash);
}
/// <summary>
/// 清除设置中存储的密码信息。
/// </summary>
/// <param name="settings">要更新的设置对象;将把其 Security.PasswordSalt 和 Security.PasswordHash 设为空字符串。若 <paramref name="settings"/> 为 null 或其 Security 为 null 则不执行任何操作。</param>
public static void ClearPassword(Settings settings)
{
if (settings?.Security == null) return;
settings.Security.PasswordSalt = "";
settings.Security.PasswordHash = "";
}
/// <summary>
/// 使用 PBKDF2Rfc2898)从给定的密码和盐派生指定长度的密钥字节。
/// </summary>
/// <param name="password">用于派生的密码字符串。</param>
/// <param name="salt">用于派生的盐字节数组(不可为 null)。</param>
/// <param name="keyBytes">要返回的密钥字节长度(以字节为单位)。</param>
/// <returns>派生出的密钥字节数组,长度等于 <paramref name="keyBytes"/>。</returns>
private static byte[] DeriveKey(string password, byte[] salt, int keyBytes)
{
// 注意:Rfc2898DeriveBytes 在 net472 默认 HMACSHA1
using (var kdf = new Rfc2898DeriveBytes(password, salt, Pbkdf2Iterations))
{
return kdf.GetBytes(keyBytes);
}
}
/// <summary>
/// 以固定时间方式比较两个字节数组的内容是否完全相同,防止基于时序的比对攻击。
/// </summary>
/// <param name="a">要比较的第一个字节数组。</param>
/// <param name="b">要比较的第二个字节数组。</param>
/// <returns>`true` 如果两个数组长度相同且所有字节相等,`false` 否则。</returns>
private static bool FixedTimeEquals(byte[] a, byte[] b)
{
if (a == null || b == null) return false;
if (a.Length != b.Length) return false;
var diff = 0;
for (int i = 0; i < a.Length; i++)
{
diff |= a[i] ^ b[i];
}
return diff == 0;
}
}
}
+122 -46
View File
@@ -1,72 +1,148 @@
using Microsoft.Win32;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
namespace Ink_Canvas.Helpers
{
internal class SoftwareLauncher
internal static class SoftwareLauncher
{
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
/// <summary>与 ICA 一致:在「程序和功能」卸载列表中按 DisplayName 匹配后启动 sweclauncher.exe。</summary>
public static void LaunchEasiCamera(string softwareName)
{
string executablePath = FindEasiCameraExecutablePath(softwareName);
if (!string.IsNullOrEmpty(executablePath))
if (string.IsNullOrEmpty(executablePath))
{
try
{
Process.Start(executablePath);
//Console.WriteLine(softwareName + " 启动成功!");
}
catch (Exception ex)
{
Console.WriteLine("启动失败: " + ex.Message);
//MessageBox.Show("启动失败: " + ex.Message);
}
MessageBox.Show(
"未找到希沃视频展台安装信息(已扫描 64 位与 32 位卸载注册表)。请确认已通过官方安装包安装「希沃视频展台」。",
"Ink Canvas",
MessageBoxButton.OK,
MessageBoxImage.Information);
return;
}
try
{
var directory = Path.GetDirectoryName(executablePath);
var psi = new ProcessStartInfo
{
FileName = executablePath,
UseShellExecute = true,
WorkingDirectory = string.IsNullOrEmpty(directory) ? Environment.SystemDirectory : directory
};
Process.Start(psi);
}
catch (Exception ex)
{
MessageBox.Show(
"无法启动希沃视频展台:" + ex.Message,
"Ink Canvas",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
//Console.WriteLine(softwareName + " 未找到可执行文件路径。");
}
private static string FindEasiCameraExecutablePath(string softwareName)
{
string executablePath = null;
if (string.IsNullOrWhiteSpace(softwareName))
return null;
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall"))
// 须用 OpenBaseKey + RegistryView 显式指定视图:Registry.LocalMachine.OpenSubKey 跟随进程位数,
// 32 位进程下无法靠拼接 WOW6432Node 路径进入 64 位视图,会找不到 64 位安装的展台。
const string uninstallSubKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
foreach (RegistryView view in new[] { RegistryView.Registry64, RegistryView.Registry32 })
{
foreach (string subkeyName in key.GetSubKeyNames())
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, view))
using (RegistryKey key = baseKey.OpenSubKey(uninstallSubKey))
{
using (RegistryKey subkey = key.OpenSubKey(subkeyName))
{
string displayName = subkey.GetValue("DisplayName") as string;
string installLocation = subkey.GetValue("InstallLocation") as string;
string uninstallString = subkey.GetValue("UninstallString") as string;
if (!string.IsNullOrEmpty(displayName) && displayName.Contains(softwareName))
{
if (!string.IsNullOrEmpty(installLocation))
{
executablePath = Path.Combine(installLocation, "sweclauncher.exe");
}
else if (!string.IsNullOrEmpty(uninstallString))
{
int lastSlashIndex = uninstallString.LastIndexOf("\\");
if (lastSlashIndex >= 0)
{
string folderPath = uninstallString.Substring(0, lastSlashIndex);
executablePath = Path.Combine(folderPath, "sweclauncher", "sweclauncher.exe");
}
}
break;
}
}
if (key == null) continue;
string found = FindInUninstallKey(key, softwareName);
if (!string.IsNullOrEmpty(found))
return found;
}
}
return executablePath;
return null;
}
private static string FindInUninstallKey(RegistryKey uninstallKey, string softwareName)
{
foreach (string subkeyName in uninstallKey.GetSubKeyNames())
{
using (RegistryKey subkey = uninstallKey.OpenSubKey(subkeyName))
{
if (subkey == null) continue;
string displayName = subkey.GetValue("DisplayName") as string;
if (string.IsNullOrEmpty(displayName) || !displayName.Contains(softwareName))
continue;
string installLocation = subkey.GetValue("InstallLocation") as string;
string uninstallString = subkey.GetValue("UninstallString") as string;
string resolved = TryResolveSweclauncher(installLocation, uninstallString);
if (!string.IsNullOrEmpty(resolved) && File.Exists(resolved))
return resolved;
}
}
return null;
}
private static string TryResolveSweclauncher(string installLocation, string uninstallString)
{
if (!string.IsNullOrWhiteSpace(installLocation))
{
string fromLoc = ResolveSweclauncherUnderInstallRoot(installLocation.Trim().TrimEnd('\\'));
if (!string.IsNullOrEmpty(fromLoc))
return fromLoc;
}
if (!string.IsNullOrWhiteSpace(uninstallString))
{
// 常见:"...\uninstall.exe" 或带引号路径
string trimmed = uninstallString.Trim();
if (trimmed.Length >= 2 && trimmed[0] == '"')
{
int end = trimmed.IndexOf('"', 1);
if (end > 1)
trimmed = trimmed.Substring(1, end - 1);
}
int lastSlash = trimmed.LastIndexOf('\\');
if (lastSlash < 0)
return null;
string folderPath = trimmed.Substring(0, lastSlash);
string candidate = Path.Combine(folderPath, "sweclauncher", "sweclauncher.exe");
if (File.Exists(candidate))
return candidate;
candidate = Path.Combine(folderPath, "sweclauncher.exe");
if (File.Exists(candidate))
return candidate;
}
return null;
}
private static string ResolveSweclauncherUnderInstallRoot(string installRoot)
{
string[] candidates =
{
Path.Combine(installRoot, "sweclauncher.exe"),
Path.Combine(installRoot, "sweclauncher", "sweclauncher.exe"),
};
foreach (string p in candidates)
{
if (File.Exists(p))
return p;
}
return null;
}
}
}
+4 -3
View File
@@ -1,3 +1,4 @@
using System;
using System.IO;
namespace Ink_Canvas.Helpers
@@ -18,7 +19,7 @@ namespace Ink_Canvas.Helpers
return count;
}
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return 0;
}
@@ -31,7 +32,7 @@ namespace Ink_Canvas.Helpers
{
File.WriteAllText(CountFilePath, count.ToString());
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
@@ -44,7 +45,7 @@ namespace Ink_Canvas.Helpers
if (File.Exists(CountFilePath))
File.Delete(CountFilePath);
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
}
}
+209
View File
@@ -0,0 +1,209 @@
using Sentry;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
internal static class TelemetryUploader
{
private static readonly Regex EmailRegex = new Regex(
@"(?i)\b[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,}\b",
RegexOptions.Compiled);
private static readonly Regex PhoneRegex = new Regex(
@"\b1[3-9]\d{9}\b",
RegexOptions.Compiled);
private static readonly Regex IPv4Regex = new Regex(
@"\b(?:\d{1,3}\.){3}\d{1,3}\b",
RegexOptions.Compiled);
private static readonly Regex WindowsPathRegex = new Regex(
@"\b[A-Za-z]:\\[^\s<>|]+\b",
RegexOptions.Compiled);
private static readonly Regex UncPathRegex = new Regex(
@"\\\\[^\s]+",
RegexOptions.Compiled);
private static readonly Regex KeyValueSecretRegex = new Regex(
@"(?i)(\b(?:access[_-]?token|refresh[_-]?token|token|password|passwd|pwd|secret|authorization)\b\s*[:=]\s*)([^\s,;]+)",
RegexOptions.Compiled);
private static readonly Regex JsonSecretRegex = new Regex(
"(?i)(\"(?:access_token|refresh_token|token|password|passwd|pwd|secret|authorization)\"\\s*:\\s*\")([^\"]*)(\")",
RegexOptions.Compiled);
private static readonly Regex UrlSecretRegex = new Regex(
@"(?i)([?&](?:access_token|token|password|pwd|secret)=)[^&\s]+",
RegexOptions.Compiled);
public static Task UploadTelemetryIfNeededAsync()
{
return Task.Run(() =>
{
try
{
var settings = MainWindow.Settings;
if (settings == null || settings.Startup == null)
{
return;
}
var level = settings.Startup.TelemetryUploadLevel;
if (level == TelemetryUploadLevel.None)
{
return;
}
string deviceId = DeviceIdentifier.GetDeviceId();
if (string.IsNullOrWhiteSpace(deviceId) || deviceId.Length < 5)
{
LogHelper.WriteLogToFile("TelemetryUploader | 设备ID无效,取消遥测上传", LogHelper.LogType.Warning);
return;
}
// Basic 和 Extended 均上传崩溃日志(脱敏)
object crashFile = TryGetLatestSanitizedFile(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Crashes"),
"Crash_*.txt",
"崩溃日志");
// Extended 额外上传运行日志(脱敏)
object runtimeLogFile = null;
if (level == TelemetryUploadLevel.Extended)
{
runtimeLogFile = TryGetLatestSanitizedFile(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"),
"Log_*.txt",
"运行日志");
}
var telemetryData = new
{
telemetry_level = level.ToString(),
device_id = deviceId,
update_channel = settings.Startup.UpdateChannel.ToString(),
app_version = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
os_version = Environment.OSVersion.VersionString,
has_crash_log = crashFile != null,
has_runtime_log = runtimeLogFile != null
};
// 通过 Sentry 上报一个包含遥测信息的事件
string userName = Environment.UserName;
SentrySdk.ConfigureScope(scope =>
{
scope.User = new SentryUser
{
Id = deviceId,
Username = userName,
Email = $"{userName}",
IpAddress = "{{auto}}"
};
});
var evt = new SentryEvent
{
Message = "ICC CE Telemetry",
Level = SentryLevel.Info
};
evt.User = new SentryUser
{
Id = deviceId,
Username = userName,
Email = $"{userName}",
IpAddress = "{{auto}}"
};
evt.SetTag("telemetry_level", level.ToString());
evt.SetTag("device_id", deviceId);
evt.SetTag("update_channel", settings.Startup.UpdateChannel.ToString());
evt.SetTag("app_version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
evt.SetTag("os_version", Environment.OSVersion.VersionString);
evt.SetExtra("telemetry_data", telemetryData);
if (crashFile != null)
{
evt.SetExtra("crash_file", crashFile);
}
if (runtimeLogFile != null)
{
evt.SetExtra("runtime_log_file", runtimeLogFile);
}
SentrySdk.CaptureEvent(evt);
LogHelper.WriteLogToFile("TelemetryUploader | 遥测数据已通过 Sentry 上报", LogHelper.LogType.Event);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"TelemetryUploader | 遥测上传失败: {ex.Message}", LogHelper.LogType.Warning);
}
});
}
private static object TryGetLatestSanitizedFile(string directory, string pattern, string fileType)
{
try
{
if (!Directory.Exists(directory))
{
return null;
}
var latest = new DirectoryInfo(directory)
.GetFiles(pattern)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();
if (latest == null)
{
return null;
}
string content = File.ReadAllText(latest.FullName);
string sanitizedContent = SanitizeLogContent(content);
return new
{
file_type = fileType,
file_name = latest.Name,
last_write_time = latest.LastWriteTime.ToString("o"),
content = sanitizedContent
};
}
catch (Exception ex)
{
LogHelper.WriteLogToFile(
$"TelemetryUploader | 收集{fileType}失败: {ex.Message}",
LogHelper.LogType.Warning);
return null;
}
}
private static string SanitizeLogContent(string content)
{
if (string.IsNullOrEmpty(content))
{
return content;
}
string sanitized = content;
sanitized = EmailRegex.Replace(sanitized, "[REDACTED_EMAIL]");
sanitized = PhoneRegex.Replace(sanitized, "[REDACTED_PHONE]");
sanitized = IPv4Regex.Replace(sanitized, "[REDACTED_IP]");
sanitized = WindowsPathRegex.Replace(sanitized, "[REDACTED_PATH]");
sanitized = UncPathRegex.Replace(sanitized, "[REDACTED_PATH]");
sanitized = UrlSecretRegex.Replace(sanitized, "$1[REDACTED]");
sanitized = KeyValueSecretRegex.Replace(sanitized, "$1[REDACTED]");
sanitized = JsonSecretRegex.Replace(sanitized, "$1[REDACTED]$3");
return sanitized;
}
}
}
+21 -5
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Ink;
@@ -92,16 +92,26 @@ namespace Ink_Canvas.Helpers
public TimeMachineHistory Undo()
{
if (_currentIndex < 0 || _currentIndex >= _currentStrokeHistory.Count)
{
return null;
}
var item = _currentStrokeHistory[_currentIndex];
item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared;
_currentIndex--;
OnUndoStateChanged?.Invoke(_currentIndex > -1);
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0);
OnUndoStateChanged?.Invoke(CanUndo);
OnRedoStateChanged?.Invoke(CanRedo);
return item;
}
public TimeMachineHistory Redo()
{
if (_currentStrokeHistory.Count == 0 || _currentIndex >= _currentStrokeHistory.Count - 1)
{
return null;
}
var item = _currentStrokeHistory[++_currentIndex];
item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared;
NotifyUndoRedoState();
@@ -127,9 +137,15 @@ namespace Ink_Canvas.Helpers
}
private void NotifyUndoRedoState()
{
OnUndoStateChanged?.Invoke(_currentIndex > -1);
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0);
OnUndoStateChanged?.Invoke(CanUndo);
OnRedoStateChanged?.Invoke(CanRedo);
}
/// <summary>当前历史是否允许撤销。</summary>
public bool CanUndo => _currentIndex > -1;
/// <summary>当前历史是否允许重做。</summary>
public bool CanRedo => _currentStrokeHistory.Count > 0 && _currentStrokeHistory.Count - _currentIndex - 1 > 0;
}
public class TimeMachineHistory
+269
View File
@@ -0,0 +1,269 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 上传提供者接口
/// </summary>
public interface IUploadProvider
{
/// <summary>
/// 提供者名称
/// </summary>
string Name { get; }
/// <summary>
/// 是否启用
/// </summary>
bool IsEnabled { get; }
/// <summary>
/// 上传文件
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="cancellationToken">取消令牌</param>
/// <returns>是否上传成功</returns>
Task<bool> UploadAsync(string filePath, CancellationToken cancellationToken = default);
}
/// <summary>
/// Dlass上传提供者
/// </summary>
public class DlassUploadProvider : IUploadProvider
{
public static readonly DlassUploadQueue Queue = new DlassUploadQueue();
/// <summary>
/// 提供者名称
/// </summary>
public string Name => "Dlass";
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled => MainWindow.Settings?.Upload?.EnabledProviders?.Contains(Name) ?? false;
/// <summary>
/// 上传文件
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="cancellationToken">取消令牌</param>
/// <returns>是否上传成功</returns>
public async Task<bool> UploadAsync(string filePath, CancellationToken cancellationToken = default)
{
return await Queue.UploadFileAsync(filePath, cancellationToken).ConfigureAwait(false);
}
}
/// <summary>
/// WebDav上传提供者
/// </summary>
public class WebDavUploadProvider : IUploadProvider
{
public static readonly WebDavUploadQueue Queue = new WebDavUploadQueue();
/// <summary>
/// 提供者名称
/// </summary>
public string Name => "WebDav";
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled => MainWindow.Settings?.Upload?.EnabledProviders?.Contains(Name) ?? false;
/// <summary>
/// 上传文件
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="cancellationToken">取消令牌</param>
/// <returns>是否上传成功</returns>
public async Task<bool> UploadAsync(string filePath, CancellationToken cancellationToken = default)
{
return await Queue.UploadFileAsync(filePath, cancellationToken).ConfigureAwait(false);
}
}
/// <summary>
/// 上传帮助类
/// </summary>
public static class UploadHelper
{
private static readonly List<IUploadProvider> _providers = new List<IUploadProvider>();
private static bool _initialized;
private static readonly object s_sync = new object();
/// <summary>
/// 初始化上传帮助类
/// </summary>
public static void Initialize()
{
lock (s_sync)
{
if (_initialized)
return;
// 注册默认上传提供者
RegisterProviderInternal(new DlassUploadProvider());
RegisterProviderInternal(new WebDavUploadProvider());
// 注册上传队列
UploadQueueHelper.RegisterQueue(DlassUploadProvider.Queue);
UploadQueueHelper.RegisterQueue(WebDavUploadProvider.Queue);
// 初始化所有上传队列
UploadQueueHelper.InitializeAllQueues();
_initialized = true;
}
}
/// <summary>
/// 注册上传提供者
/// </summary>
/// <param name="provider">上传提供者</param>
public static void RegisterProvider(IUploadProvider provider)
{
if (provider == null)
return;
lock (s_sync)
{
RegisterProviderInternal(provider);
}
}
private static void RegisterProviderInternal(IUploadProvider provider)
{
if (provider != null)
{
bool providerExists = _providers.Any(p => p.GetType() == provider.GetType());
if (!providerExists)
{
_providers.Add(provider);
}
}
}
/// <summary>
/// 上传文件到所有启用的提供者
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="cancellationToken">取消令牌</param>
/// <returns>是否至少有一个提供者上传成功</returns>
public static async Task<bool> UploadFileAsync(string filePath, CancellationToken cancellationToken = default)
{
if (!_initialized)
{
Initialize();
}
List<IUploadProvider> providersSnapshot;
lock (s_sync)
{
providersSnapshot = new List<IUploadProvider>(_providers);
}
bool anySuccess = false;
// 获取上传延迟时间
int delayMinutes = MainWindow.Settings?.Upload?.UploadDelayMinutes ?? 0;
// 应用上传延迟
if (delayMinutes > 0)
{
LogHelper.WriteLogToFile($"上传延迟 {delayMinutes} 分钟", LogHelper.LogType.Event);
cancellationToken.ThrowIfCancellationRequested();
await Task.Delay(TimeSpan.FromMinutes(delayMinutes), cancellationToken).ConfigureAwait(false);
}
// 上传前验证文件是否存在且可访问
if (!File.Exists(filePath))
{
LogHelper.WriteLogToFile($"上传失败:文件不存在 - {filePath}", LogHelper.LogType.Error);
return false;
}
try
{
// 检查文件是否可访问
using (var fileStream = File.OpenRead(filePath))
{
// 文件可访问
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"上传失败:文件不可访问 - {filePath}, 原因: {ex.Message}", LogHelper.LogType.Error);
return false;
}
foreach (var provider in providersSnapshot)
{
try
{
if (provider.IsEnabled)
{
bool success = await provider.UploadAsync(filePath, cancellationToken).ConfigureAwait(false);
if (success)
{
anySuccess = true;
}
}
}
catch (OperationCanceledException)
{
LogHelper.WriteLogToFile($"上传被取消: {provider.Name}", LogHelper.LogType.Event);
throw;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"使用 {provider.Name} 上传失败: {ex}", LogHelper.LogType.Error);
}
}
return anySuccess;
}
/// <summary>
/// 获取所有上传提供者
/// </summary>
/// <returns>上传提供者列表</returns>
public static List<IUploadProvider> GetProviders()
{
if (!_initialized)
{
Initialize();
}
lock (s_sync)
{
return new List<IUploadProvider>(_providers);
}
}
/// <summary>
/// 获取所有启用的上传提供者
/// </summary>
/// <returns>启用的上传提供者列表</returns>
public static List<IUploadProvider> GetEnabledProviders()
{
if (!_initialized)
{
Initialize();
}
lock (s_sync)
{
return _providers.FindAll(p => p.IsEnabled);
}
}
}
}
+92
View File
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 上传队列帮助类,提供统一的队列管理功能
/// </summary>
public static class UploadQueueHelper
{
private static readonly List<BaseUploadQueue> _queues = new List<BaseUploadQueue>();
private static readonly object _syncLock = new object();
private static volatile bool _initialized = false;
/// <summary>
/// 初始化所有上传队列
/// </summary>
public static void InitializeAllQueues()
{
lock (_syncLock)
{
if (_initialized)
return;
// 初始化所有注册的队列
foreach (var queue in _queues)
{
try
{
queue.InitializeQueue();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[UploadQueueHelper] 初始化队列时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
_initialized = true;
}
}
/// <summary>
/// 注册上传队列
/// </summary>
/// <param name="queue">上传队列实例</param>
public static void RegisterQueue(BaseUploadQueue queue)
{
if (queue == null)
return;
lock (_syncLock)
{
if (!_queues.Contains(queue))
{
try
{
// 先初始化队列,再添加到列表
queue.InitializeQueue();
_queues.Add(queue);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[UploadQueueHelper] 注册队列时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
}
/// <summary>
/// 获取所有注册的上传队列
/// </summary>
/// <returns>上传队列列表</returns>
public static IReadOnlyList<BaseUploadQueue> GetAllQueues()
{
lock (_syncLock)
{
return new List<BaseUploadQueue>(_queues).AsReadOnly();
}
}
/// <summary>
/// 确保所有队列都已初始化
/// </summary>
public static void EnsureQueuesInitialized()
{
if (!_initialized)
{
InitializeAllQueues();
}
}
}
}
+118
View File
@@ -0,0 +1,118 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
namespace Ink_Canvas.Helpers
{
public static class UriSchemeHelper
{
private const string SchemeName = "icc";
private const string FriendlyName = "URL:Ink Canvas Protocol";
public static bool RegisterUriScheme()
{
try
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
// 使用 CurrentUser\Software\Classes 代替 ClassesRoot,无需管理员权限
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + SchemeName))
{
key.SetValue("", FriendlyName);
key.SetValue("URL Protocol", "");
using (RegistryKey defaultIconKey = key.CreateSubKey("DefaultIcon"))
{
// 修正引号转义
defaultIconKey.SetValue("", "\"" + exePath + "\",1");
}
using (RegistryKey shellKey = key.CreateSubKey("shell"))
using (RegistryKey openKey = shellKey.CreateSubKey("open"))
using (RegistryKey commandKey = openKey.CreateSubKey("command"))
{
// 修正引号转义
commandKey.SetValue("", "\"" + exePath + "\" \"%1\"");
}
}
LogHelper.WriteLogToFile($"成功注册URI Scheme: {SchemeName}://", LogHelper.LogType.Event);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"注册URI Scheme失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
public static bool UnregisterUriScheme()
{
try
{
// 使用 CurrentUser\Software\Classes
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Classes\" + SchemeName, false);
LogHelper.WriteLogToFile($"成功注销URI Scheme: {SchemeName}://", LogHelper.LogType.Event);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"注销URI Scheme失败: {ex.Message}", LogHelper.LogType.Error);
return false;
}
}
public static bool IsUriSchemeRegistered()
{
try
{
// 使用 CurrentUser\Software\Classes
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Classes\" + SchemeName))
{
if (key == null) return false;
// 修正反斜杠路径
using (RegistryKey shellKey = key.OpenSubKey(@"shell\open\command"))
{
if (shellKey == null) return false;
string command = shellKey.GetValue("") as string;
if (string.IsNullOrEmpty(command)) return false;
// 提取第一个标记作为可执行文件路径(处理带引号的情况)
string registeredExePath = "";
if (command.StartsWith("\""))
{
int nextQuote = command.IndexOf("\"", 1);
if (nextQuote > 1)
{
registeredExePath = command.Substring(1, nextQuote - 1);
}
}
else
{
int firstSpace = command.IndexOf(" ");
registeredExePath = firstSpace > 0 ? command.Substring(0, firstSpace) : command;
}
if (string.IsNullOrEmpty(registeredExePath)) return false;
string currentExePath = Process.GetCurrentProcess().MainModule.FileName;
try
{
string normalizedRegisteredPath = System.IO.Path.GetFullPath(registeredExePath);
string normalizedCurrentPath = System.IO.Path.GetFullPath(currentExePath);
return string.Equals(normalizedRegisteredPath, normalizedCurrentPath, StringComparison.OrdinalIgnoreCase);
}
catch
{
return string.Equals(registeredExePath, currentExePath, StringComparison.OrdinalIgnoreCase);
}
}
}
}
catch
{
return false;
}
}
}
}
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// WebDAV上传队列
/// </summary>
public class WebDavUploadQueue : BaseUploadQueue
{
/// <summary>
/// 队列文件名
/// </summary>
protected override string QueueFileName => "WebDavUploadQueue.json";
/// <summary>
/// 检查上传是否启用
/// </summary>
protected override bool IsUploadEnabled()
{
return WebDavUploader.IsWebDavEnabled();
}
/// <summary>
/// 内部上传方法,执行实际上传操作
/// </summary>
protected override async Task<bool> UploadFileInternalAsync(string filePath, CancellationToken cancellationToken)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
// 再次检查文件是否存在(可能在队列等待时被删除)
if (!File.Exists(filePath))
{
return false;
}
// 检查WebDAV是否仍然启用
if (!WebDavUploader.IsWebDavEnabled())
{
return false;
}
// 调用WebDavUploader进行实际上传
var success = await WebDavUploader.UploadFileAsync(filePath, cancellationToken);
return success;
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception)
{
throw;
}
}
}
}
+171
View File
@@ -0,0 +1,171 @@
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using WebDav;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// WebDav上传工具类
/// </summary>
public static class WebDavUploader
{
/// <summary>
/// 上传文件到WebDav服务器
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="cancellationToken">取消令牌</param>
/// <returns>是否上传成功</returns>
public static async Task<bool> UploadFileAsync(string filePath, CancellationToken cancellationToken = default)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
// 检查文件是否存在
if (!File.Exists(filePath))
{
return false;
}
// 获取WebDav设置
var webDavUrl = MainWindow.Settings?.Dlass?.WebDavUrl;
var username = MainWindow.Settings?.Dlass?.WebDavUsername;
var password = MainWindow.Settings?.Dlass?.WebDavPassword;
var rootDirectory = MainWindow.Settings?.Dlass?.WebDavRootDirectory;
// 验证设置
if (string.IsNullOrEmpty(webDavUrl))
{
return false;
}
// 构建完整的目标路径
var fileName = Path.GetFileName(filePath);
var targetPath = Path.Combine(rootDirectory ?? string.Empty, fileName).Replace("\\", "/");
if (targetPath.StartsWith("/"))
{
targetPath = targetPath.Substring(1);
}
// 创建WebDav客户端
var clientParams = new WebDavClientParams
{
BaseAddress = new Uri(webDavUrl),
Credentials = new NetworkCredential(username ?? string.Empty, password ?? string.Empty)
};
using (var client = new WebDavClient(clientParams))
{
cancellationToken.ThrowIfCancellationRequested();
// 先直接尝试上传文件
using (var fileStream = File.OpenRead(filePath))
{
// 检查取消令牌
cancellationToken.ThrowIfCancellationRequested();
var result = await client.PutFile(targetPath, fileStream);
if (result.IsSuccessful)
{
return true;
}
else
{
// 上传失败,尝试创建目录
var directoryPath = Path.GetDirectoryName(targetPath);
if (!string.IsNullOrEmpty(directoryPath))
{
await EnsureDirectoryExistsAsync(client, directoryPath, cancellationToken);
// 再次尝试上传文件
cancellationToken.ThrowIfCancellationRequested();
using (var retryStream = File.OpenRead(filePath))
{
var retryResult = await client.PutFile(targetPath, retryStream);
return retryResult.IsSuccessful;
}
}
else
{
// 没有目录路径,直接返回失败
return false;
}
}
}
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// 确保WebDav目录存在
/// </summary>
/// <param name="client">WebDav客户端</param>
/// <param name="directoryPath">目录路径</param>
/// <param name="cancellationToken">取消令牌</param>
private static async Task EnsureDirectoryExistsAsync(IWebDavClient client, string directoryPath, CancellationToken cancellationToken)
{
try
{
// 分割路径并逐级创建目录
var pathParts = directoryPath.Split('/');
var currentPath = string.Empty;
foreach (var part in pathParts)
{
cancellationToken.ThrowIfCancellationRequested();
if (string.IsNullOrEmpty(part))
continue;
currentPath = Path.Combine(currentPath, part).Replace("\\", "/");
// 检查取消令牌
cancellationToken.ThrowIfCancellationRequested();
// 尝试创建目录
await client.Mkcol(currentPath);
}
}
catch (Exception)
{
// 静默处理目录创建错误
}
}
/// <summary>
/// 检查WebDAV是否已启用
/// </summary>
/// <returns>是否启用</returns>
public static bool IsWebDavEnabled()
{
// 检查WebDav设置是否有效
var webDavUrl = MainWindow.Settings?.Dlass?.WebDavUrl;
if (string.IsNullOrEmpty(webDavUrl))
{
return false;
}
// 尝试解析URL
try
{
new Uri(webDavUrl);
return true;
}
catch
{
return false;
}
}
}
}
@@ -0,0 +1,830 @@
using OSVersionExtension;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using WinAnalysis = global::Windows.UI.Input.Inking.Analysis;
using WinRtInk = global::Windows.UI.Input.Inking;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// WinRT 手写体识别,以及将识别结果用手写风格字体轮廓转为墨迹笔画(「识别转手写体字形」)。
/// </summary>
internal static class WinRtHandwritingRecognizer
{
private static WinRtInk.InkRecognizer _preferredHandwritingRecognizer;
private static bool _preferredHandwritingRecognizerResolved;
private static void LogHandwriting(string message, LogHelper.LogType logType = LogHelper.LogType.Info)
{
LogHelper.WriteLogToFile("[手写体] " + message, logType);
}
public static bool IsApiAvailable =>
OSVersion.GetOperatingSystem() >= OSVersionExtension.OperatingSystem.Windows10;
/// <summary>
/// 启动阶段不再预热线程内 WinRT 手写管线。历史上曾用 <see cref="WinRtInkShapeRecognizer.CreateMinimalWarmupStrokeCollection"/> 跑全链路,
/// 会显著拖慢启动;与更早的「空 <see cref="StrokeCollection"/>」一样,此处不再在 Idle 上做任何工作。
/// 首次真正需要手写识别时由 <see cref="RecognizeHandwritingAsync"/> 承担冷启动成本。
/// </summary>
public static void Warmup()
{
}
/// <summary>
/// 将当前笔画集合识别为文字片段(含候选):先用墨迹分析得到分词与 <see cref="WinAnalysis.InkAnalysisInkWord.RecognizedText"/>
/// 再对每一分词用 <see cref="WinRtInk.InkRecognizerContainer"/> 取 <c>GetTextCandidates</c>(与当前 SDK 中部分版本的
/// <see cref="WinRtInk.InkRecognitionResult"/> 未暴露笔画映射的局限兼容)。
/// </summary>
/// <param name="verboseTrace">为 false 时跳过详细识别日志(用于 <see cref="Warmup"/> 等)。</param>
public static async Task<HandwritingRecognitionResult> RecognizeHandwritingAsync(
StrokeCollection strokes,
bool verboseTrace = true)
{
if (!IsApiAvailable || strokes == null || strokes.Count == 0)
return HandwritingRecognitionResult.Empty;
var traceRecognition = verboseTrace;
try
{
var recognizer = new WinRtInk.InkRecognizerContainer();
TryApplyPreferredHandwritingRecognizer(recognizer, traceRecognition);
var analyzer = new WinAnalysis.InkAnalyzer();
var idToWpf = new Dictionary<uint, Stroke>();
foreach (Stroke s in strokes)
{
var ink = WinRtInkShapeRecognizer.CreateInkStrokeFromWpf(s);
if (ink == null) continue;
analyzer.AddDataForStroke(ink);
analyzer.SetStrokeDataKind(ink.Id, WinAnalysis.InkAnalysisStrokeKind.Writing);
idToWpf[ink.Id] = s;
}
if (idToWpf.Count == 0)
{
if (traceRecognition)
LogHandwriting("识别:无有效 WinRT 笔画(全部转换失败),输入笔画数=" + strokes.Count);
return HandwritingRecognitionResult.Empty;
}
var analysisResult = await analyzer.AnalyzeAsync().AsTask().ConfigureAwait(true);
if (analysisResult == null || analysisResult.Status != WinAnalysis.InkAnalysisStatus.Updated)
{
if (traceRecognition)
LogHandwriting(
"识别:AnalyzeAsync 未得到 UpdatedStatus=" +
(analysisResult == null ? "null" : analysisResult.Status.ToString()) +
",有效笔画数=" + idToWpf.Count +
",尝试整批 RecognizeAsync 回退。");
return await RecognizeHandwritingWholeInkAsync(strokes, traceRecognition).ConfigureAwait(true);
}
var wordNodes = analyzer.AnalysisRoot?.FindNodes(WinAnalysis.InkAnalysisNodeKind.InkWord);
if (wordNodes == null || wordNodes.Count == 0)
{
if (traceRecognition)
LogHandwriting(
"识别:未找到 InkWord 节点(墨迹分析常将非横平笔划判为绘图),有效笔画数=" + idToWpf.Count +
",改用整批 RecognizeAsync 回退。");
return await RecognizeHandwritingWholeInkAsync(strokes, traceRecognition).ConfigureAwait(true);
}
var segments = new List<HandwritingWordSegment>();
foreach (var node in wordNodes)
{
if (!(node is WinAnalysis.InkAnalysisInkWord word))
continue;
var ids = word.GetStrokeIds();
if (ids == null || ids.Count == 0)
continue;
var group = new List<Stroke>();
foreach (var sid in ids)
{
if (idToWpf.TryGetValue(sid, out var st))
group.Add(st);
}
if (group.Count == 0)
continue;
var wbr = word.BoundingRect;
var wpfRect = new Rect(wbr.X, wbr.Y, wbr.Width, wbr.Height);
var analysisText = word.RecognizedText ?? string.Empty;
IReadOnlyList<string> candList = Array.Empty<string>();
try
{
if (recognizer != null)
{
var mini = new WinRtInk.InkStrokeContainer();
foreach (var st in group)
{
var ink = WinRtInkShapeRecognizer.CreateInkStrokeFromWpf(st);
if (ink != null)
mini.AddStroke(ink);
}
var miniStrokes = mini.GetStrokes();
if (miniStrokes != null && miniStrokes.Count > 0)
{
var rr = await recognizer
.RecognizeAsync(mini, WinRtInk.InkRecognitionTarget.All)
.AsTask()
.ConfigureAwait(true);
if (rr != null && rr.Count > 0 && rr[0] != null)
{
var cands = rr[0].GetTextCandidates();
if (cands != null && cands.Count > 0)
candList = cands.ToList();
}
}
}
}
catch
{
candList = Array.Empty<string>();
}
var primary = candList.Count > 0 ? candList[0] : analysisText;
var mergedCandidates = new List<string>();
if (candList.Count > 0)
{
foreach (var c in candList)
{
if (!string.IsNullOrEmpty(c) && !mergedCandidates.Contains(c))
mergedCandidates.Add(c);
}
}
if (!string.IsNullOrEmpty(analysisText) && !mergedCandidates.Contains(analysisText))
mergedCandidates.Insert(0, analysisText);
if (mergedCandidates.Count == 0 && !string.IsNullOrEmpty(primary))
mergedCandidates.Add(primary);
segments.Add(new HandwritingWordSegment(
primary,
mergedCandidates,
wpfRect,
group));
}
if (segments.Count == 0)
{
if (traceRecognition)
LogHandwriting("识别:分词列表为空(InkWord 无有效笔画映射)。");
return HandwritingRecognitionResult.Empty;
}
var hr = new HandwritingRecognitionResult(segments);
if (traceRecognition)
{
var preview = hr.CombinedText;
if (preview.Length > 120)
preview = preview.Substring(0, 117) + "...";
LogHandwriting(
"识别成功:词数=" + segments.Count +
",合并文本=\"" + preview + "\"" +
",进程位数=" + (Environment.Is64BitProcess ? "x64" : "x86"));
for (var i = 0; i < segments.Count; i++)
{
var seg = segments[i];
var t = seg.Text ?? "";
if (t.Length > 40)
t = t.Substring(0, 37) + "...";
LogHandwriting(
" 词[" + i + "] 文本=\"" + t + "\",笔画数=" + seg.Strokes.Count +
",候选数=" + (seg.TextCandidates?.Count ?? 0) +
",框=(" + Math.Round(seg.BoundingRectangle.X, 1) + "," +
Math.Round(seg.BoundingRectangle.Y, 1) + "," +
Math.Round(seg.BoundingRectangle.Width, 1) + "×" +
Math.Round(seg.BoundingRectangle.Height, 1) + ")");
}
}
return hr;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("WinRT 手写识别失败: " + ex.Message, LogHelper.LogType.Warning);
if (strokes != null && strokes.Count > 0)
LogHandwriting("识别异常:" + ex.Message, LogHelper.LogType.Warning);
return HandwritingRecognitionResult.Empty;
}
}
private static void TryApplyPreferredHandwritingRecognizer(
WinRtInk.InkRecognizerContainer container,
bool logDetail)
{
if (container == null)
return;
try
{
if (!_preferredHandwritingRecognizerResolved)
{
_preferredHandwritingRecognizerResolved = true;
var all = container.GetRecognizers();
_preferredHandwritingRecognizer = SelectBestInkRecognizer(all);
if (logDetail)
{
if (_preferredHandwritingRecognizer != null)
LogHandwriting("识别器:已选用 \"" + _preferredHandwritingRecognizer.Name + "\"。");
else if (all != null && all.Count > 0)
LogHandwriting("识别器:未匹配到与 UI/区域语言对应的引擎,使用系统默认(共 " + all.Count + " 个)。");
}
}
if (_preferredHandwritingRecognizer != null)
container.SetDefaultRecognizer(_preferredHandwritingRecognizer);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("[手写体] 设置默认手写识别器失败: " + ex.Message, LogHelper.LogType.Warning);
}
}
private static WinRtInk.InkRecognizer SelectBestInkRecognizer(
IReadOnlyList<WinRtInk.InkRecognizer> list)
{
if (list == null || list.Count == 0)
return null;
var culture = PrimaryHandwritingCulture();
var lang = (culture?.TwoLetterISOLanguageName ?? string.Empty).ToLowerInvariant();
var name = culture?.Name ?? string.Empty;
bool wantZhHans = lang == "zh" &&
(name.IndexOf("hans", StringComparison.OrdinalIgnoreCase) >= 0 ||
name.Equals("zh-cn", StringComparison.OrdinalIgnoreCase) ||
name.Equals("zh-sg", StringComparison.OrdinalIgnoreCase) ||
(name.IndexOf("hant", StringComparison.OrdinalIgnoreCase) < 0 &&
!name.Equals("zh-tw", StringComparison.OrdinalIgnoreCase) &&
!name.Equals("zh-hk", StringComparison.OrdinalIgnoreCase) &&
!name.Equals("zh-mo", StringComparison.OrdinalIgnoreCase)));
bool wantZhHant = lang == "zh" &&
(name.IndexOf("hant", StringComparison.OrdinalIgnoreCase) >= 0 ||
name.Equals("zh-tw", StringComparison.OrdinalIgnoreCase) ||
name.Equals("zh-hk", StringComparison.OrdinalIgnoreCase) ||
name.Equals("zh-mo", StringComparison.OrdinalIgnoreCase));
WinRtInk.InkRecognizer Pick(Func<string, bool> match)
{
foreach (var r in list)
{
var n = r?.Name;
if (string.IsNullOrEmpty(n))
continue;
if (match(n))
return r;
}
return null;
}
if (wantZhHans)
{
var r = Pick(n =>
n.IndexOf("简体", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("簡體", StringComparison.OrdinalIgnoreCase) >= 0 ||
(n.IndexOf("中文", StringComparison.OrdinalIgnoreCase) >= 0 &&
(n.IndexOf("简体", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("簡體", StringComparison.OrdinalIgnoreCase) >= 0)) ||
(n.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0 &&
(n.IndexOf("Simplified", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Hans", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("PRC", StringComparison.OrdinalIgnoreCase) >= 0)));
if (r != null)
return r;
r = Pick(n =>
n.IndexOf("中文", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0);
if (r != null)
return r;
}
else if (wantZhHant)
{
var r = Pick(n =>
n.IndexOf("繁体", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("繁體", StringComparison.OrdinalIgnoreCase) >= 0 ||
(n.IndexOf("中文", StringComparison.OrdinalIgnoreCase) >= 0 &&
(n.IndexOf("繁体", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("繁體", StringComparison.OrdinalIgnoreCase) >= 0)) ||
(n.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0 &&
(n.IndexOf("Traditional", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Hant", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Taiwan", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Hong Kong", StringComparison.OrdinalIgnoreCase) >= 0)));
if (r != null)
return r;
r = Pick(n =>
n.IndexOf("中文", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0);
if (r != null)
return r;
}
else if (lang == "ja")
{
var r = Pick(n =>
n.IndexOf("Japanese", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("日本語", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("日语", StringComparison.OrdinalIgnoreCase) >= 0);
if (r != null)
return r;
}
else if (lang == "en")
{
var r = Pick(n => n.IndexOf("English", StringComparison.OrdinalIgnoreCase) >= 0);
if (r != null)
return r;
}
if (lang == "zh")
{
var r = Pick(n =>
n.IndexOf("中文", StringComparison.OrdinalIgnoreCase) >= 0 ||
n.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0);
if (r != null)
return r;
}
return null;
}
private static CultureInfo PrimaryHandwritingCulture()
{
var ui = CultureInfo.CurrentUICulture;
var ct = CultureInfo.CurrentCulture;
if (string.Equals(ui.TwoLetterISOLanguageName, "zh", StringComparison.OrdinalIgnoreCase))
return ui;
if (string.Equals(ct.TwoLetterISOLanguageName, "zh", StringComparison.OrdinalIgnoreCase))
return ct;
return ui;
}
private static async Task<HandwritingRecognitionResult> RecognizeHandwritingWholeInkAsync(
StrokeCollection strokes,
bool traceRecognition)
{
if (strokes == null || strokes.Count == 0)
return HandwritingRecognitionResult.Empty;
var container = new WinRtInk.InkStrokeContainer();
foreach (Stroke s in strokes)
{
var ink = WinRtInkShapeRecognizer.CreateInkStrokeFromWpf(s);
if (ink != null)
container.AddStroke(ink);
}
var winStrokes = container.GetStrokes();
if (winStrokes == null || winStrokes.Count == 0)
{
if (traceRecognition)
LogHandwriting("整批回退:无有效 WinRT 笔画。");
return HandwritingRecognitionResult.Empty;
}
var reco = new WinRtInk.InkRecognizerContainer();
TryApplyPreferredHandwritingRecognizer(reco, false);
IReadOnlyList<WinRtInk.InkRecognitionResult> rr;
try
{
rr = await reco
.RecognizeAsync(container, WinRtInk.InkRecognitionTarget.All)
.AsTask()
.ConfigureAwait(true);
}
catch (Exception ex)
{
if (traceRecognition)
LogHandwriting("整批回退:RecognizeAsync 异常:" + ex.Message);
return HandwritingRecognitionResult.Empty;
}
if (rr == null || rr.Count == 0 || rr[0] == null)
{
if (traceRecognition)
LogHandwriting("整批回退:RecognizeAsync 无结果。");
return HandwritingRecognitionResult.Empty;
}
var cands = rr[0].GetTextCandidates();
var primary = (cands != null && cands.Count > 0) ? cands[0] : string.Empty;
if (string.IsNullOrWhiteSpace(primary))
{
if (traceRecognition)
LogHandwriting("整批回退:候选文本为空。");
return HandwritingRecognitionResult.Empty;
}
var merged = new List<string>();
if (cands != null)
{
foreach (var c in cands)
{
if (!string.IsNullOrEmpty(c) && !merged.Contains(c))
merged.Add(c);
}
}
var bounds = UnionStrokeBounds(strokes);
var group = new List<Stroke>();
foreach (Stroke s in strokes)
group.Add(s);
var seg = new HandwritingWordSegment(primary, merged, bounds, group);
return new HandwritingRecognitionResult(new List<HandwritingWordSegment> { seg });
}
private static Rect UnionStrokeBounds(StrokeCollection strokes)
{
if (strokes == null || strokes.Count == 0)
return Rect.Empty;
var r = strokes[0].GetBounds();
for (var i = 1; i < strokes.Count; i++)
r = Rect.Union(r, strokes[i].GetBounds());
return r;
}
private const string DefaultHandwritingFontFamilyList = "Ink Free,KaiTi,Segoe Script";
/// <summary>
/// 识别手写词后,将「有识别文本」的分词替换为指定手写风格字体的字形轮廓墨迹;未识别或空文本的词保留原笔画。
/// </summary>
public static async Task<StrokeCollection> ConvertRecognizedTextToHandwritingInkAsync(
StrokeCollection strokes,
string handwritingFontFamilyList)
{
if (!IsApiAvailable || strokes == null || strokes.Count == 0)
{
if (strokes != null && strokes.Count > 0 && !IsApiAvailable)
LogHandwriting("字形替换:跳过,IsApiAvailable=false。");
return strokes;
}
var fontList = string.IsNullOrWhiteSpace(handwritingFontFamilyList)
? DefaultHandwritingFontFamilyList
: handwritingFontFamilyList.Trim();
LogHandwriting(
"字形替换开始:输入笔画数=" + strokes.Count +
",字体链=\"" + fontList + "\"" +
"PixelsPerDip=" + Math.Round(GetPixelsPerDipSafe(), 3));
try
{
var reco = await RecognizeHandwritingAsync(strokes).ConfigureAwait(true);
if (!reco.IsSuccess || reco.Words == null || reco.Words.Count == 0)
{
LogHandwriting(
"字形替换中止:识别未成功(IsSuccess=" + reco.IsSuccess +
",词数=" + (reco.Words?.Count ?? 0) + "),原样返回笔画。");
return strokes;
}
var firstStrokeToSegment = new Dictionary<Stroke, HandwritingWordSegment>();
foreach (var w in reco.Words)
{
if (w?.Strokes == null || w.Strokes.Count == 0)
continue;
var ordered = w.Strokes.OrderBy(st => IndexOfStrokeInCollection(strokes, st)).ToList();
var first = ordered[0];
if (!firstStrokeToSegment.ContainsKey(first))
firstStrokeToSegment[first] = w;
}
if (firstStrokeToSegment.Count == 0)
{
LogHandwriting("字形替换中止:无法建立「首笔画→分词」映射,原样返回。");
return strokes;
}
var consumed = new HashSet<Stroke>();
var result = new StrokeCollection();
var pixelsPerDip = GetPixelsPerDipSafe();
var replacedWordCount = 0;
var keptOriginalWordCount = 0;
var glyphStrokeTotal = 0;
foreach (Stroke s in strokes)
{
if (consumed.Contains(s))
continue;
if (!firstStrokeToSegment.TryGetValue(s, out var seg))
{
result.Add(s);
continue;
}
if (string.IsNullOrWhiteSpace(seg.Text))
{
LogHandwriting(
" 分词:文本为空,保留原笔画,笔画数=" + seg.Strokes.Count);
keptOriginalWordCount++;
foreach (var z in seg.Strokes)
{
if (!consumed.Contains(z))
{
result.Add(z);
consumed.Add(z);
}
}
continue;
}
var templateDa = seg.Strokes[0]?.DrawingAttributes?.Clone() ?? new DrawingAttributes();
OutlineAttributesForGlyphInk(templateDa);
var glyphStrokes = CreateHandwritingGlyphStrokes(
seg.Text.Trim(),
seg.BoundingRectangle,
templateDa,
fontList,
pixelsPerDip);
if (glyphStrokes == null || glyphStrokes.Count == 0)
{
LogHandwriting(
" 分词:字形轮廓生成失败,保留原笔画。文本=\"" +
(seg.Text.Length > 30 ? seg.Text.Substring(0, 27) + "..." : seg.Text) + "\"");
keptOriginalWordCount++;
foreach (var z in seg.Strokes)
{
if (!consumed.Contains(z))
{
result.Add(z);
consumed.Add(z);
}
}
continue;
}
foreach (var nk in glyphStrokes)
result.Add(nk);
glyphStrokeTotal += glyphStrokes.Count;
replacedWordCount++;
LogHandwriting(
" 分词:已替换为手写体字形墨迹,文本=\"" +
(seg.Text.Length > 30 ? seg.Text.Substring(0, 27) + "..." : seg.Text) +
"\",生成笔画数=" + glyphStrokes.Count + ",移除原笔画数=" + seg.Strokes.Count);
foreach (var z in seg.Strokes)
consumed.Add(z);
}
LogHandwriting(
"字形替换结束:输出笔画数=" + result.Count +
"(输入=" + strokes.Count + "),替换词数=" + replacedWordCount +
",保留原迹词数=" + keptOriginalWordCount +
",字形子笔画合计=" + glyphStrokeTotal);
return result;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile("WinRT 手写体字形替换失败: " + ex.Message, LogHelper.LogType.Warning);
LogHandwriting("字形替换异常:" + ex, LogHelper.LogType.Warning);
return strokes;
}
}
private static int IndexOfStrokeInCollection(StrokeCollection collection, Stroke stroke)
{
if (collection == null || stroke == null)
return int.MaxValue;
for (var i = 0; i < collection.Count; i++)
{
if (ReferenceEquals(collection[i], stroke))
return i;
}
return int.MaxValue;
}
private static void OutlineAttributesForGlyphInk(DrawingAttributes da)
{
if (da == null) return;
var w = Math.Max(0.8, Math.Min(da.Width, da.Height) * 0.2);
da.Width = w;
da.Height = w;
da.StylusTip = StylusTip.Ellipse;
da.IsHighlighter = false;
}
private static double GetPixelsPerDipSafe()
{
try
{
if (Application.Current?.MainWindow is Visual v)
return VisualTreeHelper.GetDpi(v).PixelsPerDip;
}
catch
{
// ignore
}
return 1.0;
}
private static Typeface ResolveHandwritingTypeface(string fontFamilyList)
{
try
{
var ff = new FontFamily(fontFamilyList ?? DefaultHandwritingFontFamilyList);
return new Typeface(ff, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
}
catch
{
return new Typeface(
SystemFonts.MessageFontFamily,
SystemFonts.MessageFontStyle,
SystemFonts.MessageFontWeight,
FontStretches.Normal);
}
}
private static List<Stroke> CreateHandwritingGlyphStrokes(
string text,
Rect placeRect,
DrawingAttributes templateDa,
string fontFamilyList,
double pixelsPerDip)
{
var list = new List<Stroke>();
if (string.IsNullOrEmpty(text) || placeRect.Width < 1 || placeRect.Height < 1)
return list;
var typeface = ResolveHandwritingTypeface(fontFamilyList);
var culture = CultureInfo.CurrentCulture;
var em = Math.Max(6.0, placeRect.Height * 0.72);
FormattedText ft = null;
for (var i = 0; i < 14; i++)
{
ft = new FormattedText(
text,
culture,
FlowDirection.LeftToRight,
typeface,
em,
Brushes.Black,
new NumberSubstitution(NumberCultureSource.Text, culture, NumberSubstitutionMethod.Context),
TextFormattingMode.Display,
pixelsPerDip);
if (ft.Width <= placeRect.Width * 0.96 && ft.Height <= placeRect.Height * 0.96)
break;
em *= 0.9;
if (em < 4.5)
break;
}
if (ft == null || ft.Width < 0.5 || ft.Height < 0.5)
return list;
var scale = Math.Min(
placeRect.Width * 0.94 / Math.Max(1e-6, ft.Width),
placeRect.Height * 0.94 / Math.Max(1e-6, ft.Height));
var tx = placeRect.Left + (placeRect.Width - ft.Width * scale) / 2.0;
var ty = placeRect.Top + (placeRect.Height - ft.Height * scale) / 2.0;
Geometry geom;
try
{
geom = ft.BuildGeometry(new Point(0, 0));
}
catch
{
return list;
}
if (geom == null || geom.IsEmpty())
return list;
var m = new Matrix(scale, 0, 0, scale, tx, ty);
geom.Transform = new MatrixTransform(m);
return StrokesFromOutlinedGeometry(geom, templateDa, 0.35);
}
private static List<Stroke> StrokesFromOutlinedGeometry(Geometry geometry, DrawingAttributes da, double tolerance)
{
var list = new List<Stroke>();
if (geometry == null || geometry.IsEmpty() || da == null)
return list;
Geometry outlined;
try
{
outlined = geometry.GetOutlinedPathGeometry(tolerance, ToleranceType.Absolute);
}
catch
{
return list;
}
if (outlined == null || outlined.IsEmpty())
return list;
Geometry flat;
try
{
flat = outlined.GetFlattenedPathGeometry(tolerance, ToleranceType.Absolute);
}
catch
{
return list;
}
if (!(flat is PathGeometry pg))
return list;
foreach (var fig in pg.Figures)
{
var pts = new StylusPointCollection();
pts.Add(new StylusPoint(fig.StartPoint.X, fig.StartPoint.Y, 0.5f));
foreach (var seg in fig.Segments)
{
switch (seg)
{
case LineSegment ls:
pts.Add(new StylusPoint(ls.Point.X, ls.Point.Y, 0.5f));
break;
case PolyLineSegment pls:
foreach (var p in pls.Points)
pts.Add(new StylusPoint(p.X, p.Y, 0.5f));
break;
}
}
if (pts.Count >= 2)
list.Add(new Stroke(pts) { DrawingAttributes = da.Clone() });
}
return list;
}
}
/// <summary>单个手写词片段的识别结果。</summary>
public sealed class HandwritingWordSegment
{
public HandwritingWordSegment(
string text,
IReadOnlyList<string> textCandidates,
Rect boundingRectangle,
IReadOnlyList<Stroke> strokes)
{
Text = text ?? string.Empty;
TextCandidates = textCandidates ?? Array.Empty<string>();
BoundingRectangle = boundingRectangle;
Strokes = strokes ?? Array.Empty<Stroke>();
}
public string Text { get; }
public IReadOnlyList<string> TextCandidates { get; }
public Rect BoundingRectangle { get; }
public IReadOnlyList<Stroke> Strokes { get; }
}
/// <summary>一次手写识别批次的汇总结果。</summary>
public sealed class HandwritingRecognitionResult
{
public static readonly HandwritingRecognitionResult Empty = new HandwritingRecognitionResult();
private HandwritingRecognitionResult()
{
Words = Array.Empty<HandwritingWordSegment>();
IsSuccess = false;
CombinedText = string.Empty;
}
public HandwritingRecognitionResult(IReadOnlyList<HandwritingWordSegment> words)
{
Words = words ?? Array.Empty<HandwritingWordSegment>();
IsSuccess = Words.Count > 0;
CombinedText = string.Join("", Words.Select(w => w.Text ?? string.Empty));
}
public bool IsSuccess { get; }
public IReadOnlyList<HandwritingWordSegment> Words { get; }
public string CombinedText { get; }
}
}
@@ -0,0 +1,282 @@
using OSVersionExtension;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using SysPoint = System.Windows.Point;
using WinRtInkAnalyzer = global::Windows.UI.Input.Inking.Analysis.InkAnalyzer;
namespace Ink_Canvas.Helpers
{
/// <summary>基于 Windows.UI.Input.Inking.Analysis 的形状识别(适用于 64 位进程等场景)。</summary>
internal static class WinRtInkShapeRecognizer
{
public static bool IsApiAvailable =>
OSVersion.GetOperatingSystem() >= OSVersionExtension.OperatingSystem.Windows10;
public static void Warmup()
{
if (!IsApiAvailable) return;
try
{
var d = Application.Current?.Dispatcher;
if (d == null) return;
d.BeginInvoke(new Action(async () =>
{
try
{
// 空 StrokeCollection 在 RecognizeShapeAsync 入口会直接返回,无法预热 WinRT InkAnalyzer。
await RecognizeShapeAsync(CreateMinimalWarmupStrokeCollection()).ConfigureAwait(true);
}
catch
{
// ignore
}
}));
}
catch
{
// ignore
}
}
/// <summary>由 <see cref="ModernInkProcessor"/> / <see cref="InkRecognitionManager"/> 在 UI 上 await(勿在收笔回调中同步阻塞)。</summary>
internal static async Task<InkShapeRecognitionResult> RecognizeShapeAsync(StrokeCollection strokes)
{
if (!IsApiAvailable || strokes == null || strokes.Count == 0)
return InkShapeRecognitionResult.Empty;
try
{
var analyzer = new WinRtInkAnalyzer();
var added = 0;
foreach (Stroke s in strokes)
{
var inkStroke = CreateInkStrokeFromWpf(s);
if (inkStroke == null)
continue;
analyzer.AddDataForStroke(inkStroke);
analyzer.SetStrokeDataKind(
inkStroke.Id,
global::Windows.UI.Input.Inking.Analysis.InkAnalysisStrokeKind.Drawing);
added++;
}
if (added == 0)
return InkShapeRecognitionResult.Empty;
await analyzer.AnalyzeAsync().AsTask().ConfigureAwait(true);
var drawing = FindPrimaryDrawing(analyzer);
if (drawing == null)
return InkShapeRecognitionResult.Empty;
if (drawing.DrawingKind == global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Drawing)
return InkShapeRecognitionResult.Empty;
var name = MapDrawingKindToShapeName(drawing.DrawingKind);
if (string.IsNullOrEmpty(name) || name == "Drawing")
return InkShapeRecognitionResult.Empty;
var winPts = CopyWinRtPoints(drawing);
var hot = ToWpfPointCollection(winPts);
var c = drawing.Center;
var centroid = new SysPoint(c.X, c.Y);
BoundsFromPoints(winPts, out double w, out double h);
var toRemove = new StrokeCollection();
foreach (Stroke s in strokes)
toRemove.Add(s);
return new InkShapeRecognitionResult(name, centroid, hot, w, h, toRemove);
}
catch (Exception)
{
return InkShapeRecognitionResult.Empty;
}
}
/// <summary>
/// 极短合成笔画,供 <see cref="Warmup"/> 等场景走完整 WinRT 转换与分析管线(空集合在入口处会被直接返回)。
/// </summary>
internal static StrokeCollection CreateMinimalWarmupStrokeCollection()
{
var da = new DrawingAttributes { Color = Colors.Black, Width = 2, Height = 2 };
var pts = new StylusPointCollection
{
new StylusPoint(8, 8),
new StylusPoint(14, 10),
new StylusPoint(20, 8),
};
var col = new StrokeCollection();
col.Add(new Stroke(pts, da));
return col;
}
/// <summary>供 WinRT 手写等模块复用:将 WPF <see cref="Stroke"/> 转为 WinRT <see cref="global::Windows.UI.Input.Inking.InkStroke"/>。</summary>
internal static global::Windows.UI.Input.Inking.InkStroke CreateInkStrokeFromWpf(Stroke stroke)
{
if (stroke?.StylusPoints == null || stroke.StylusPoints.Count == 0)
return null;
var da = stroke.DrawingAttributes;
if (da == null)
return null;
var wda = new global::Windows.UI.Input.Inking.InkDrawingAttributes
{
PenTip = global::Windows.UI.Input.Inking.PenTipShape.Circle,
Color = global::Windows.UI.Color.FromArgb(da.Color.A, da.Color.R, da.Color.G, da.Color.B),
Size = new global::Windows.Foundation.Size((float)da.Width, (float)da.Height)
};
var builder = new global::Windows.UI.Input.Inking.InkStrokeBuilder();
builder.SetDefaultDrawingAttributes(wda);
var points = new List<global::Windows.Foundation.Point>(stroke.StylusPoints.Count);
foreach (StylusPoint sp in stroke.StylusPoints)
{
var pi = sp.ToPoint();
points.Add(new global::Windows.Foundation.Point((float)pi.X, (float)pi.Y));
}
if (points.Count == 0)
return null;
return builder.CreateStroke(points);
}
private static global::Windows.UI.Input.Inking.Analysis.InkAnalysisInkDrawing FindPrimaryDrawing(
WinRtInkAnalyzer analyzer)
{
global::Windows.UI.Input.Inking.Analysis.InkAnalysisInkDrawing best = null;
double bestArea = -1;
if (analyzer?.AnalysisRoot != null)
Visit(analyzer.AnalysisRoot);
return best;
void Visit(global::Windows.UI.Input.Inking.Analysis.IInkAnalysisNode node)
{
if (node == null) return;
if (node is global::Windows.UI.Input.Inking.Analysis.InkAnalysisInkDrawing d &&
d.DrawingKind != global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Drawing)
{
double area = EstimateDrawingArea(d);
if (area > bestArea)
{
bestArea = area;
best = d;
}
}
// WinRT IInkAnalysisNode.Children 可能为 null,不可直接 foreach。
var children = node.Children;
if (children == null) return;
foreach (var child in children)
Visit(child);
}
}
private static double EstimateDrawingArea(global::Windows.UI.Input.Inking.Analysis.InkAnalysisInkDrawing drawing)
{
var pts = CopyWinRtPoints(drawing);
BoundsFromPoints(pts, out double w, out double h);
return w * h;
}
private static global::Windows.Foundation.Point[] CopyWinRtPoints(
global::Windows.UI.Input.Inking.Analysis.InkAnalysisInkDrawing drawing)
{
var src = drawing?.Points;
if (src == null)
return Array.Empty<global::Windows.Foundation.Point>();
var n = src.Count;
if (n == 0)
return Array.Empty<global::Windows.Foundation.Point>();
var arr = new global::Windows.Foundation.Point[n];
for (var i = 0; i < n; i++)
arr[i] = src[i];
return arr;
}
private static void BoundsFromPoints(
System.Collections.Generic.IReadOnlyList<global::Windows.Foundation.Point> points,
out double w,
out double h)
{
if (points == null || points.Count == 0)
{
w = h = 0;
return;
}
double minX = double.MaxValue, maxX = double.MinValue, minY = double.MaxValue, maxY = double.MinValue;
for (int i = 0; i < points.Count; i++)
{
var pt = points[i];
minX = Math.Min(minX, pt.X);
maxX = Math.Max(maxX, pt.X);
minY = Math.Min(minY, pt.Y);
maxY = Math.Max(maxY, pt.Y);
}
w = Math.Max(0, maxX - minX);
h = Math.Max(0, maxY - minY);
}
private static PointCollection ToWpfPointCollection(
System.Collections.Generic.IReadOnlyList<global::Windows.Foundation.Point> points)
{
var hot = new PointCollection();
if (points == null) return hot;
for (int i = 0; i < points.Count; i++)
{
var pt = points[i];
hot.Add(new SysPoint(pt.X, pt.Y));
}
return hot;
}
private static string MapDrawingKindToShapeName(
global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind kind)
{
switch (kind)
{
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Circle:
return "Circle";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Ellipse:
return "Ellipse";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Triangle:
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.IsoscelesTriangle:
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.EquilateralTriangle:
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.RightTriangle:
return "Triangle";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Rectangle:
return "Rectangle";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Square:
return "Square";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Diamond:
return "Diamond";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Trapezoid:
return "Trapezoid";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Parallelogram:
return "Parallelogram";
case global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Quadrilateral:
return "Quadrilateral";
default:
return kind == global::Windows.UI.Input.Inking.Analysis.InkAnalysisDrawingKind.Drawing
? "Drawing"
: kind.ToString();
}
}
}
}
+611
View File
@@ -0,0 +1,611 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace Ink_Canvas.Helpers
{
/// <summary>
/// 矩形结构体(用于窗口位置和大小)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct WindowRect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
public int Width => Right - Left;
public int Height => Bottom - Top;
}
/// <summary>
/// 窗口信息结构
/// </summary>
public class WindowInfo
{
public IntPtr Handle { get; set; }
public string Title { get; set; }
public string ClassName { get; set; }
public string ProcessName { get; set; }
public string ProcessPath { get; set; }
public WindowRect Rect { get; set; }
public bool IsVisible { get; set; }
public bool IsMinimized { get; set; }
public bool IsMaximized { get; set; }
public int ZOrder { get; set; }
public uint ProcessId { get; set; }
public bool IsFullScreen { get; set; }
/// <summary>
/// 计算窗口是否覆盖指定区域
/// </summary>
public bool CoversArea(WindowRect area)
{
if (!IsVisible || IsMinimized) return false;
// 计算交集
int left = Math.Max(Rect.Left, area.Left);
int top = Math.Max(Rect.Top, area.Top);
int right = Math.Min(Rect.Right, area.Right);
int bottom = Math.Min(Rect.Bottom, area.Bottom);
// 如果有交集,说明窗口覆盖了该区域
return left < right && top < bottom;
}
/// <summary>
/// 计算窗口覆盖指定区域的比例
/// </summary>
public double GetCoverageRatio(WindowRect area)
{
if (!IsVisible || IsMinimized) return 0.0;
// 计算交集
int left = Math.Max(Rect.Left, area.Left);
int top = Math.Max(Rect.Top, area.Top);
int right = Math.Min(Rect.Right, area.Right);
int bottom = Math.Min(Rect.Bottom, area.Bottom);
if (left >= right || top >= bottom) return 0.0;
// 计算交集面积
double intersectionArea = (right - left) * (bottom - top);
// 计算目标区域面积
double targetArea = area.Width * area.Height;
if (targetArea == 0) return 0.0;
return intersectionArea / targetArea;
}
}
/// <summary>
/// 窗口概览模型 - 实时监控桌面所有可见窗口并计算遮挡情况
/// </summary>
public class WindowOverviewModel : IDisposable
{
#region Win32 API Declarations
[DllImport("user32.dll")]
private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetWindowRect(IntPtr hWnd, out WindowRect lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsZoomed(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
private const uint GW_HWNDNEXT = 2;
private const uint GW_HWNDPREV = 3;
private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
#endregion
private readonly object _lockObject = new object();
private List<WindowInfo> _windows = new List<WindowInfo>();
private Timer _updateTimer;
private bool _isDisposed = false;
private readonly int _updateInterval = 1000; // 更新间隔(毫秒)
private readonly Dictionary<uint, ProcessCacheInfo> _processCache = new Dictionary<uint, ProcessCacheInfo>();
private readonly object _processCacheLock = new object();
private DateTime _lastProcessCacheCleanup = DateTime.Now;
private const int PROCESS_CACHE_CLEANUP_INTERVAL_MS = 30000;
// 窗口缓存,用于增量更新
private readonly Dictionary<IntPtr, WindowInfo> _windowCache = new Dictionary<IntPtr, WindowInfo>();
/// <summary>
/// 进程缓存信息
/// </summary>
private class ProcessCacheInfo
{
public string ProcessName { get; set; }
public string ProcessPath { get; set; }
public DateTime LastAccessTime { get; set; }
}
/// <summary>
/// 窗口列表更新事件
/// </summary>
public event EventHandler<List<WindowInfo>> WindowsUpdated;
/// <summary>
/// 当前窗口列表(按Z顺序排序,最上层在前)
/// </summary>
public List<WindowInfo> Windows
{
get
{
lock (_lockObject)
{
return new List<WindowInfo>(_windows);
}
}
}
/// <summary>
/// 构造函数
/// </summary>
public WindowOverviewModel()
{
// 立即执行一次更新
UpdateWindows();
// 启动定时器,定期更新窗口列表
_updateTimer = new Timer(OnUpdateTimer, null, _updateInterval, _updateInterval);
}
/// <summary>
/// 定时器回调
/// </summary>
private void OnUpdateTimer(object state)
{
if (_isDisposed) return;
try
{
UpdateWindows();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"窗口概览模型更新失败: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 获取进程信息
/// </summary>
private (string processName, string processPath) GetProcessInfo(uint processId)
{
lock (_processCacheLock)
{
// 定期清理缓存
var now = DateTime.Now;
if ((now - _lastProcessCacheCleanup).TotalMilliseconds > PROCESS_CACHE_CLEANUP_INTERVAL_MS)
{
var keysToRemove = _processCache
.Where(kvp => (now - kvp.Value.LastAccessTime).TotalMilliseconds > PROCESS_CACHE_CLEANUP_INTERVAL_MS)
.Select(kvp => kvp.Key)
.ToList();
foreach (var key in keysToRemove)
{
_processCache.Remove(key);
}
_lastProcessCacheCleanup = now;
}
// 检查缓存
if (_processCache.TryGetValue(processId, out var cachedInfo))
{
cachedInfo.LastAccessTime = now;
return (cachedInfo.ProcessName, cachedInfo.ProcessPath);
}
// 缓存未命中,获取进程信息
string processName = "Unknown";
string processPath = "Unknown";
try
{
Process process = Process.GetProcessById((int)processId);
processName = process.ProcessName;
try
{
processPath = process.MainModule?.FileName ?? "Unknown";
}
catch
{
processPath = "Unknown";
}
}
catch
{
// 进程可能已退出
}
// 添加到缓存
_processCache[processId] = new ProcessCacheInfo
{
ProcessName = processName,
ProcessPath = processPath,
LastAccessTime = now
};
return (processName, processPath);
}
}
/// <summary>
/// 检查窗口信息是否发生变化
/// </summary>
private bool HasWindowChanged(IntPtr hWnd, WindowRect rect, bool isMinimized, bool isMaximized, bool isFullScreen)
{
if (!_windowCache.TryGetValue(hWnd, out var cachedWindow))
{
return true; // 新窗口
}
// 检查关键属性是否变化
return cachedWindow.Rect.Left != rect.Left ||
cachedWindow.Rect.Top != rect.Top ||
cachedWindow.Rect.Right != rect.Right ||
cachedWindow.Rect.Bottom != rect.Bottom ||
cachedWindow.IsMinimized != isMinimized ||
cachedWindow.IsMaximized != isMaximized ||
cachedWindow.IsFullScreen != isFullScreen;
}
/// <summary>
/// 更新窗口列表
/// </summary>
public void UpdateWindows()
{
var windows = new List<WindowInfo>();
var zOrder = 0;
var currentWindowHandles = new HashSet<IntPtr>();
EnumWindows((hWnd, lParam) =>
{
try
{
// 检查窗口是否可见
if (!IsWindowVisible(hWnd)) return true;
// 检查窗口是否最小化
bool isMinimized = IsIconic(hWnd);
if (isMinimized) return true;
// 获取窗口矩形
if (!GetWindowRect(hWnd, out WindowRect rect)) return true;
// 过滤掉无效的窗口
if (rect.Width <= 0 || rect.Height <= 0) return true;
if (rect.Right < rect.Left || rect.Bottom < rect.Top) return true;
// 检查是否最大化
bool isMaximized = IsZoomed(hWnd);
// 检查是否全屏(窗口大小接近屏幕大小)
bool isFullScreen = false;
try
{
var screen = System.Windows.Forms.Screen.FromHandle(hWnd);
var screenBounds = screen.Bounds;
// 如果窗口大小接近屏幕大小(允许10像素误差),认为是全屏
isFullScreen = rect.Width >= screenBounds.Width - 10 &&
rect.Height >= screenBounds.Height - 10 &&
Math.Abs(rect.Left - screenBounds.Left) <= 10 &&
Math.Abs(rect.Top - screenBounds.Top) <= 10;
}
catch
{
// 无法获取屏幕信息,使用默认值
}
// 检查窗口是否发生变化
bool windowChanged = HasWindowChanged(hWnd, rect, isMinimized, isMaximized, isFullScreen);
// 获取进程信息
GetWindowThreadProcessId(hWnd, out uint processId);
// 使用缓存的进程信息
var (processName, processPath) = GetProcessInfo(processId);
// 跳过当前应用程序的窗口(避免检测到自己)
if (processName == "InkCanvasForClass" || processName == "Ink Canvas")
{
return true;
}
// 如果窗口信息未变化且已缓存,尝试重用缓存的数据
WindowInfo windowInfo;
if (!windowChanged && _windowCache.TryGetValue(hWnd, out var cachedInfo))
{
// 重用缓存的窗口信息,只更新Z顺序和可能变化的状态
windowInfo = new WindowInfo
{
Handle = hWnd,
Title = cachedInfo.Title,
ClassName = cachedInfo.ClassName,
ProcessName = cachedInfo.ProcessName,
ProcessPath = cachedInfo.ProcessPath,
Rect = rect, // 使用最新的rect(虽然理论上应该相同)
IsVisible = true,
IsMinimized = false,
IsMaximized = isMaximized,
ZOrder = zOrder++,
ProcessId = processId,
IsFullScreen = isFullScreen
};
// 更新缓存以保持ZOrder等属性最新
_windowCache[hWnd] = windowInfo;
}
else
{
// 窗口信息变化或新窗口,需要获取完整信息
// 获取窗口标题
const int nChars = 256;
StringBuilder windowTitle = new StringBuilder(nChars);
GetWindowText(hWnd, windowTitle, nChars);
string title = windowTitle.ToString();
// 获取窗口类名
StringBuilder className = new StringBuilder(nChars);
GetClassName(hWnd, className, nChars);
string classNameStr = className.ToString();
windowInfo = new WindowInfo
{
Handle = hWnd,
Title = title,
ClassName = classNameStr,
ProcessName = processName,
ProcessPath = processPath,
Rect = rect,
IsVisible = true,
IsMinimized = false,
IsMaximized = isMaximized,
ZOrder = zOrder++,
ProcessId = processId,
IsFullScreen = isFullScreen
};
// 更新缓存
_windowCache[hWnd] = windowInfo;
}
windows.Add(windowInfo);
currentWindowHandles.Add(hWnd);
}
catch
{
// 忽略单个窗口的错误,继续枚举其他窗口
}
return true; // 继续枚举
}, IntPtr.Zero);
// 清理已关闭的窗口缓存
var handlesToRemove = _windowCache.Keys.Where(h => !currentWindowHandles.Contains(h)).ToList();
foreach (var handle in handlesToRemove)
{
_windowCache.Remove(handle);
}
windows = windows.OrderByDescending(w => w.ZOrder).ToList();
lock (_lockObject)
{
_windows = windows;
}
// 触发更新事件
WindowsUpdated?.Invoke(this, windows);
}
/// <summary>
/// 检查指定区域是否被其他窗口覆盖
/// </summary>
/// <param name="area">要检查的区域</param>
/// <param name="excludeProcessNames">要排除的进程名列表(例如当前应用程序)</param>
/// <param name="coverageThreshold">覆盖阈值(0.0-1.0),超过此阈值认为被覆盖</param>
/// <returns>如果被覆盖返回true</returns>
public bool IsAreaCovered(WindowRect area, List<string> excludeProcessNames = null, double coverageThreshold = 0.5)
{
lock (_lockObject)
{
excludeProcessNames = excludeProcessNames ?? new List<string>();
// 从最上层窗口开始检查
foreach (var window in _windows)
{
// 跳过排除的进程
if (excludeProcessNames.Contains(window.ProcessName)) continue;
// 计算覆盖比例
double coverage = window.GetCoverageRatio(area);
if (coverage >= coverageThreshold)
{
return true;
}
}
return false;
}
}
/// <summary>
/// 检查指定区域是否被全屏窗口覆盖
/// </summary>
/// <param name="area">要检查的区域</param>
/// <param name="excludeProcessNames">要排除的进程名列表</param>
/// <returns>如果被全屏窗口覆盖返回true</returns>
public bool IsAreaCoveredByFullScreenWindow(WindowRect area, List<string> excludeProcessNames = null)
{
lock (_lockObject)
{
excludeProcessNames = excludeProcessNames ?? new List<string>();
// 查找全屏窗口
foreach (var window in _windows)
{
// 跳过排除的进程
if (excludeProcessNames.Contains(window.ProcessName)) continue;
// 只检查全屏窗口
if (window.IsFullScreen && window.CoversArea(area))
{
return true;
}
}
return false;
}
}
/// <summary>
/// 获取覆盖指定区域的所有窗口
/// </summary>
/// <param name="area">要检查的区域</param>
/// <param name="excludeProcessNames">要排除的进程名列表</param>
/// <param name="coverageThreshold">覆盖阈值</param>
/// <returns>覆盖该区域的窗口列表(按Z顺序,最上层在前)</returns>
public List<WindowInfo> GetCoveringWindows(WindowRect area, List<string> excludeProcessNames = null, double coverageThreshold = 0.1)
{
lock (_lockObject)
{
excludeProcessNames = excludeProcessNames ?? new List<string>();
var coveringWindows = new List<WindowInfo>();
foreach (var window in _windows)
{
// 跳过排除的进程
if (excludeProcessNames.Contains(window.ProcessName)) continue;
// 计算覆盖比例
double coverage = window.GetCoverageRatio(area);
if (coverage >= coverageThreshold)
{
coveringWindows.Add(window);
}
}
return coveringWindows;
}
}
/// <summary>
/// 检查是否有全屏窗口
/// </summary>
/// <param name="excludeProcessNames">要排除的进程名列表</param>
/// <returns>如果有全屏窗口返回true</returns>
public bool HasFullScreenWindow(List<string> excludeProcessNames = null)
{
lock (_lockObject)
{
excludeProcessNames = excludeProcessNames ?? new List<string>();
return _windows.Any(w => !excludeProcessNames.Contains(w.ProcessName) && w.IsFullScreen);
}
}
/// <summary>
/// 获取所有全屏窗口
/// </summary>
/// <param name="excludeProcessNames">要排除的进程名列表</param>
/// <returns>全屏窗口列表</returns>
public List<WindowInfo> GetFullScreenWindows(List<string> excludeProcessNames = null)
{
lock (_lockObject)
{
excludeProcessNames = excludeProcessNames ?? new List<string>();
return _windows.Where(w => !excludeProcessNames.Contains(w.ProcessName) && w.IsFullScreen).ToList();
}
}
/// <summary>
/// 根据进程名查找窗口
/// </summary>
/// <param name="processName">进程名</param>
/// <returns>匹配的窗口列表</returns>
public List<WindowInfo> FindWindowsByProcessName(string processName)
{
lock (_lockObject)
{
return _windows.Where(w => w.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)).ToList();
}
}
/// <summary>
/// 根据窗口标题查找窗口
/// </summary>
/// <param name="title">窗口标题(支持部分匹配)</param>
/// <returns>匹配的窗口列表</returns>
public List<WindowInfo> FindWindowsByTitle(string title)
{
lock (_lockObject)
{
return _windows.Where(w => w.Title.IndexOf(title, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
}
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
if (_isDisposed) return;
_isDisposed = true;
_updateTimer?.Dispose();
_updateTimer = null;
lock (_lockObject)
{
_windows.Clear();
}
lock (_processCacheLock)
{
_processCache.Clear();
}
_windowCache.Clear();
}
}
}
@@ -0,0 +1,61 @@
using H.NotifyIcon;
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Windows;
namespace Ink_Canvas.Helpers
{
internal static class WindowsNotificationHelper
{
private const string APP_ID = "InkCanvasForClass.CE";
public static void ShowNewVersionToast(string version)
{
try
{
var os = Environment.OSVersion.Version;
if (os.Major == 6 && os.Minor == 1)
{
ShowBalloonForWin7(version);
}
else
{
ShowToastForModernWindows(version);
}
}
catch
{
}
}
private static void ShowBalloonForWin7(string version)
{
Application.Current?.Dispatcher.Invoke(() =>
{
try
{
var taskbar = Application.Current.Resources["TaskbarTrayIcon"] as TaskbarIcon;
if (taskbar == null) return;
taskbar.Visibility = Visibility.Visible;
taskbar.ShowNotification(
"InkCanvasForClass CE",
$"发现新版本!:{version}");
}
catch
{
}
});
}
private static void ShowToastForModernWindows(string version)
{
new ToastContentBuilder()
.AddText("InkCanvasForClass CE")
.AddText($"发现新版本!:{version}")
.Show();
}
}
}
+88 -66
View File
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<RuntimeIdentifiers>win;win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<OutputType>WinExe</OutputType>
<RootNamespace>Ink_Canvas</RootNamespace>
<AssemblyName>InkCanvasForClass</AssemblyName>
<TargetFramework>net472</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>false</IsWebBootstrapper>
@@ -24,91 +25,78 @@
<BootstrapperEnabled>false</BootstrapperEnabled>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<Configurations>Debug;Release;x86 Debug</Configurations>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x86;x64;ARM64</Platforms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>embedded</DebugType>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Prefer32Bit>True</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='x86 Debug|AnyCPU'">
<DebugType>embedded</DebugType>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Prefer32Bit>True</Prefer32Bit>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>embedded</DebugType>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Prefer32Bit>True</Prefer32Bit>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\icc.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>full</DebugType>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='x86 Debug|x86'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>full</DebugType>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<DebugType>embedded</DebugType>
<LangVersion>7.3</LangVersion>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>pdbonly</DebugType>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<DebugType>embedded</DebugType>
<LangVersion>7.3</LangVersion>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Title>InkCanvasForClass</Title>
<Version>5.0.4</Version>
<Authors>Dubi906w</Authors>
<Version>1.7</Version>
<Authors>CJK_mkp</Authors>
<Product>InkCanvasForClass</Product>
<Copyright>© Copyright HARKOTEK Studio 2024-now</Copyright>
<PackageProjectUrl>https://icc.bliemhax.com</PackageProjectUrl>
<Copyright>© Copyright CJK_mkp 2025-now</Copyright>
<PackageProjectUrl>https://inkcanvasforclass.github.io</PackageProjectUrl>
<FileVersion>bundled</FileVersion>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<DebugType>full</DebugType>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='x86 Debug|ARM64'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>full</DebugType>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
<PlatformTarget>ARM64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<DebugType>pdbonly</DebugType>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
<PlatformTarget>ARM64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>full</DebugType>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='x86 Debug|x64'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>full</DebugType>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
<DebugType>pdbonly</DebugType>
<OutputPath>bin\$(Configuration)\$(Platform)\</OutputPath>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<LangVersion>7.3</LangVersion>
<Prefer32Bit>true</Prefer32Bit>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="IACore">
@@ -126,6 +114,7 @@
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="netstandard" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Management" />
@@ -146,22 +135,31 @@
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.27" />
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.0.131" />
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.10.2.1" />
<PackageReference Include="iNKORE.UI.WPF" Version="1.2.8" />
<PackageReference Include="MdXaml" Version="1.27.0" />
<PackageReference Include="Microsoft.Office.Interop.PowerPoint" Version="15.0.4420.1018" />
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.2" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
<PackageReference Include="MicrosoftOfficeCore" Version="15.0.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.International.Converters.PinYinConverter" Version="1.0.0" />
<PackageReference Include="Sentry" Version="6.2.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
<PackageReference Include="OSVersionExt" Version="3.0.0" />
<PackageReference Include="AForge.Video" Version="2.2.5" />
<PackageReference Include="AForge.Video.DirectShow" Version="2.2.5" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="NHotkey.Wpf" Version="4.0.0" />
<PackageReference Include="OSVersionExt" Version="4.1.0" />
<PackageReference Include="AForge.Video" Version="2.2.5" />
<PackageReference Include="AForge.Video.DirectShow" Version="2.2.5" />
<PackageReference Include="AForge.Imaging" Version="2.2.5" />
<PackageReference Include="AForge.Math" Version="2.2.5" />
<PackageReference Include="WebDav.Client" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(MSBuildRuntimeType)' == 'Full'">
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
@@ -180,15 +178,18 @@
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="VBIDE">
<Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
<VersionMajor>5</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
</ItemGroup>
<ItemGroup Condition="'$(MSBuildRuntimeType)' != 'Full'">
<Reference Include="Interop.IWshRuntimeLibrary">
<HintPath>libs\Interop.IWshRuntimeLibrary.dll</HintPath>
<Private>False</Private>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</Reference>
<Reference Include="Interop.stdole">
<HintPath>libs\Interop.stdole.dll</HintPath>
<Private>False</Private>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\TimerDownNotice.wav" />
@@ -267,6 +268,7 @@
<Resource Include="Resources\DeveloperAvatars\STBBRD.png" />
<Resource Include="Resources\DeveloperAvatars\WXRIW.png" />
<Resource Include="Resources\DeveloperAvatars\PrefacedCorg.jpg" />
<Resource Include="Resources\DeveloperAvatars\PANDA-JSR.jpg" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons-png\down.png" />
@@ -292,6 +294,17 @@
<ItemGroup>
<Resource Include="Resources\Icons-Fluent\ic_fluent_delete_24_regular.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="privacy.txt" />
<EmbeddedResource Include="telemetry_dsn.txt" Condition="Exists('telemetry_dsn.txt') AND '$(DLASS_SENTRY_DSN)' == ''">
<Link>telemetry_dsn.txt</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildProjectDirectory)\telemetry_dsn.generated.txt" Condition="'$(DLASS_SENTRY_DSN)' != ''">
<Link>telemetry_dsn.txt</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons-Fluent\ic_fluent_cursorWITHdelete_24_regular.png" />
</ItemGroup>
@@ -421,6 +434,7 @@
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\new-icons\gesture.png" />
<Resource Include="Resources\new-icons\gesture_white.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\new-icons\gesture-enabled.png" />
@@ -551,6 +565,7 @@
<ItemGroup>
<Compile Remove="AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="MainWindow.xaml~RF6c3144.TMP" />
<None Remove="Resources\Cursors\Cursor.cur" />
@@ -653,4 +668,11 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
<Target Name="GenerateTelemetryDsn" BeforeTargets="PrepareResources" Condition="'$(DLASS_SENTRY_DSN)' != ''">
<WriteLinesToFile File="$(MSBuildProjectDirectory)\telemetry_dsn.generated.txt" Lines="$(DLASS_SENTRY_DSN)" Overwrite="true" />
</Target>
<Target Name="CleanTelemetryDsn" AfterTargets="Build;Clean" Condition="Exists('$(MSBuildProjectDirectory)\telemetry_dsn.generated.txt')">
<Delete Files="$(MSBuildProjectDirectory)\telemetry_dsn.generated.txt" />
</Target>
</Project>
+3137 -1915
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+7 -1
View File
@@ -1,5 +1,11 @@
namespace Ink_Canvas
namespace Ink_Canvas
{
/// <summary>
/// 配置助手类(预留),用于未来扩展配置相关的辅助方法。
/// </summary>
/// <remarks>
/// 该类目前为预留类,用于未来扩展配置相关的辅助方法。
/// </remarks>
internal class ConfigHelper
{
}
+248 -4
View File
@@ -1,4 +1,4 @@
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using System;
using System.Threading;
@@ -13,9 +13,31 @@ namespace Ink_Canvas
{
public partial class MainWindow : Window
{
/// <summary>
/// 浮动栏是否折叠的标志。
/// </summary>
public bool isFloatingBarFolded;
/// <summary>
/// 浮动栏正在改变隐藏模式的标志,用于防止重复操作。
/// </summary>
private bool isFloatingBarChangingHideMode;
/// <summary>
/// 立即关闭白板模式,恢复到批注模式。
/// </summary>
/// <remarks>
/// 操作包括:
/// 1. 检查是否正在显示或隐藏黑板,如果是则直接返回
/// 2. 设置显示/隐藏黑板的标志为true
/// 3. 立即隐藏所有子面板
/// 4. 如果启用了自动切换多指手势,则关闭多指平移
/// 5. 隐藏所有水印
/// 6. 切换到批注模式
/// 7. 设置退出按钮前景色为白色
/// 8. 设置应用主题为深色
/// 9. 200毫秒后重置显示/隐藏黑板的标志为false
/// </remarks>
private void CloseWhiteboardImmediately()
{
if (isDisplayingOrHidingBlackboard) return;
@@ -38,11 +60,35 @@ namespace Ink_Canvas
}).Start();
}
/// <summary>
/// 处理折叠浮动栏的鼠标点击事件。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="e">鼠标按钮事件参数。</param>
public async void FoldFloatingBar_MouseUp(object sender, MouseButtonEventArgs e)
{
await FoldFloatingBar(sender);
}
/// <summary>
/// 折叠浮动栏,将其收纳到侧边栏。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="isAutoFoldCommand">是否为自动折叠命令。</param>
/// <returns>表示异步操作的任务。</returns>
/// <remarks>
/// 操作包括:
/// 1. 检查是否应该拒绝操作(如点击了折叠图标但上次鼠标按下的对象不是折叠图标)
/// 2. 设置折叠/展开标志
/// 3. 检查浮动栏是否已经折叠或正在改变隐藏模式,如果是则直接返回
/// 4. 处理墨迹重放相关的UI元素
/// 5. 设置浮动栏状态标志,关闭白板模式(如果当前在白板模式)
/// 6. 如果是用户手动折叠且画布上有较多墨迹,显示通知
/// 7. 清空画布墨迹
/// 8. 隐藏PPT导航面板和浮动栏拖动网格
/// 9. 执行浮动栏和侧边栏的动画
/// 10. 如果开启了彻底隐藏,则隐藏主窗口
/// </remarks>
public async Task FoldFloatingBar(object sender, bool isAutoFoldCommand = false)
{
var isShouldRejectAction = false;
@@ -54,7 +100,10 @@ namespace Ink_Canvas
if (sender == Fold_Icon && lastBorderMouseDownObject != Fold_Icon) isShouldRejectAction = true;
});
if (isShouldRejectAction) return;
if (isShouldRejectAction)
{
return;
}
// FloatingBarIcons_MouseUp_New(sender);
if (sender == null)
@@ -63,7 +112,12 @@ namespace Ink_Canvas
foldFloatingBarByUser = true;
unfoldFloatingBarByUser = false;
if (isFloatingBarChangingHideMode) return;
if (isFloatingBarFolded) return;
if (isFloatingBarChangingHideMode)
{
return;
}
await Dispatcher.InvokeAsync(() =>
{
@@ -103,8 +157,28 @@ namespace Ink_Canvas
HideSubPanels("cursor");
SidePannelMarginAnimation(-10);
});
// 新增:如果开启了彻底隐藏,则隐藏主窗口
if (Settings.Automation.ThoroughlyHideWhenFolded)
{
await Dispatcher.InvokeAsync(() =>
{
this.Visibility = Visibility.Hidden;
});
}
}
/// <summary>
/// 处理左侧展开按钮显示快捷面板的鼠标点击事件。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="e">鼠标按钮事件参数。</param>
/// <remarks>
/// 操作包括:
/// 1. 检查是否显示快捷面板
/// 2. 如果显示快捷面板,则隐藏右侧快捷面板,显示左侧快捷面板并执行动画
/// 3. 否则,调用展开浮动栏的方法
/// </remarks>
private async void LeftUnFoldButtonDisplayQuickPanel_MouseUp(object sender, MouseButtonEventArgs e)
{
if (Settings.Appearance.IsShowQuickPanel)
@@ -135,6 +209,17 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理右侧展开按钮显示快捷面板的鼠标点击事件。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="e">鼠标按钮事件参数。</param>
/// <remarks>
/// 操作包括:
/// 1. 检查是否显示快捷面板
/// 2. 如果显示快捷面板,则隐藏左侧快捷面板,显示右侧快捷面板并执行动画
/// 3. 否则,调用展开浮动栏的方法
/// </remarks>
private async void RightUnFoldButtonDisplayQuickPanel_MouseUp(object sender, MouseButtonEventArgs e)
{
if (Settings.Appearance.IsShowQuickPanel)
@@ -165,6 +250,15 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 隐藏左侧快捷面板。
/// </summary>
/// <remarks>
/// 操作包括:
/// 1. 检查左侧快捷面板是否可见,如果不可见则直接返回
/// 2. 执行左侧快捷面板的隐藏动画
/// 3. 等待动画完成后,设置左侧快捷面板的边距并将其折叠
/// </remarks>
private async void HideLeftQuickPanel()
{
if (LeftUnFoldButtonQuickPanel.Visibility == Visibility.Visible)
@@ -190,6 +284,15 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 隐藏右侧快捷面板。
/// </summary>
/// <remarks>
/// 操作包括:
/// 1. 检查右侧快捷面板是否可见,如果不可见则直接返回
/// 2. 执行右侧快捷面板的隐藏动画
/// 3. 等待动画完成后,设置右侧快捷面板的边距并将其折叠
/// </remarks>
private async void HideRightQuickPanel()
{
if (RightUnFoldButtonQuickPanel.Visibility == Visibility.Visible)
@@ -215,19 +318,61 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理隐藏快捷面板的鼠标点击事件。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="e">鼠标按钮事件参数。</param>
/// <remarks>
/// 操作包括:
/// 1. 隐藏左侧快捷面板
/// 2. 隐藏右侧快捷面板
/// </remarks>
private void HideQuickPanel_MouseUp(object sender, MouseButtonEventArgs e)
{
HideLeftQuickPanel();
HideRightQuickPanel();
}
/// <summary>
/// 处理展开浮动栏的鼠标点击事件。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="e">鼠标按钮事件参数。</param>
public async void UnFoldFloatingBar_MouseUp(object sender, MouseButtonEventArgs e)
{
await UnFoldFloatingBar(sender);
}
/// <summary>
/// 展开浮动栏,将其从侧边栏恢复到正常状态。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <returns>表示异步操作的任务。</returns>
/// <remarks>
/// 操作包括:
/// 1. 如果之前彻底隐藏了主窗口,先恢复显示
/// 2. 隐藏左右侧快捷面板
/// 3. 设置展开/折叠标志
/// 4. 检查浮动栏是否正在改变隐藏模式,如果是则直接返回
/// 5. 设置浮动栏状态标志,标记为未折叠
/// 6. 根据设置决定是否自动切换至批注模式
/// 7. 根据PPT放映模式和设置显示或隐藏翻页按钮
/// 8. 在屏幕模式下显示浮动栏并执行动画
/// 9. 执行侧边栏动画
/// 10. 等待UI完全更新后,重新设置当前选中模式的按钮高亮状态
/// </remarks>
public async Task UnFoldFloatingBar(object sender)
{
// 新增:如果之前彻底隐藏了,先恢复显示
if (this.Visibility != Visibility.Visible)
{
await Dispatcher.InvokeAsync(() =>
{
this.Visibility = Visibility.Visible;
});
}
await Dispatcher.InvokeAsync(() =>
{
LeftUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
@@ -239,7 +384,11 @@ namespace Ink_Canvas
unfoldFloatingBarByUser = true;
foldFloatingBarByUser = false;
if (isFloatingBarChangingHideMode) return;
if (isFloatingBarChangingHideMode)
{
return;
}
await Dispatcher.InvokeAsync(() =>
{
@@ -326,6 +475,21 @@ namespace Ink_Canvas
}
/// <summary>
/// 执行侧边栏边距动画,用于折叠或展开侧边栏。
/// </summary>
/// <param name="MarginFromEdge">侧边栏距边缘的边距值。可能的值:-50(完全折叠), -10(半展开)</param>
/// <param name="isNoAnimation">是否禁用动画效果。</param>
/// <remarks>
/// 操作包括:
/// 1. 如果边距值为-10(半展开),则显示左侧边栏
/// 2. 创建并执行左侧边栏的边距动画
/// 3. 创建并执行右侧边栏的边距动画
/// 4. 等待600毫秒让动画完成
/// 5. 直接设置侧边栏的最终边距值
/// 6. 如果边距值为-50(完全折叠),则隐藏左侧边栏
/// 7. 重置浮动栏正在改变隐藏模式的标志为false
/// </remarks>
private async void SidePannelMarginAnimation(int MarginFromEdge, bool isNoAnimation = false) // Possible value: -50, -10
{
await Dispatcher.InvokeAsync(() =>
@@ -361,5 +525,85 @@ namespace Ink_Canvas
});
isFloatingBarChangingHideMode = false;
}
private bool IsFloatingBarUiAbsentFromScreens()
{
try
{
if (ViewboxFloatingBar == null) return true;
if (Settings?.Automation?.ThoroughlyHideWhenFolded == true &&
(!IsVisible || Visibility != Visibility.Visible))
return true;
if (ViewboxFloatingBar.Visibility != Visibility.Visible)
return true;
return IsOutsideOfScreenHelper.IsOutsideOfScreen(ViewboxFloatingBar);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动收纳校验:检测浮动栏可见性时出错: {ex.Message}", LogHelper.LogType.Warning);
return true;
}
}
private async Task WaitUntilFloatingBarHideModeIdleAsync(TimeSpan timeout)
{
var start = DateTime.UtcNow;
while (DateTime.UtcNow - start < timeout)
{
bool busy = await Dispatcher.InvokeAsync(() => isFloatingBarChangingHideMode);
if (!busy) return;
await Task.Delay(50).ConfigureAwait(false);
}
}
private async Task WaitForStartupFoldSettledAsync(TimeSpan timeout)
{
var start = DateTime.UtcNow;
while (DateTime.UtcNow - start < timeout)
{
var settled = await Dispatcher.InvokeAsync(() => isFloatingBarFolded && !isFloatingBarChangingHideMode);
if (settled) return;
await Task.Delay(50).ConfigureAwait(false);
}
}
private async Task VerifyStartupFoldAbsenceAfterDelayAsync()
{
try
{
if (!Settings.Startup.IsFoldAtStartup || App.StartWithBoardMode || App.StartWithShowMode)
return;
await WaitForStartupFoldSettledAsync(TimeSpan.FromSeconds(30)).ConfigureAwait(false);
await Task.Delay(3000).ConfigureAwait(false);
bool needRetry = await Dispatcher.InvokeAsync(() =>
{
if (!isFloatingBarFolded) return false;
if (currentMode != 0) return false;
return !IsFloatingBarUiAbsentFromScreens();
});
if (!needRetry) return;
LogHelper.WriteLogToFile("启动收纳校验:检测到浮动栏仍在屏幕上,将展开后等待 0.2s 再次收纳", LogHelper.LogType.Event);
await UnFoldFloatingBar(null);
await WaitUntilFloatingBarHideModeIdleAsync(TimeSpan.FromSeconds(15)).ConfigureAwait(false);
await Task.Delay(200).ConfigureAwait(false);
await FoldFloatingBar(new object()).ConfigureAwait(false);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动收纳校验失败: {ex.Message}", LogHelper.LogType.Error);
}
}
private void ScheduleStartupFoldAbsenceVerification()
{
_ = VerifyStartupFoldAbsenceAfterDelayAsync();
}
}
}
+27 -1
View File
@@ -1,4 +1,4 @@
using IWshRuntimeLibrary;
using IWshRuntimeLibrary;
using System;
using System.Windows;
using Application = System.Windows.Forms.Application;
@@ -8,6 +8,22 @@ namespace Ink_Canvas
{
public partial class MainWindow : Window
{
/// <summary>
/// 创建开机自启动快捷方式。
/// </summary>
/// <param name="exeName">可执行文件名,用于命名快捷方式。</param>
/// <returns>创建成功返回true,失败返回false。</returns>
/// <remarks>
/// 操作包括:
/// 1. 创建Windows Shell对象
/// 2. 在启动文件夹中创建快捷方式
/// 3. 设置快捷方式的目标路径为当前可执行文件路径
/// 4. 设置工作目录为当前目录
/// 5. 设置窗口样式为普通窗口
/// 6. 设置快捷方式描述
/// 7. 保存快捷方式
/// 8. 捕获可能的异常,确保方法不会因异常而崩溃
/// </remarks>
public static bool StartAutomaticallyCreate(string exeName)
{
try
@@ -34,6 +50,16 @@ namespace Ink_Canvas
return false;
}
/// <summary>
/// 删除开机自启动快捷方式。
/// </summary>
/// <param name="exeName">可执行文件名,用于定位要删除的快捷方式。</param>
/// <returns>删除成功返回true,失败返回false。</returns>
/// <remarks>
/// 操作包括:
/// 1. 在启动文件夹中删除指定名称的快捷方式
/// 2. 捕获可能的异常,确保方法不会因异常而崩溃
/// </remarks>
public static bool StartAutomaticallyDel(string exeName)
{
try
+119 -24
View File
@@ -1,19 +1,29 @@
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using Application = System.Windows.Application;
using ui = iNKORE.UI.WPF.Modern.Controls;
using ui = iNKORE.UI.WPF.Controls;
namespace Ink_Canvas
{
public partial class MainWindow : Window
{
/// <summary>
/// 浮动栏前景色,根据当前主题动态更新。
/// </summary>
private Color FloatBarForegroundColor;
/// <summary>
/// 应用并切换到指定的主题("Light" 或 "Dark"),更新主题资源并刷新相关 UI 元素以反映主题变化。
/// </summary>
/// <param name="theme">主题标识,支持 "Light" 或 "Dark"(区分大小写)。</param>
/// <param name="autoSwitchIcon">若为 true,则根据主题自动切换并保存浮动工具栏的图标设置。</param>
private void SetTheme(string theme, bool autoSwitchIcon = false)
{
// 清理现有的主题资源
@@ -35,22 +45,38 @@ namespace Ink_Canvas
if (theme == "Light")
{
// 先加载主题
var rd1 = new ResourceDictionary
{ Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative) };
{
Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd1);
// 在主题资源之后添加其他资源
var rd2 = new ResourceDictionary
{ Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd2);
// 异步加载图形资源,避免阻塞启动
_ = Task.Run(async () =>
{
await Task.Delay(100);
Dispatcher.Invoke(() =>
{
var rd2 = new ResourceDictionary
{
Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd2);
var rd3 = new ResourceDictionary
{ Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd3);
var rd3 = new ResourceDictionary
{
Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd3);
var rd4 = new ResourceDictionary
{ Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd4);
var rd4 = new ResourceDictionary
{
Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd4);
});
});
ThemeManager.SetRequestedTheme(window, ElementTheme.Light);
@@ -65,6 +91,9 @@ namespace Ink_Canvas
// 刷新图片选中栏图标
RefreshImageSelectionIcons();
// 刷新手势按钮图标
RefreshGestureButtonIcon();
RefreshFloatingBarHighlightColors();
if (autoSwitchIcon)
@@ -80,21 +109,35 @@ namespace Ink_Canvas
}
else if (theme == "Dark")
{
// 先加载主题
var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd1);
// 在主题资源之后添加其他资源
var rd2 = new ResourceDictionary
{ Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd2);
// 异步加载图形资源,避免阻塞启动
_ = Task.Run(async () =>
{
await Task.Delay(100);
Dispatcher.Invoke(() =>
{
var rd2 = new ResourceDictionary
{
Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd2);
var rd3 = new ResourceDictionary
{ Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd3);
var rd3 = new ResourceDictionary
{
Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd3);
var rd4 = new ResourceDictionary
{ Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd4);
var rd4 = new ResourceDictionary
{
Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative)
};
Application.Current.Resources.MergedDictionaries.Add(rd4);
});
});
ThemeManager.SetRequestedTheme(window, ElementTheme.Dark);
@@ -109,6 +152,9 @@ namespace Ink_Canvas
// 刷新图片选中栏图标
RefreshImageSelectionIcons();
// 刷新手势按钮图标
RefreshGestureButtonIcon();
RefreshFloatingBarHighlightColors();
if (autoSwitchIcon)
@@ -290,6 +336,18 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理系统主题偏好变化事件,根据当前设置更新应用主题。
/// </summary>
/// <param name="sender">事件发送者。</param>
/// <param name="e">用户偏好变化事件参数。</param>
/// <remarks>
/// 操作包括:
/// 1. 根据当前主题设置(Settings.Appearance.Theme)决定使用哪种主题
/// 2. 如果设置为0(浅色主题),则设置为Light主题
/// 3. 如果设置为1(深色主题),则设置为Dark主题
/// 4. 如果设置为2(跟随系统主题),则根据系统主题设置应用相应的主题
/// </remarks>
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
switch (Settings.Appearance.Theme)
@@ -307,6 +365,17 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 检查系统主题是否为浅色主题。
/// </summary>
/// <returns>系统主题为浅色返回true,深色返回false。</returns>
/// <remarks>
/// 操作包括:
/// 1. 从注册表中读取系统主题设置
/// 2. 检查"SystemUsesLightTheme"键的值
/// 3. 如果值为1,则表示系统使用浅色主题
/// 4. 捕获可能的异常,确保方法不会因异常而崩溃
/// </remarks>
private bool IsSystemThemeLight()
{
var light = false;
@@ -319,7 +388,7 @@ namespace Ink_Canvas
if (themeKey != null) keyValue = (int)themeKey.GetValue("SystemUsesLightTheme");
if (keyValue == 1) light = true;
}
catch { }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return light;
}
@@ -492,6 +561,21 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 刷新手势按钮图标
/// </summary>
private void RefreshGestureButtonIcon()
{
try
{
// 调用手势按钮颜色和图标更新方法,该方法会根据当前主题和手势状态设置正确的图标
CheckEnableTwoFingerGestureBtnColorPrompt();
}
catch (Exception)
{
}
}
/// <summary>
/// 刷新其他窗口的主题
/// </summary>
@@ -515,6 +599,17 @@ namespace Ink_Canvas
operatingGuideWindow.RefreshTheme();
}
}
// 刷新计时器控件
if (TimerControl != null)
{
TimerControl.RefreshTheme();
}
if (MinimizedTimerControl != null)
{
MinimizedTimerControl.RefreshTheme();
}
}
catch (Exception)
{
+283 -46
View File
@@ -1,27 +1,63 @@
using Ink_Canvas.Helpers;
using Ink_Canvas.Controls;
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Media;
using System.Windows.Threading;
namespace Ink_Canvas
{
public partial class MainWindow : Window
{
/// <summary>
/// 存储每个白板页面的墨迹集合
/// </summary>
private StrokeCollection[] strokeCollections = new StrokeCollection[101];
/// <summary>
/// 存储每个白板页面的最后操作模式是否为重做
/// </summary>
private bool[] whiteboadLastModeIsRedo = new bool[101];
/// <summary>
/// 存储最后一次触摸按下时的墨迹集合
/// </summary>
private StrokeCollection lastTouchDownStrokeCollection = new StrokeCollection();
/// <summary>
/// 当前白板页面索引
/// </summary>
private int CurrentWhiteboardIndex = 1;
/// <summary>
/// 白板页面总数
/// </summary>
private int WhiteboardTotalCount = 1;
/// <summary>
/// 存储每个白板页面的时间机器历史记录
/// </summary>
private TimeMachineHistory[][] TimeMachineHistories = new TimeMachineHistory[101][];
/// <summary>
/// 存储每个白板页面的多指书写模式状态
/// </summary>
private bool[] savedMultiTouchModeStates = new bool[101];
// 保存每页白板图片信息
/// <summary>
/// 将当前画布上的所有未保存的图片/媒体和墨迹提交到时间机器历史并将导出结果保存为指定页的快照。
/// </summary>
/// <param name="isBackupMain">为 true 时将导出结果保存到主备份槽(索引 0);为 false 时保存到当前白板索引。</param>
/// <remarks>
/// - 会提交画布上缺失于历史记录的 Image/MediaElement(但跳过 Tag 等于 VideoPresenterLiveFrameTag 的 Image)和缺失的墨迹;
/// - 导出后把结果存入 TimeMachineHistories 的相应索引,并保存当前多指书写模式到 savedMultiTouchModeStates
/// - 导出后会清除时间机器的临时墨迹历史以释放内存。
/// - 此方法有副作用:修改 TimeMachineHistories、savedMultiTouchModeStates,并通过 timeMachine 的提交方法改变其内部历史状态。
/// </remarks>
private void SaveStrokes(bool isBackupMain = false)
{
// 确保画布上的所有UI元素都被保存到时间机器历史记录中
@@ -46,8 +82,12 @@ namespace Ink_Canvas
var missingElements = 0;
foreach (UIElement child in inkCanvas.Children)
{
if (child is Image || child is MediaElement)
if (child is Image || child is MediaElement || child is PdfEmbeddedView)
{
if (child is Image img && img.Tag is string tag && tag == VideoPresenterLiveFrameTag)
{
continue;
}
if (!elementsInHistory.Contains(child))
{
timeMachine.CommitElementInsertHistory(child);
@@ -116,6 +156,15 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 清除画布上的所有墨迹并执行内存清理
/// </summary>
/// <param name="isErasedByCode">是否由代码触发的清除操作</param>
/// <remarks>
/// - 根据参数设置当前提交类型
/// - 清除画布上的所有墨迹
/// - 恢复当前提交类型为用户输入
/// </remarks>
private void ClearStrokes(bool isErasedByCode)
{
_currentCommitType = CommitReason.ClearingCanvas;
@@ -123,24 +172,32 @@ namespace Ink_Canvas
inkCanvas.Strokes.Clear();
// 执行内存清理
PerformLightweightMemoryCleanup();
_currentCommitType = CommitReason.UserInput;
}
/// <summary>
/// 执行内存清理
/// </summary>
private void PerformLightweightMemoryCleanup()
private static HashSet<UIElement> CollectRemovedElementsFromHistory(TimeMachineHistory[] history)
{
Task.Run(() =>
var set = new HashSet<UIElement>();
if (history == null) return set;
foreach (var h in history)
{
GC.Collect();
});
if (h.CommitType == TimeMachineHistoryType.ElementInsert && h.StrokeHasBeenCleared && h.InsertedElement != null)
set.Add(h.InsertedElement);
}
return set;
}
// 恢复每页白板图片信息
/// <summary>
/// 恢复指定白板页面的墨迹和元素信息
/// </summary>
/// <param name="isBackupMain">是否恢复主备份页面</param>
/// <remarks>
/// - 隐藏图片选择工具栏
/// - 清空当前画布的墨迹和所有内容
/// - 从时间机器历史记录中恢复页面内容
/// - 恢复多指书写模式状态
/// - 包含异常处理
/// </remarks>
private void RestoreStrokes(bool isBackupMain = false)
{
try
@@ -169,23 +226,47 @@ namespace Ink_Canvas
if (TimeMachineHistories[targetIndex] == null)
{
timeMachine.ClearStrokeHistory();
SyncPdfPageSidebarWithCanvas();
return;
}
if (isBackupMain)
{
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[0]);
foreach (var item in TimeMachineHistories[0]) ApplyHistoryToCanvas(item);
// 恢复多指书写模式状态
var removed0 = CollectRemovedElementsFromHistory(TimeMachineHistories[0]);
var elementsToProcess = new List<UIElement>();
foreach (var item in TimeMachineHistories[0])
{
if (item.CommitType == TimeMachineHistoryType.ElementInsert &&
!item.StrokeHasBeenCleared &&
item.InsertedElement != null &&
!removed0.Contains(item.InsertedElement))
{
elementsToProcess.Add(item.InsertedElement);
}
ApplyHistoryToCanvas(item, null, removed0);
}
RestoreMultiTouchModeState(0);
ProcessElementsAfterRestore(elementsToProcess);
}
else
{
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[CurrentWhiteboardIndex]);
// 通过时间机器历史恢复所有内容(墨迹和图片)
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) ApplyHistoryToCanvas(item);
// 恢复多指书写模式状态
var removed = CollectRemovedElementsFromHistory(TimeMachineHistories[CurrentWhiteboardIndex]);
var elementsToProcess = new List<UIElement>();
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex])
{
if (item.CommitType == TimeMachineHistoryType.ElementInsert &&
!item.StrokeHasBeenCleared &&
item.InsertedElement != null &&
!removed.Contains(item.InsertedElement))
{
elementsToProcess.Add(item.InsertedElement);
}
ApplyHistoryToCanvas(item, null, removed);
}
RestoreMultiTouchModeState(CurrentWhiteboardIndex);
ProcessElementsAfterRestore(elementsToProcess);
}
@@ -196,6 +277,61 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 在恢复页面后统一处理所有图片/媒体元素的位置和事件绑定,提升含图片页面的加载性能。
/// 先批量添加所有元素到画布,再统一处理位置和事件,减少布局更新次数。
/// </summary>
private void ProcessElementsAfterRestore(List<UIElement> elements)
{
if (elements == null || elements.Count == 0)
{
SyncPdfPageSidebarWithCanvas();
return;
}
// 使用低优先级异步处理,让 UI 先响应,图片位置和事件绑定稍后完成
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
{
foreach (var element in elements)
{
if (!inkCanvas.Children.Contains(element)) continue;
if (element is Image img)
{
double left = InkCanvas.GetLeft(img);
double top = InkCanvas.GetTop(img);
if (double.IsNaN(left) || double.IsNaN(top))
{
CenterAndScaleElement(img);
}
BindElementEvents(img);
}
else if (element is MediaElement media)
{
double left = InkCanvas.GetLeft(media);
double top = InkCanvas.GetTop(media);
if (double.IsNaN(left) || double.IsNaN(top))
{
CenterAndScaleElement(media);
}
BindElementEvents(media);
}
else if (element is PdfEmbeddedView pdf)
{
double left = InkCanvas.GetLeft(pdf);
double top = InkCanvas.GetTop(pdf);
if (double.IsNaN(left) || double.IsNaN(top))
{
CenterAndScaleElement(pdf);
}
BindElementEvents(pdf);
}
}
SyncPdfPageSidebarWithCanvas();
}));
}
/// <summary>
/// 恢复多指书写模式状态
/// </summary>
@@ -206,9 +342,6 @@ namespace Ink_Canvas
// 检查是否保存了多指书写模式状态
if (savedMultiTouchModeStates[pageIndex])
{
// 恢复多指书写模式
EnterMultiTouchModeIfNeeded();
// 更新UI状态
if (ToggleSwitchEnableMultiTouchMode != null)
{
@@ -219,9 +352,6 @@ namespace Ink_Canvas
}
else
{
// 确保多指书写模式关闭
ExitMultiTouchModeIfNeeded();
// 更新UI状态
if (ToggleSwitchEnableMultiTouchMode != null)
{
@@ -235,6 +365,16 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理白板页面索引按钮点击事件,显示或隐藏侧边页面列表
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 处理左侧页面列表按钮点击:显示或隐藏左侧页面列表
/// - 处理右侧页面列表按钮点击:显示或隐藏右侧页面列表
/// - 显示页面列表时会刷新列表内容并滚动到当前页面
/// </remarks>
private async void BtnWhiteBoardPageIndex_Click(object sender, EventArgs e)
{
if (sender == BtnLeftPageListWB)
@@ -280,6 +420,12 @@ namespace Ink_Canvas
}
/// <summary>
/// 切换到前一白板页并在切换过程中保存与恢复画布和相关状态(如果当前已是第一页则不执行任何操作)。
/// </summary>
/// <remarks>
/// 该方法在切换前会取消当前选中元素(同时保留并恢复编辑模式)、调用视频呈现器的离开页前钩子、保存当前页的笔迹与元素、清空画布;切换到前一页后恢复该页内容、调用视频呈现器的页已更改钩子并刷新页面索引显示。
/// </remarks>
private void BtnWhiteBoardSwitchPrevious_Click(object sender, EventArgs e)
{
if (CurrentWhiteboardIndex <= 1) return;
@@ -295,22 +441,30 @@ namespace Ink_Canvas
currentSelectedElement = null;
}
VideoPresenter_BeforePageLeave();
SaveStrokes();
ClearStrokes(true);
CurrentWhiteboardIndex--;
RestoreStrokes();
VideoPresenter_OnPageChanged();
UpdateIndexInfoDisplay();
}
/// <summary>
/// 切换到白板的下一页;在到达最后一页时会新增一页。方法在切页前保存当前页面的笔迹/多媒体状态,在切页后恢复目标页面的内容并更新界面状态。
/// </summary>
/// <param name="sender">触发事件的源对象(通常为按钮)。</param>
/// <param name="e">事件参数。</param>
private void BtnWhiteBoardSwitchNext_Click(object sender, EventArgs e)
{
Trace.WriteLine("113223234");
if (CurrentWhiteboardIndex < WhiteboardTotalCount &&
Settings.Automation.IsAutoSaveStrokesAtClear &&
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber)
CaptureAndEnqueueScreenshotSave(isHideNotification: true);
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
if (CurrentWhiteboardIndex >= WhiteboardTotalCount)
{
// 在最后一页时,点击"新页面"按钮直接新增一页
@@ -329,21 +483,34 @@ namespace Ink_Canvas
currentSelectedElement = null;
}
VideoPresenter_BeforePageLeave();
SaveStrokes();
ClearStrokes(true);
CurrentWhiteboardIndex++;
RestoreStrokes();
VideoPresenter_OnPageChanged();
UpdateIndexInfoDisplay();
}
/// <summary>
/// 在白板集合中添加一个新页面:在切换前保存并清除当前页面的笔迹与状态,插入新空白页面,恢复并刷新与页面相关的 UI 状态。
/// </summary>
/// <remarks>
/// - 在达到最大页面数(99)时不执行任何操作。
/// - 在切换前若启用了自动保存且笔迹数量超过阈值,会保存当前画面截图。
/// - 若有选中元素,会取消选中并恢复编辑模式。
/// - 将当前页面的历史保存到时间轴并清空画布,然后在白板集合中插入一个空白页面(其历史为 null),随后恢复该页面并触发页面变更回调。
/// - 更新页码显示并在达到上限时禁用添加按钮;若侧边页列表可见,则刷新该列表。
/// </remarks>
private void BtnWhiteBoardAdd_Click(object sender, EventArgs e)
{
if (WhiteboardTotalCount >= 99) return;
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber)
CaptureAndEnqueueScreenshotSave(isHideNotification: true);
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
@@ -356,6 +523,7 @@ namespace Ink_Canvas
currentSelectedElement = null;
}
VideoPresenter_BeforePageLeave();
SaveStrokes();
ClearStrokes(true);
@@ -363,14 +531,20 @@ namespace Ink_Canvas
CurrentWhiteboardIndex++;
if (CurrentWhiteboardIndex != WhiteboardTotalCount)
{
for (var i = WhiteboardTotalCount; i > CurrentWhiteboardIndex; i--)
{
TimeMachineHistories[i] = TimeMachineHistories[i - 1];
savedMultiTouchModeStates[i] = savedMultiTouchModeStates[i - 1];
}
}
// 确保新页面的历史记录为空
TimeMachineHistories[CurrentWhiteboardIndex] = null;
// 恢复新页面(这会清空画布,因为历史记录为null)
RestoreStrokes();
VideoPresenter_OnPageChanged();
UpdateIndexInfoDisplay();
@@ -382,36 +556,93 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理白板页面删除按钮点击事件,删除当前白板页面
/// </summary>
private void BtnWhiteBoardDelete_Click(object sender, RoutedEventArgs e)
{
// 隐藏图片选择工具栏
DeleteWhiteBoardPageByIndex(CurrentWhiteboardIndex);
}
/// <summary>
/// 按页码删除指定白板页(用于预览列表等)。仅当总页数大于 1 时有效。
/// </summary>
/// <param name="pageIndex">要删除的页码(1 到 WhiteboardTotalCount</param>
private void DeleteWhiteBoardPageByIndex(int pageIndex)
{
if (WhiteboardTotalCount <= 1 || pageIndex < 1 || pageIndex > WhiteboardTotalCount)
return;
if (currentSelectedElement != null)
{
// 保存当前编辑模式
var previousEditingMode = inkCanvas.EditingMode;
UnselectElement(currentSelectedElement);
// 恢复编辑模式
inkCanvas.EditingMode = previousEditingMode;
currentSelectedElement = null;
}
ClearStrokes(true);
if (pageIndex == CurrentWhiteboardIndex)
{
ClearStrokes(true);
if (CurrentWhiteboardIndex != WhiteboardTotalCount)
for (var i = CurrentWhiteboardIndex; i <= WhiteboardTotalCount; i++)
TimeMachineHistories[i] = TimeMachineHistories[i + 1];
else
var oldTotal = WhiteboardTotalCount;
if (CurrentWhiteboardIndex != oldTotal)
{
for (var i = CurrentWhiteboardIndex; i < oldTotal; i++)
{
TimeMachineHistories[i] = FlattenPageHistory(TimeMachineHistories[i + 1]);
savedMultiTouchModeStates[i] = savedMultiTouchModeStates[i + 1];
}
}
else
{
CurrentWhiteboardIndex--;
}
TimeMachineHistories[oldTotal] = null;
WhiteboardTotalCount--;
RestoreStrokes();
}
else if (pageIndex < CurrentWhiteboardIndex)
{
for (var i = pageIndex; i < WhiteboardTotalCount; i++)
{
TimeMachineHistories[i] = FlattenPageHistory(TimeMachineHistories[i + 1]);
savedMultiTouchModeStates[i] = savedMultiTouchModeStates[i + 1];
}
TimeMachineHistories[WhiteboardTotalCount] = null;
WhiteboardTotalCount--;
CurrentWhiteboardIndex--;
WhiteboardTotalCount--;
RestoreStrokes();
}
else
{
for (var i = pageIndex; i < WhiteboardTotalCount; i++)
{
TimeMachineHistories[i] = FlattenPageHistory(TimeMachineHistories[i + 1]);
savedMultiTouchModeStates[i] = savedMultiTouchModeStates[i + 1];
}
TimeMachineHistories[WhiteboardTotalCount] = null;
WhiteboardTotalCount--;
}
UpdateIndexInfoDisplay();
if (WhiteboardTotalCount < 99) BtnWhiteBoardAdd.IsEnabled = true;
if (BoardBorderLeftPageListView?.Visibility == Visibility.Visible ||
BoardBorderRightPageListView?.Visibility == Visibility.Visible)
RefreshBlackBoardSidePageListView();
}
/// <summary>
/// 更新白板页码信息显示和按钮状态
/// </summary>
/// <remarks>
/// - 更新页码显示文本
/// - 设置下一页按钮文本(根据是否为最后一页)
/// - 启用或禁用下一页按钮(根据是否为最后一页和最大页面数)
/// - 设置按钮颜色和透明度
/// - 启用或禁用上一页按钮(根据是否为第一页)
/// - 设置删除按钮状态(根据页面总数)
/// </remarks>
private void UpdateIndexInfoDisplay()
{
TextBlockWhiteBoardIndexInfo.Text =
@@ -424,8 +655,14 @@ namespace Ink_Canvas
BtnLeftWhiteBoardSwitchNextLabel.Text = isLastPage ? "新页面" : "下一页";
BtnRightWhiteBoardSwitchNextLabel.Text = isLastPage ? "新页面" : "下一页";
// 始终允许点击"下一页/新页面"按钮(除非已达最大页数)
BtnWhiteBoardSwitchNext.IsEnabled = !isMaxPage;
if (isLastPage)
{
BtnWhiteBoardSwitchNext.IsEnabled = !isMaxPage;
}
else
{
BtnWhiteBoardSwitchNext.IsEnabled = true;
}
// 获取主题颜色资源
var iconForegroundBrush = Application.Current.FindResource("IconForeground") as SolidColorBrush;
+111 -6
View File
@@ -1,4 +1,4 @@
using Ink_Canvas.Helpers;
using Ink_Canvas.Helpers;
using System;
using System.Diagnostics;
using System.Windows;
@@ -12,6 +12,19 @@ namespace Ink_Canvas
{
public partial class MainWindow : Window
{
/// <summary>
/// 处理背景颜色按钮点击事件,显示或隐藏背景颜色选项面板
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 检查应用是否已加载
/// - 创建背景选项面板(如果不存在)
/// - 显示或隐藏背景选项面板
/// - 隐藏其他可能显示的面板
/// - 处理白板/黑板模式切换
/// - 更新背景颜色和墨迹颜色
/// </remarks>
private void BoardChangeBackgroundColorBtn_MouseUp(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
@@ -124,7 +137,18 @@ namespace Ink_Canvas
CheckColorTheme(true);
}
// 创建背景选项面板
/// <summary>
/// 创建背景颜色选项面板
/// </summary>
/// <remarks>
/// - 加载自定义背景色
/// - 创建背景选项面板UI
/// - 添加标题栏和关闭按钮
/// - 添加白板/黑板模式选择按钮
/// - 添加RGB颜色选择器
/// - 添加颜色预览和应用按钮
/// - 将面板添加到主网格
/// </remarks>
private void CreateBackgroundPalette()
{
// 确保加载自定义背景色
@@ -543,7 +567,13 @@ namespace Ink_Canvas
}
}
// 更新背景按钮状态
/// <summary>
/// 更新背景颜色选项面板中的按钮状态
/// </summary>
/// <remarks>
/// - 更新白板和黑板按钮的背景和前景色
/// - 根据当前使用的模式设置按钮状态
/// </remarks>
private void UpdateBackgroundButtonsState()
{
if (BackgroundPalette != null && BackgroundPalette.Child is StackPanel stackPanel)
@@ -582,10 +612,14 @@ namespace Ink_Canvas
}
}
// 添加成员变量保存背景面板引用
/// <summary>
/// 背景颜色选项面板
/// </summary>
private Border BackgroundPalette { get; set; }
// 添加成员变量保存当前自定义背景色
/// <summary>
/// 当前自定义背景色
/// </summary>
private Color? CustomBackgroundColor { get; set; }
/// <summary>
@@ -702,6 +736,17 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理套索工具图标点击事件,切换到选择模式
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 禁用橡皮擦模式
/// - 禁用形状绘制模式
/// - 设置当前工具模式为选择模式
/// - 根据编辑模式设置光标
/// </remarks>
private void BoardLassoIcon_Click(object sender, RoutedEventArgs e)
{
forceEraser = false;
@@ -712,6 +757,22 @@ namespace Ink_Canvas
SetCursorBasedOnEditingMode(inkCanvas);
}
/// <summary>
/// 处理橡皮擦图标点击事件,切换到按笔画擦除模式
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 禁用高级橡皮擦系统
/// - 启用橡皮擦模式
/// - 设置橡皮擦形状为圆形
/// - 设置当前工具模式为按笔画擦除
/// - 禁用形状绘制模式
/// - 重置钢笔类型和属性
/// - 触发编辑模式变更事件
/// - 取消单指拖动模式
/// - 隐藏子面板
/// </remarks>
private void BoardEraserIconByStrokes_Click(object sender, RoutedEventArgs e)
{
//if (BoardEraserByStrokes.Background.ToString() == "#FF679CF4") {
@@ -740,6 +801,18 @@ namespace Ink_Canvas
//}
}
/// <summary>
/// 处理删除图标点击事件,清空画布内容
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 调用钢笔图标点击事件
/// - 调用符号删除鼠标抬起事件
/// - 根据设置决定是否清空图片
/// - 如果设置为清空图片,则清空所有子元素
/// - 否则,保存非笔画元素并在清空后恢复
/// </remarks>
private void BoardSymbolIconDelete_MouseUp(object sender, RoutedEventArgs e)
{
PenIcon_Click(null, null);
@@ -764,6 +837,19 @@ namespace Ink_Canvas
Debug.WriteLine($"BoardSymbolIconDelete: inkCanvas.Children.Count after restore: {inkCanvas.Children.Count}");
}
}
/// <summary>
/// 处理删除墨迹和历史记录图标点击事件,清空画布内容和时间机器历史
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 调用钢笔图标点击事件
/// - 调用符号删除鼠标抬起事件
/// - 根据设置决定是否清空时间机器历史
/// - 根据设置决定是否清空图片
/// - 如果设置为清空图片,则清空所有子元素
/// - 否则,保存非笔画元素并在清空后恢复
/// </remarks>
private void BoardSymbolIconDeleteInkAndHistories_MouseUp(object sender, RoutedEventArgs e)
{
PenIcon_Click(null, null);
@@ -790,12 +876,31 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 处理启动希沃视频展台图标点击事件
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 调用图片黑板鼠标抬起事件
/// - 启动希沃视频展台软件
/// </remarks>
private void BoardLaunchEasiCamera_MouseUp(object sender, MouseButtonEventArgs e)
{
ImageBlackboard_MouseUp(null, null);
SoftwareLauncher.LaunchEasiCamera("希沃视频展台");
}
/// <summary>
/// 处理启动Desmos计算器图标点击事件
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数</param>
/// <remarks>
/// - 立即隐藏所有子面板
/// - 调用图片黑板鼠标抬起事件
/// - 打开Desmos计算器网页
/// </remarks>
private void BoardLaunchDesmos_MouseUp(object sender, MouseButtonEventArgs e)
{
HideSubPanelsImmediately();
@@ -857,4 +962,4 @@ namespace Ink_Canvas
}
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More