diff --git a/App.xaml.cs b/App.xaml.cs index 1127de7..cf4f60b 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Configuration; using System.Data; +using System.IO; using System.Linq; +using System.Text; using System.Windows; namespace BallanceTASEditor { @@ -10,5 +12,48 @@ namespace BallanceTASEditor { /// App.xaml 的交互逻辑 /// public partial class App : Application { + + protected override void OnStartup(StartupEventArgs e) { + base.OnStartup(e); + +#if DEBUG +#else + AppDomain.CurrentDomain.UnhandledException += (sender, ex) => { + if (ex.ExceptionObject is System.Exception) { + var exx = (System.Exception)ex.ExceptionObject; + UncatchedErrorHandle(exx.Message, exx.StackTrace); + } + }; +#endif + } + + private void UncatchedErrorHandle(string message, string stackTrace) { + try { + if (!Directory.Exists("./logs")) + Directory.CreateDirectory("./logs"); + + int counter = 1; + var filename = ""; + var datetime = DateTime.Now; + while (true) { + filename = $"./logs/crash-{datetime.ToString("yyyyMMddHHmmss")}-{counter.ToString().PadLeft(2, '0')}.log"; + if (!File.Exists(filename)) break; + } + + var fs = new StreamWriter(filename, false, Encoding.UTF8); + fs.WriteLine("[SYS][ERROR] FATAL ERROR !"); + fs.WriteLine(message); + fs.WriteLine(stackTrace); + fs.Close(); + fs.Dispose(); + } catch { + ;//skip + } + + MessageBox.Show("A fatal error occurs. The application should exit. Please send the error log, reproduce step and corresponding TAS file(is possible) to use to help fixing this problem.", "Ballance TAS Editor", MessageBoxButton.OK, MessageBoxImage.Error); + App.Current.Shutdown(); + } + + } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 981889f..795d642 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -5,8 +5,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:BallanceTASEditor" xmlns:controls="clr-namespace:BallanceTASEditor.UI" + xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore" mc:Ignorable="d" - Title="Ballance TAS Editor" Height="500" Width="800" KeyUp="funcWindow_KeyUp"> + Title="Ballance TAS Editor" Height="500" Width="800" KeyUp="funcWindow_KeyUp" + input:InputMethod.IsInputMethodEnabled="False"> diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 23f6f0c..cffac24 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -36,7 +36,7 @@ namespace BallanceTASEditor { } private void funcMenu_Help_About(object sender, RoutedEventArgs e) { - MessageBox.Show("Under MIT License\nVersion 0\nyyc12345.", "Ballance TAS Editor"); + MessageBox.Show("Under MIT License\nVersion: 1.0 alpha\nyyc12345.", "Ballance TAS Editor"); } private void funcMenu_File_Open(object sender, RoutedEventArgs e) { @@ -107,6 +107,8 @@ namespace BallanceTASEditor { // move keyboard private void funcWindow_KeyUp(object sender, KeyEventArgs e) { + if (mFile == null || mViewer == null) return; + switch(e.Key) { case Key.A: MoveSliderManually(true, true);