11using System . Runtime . InteropServices ;
2- using System . Security . Cryptography ;
3- using System . Text . Json ;
4- using Windows . ApplicationModel ;
5- using MaiChartManager . Controllers . Music ;
6- using Microsoft . IdentityModel . JsonWebTokens ;
7- using Microsoft . IdentityModel . Tokens ;
8- using Xabe . FFmpeg ;
2+ using SingleInstanceCore ;
93
104namespace MaiChartManager ;
115
126public static partial class Program
137{
14- public const string Version = "1.3.2" ;
15- public static Browser ? BrowserWin { get ; set ; }
16-
178 [ LibraryImport ( "kernel32.dll" , SetLastError = true ) ]
189 private static partial void SetConsoleOutputCP ( uint wCodePageID ) ;
1910
20- private static ILoggerFactory _loggerFactory = LoggerFactory . Create ( builder =>
21- {
22- builder . AddConsole ( ) ;
23- builder . SetMinimumLevel ( LogLevel . Information ) ;
24- } ) ;
25-
26- public static ILogger GetLogger < T > ( ) => _loggerFactory . CreateLogger < T > ( ) ;
27-
2811 /// <summary>
2912 /// The main entry point for the application.
3013 /// </summary>
3114 [ STAThread ]
3215 public static void Main ( )
3316 {
3417 SetConsoleOutputCP ( 65001 ) ;
35- try
36- {
37- SentrySdk . Init ( o =>
38- {
39- // Tells which project in Sentry to send events to:
40- o . Dsn = "https://[email protected] /3" ; 41- // Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
42- // We recommend adjusting this value in production.
43- o . TracesSampleRate = 0.5 ;
44- # if DEBUG
45- o . Environment = "development" ;
46- # endif
47- }
48- ) ;
49-
50- Application . SetUnhandledExceptionMode ( UnhandledExceptionMode . ThrowException ) ;
51- ApplicationConfiguration . Initialize ( ) ;
52- FFmpeg . SetExecutablesPath ( StaticSettings . exeDir ) ;
53- MovieConvertController . CheckHardwareAcceleration ( ) ;
5418
55- Directory . CreateDirectory ( StaticSettings . appData ) ;
56- Directory . CreateDirectory ( StaticSettings . tempPath ) ;
57- if ( File . Exists ( Path . Combine ( StaticSettings . appData , "config.json" ) ) )
58- StaticSettings . Config = JsonSerializer . Deserialize < Config > ( File . ReadAllText ( Path . Combine ( StaticSettings . appData , "config.json" ) ) ) ;
59- IapManager . Init ( ) ;
19+ var app = new AppMain ( ) ;
6020
61- new Launcher ( ) ;
62-
63- Application . Run ( ) ;
64- }
65- catch ( Exception e )
21+ var isFirstInstance = app . InitializeAsFirstInstance ( "MaiChartManager" ) ;
22+ if ( isFirstInstance )
6623 {
67- SentrySdk . CaptureException ( e ) ;
68- MessageBox . Show ( e . Message , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
69- throw ;
24+ try
25+ {
26+ app . Run ( ) ;
27+ }
28+ finally
29+ {
30+ SingleInstance . Cleanup ( ) ;
31+ }
7032 }
7133 }
7234}
0 commit comments