2021-05-13 15:49:26 +08:00
using System ;
using System.Collections.Generic ;
using System.Configuration ;
using System.Data ;
2021-08-08 12:04:17 +08:00
using System.Globalization ;
2021-05-22 13:53:10 +08:00
using System.IO ;
2021-05-13 15:49:26 +08:00
using System.Linq ;
2021-05-22 13:53:10 +08:00
using System.Text ;
2021-05-13 15:49:26 +08:00
using System.Windows ;
namespace BallanceTASEditor {
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application {
2021-05-22 13:53:10 +08:00
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
2021-08-08 12:04:17 +08:00
// init configure manager
GlobalVariable . configManager = new Core . ConfigManager ( "ballance-tas-editor.cfg" , new Dictionary < string , string > ( ) {
2021-09-20 13:58:10 +08:00
{ Core . ConfigManager . CfgNode_Language , CultureInfo . CurrentCulture . ThreeLetterWindowsLanguageName } ,
{ Core . ConfigManager . CfgNode_ItemCount , "15" } ,
{ Core . ConfigManager . CfgNode_IsHorizonLayout , "True" }
2021-08-08 12:04:17 +08:00
} ) ;
// init i18n
2021-09-20 13:58:10 +08:00
Core . I18NProcessor . ChangeLanguage ( GlobalVariable . configManager . Configuration [ Core . ConfigManager . CfgNode_Language ] ) ;
2021-08-08 12:04:17 +08:00
2021-05-22 13:53:10 +08:00
}
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
}
2021-08-08 12:04:17 +08:00
MessageBox . Show ( "A fatal error occurs. The application should exit. Please send the error log, reproduce step and corresponding TAS file(if possible) to developer to help fixing this problem." ,
"Ballance TAS Editor" ,
MessageBoxButton . OK , MessageBoxImage . Error
) ;
2021-05-22 13:53:10 +08:00
App . Current . Shutdown ( ) ;
}
2021-05-13 15:49:26 +08:00
}
}