优化代码

This commit is contained in:
2026-03-03 16:04:20 +08:00
parent 62e79ff5b3
commit a948c0d7fb
73 changed files with 944 additions and 997 deletions
+2 -2
View File
@@ -1,8 +1,10 @@
using Hardcodet.Wpf.TaskbarNotification;
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;
@@ -18,10 +20,8 @@ using System.Windows.Input;
using System.Windows.Threading;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;
using Ink_Canvas.Properties;
using SplashScreen = Ink_Canvas.Windows.SplashScreen;
using Timer = System.Threading.Timer;
using Sentry;
namespace Ink_Canvas
{
-1
View File
@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
-1
View File
@@ -1,5 +1,4 @@
using System;
using Microsoft.Office.Interop.PowerPoint;
namespace Ink_Canvas.Helpers
{
-1
View File
@@ -1,5 +1,4 @@
using System;
using Microsoft.Office.Interop.PowerPoint;
namespace Ink_Canvas.Helpers
{
+1 -1
View File
@@ -1,6 +1,6 @@
using Ink_Canvas.Properties;
using System.Globalization;
using System.Threading;
using Ink_Canvas.Properties;
namespace Ink_Canvas.Helpers
{
+4 -4
View File
@@ -2,8 +2,6 @@ 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
@@ -455,7 +453,8 @@ namespace Ink_Canvas.Helpers
{
for (int i = 0; i < _memoryStreams.Length; i++)
{
try { _memoryStreams[i]?.Dispose(); } catch (Exception ex) { LogHelper.WriteLogToFile($"释放内存流 {i} 失败: {ex}", LogHelper.LogType.Warning); }
try { _memoryStreams[i]?.Dispose(); }
catch (Exception ex) { LogHelper.WriteLogToFile($"释放内存流 {i} 失败: {ex}", LogHelper.LogType.Warning); }
finally { _memoryStreams[i] = null; }
}
_memoryStreams = new MemoryStream[_maxSlides + 2];
@@ -544,7 +543,8 @@ namespace Ink_Canvas.Helpers
if (_memoryStreams[i] != null)
{
long len = _memoryStreams[i].Length;
try { _memoryStreams[i].Dispose(); freed += len; cleaned++; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
try { _memoryStreams[i].Dispose(); freed += len; cleaned++; }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
finally { _memoryStreams[i] = null; }
}
}
+11 -14
View File
@@ -1,13 +1,10 @@
using Microsoft.Office.Interop.PowerPoint;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
namespace Ink_Canvas.Helpers
{
@@ -426,21 +423,21 @@ namespace Ink_Canvas.Helpers
if (fgPid == sswPid) return true;
try
try
{
using (Process fgProc = Process.GetProcessById((int)fgPid))
using (Process appProc = Process.GetProcessById((int)sswPid))
{
using (Process fgProc = Process.GetProcessById((int)fgPid))
using (Process appProc = Process.GetProcessById((int)sswPid))
{
string fgName = fgProc.ProcessName.ToLower();
string appName = appProc.ProcessName.ToLower();
string fgName = fgProc.ProcessName.ToLower();
string appName = appProc.ProcessName.ToLower();
if (fgName.StartsWith("wps") && appName.StartsWith("wpp"))
{
return true;
}
if (fgName.StartsWith("wps") && appName.StartsWith("wpp"))
{
return true;
}
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
return false;
}
@@ -2,7 +2,6 @@ using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
+146 -149
View File
@@ -3,13 +3,10 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Threading;
using Application = System.Windows.Application;
using Timer = System.Timers.Timer;
namespace Ink_Canvas.Helpers
@@ -323,10 +320,10 @@ namespace Ink_Canvas.Helpers
catch
{
LogHelper.WriteLogToFile("成功绑定!", LogHelper.LogType.Trace);
}
}
catch (Exception ex)
{
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"绑定失败: {ex.Message}", LogHelper.LogType.Warning);
DisconnectFromPPT();
}
@@ -399,9 +396,9 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"检查演示文稿状态COM异常: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
DisconnectFromPPT();
continue;
}
catch (Exception ex)
{
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"检查演示文稿状态失败: {ex.Message}", LogHelper.LogType.Warning);
DisconnectFromPPT();
continue;
@@ -763,14 +760,14 @@ namespace Ink_Canvas.Helpers
{
// COM对象已失效,断开连接
LogHelper.WriteLogToFile("检测到COM对象失效,断开连接", LogHelper.LogType.Trace);
DisconnectFromPPT();
}
DisconnectFromPPT();
}
catch (COMException comEx)
{
{
// COM异常,记录并断开连接
var hr = (uint)comEx.HResult;
LogHelper.WriteLogToFile($"PPT连接检查COM异常: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
DisconnectFromPPT();
DisconnectFromPPT();
}
catch (Exception ex)
{
@@ -838,9 +835,9 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"检查演示文稿状态COM异常: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
DisconnectFromPPT();
return;
}
catch (Exception ex)
{
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"检查演示文稿状态失败: {ex.Message},继续使用轮询模式", LogHelper.LogType.Warning);
activePresentation = null;
}
@@ -856,9 +853,9 @@ namespace Ink_Canvas.Helpers
try
{
if (activePresentation == null)
{
try
{
{
try
{
activePresentation = PPTApplication.ActivePresentation;
}
catch (Exception ex)
@@ -968,9 +965,9 @@ namespace Ink_Canvas.Helpers
{
LogHelper.WriteLogToFile($"轮询模式检测到页码变化: {_lastPolledSlideNumber} -> {currentPage},触发事件", LogHelper.LogType.Trace);
SlideShowNextSlide?.Invoke(_pptSlideShowWindow);
}
catch (Exception ex)
{
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"触发轮询模式幻灯片切换事件失败: {ex.Message}", LogHelper.LogType.Warning);
}
}
@@ -1001,9 +998,9 @@ namespace Ink_Canvas.Helpers
}
if (_polling != 0)
{
try
{
{
try
{
int currentPage = GetCurrentSlideIndex(_pptSlideShowWindow);
if (_lastPolledSlideNumber != -1 && currentPage != _lastPolledSlideNumber)
@@ -1123,8 +1120,8 @@ namespace Ink_Canvas.Helpers
try
{
if (pptApp != null)
{
PPTApplication = pptApp;
{
PPTApplication = pptApp;
}
try
@@ -1218,7 +1215,7 @@ namespace Ink_Canvas.Helpers
_bindingEvents = true;
LogHelper.WriteLogToFile("PPT事件注册成功", LogHelper.LogType.Trace);
LogHelper.WriteLogToFile("PPT事件注册成功", LogHelper.LogType.Trace);
}
else
{
@@ -1226,9 +1223,9 @@ namespace Ink_Canvas.Helpers
_forcePolling = true;
LogHelper.WriteLogToFile("无法转换为强类型Application,使用轮询模式", LogHelper.LogType.Trace);
}
}
catch (Exception ex)
{
}
catch (Exception ex)
{
_bindingEvents = false;
_forcePolling = true;
LogHelper.WriteLogToFile($"事件注册失败: {ex.Message},使用轮询模式", LogHelper.LogType.Trace);
@@ -1252,10 +1249,10 @@ namespace Ink_Canvas.Helpers
if (_pptActivePresentation != null)
{
UpdateCurrentPresentationInfo();
UpdateCurrentPresentationInfo();
}
PPTConnectionChanged?.Invoke(true);
PPTConnectionChanged?.Invoke(true);
try
{
@@ -1335,9 +1332,9 @@ namespace Ink_Canvas.Helpers
app.SlideShowEnd -= new EApplication_SlideShowEndEventHandler(OnSlideShowEndForComEvent);
app.PresentationBeforeClose -= new EApplication_PresentationBeforeCloseEventHandler(OnPresentationBeforeClose);
}
}
catch (Exception ex)
{
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"取消PPT事件注册失败: {ex.Message}", LogHelper.LogType.Trace);
}
@@ -1581,28 +1578,28 @@ namespace Ink_Canvas.Helpers
if (CurrentSlides != null)
{
try
{
var slideCount = CurrentSlides.Count;
if (slideCount > 0)
try
{
SlidesCount = slideCount;
var slideCount = CurrentSlides.Count;
if (slideCount > 0)
{
SlidesCount = slideCount;
}
else
{
SlidesCount = 0;
LogHelper.WriteLogToFile("PPT演示文稿页数为0,可能为空演示文稿", LogHelper.LogType.Warning);
}
}
else
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
SlidesCount = 0;
LogHelper.WriteLogToFile("PPT演示文稿页数为0,可能为空演示文稿", LogHelper.LogType.Warning);
LogHelper.WriteLogToFile($"读取PPT页数失败: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
SlidesCount = 0;
LogHelper.WriteLogToFile($"读取PPT页数失败: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
}
try
{
try
{
if (IsInSlideShow && _pptSlideShowWindow != null)
{
try
@@ -1618,57 +1615,57 @@ namespace Ink_Canvas.Helpers
catch (Exception ex)
{
LogHelper.WriteLogToFile($"获取SlideShowWindow的Slide失败: {ex.Message}", LogHelper.LogType.Trace);
}
}
}
else
{
activeWindow = PPTApplication.ActiveWindow;
if (activeWindow != null)
else
{
dynamic aw = activeWindow;
selection = aw.Selection;
if (selection != null)
activeWindow = PPTApplication.ActiveWindow;
if (activeWindow != null)
{
dynamic sel = selection;
slideRange = sel.SlideRange;
if (slideRange != null)
dynamic aw = activeWindow;
selection = aw.Selection;
if (selection != null)
{
dynamic sr = slideRange;
int slideNumber = sr.SlideNumber;
if (slideNumber > 0 && slideNumber <= SlidesCount)
dynamic sel = selection;
slideRange = sel.SlideRange;
if (slideRange != null)
{
CurrentSlide = CurrentSlides[slideNumber];
dynamic sr = slideRange;
int slideNumber = sr.SlideNumber;
if (slideNumber > 0 && slideNumber <= SlidesCount)
{
CurrentSlide = CurrentSlides[slideNumber];
}
}
}
}
if (CurrentSlide == null && SlidesCount > 0)
{
CurrentSlide = CurrentSlides[1];
}
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr != 0x8001010E && hr != 0x80004005)
{
LogHelper.WriteLogToFile($"获取当前幻灯片失败: {comEx.Message}", LogHelper.LogType.Warning);
}
if (CurrentSlide == null && SlidesCount > 0)
if (SlidesCount > 0)
{
CurrentSlide = CurrentSlides[1];
}
}
}
catch (COMException comEx)
else
{
var hr = (uint)comEx.HResult;
if (hr != 0x8001010E && hr != 0x80004005)
{
LogHelper.WriteLogToFile($"获取当前幻灯片失败: {comEx.Message}", LogHelper.LogType.Warning);
}
if (SlidesCount > 0)
{
CurrentSlide = CurrentSlides[1];
}
}
}
else
{
CurrentPresentation = null;
CurrentSlides = null;
CurrentSlide = null;
SlidesCount = 0;
CurrentPresentation = null;
CurrentSlides = null;
CurrentSlide = null;
SlidesCount = 0;
}
}
}
@@ -2000,46 +1997,46 @@ namespace Ink_Canvas.Helpers
try
{
object slideShowWindows = PPTApplication.SlideShowWindows;
if (slideShowWindows != null)
{
dynamic ssw = slideShowWindows;
if (slideShowWindows != null)
{
dynamic ssw = slideShowWindows;
object slideShowWindow = ssw[1];
if (slideShowWindow != null)
{
dynamic sswObj = slideShowWindow;
if (slideShowWindow != null)
{
dynamic sswObj = slideShowWindow;
try
{
sswObj.Activate();
sswObj.Activate();
}
catch { }
try
{
object view = sswObj.View;
if (view != null)
{
dynamic viewObj = view;
viewObj.Next();
}
}
if (view != null)
{
dynamic viewObj = view;
viewObj.Next();
}
}
catch { }
SafeReleaseComObject(slideShowWindow);
}
}
SafeReleaseComObject(slideShowWindows);
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005)
{
DisconnectFromPPT();
}
LogHelper.WriteLogToFile($"切换到下一页失败: {comEx.Message}", LogHelper.LogType.Error);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换到下一页失败: {ex}", LogHelper.LogType.Error);
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005)
{
DisconnectFromPPT();
}
LogHelper.WriteLogToFile($"切换到下一页失败: {comEx.Message}", LogHelper.LogType.Error);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换到下一页失败: {ex}", LogHelper.LogType.Error);
}
}).Start();
return true;
}
@@ -2063,46 +2060,46 @@ namespace Ink_Canvas.Helpers
try
{
object slideShowWindows = PPTApplication.SlideShowWindows;
if (slideShowWindows != null)
{
dynamic ssw = slideShowWindows;
if (slideShowWindows != null)
{
dynamic ssw = slideShowWindows;
object slideShowWindow = ssw[1];
if (slideShowWindow != null)
{
dynamic sswObj = slideShowWindow;
if (slideShowWindow != null)
{
dynamic sswObj = slideShowWindow;
try
{
sswObj.Activate();
sswObj.Activate();
}
catch { }
try
{
object view = sswObj.View;
if (view != null)
{
dynamic viewObj = view;
viewObj.Previous();
}
}
if (view != null)
{
dynamic viewObj = view;
viewObj.Previous();
}
}
catch { }
SafeReleaseComObject(slideShowWindow);
}
}
SafeReleaseComObject(slideShowWindows);
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005)
{
DisconnectFromPPT();
}
LogHelper.WriteLogToFile($"切换到上一页失败: {comEx.Message}", LogHelper.LogType.Error);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换到上一页失败: {ex}", LogHelper.LogType.Error);
}
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x8001010E || hr == 0x80004005)
{
DisconnectFromPPT();
}
LogHelper.WriteLogToFile($"切换到上一页失败: {comEx.Message}", LogHelper.LogType.Error);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换到上一页失败: {ex}", LogHelper.LogType.Error);
}
}).Start();
return true;
}
@@ -2327,9 +2324,9 @@ namespace Ink_Canvas.Helpers
dynamic ssw = slideShowWindow;
view = ssw.View;
if (view != null)
{
dynamic viewObj = view;
if (view != null)
{
dynamic viewObj = view;
slide = viewObj.Slide;
if (slide != null)
{
@@ -2885,8 +2882,8 @@ namespace Ink_Canvas.Helpers
try
{
Marshal.ReleaseComObject(PPTApplication);
PPTApplication = null;
LogHelper.WriteLogToFile("已释放pptApp对象", LogHelper.LogType.Trace);
PPTApplication = null;
LogHelper.WriteLogToFile("已释放pptApp对象", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
+3 -5
View File
@@ -1,12 +1,10 @@
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Ink_Canvas.Windows;
using iNKORE.UI.WPF.Modern.Controls;
using MessageBox=iNKORE.UI.WPF.Modern.Controls.MessageBox;
using System.Threading.Tasks;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
namespace Ink_Canvas.Helpers
{
+2 -3
View File
@@ -1,10 +1,9 @@
using Sentry;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Sentry;
using Sentry.Protocol;
namespace Ink_Canvas.Helpers
{
@@ -146,7 +145,7 @@ namespace Ink_Canvas.Helpers
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);
evt.SetExtra("telemetry_data", telemetryData);
if (crashFiles != null)
{
+1 -1
View File
@@ -2,8 +2,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
-2
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Ink_Canvas.Helpers
{
-1
View File
@@ -1,7 +1,6 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Security;
namespace Ink_Canvas.Helpers
{
@@ -5,8 +5,6 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace Ink_Canvas.Helpers
{
@@ -1,7 +1,6 @@
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -5,7 +5,6 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Interop;
+13 -13
View File
@@ -593,22 +593,22 @@ namespace Ink_Canvas
}
// 创建ZIP文件
if (File.Exists(zipFileName))
File.Delete(zipFileName);
if (File.Exists(zipFileName))
File.Delete(zipFileName);
ZipFile.CreateFromDirectory(tempDir, zipFileName);
ZipFile.CreateFromDirectory(tempDir, zipFileName);
// 异步上传ZIP文件到Dlass
_ = Task.Run(async () =>
{
try
// 异步上传ZIP文件到Dlass
_ = Task.Run(async () =>
{
await Helpers.UploadHelper.UploadFileAsync(zipFileName);
}
catch (Exception)
{
}
});
try
{
await Helpers.UploadHelper.UploadFileAsync(zipFileName);
}
catch (Exception)
{
}
});
if (newNotice)
{
+2 -2
View File
@@ -1,3 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
@@ -6,9 +7,8 @@ using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Windows.Ink;
using Ink_Canvas.Helpers;
using System.Windows.Media.Imaging;
namespace Ink_Canvas
{
@@ -1025,8 +1025,8 @@ namespace Ink_Canvas
{
// 四个边选择点,向外扩展8像素
TopHandle.Margin = new Thickness(bounds.Left + bounds.Width / 2 - 4, bounds.Top - 12, 0, 0);
BottomHandle.Margin = new Thickness(bounds.Left + bounds.Width / 2 - 4, bounds.Bottom + 4 , 0, 0);
LeftHandle.Margin = new Thickness(bounds.Left - 12 , bounds.Top + bounds.Height / 2 - 4, 0, 0);
BottomHandle.Margin = new Thickness(bounds.Left + bounds.Width / 2 - 4, bounds.Bottom + 4, 0, 0);
LeftHandle.Margin = new Thickness(bounds.Left - 12, bounds.Top + bounds.Height / 2 - 4, 0, 0);
RightHandle.Margin = new Thickness(bounds.Right + 4, bounds.Top + bounds.Height / 2 - 4, 0, 0);
// 四个角选择点,完全位于选择框外部
+2 -1
View File
@@ -1027,7 +1027,8 @@ namespace Ink_Canvas
var windowTitle = ForegroundWindowInfo.WindowTitle();
Thickness currentMargin = new Thickness();
Dispatcher.Invoke(() => {
Dispatcher.Invoke(() =>
{
currentMargin = ViewboxFloatingBar.Margin;
});
@@ -5,7 +5,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@@ -1,9 +1,7 @@
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
namespace Ink_Canvas
@@ -11,7 +11,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
+1 -1
View File
@@ -1,6 +1,6 @@
using Ink_Canvas.Properties;
using System;
using System.Windows.Markup;
using Ink_Canvas.Properties;
namespace Ink_Canvas.MarkupExtensions
{
+1 -1
View File
@@ -136,7 +136,7 @@ namespace Ink_Canvas
[JsonProperty("brushAutoRestoreColor")]
public string BrushAutoRestoreColor { get; set; } = "#FFFF0000";
[JsonProperty("brushAutoRestoreWidth")]
public double BrushAutoRestoreWidth { get; set; } =5;
public double BrushAutoRestoreWidth { get; set; } = 5;
[JsonProperty("brushAutoRestoreAlpha")]
public int BrushAutoRestoreAlpha { get; set; } = 255;
[JsonProperty("enableEraserAutoSwitchBack")]
@@ -7,7 +7,6 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
using ui = iNKORE.UI.WPF.Modern.Controls;
namespace Ink_Canvas.Windows
{
+2 -2
View File
@@ -1,4 +1,6 @@
using Ink_Canvas.Helpers;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -12,8 +14,6 @@ using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.Win32;
using Newtonsoft.Json;
using SystemEvents = Microsoft.Win32.SystemEvents;
namespace Ink_Canvas.Windows
+34 -39
View File
@@ -1,10 +1,6 @@
using Ink_Canvas.Helpers;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
@@ -12,7 +8,6 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using File = System.IO.File;
namespace Ink_Canvas.Windows
{
@@ -160,46 +155,46 @@ namespace Ink_Canvas.Windows
DateTime now = DateTime.Now;
// 检查小时是否改变
if (lastTime != DateTime.MinValue && lastTime.Hour != now.Hour)
{
// 先更新数字内容
SetDigitDisplay("Hour1Display", now.Hour / 10);
SetDigitDisplay("Hour2Display", now.Hour % 10);
if (lastTime != DateTime.MinValue && lastTime.Hour != now.Hour)
{
// 先更新数字内容
SetDigitDisplay("Hour1Display", now.Hour / 10);
SetDigitDisplay("Hour2Display", now.Hour % 10);
// 重置Transform位置到上方
HourContentTransform.Y = -40;
HourPanel.Opacity = 0;
// 重置Transform位置到上方
HourContentTransform.Y = -40;
HourPanel.Opacity = 0;
// 播放小时滚动动画:从上方滚入
PlayHourScrollAnimation();
}
else if (lastTime == DateTime.MinValue)
{
// 首次加载,直接更新显示
SetDigitDisplay("Hour1Display", now.Hour / 10);
SetDigitDisplay("Hour2Display", now.Hour % 10);
}
// 播放小时滚动动画:从上方滚入
PlayHourScrollAnimation();
}
else if (lastTime == DateTime.MinValue)
{
// 首次加载,直接更新显示
SetDigitDisplay("Hour1Display", now.Hour / 10);
SetDigitDisplay("Hour2Display", now.Hour % 10);
}
// 检查分钟是否改变
if (lastTime != DateTime.MinValue && lastTime.Minute != now.Minute)
{
// 先更新数字内容
SetDigitDisplay("Minute1Display", now.Minute / 10);
SetDigitDisplay("Minute2Display", now.Minute % 10);
if (lastTime != DateTime.MinValue && lastTime.Minute != now.Minute)
{
// 先更新数字内容
SetDigitDisplay("Minute1Display", now.Minute / 10);
SetDigitDisplay("Minute2Display", now.Minute % 10);
// 重置Transform位置到上方
MinuteContentTransform.Y = -40;
MinutePanel.Opacity = 0;
// 重置Transform位置到上方
MinuteContentTransform.Y = -40;
MinutePanel.Opacity = 0;
// 播放分钟滚动动画:从上方滚入
PlayMinuteScrollAnimation();
}
else if (lastTime == DateTime.MinValue)
{
// 首次加载,直接更新显示
SetDigitDisplay("Minute1Display", now.Minute / 10);
SetDigitDisplay("Minute2Display", now.Minute % 10);
}
// 播放分钟滚动动画:从上方滚入
PlayMinuteScrollAnimation();
}
else if (lastTime == DateTime.MinValue)
{
// 首次加载,直接更新显示
SetDigitDisplay("Minute1Display", now.Minute / 10);
SetDigitDisplay("Minute2Display", now.Minute % 10);
}
lastTime = now;
}
@@ -1,5 +1,5 @@
using iNKORE.UI.WPF.Helpers;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Helpers;
using OSVersionExtension;
using System;
using System.Collections.Generic;
@@ -8,7 +8,6 @@ using System.IO;
using System.Management;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
@@ -16,7 +15,6 @@ using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -71,7 +69,7 @@ namespace Ink_Canvas.Windows.SettingsViews
{
var copyright = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>();
if (copyright != null && !string.IsNullOrEmpty(copyright.Copyright))
{
{
var copyrightText = copyright.Copyright;
AboutCopyright.Text = copyrightText;
AboutBottomCopyright.Text = copyrightText.Replace("Copyright ©", "© Copyright") + " 所有";
@@ -97,13 +95,13 @@ namespace Ink_Canvas.Windows.SettingsViews
if (File.Exists(filePath))
{
var bt = File.GetCreationTime(filePath);
var m = bt.Month.ToString().PadLeft(2, '0');
var d = bt.Day.ToString().PadLeft(2, '0');
var h = bt.Hour.ToString().PadLeft(2, '0');
var min = bt.Minute.ToString().PadLeft(2, '0');
var s = bt.Second.ToString().PadLeft(2, '0');
var m = bt.Month.ToString().PadLeft(2, '0');
var d = bt.Day.ToString().PadLeft(2, '0');
var h = bt.Hour.ToString().PadLeft(2, '0');
var min = bt.Minute.ToString().PadLeft(2, '0');
var s = bt.Second.ToString().PadLeft(2, '0');
AboutBuildTime.Text = $"{bt.Year}-{m}-{d} {h}:{min}:{s}";
}
}
else
{
AboutBuildTime.Text = "获取失败";
@@ -122,7 +120,7 @@ namespace Ink_Canvas.Windows.SettingsViews
try
{
var support = TouchTabletDetectHelper.IsTouchEnabled();
var touchcount = TouchTabletDetectHelper.GetTouchTabletDevices().Count;
var touchcount = TouchTabletDetectHelper.GetTouchTabletDevices().Count;
Dispatcher.BeginInvoke(() =>
{
@@ -145,8 +143,8 @@ namespace Ink_Canvas.Windows.SettingsViews
}
catch (Exception ex)
{
Dispatcher.BeginInvoke(() =>
AboutTouchTabletText.Text = "检测失败");
Dispatcher.BeginInvoke(() =>
AboutTouchTabletText.Text = "检测失败");
System.Diagnostics.Debug.WriteLine($"检测触摸设备失败: {ex.Message}");
}
});
@@ -208,12 +206,12 @@ namespace Ink_Canvas.Windows.SettingsViews
try
{
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity"))
collection = searcher.Get();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity"))
collection = searcher.Get();
foreach (var device in collection)
{
foreach (var device in collection)
{
try
{
var name = device.GetPropertyValue("Name")?.ToString() ?? "";
@@ -231,20 +229,20 @@ namespace Ink_Canvas.Windows.SettingsViews
descLower.Contains("touch") ||
descLower.Contains("digitizer"))
{
devices.Add(new USBDeviceInfo(
device.GetPropertyValue("DeviceID")?.ToString() ?? "",
device.GetPropertyValue("PNPDeviceID")?.ToString() ?? "",
description
));
devices.Add(new USBDeviceInfo(
device.GetPropertyValue("DeviceID")?.ToString() ?? "",
device.GetPropertyValue("PNPDeviceID")?.ToString() ?? "",
description
));
}
}
catch
{
continue;
}
}
}
collection.Dispose();
collection.Dispose();
}
catch (Exception ex)
{
@@ -271,10 +269,10 @@ namespace Ink_Canvas.Windows.SettingsViews
public static DateTimeOffset? GetBuildDateTime(Assembly assembly)
{
try
{
var path = assembly.Location;
if (string.IsNullOrEmpty(path) || !File.Exists(path))
{
var path = assembly.Location;
if (string.IsNullOrEmpty(path) || !File.Exists(path))
{
return null;
}
@@ -298,18 +296,18 @@ namespace Ink_Canvas.Windows.SettingsViews
fileStream.Read(fileHeader, 0, fileHeader.Length);
var pinnedBuffer = GCHandle.Alloc(fileHeader, GCHandleType.Pinned);
try
{
var coffHeader = (_IMAGE_FILE_HEADER)Marshal.PtrToStructure(pinnedBuffer.AddrOfPinnedObject(), typeof(_IMAGE_FILE_HEADER));
try
{
var coffHeader = (_IMAGE_FILE_HEADER)Marshal.PtrToStructure(pinnedBuffer.AddrOfPinnedObject(), typeof(_IMAGE_FILE_HEADER));
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var buildTime = epoch.AddSeconds(coffHeader.TimeDateStamp);
return new DateTimeOffset(buildTime.ToLocalTime());
}
finally
{
pinnedBuffer.Free();
}
}
finally
{
pinnedBuffer.Free();
}
}
}
catch
{
@@ -1,4 +1,3 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic;
@@ -1,7 +1,6 @@
using System;
using System.Windows;
using System.Windows.Controls;
using Ink_Canvas.Windows.SettingsViews;
using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
@@ -1,11 +1,7 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
@@ -1,4 +1,3 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic;
@@ -1,8 +1,6 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -1,4 +1,3 @@
using Ink_Canvas;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -1,8 +1,6 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -1,7 +1,7 @@
using Microsoft.International.Converters.PinYinConverter;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -9,7 +9,6 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.International.Converters.PinYinConverter;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -1,5 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Windows;
using System.Windows.Controls;
@@ -1,4 +1,3 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Windows;
@@ -45,7 +44,7 @@ namespace Ink_Canvas.Windows.SettingsViews
{
System.Diagnostics.Debug.WriteLine($"SettingsPanelBase 应用主题时出错: {ex.Message}");
}
LoadSettings();
LoadSettings();
_isLoaded = true;
}
@@ -1,4 +1,3 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.IO;
@@ -1,7 +1,5 @@
using Ink_Canvas;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -1,5 +1,4 @@
using System.Windows.Media;
using Ink_Canvas;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -1,13 +1,10 @@
using Ink_Canvas;
using Hardcodet.Wpf.TaskbarNotification;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Hardcodet.Wpf.TaskbarNotification;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -1,6 +1,6 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,8 +9,8 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
using static Ink_Canvas.Helpers.AutoUpdateHelper;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -1,5 +1,5 @@
using iNKORE.UI.WPF.Helpers;
using Ink_Canvas.Windows.SettingsViews;
using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;