fix:崩溃后重启选项无法修改,部分触摸问题 improve::自动更新
This commit is contained in:
@@ -20,40 +20,45 @@ namespace Ink_Canvas {
|
||||
SaveInkCanvasStrokes(true, true);
|
||||
}
|
||||
|
||||
private void SaveInkCanvasStrokes(Boolean newNotice, Boolean saveByUser) {
|
||||
private void SaveInkCanvasStrokes(Boolean newNotice, Boolean saveByUser, string userSavePath = null) {
|
||||
try {
|
||||
// 修改保存路径为软件根目录下的Saves文件夹
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (string.IsNullOrEmpty(appDirectory))
|
||||
{
|
||||
appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
}
|
||||
|
||||
string savePath = Path.Combine(appDirectory, "Saves",
|
||||
(saveByUser ? @"User Saved - " : @"Auto Saved - ") +
|
||||
(currentMode == 0 ? "Annotation Strokes" : "BlackBoard Strokes"));
|
||||
|
||||
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
|
||||
// 优先使用用户指定的保存路径,否则使用默认路径
|
||||
string savePathWithName;
|
||||
if (currentMode != 0) // 黑板模式下
|
||||
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + " Page-" +
|
||||
CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk";
|
||||
else
|
||||
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk";
|
||||
if (!string.IsNullOrEmpty(userSavePath)) {
|
||||
// 用户指定了完整保存路径(含文件名)
|
||||
savePathWithName = userSavePath;
|
||||
string dir = Path.GetDirectoryName(savePathWithName);
|
||||
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
||||
} else {
|
||||
// 默认保存到软件根目录下的Saves文件夹
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (string.IsNullOrEmpty(appDirectory))
|
||||
appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
string savePath = Path.Combine(appDirectory, "Saves",
|
||||
(saveByUser ? @"User Saved - " : @"Auto Saved - ") +
|
||||
(currentMode == 0 ? "Annotation Strokes" : "BlackBoard Strokes"));
|
||||
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
|
||||
if (currentMode != 0) // 黑板模式下
|
||||
savePathWithName = Path.Combine(savePath, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") +
|
||||
" Page-" + CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk");
|
||||
else
|
||||
savePathWithName = Path.Combine(savePath, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk");
|
||||
}
|
||||
|
||||
try {
|
||||
using (FileStream fs = new FileStream(savePathWithName, FileMode.Create)) {
|
||||
using (FileStream fs = new FileStream(savePathWithName, FileMode.Create)) {
|
||||
inkCanvas.Strokes.Save(fs);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is DirectoryNotFoundException) {
|
||||
// 修改异常处理中的备用路径为软件根目录下的Saves文件夹
|
||||
// 异常时备用路径仍为默认Saves文件夹
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (string.IsNullOrEmpty(appDirectory))
|
||||
appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
string fallbackPath = Path.Combine(appDirectory, "Saves");
|
||||
Directory.CreateDirectory(fallbackPath);
|
||||
|
||||
string fileName = Path.GetFileNameWithoutExtension(savePathWithName) + "_retry.icstk";
|
||||
string newPath = Path.Combine(fallbackPath, fileName);
|
||||
|
||||
try {
|
||||
using (FileStream fs = new FileStream(newPath, FileMode.Create)) {
|
||||
inkCanvas.Strokes.Save(fs);
|
||||
|
||||
@@ -115,6 +115,22 @@ namespace Ink_Canvas {
|
||||
Settings.Startup = new Startup();
|
||||
}
|
||||
|
||||
// 恢复崩溃后操作设置
|
||||
if (Settings.Startup != null)
|
||||
{
|
||||
// 恢复崩溃后操作选项
|
||||
if (Settings.Startup.CrashAction == 0)
|
||||
{
|
||||
App.CrashAction = App.CrashActionType.SilentRestart;
|
||||
if (RadioCrashSilentRestart != null) RadioCrashSilentRestart.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
App.CrashAction = App.CrashActionType.NoAction;
|
||||
if (RadioCrashNoAction != null) RadioCrashNoAction.IsChecked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Appearance
|
||||
if (Settings.Appearance != null) {
|
||||
if (!Settings.Appearance.IsEnableDisPlayNibModeToggler) {
|
||||
|
||||
@@ -40,9 +40,10 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void MainWindow_TouchDown(object sender, TouchEventArgs e) {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
|
||||
// 允许触摸在擦除、套索等模式下也能操作,不再直接 return
|
||||
// if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|
||||
// || inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke
|
||||
// || inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
|
||||
|
||||
if (!isHidingSubPanelsWhenInking) {
|
||||
isHidingSubPanelsWhenInking = true;
|
||||
@@ -71,7 +72,6 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void MainWindow_StylusDown(object sender, StylusDownEventArgs e) {
|
||||
|
||||
inkCanvas.CaptureStylus();
|
||||
ViewboxFloatingBar.IsHitTestVisible = false;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
|
||||
@@ -94,9 +94,9 @@ namespace Ink_Canvas {
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
|
||||
// 只在橡皮和线擦时 return,套索选区不 return
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke)
|
||||
|
||||
TouchDownPointsList[e.StylusDevice.Id] = InkCanvasEditingMode.None;
|
||||
}
|
||||
@@ -305,6 +305,9 @@ namespace Ink_Canvas {
|
||||
private InkCanvasEditingMode lastInkCanvasEditingMode = InkCanvasEditingMode.Ink;
|
||||
private bool isSingleFingerDragMode = false;
|
||||
|
||||
// 记录手掌擦前的编辑模式
|
||||
private InkCanvasEditingMode prevEditingModeBeforePalmEraser = InkCanvasEditingMode.Ink;
|
||||
|
||||
private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e) {
|
||||
|
||||
inkCanvas.CaptureTouch(e.TouchDevice);
|
||||
@@ -312,7 +315,7 @@ namespace Ink_Canvas {
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
|
||||
|
||||
dec.Add(e.TouchDevice.Id);
|
||||
//设备1个的时候,记录中心点
|
||||
// 设备1个的时候,记录中心点
|
||||
if (dec.Count == 1) {
|
||||
var touchPoint = e.GetTouchPoint(inkCanvas);
|
||||
centerPoint = touchPoint.Position;
|
||||
@@ -320,13 +323,31 @@ namespace Ink_Canvas {
|
||||
//记录第一根手指点击时的 StrokeCollection
|
||||
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
|
||||
}
|
||||
//设备两个及两个以上,将画笔功能关闭
|
||||
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture) {
|
||||
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.None ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
|
||||
lastInkCanvasEditingMode = inkCanvas.EditingMode;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
|
||||
// 多指书写功能开启时禁用手掌擦
|
||||
if (Settings.Gesture.IsEnableTwoFingerGesture) {
|
||||
// 关闭手掌擦逻辑
|
||||
if (dec.Count > 1) {
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.None && inkCanvas.EditingMode != InkCanvasEditingMode.Select) {
|
||||
lastInkCanvasEditingMode = inkCanvas.EditingMode;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 3指及以上触控时触发手掌擦
|
||||
if (dec.Count >= 3) {
|
||||
// 记录触发前的模式
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
prevEditingModeBeforePalmEraser = inkCanvas.EditingMode;
|
||||
}
|
||||
// 切换为橡皮
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
isLastTouchEraser = true;
|
||||
// 可自定义橡皮形状
|
||||
currentPalmEraserShape = GetPalmRectangleEraserShape();
|
||||
inkCanvas.EraserShape = currentPalmEraserShape;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,30 +356,23 @@ namespace Ink_Canvas {
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
//手势完成后切回之前的状态
|
||||
if (dec.Count > 1)
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.None)
|
||||
inkCanvas.EditingMode = lastInkCanvasEditingMode;
|
||||
dec.Remove(e.TouchDevice.Id);
|
||||
inkCanvas.Opacity = 1;
|
||||
|
||||
// 如果是手掌触发的面积擦抬起,需要确保橡皮擦形状被正确重置
|
||||
if (isLastTouchEraser && dec.Count == 0) {
|
||||
isLastTouchEraser = false;
|
||||
currentPalmEraserShape = null; // 清除保存的手掌擦形状
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint && forcePointEraser) {
|
||||
// 重新应用当前设置的橡皮擦形状
|
||||
ApplyCurrentEraserShape();
|
||||
|
||||
// 没有触控输入后,自动恢复手掌擦前的功能
|
||||
if (dec.Count == 0) {
|
||||
if (isLastTouchEraser) {
|
||||
isLastTouchEraser = false;
|
||||
currentPalmEraserShape = null;
|
||||
inkCanvas.EditingMode = prevEditingModeBeforePalmEraser;
|
||||
}
|
||||
}
|
||||
|
||||
if (dec.Count == 0)
|
||||
if (lastTouchDownStrokeCollection.Count() != inkCanvas.Strokes.Count() &&
|
||||
!(drawingShapeMode == 9 && !isFirstTouchCuboid)) {
|
||||
var whiteboardIndex = CurrentWhiteboardIndex;
|
||||
if (currentMode == 0) whiteboardIndex = 0;
|
||||
strokeCollections[whiteboardIndex] = lastTouchDownStrokeCollection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void inkCanvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e) {
|
||||
|
||||
Reference in New Issue
Block a user