@@ -11,7 +11,7 @@ namespace MaiChartManager;
1111
1212public class AppMain : ISingleInstance
1313{
14- public const string Version = "1.6.1 " ;
14+ public const string Version = "1.7.0 " ;
1515 public static Browser ? BrowserWin { get ; set ; }
1616
1717 private Launcher _launcher ;
@@ -24,49 +24,55 @@ public class AppMain : ISingleInstance
2424
2525 public static ILogger GetLogger < T > ( ) => _loggerFactory . CreateLogger < T > ( ) ;
2626
27- public void Run ( )
27+ public static void InitConfiguration ( bool noPopup = false )
2828 {
29- try
30- {
31- SentrySdk . Init ( o =>
32- {
33- // Tells which project in Sentry to send events to:
34- o . Dsn = "https://[email protected] /3" ; 35- // Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
36- // We recommend adjusting this value in production.
37- o . TracesSampleRate = 0.5 ;
29+ SentrySdk . Init ( o =>
30+ {
31+ // Tells which project in Sentry to send events to:
32+ o . Dsn = "https://[email protected] /3" ; 33+ // Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
34+ // We recommend adjusting this value in production.
35+ o . TracesSampleRate = 0.5 ;
3836# if DEBUG
39- o . Environment = "development" ;
37+ o . Environment = "development" ;
4038# endif
39+ }
40+ ) ;
41+
42+ var cfgFilePath = Path . Combine ( StaticSettings . appData , "config.json" ) ;
43+ if ( File . Exists ( cfgFilePath ) )
44+ {
45+ try
46+ {
47+ var cfg = JsonSerializer . Deserialize < Config > ( File . ReadAllText ( Path . Combine ( StaticSettings . appData , "config.json" ) ) ) ;
48+ if ( cfg == null )
49+ {
50+ throw new Exception ( "config.json is null" ) ;
4151 }
42- ) ;
52+ StaticSettings . Config = cfg ;
53+ }
54+ catch ( Exception e )
55+ {
56+ SentrySdk . CaptureException ( e , s => s . TransactionName = "读取配置文件" ) ;
57+ if ( ! noPopup )
58+ MessageBox . Show ( Locale . ConfigCorrupted , Locale . ConfigCorruptedTitle , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
59+ File . Delete ( cfgFilePath ) ;
60+ }
61+ }
62+ }
4363
64+ public void Run ( )
65+ {
66+ try
67+ {
4468 Application . SetUnhandledExceptionMode ( UnhandledExceptionMode . ThrowException ) ;
4569 ApplicationConfiguration . Initialize ( ) ;
4670 FFmpeg . SetExecutablesPath ( StaticSettings . exeDir ) ;
4771 VideoConvert . CheckHardwareAcceleration ( ) ;
4872
4973 Directory . CreateDirectory ( StaticSettings . appData ) ;
5074 Directory . CreateDirectory ( StaticSettings . tempPath ) ;
51- var cfgFilePath = Path . Combine ( StaticSettings . appData , "config.json" ) ;
52- if ( File . Exists ( cfgFilePath ) )
53- {
54- try
55- {
56- var cfg = JsonSerializer . Deserialize < Config > ( File . ReadAllText ( Path . Combine ( StaticSettings . appData , "config.json" ) ) ) ;
57- if ( cfg == null )
58- {
59- throw new Exception ( "config.json is null" ) ;
60- }
61- StaticSettings . Config = cfg ;
62- }
63- catch ( Exception e )
64- {
65- SentrySdk . CaptureException ( e , s => s . TransactionName = "读取配置文件" ) ;
66- MessageBox . Show ( Locale . ConfigCorrupted , Locale . ConfigCorruptedTitle , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
67- File . Delete ( cfgFilePath ) ;
68- }
69- }
75+ InitConfiguration ( ) ;
7076
7177 // 初始化语言设置
7278 if ( StaticSettings . Config . Locale == null )
@@ -91,16 +97,6 @@ public void Run()
9197 }
9298
9399 StaticSettings . Config . Locale = StaticSettings . CurrentLocale ;
94- // 保存配置
95- try
96- {
97- var json = JsonSerializer . Serialize ( StaticSettings . Config , new JsonSerializerOptions { WriteIndented = true } ) ;
98- File . WriteAllText ( cfgFilePath , json ) ;
99- }
100- catch ( Exception e )
101- {
102- _loggerFactory . CreateLogger < AppMain > ( ) . LogError ( e , "保存配置文件失败" ) ;
103- }
104100 }
105101 else
106102 {
0 commit comments