InkCanvasForClass/Ink Canvas/App.xaml.cs

71 lines
2.6 KiB
C#
Raw Normal View History

2023-12-22 00:14:15 +08:00
using Ink_Canvas.Helpers;
2021-12-16 01:21:41 +08:00
using System;
2020-11-22 11:05:12 +08:00
using System.Linq;
2021-12-16 01:21:41 +08:00
using System.Reflection;
2020-11-22 11:05:12 +08:00
using System.Windows;
namespace Ink_Canvas
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
2021-09-09 13:12:34 +08:00
System.Threading.Mutex mutex;
public static string[] StartArgs = null;
2023-05-17 22:26:09 +08:00
public static string RootPath = Environment.GetEnvironmentVariable("APPDATA") + "\\Ink Canvas\\";
2021-09-09 13:12:34 +08:00
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
}
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
Ink_Canvas.MainWindow.ShowNewMessage("抱歉,出现未预期的异常,可能导致 Ink Canvas 画板运行不稳定。\n建议保存墨迹后重启应用。", true);
LogHelper.NewLog(e.Exception.ToString());
e.Handled = true;
2021-09-09 13:12:34 +08:00
}
void App_Startup(object sender, StartupEventArgs e)
{
2023-12-22 00:14:15 +08:00
/*if (!StoreHelper.IsStoreApp) */RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
2021-12-16 01:21:41 +08:00
LogHelper.NewLog(string.Format("Ink Canvas Starting (Version: {0})", Assembly.GetExecutingAssembly().GetName().Version.ToString()));
2021-09-09 13:12:34 +08:00
bool ret;
mutex = new System.Threading.Mutex(true, "Ink_Canvas", out ret);
if (!ret && !e.Args.Contains("-m")) //-m multiple
2021-09-09 13:12:34 +08:00
{
2021-12-16 01:21:41 +08:00
LogHelper.NewLog("Detected existing instance");
2021-09-09 13:12:34 +08:00
MessageBox.Show("已有一个程序实例正在运行");
2021-12-16 01:21:41 +08:00
LogHelper.NewLog("Ink Canvas automatically closed");
2021-09-09 13:12:34 +08:00
Environment.Exit(0);
}
2021-10-31 15:34:14 +08:00
StartArgs = e.Args;
2021-09-09 13:12:34 +08:00
}
2023-10-28 22:46:22 +08:00
private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
try
{
if (System.Windows.Forms.SystemInformation.MouseWheelScrollLines == -1)
e.Handled = false;
else
try
{
System.Windows.Controls.ScrollViewer SenderScrollViewer = (System.Windows.Controls.ScrollViewer)sender;
SenderScrollViewer.ScrollToVerticalOffset(SenderScrollViewer.VerticalOffset - e.Delta * 10 * System.Windows.Forms.SystemInformation.MouseWheelScrollLines / (double)120);
e.Handled = true;
}
2023-12-22 00:14:15 +08:00
catch { }
2023-10-28 22:46:22 +08:00
}
2023-12-22 00:14:15 +08:00
catch { }
2023-10-28 22:46:22 +08:00
}
2020-11-22 11:05:12 +08:00
}
}