private static void Main(string[] args) { Directory.SetCurrentDirectory(Path.GetDirectoryName(Utils.GetExecutablePath()) ?? throw new InvalidOperationException()); var identifier = $@"Global\{Controller.HttpRequest.UpdateChecker.Name}_{Directory.GetCurrentDirectory().GetClassicHashCode()}"; using var singleInstance = new SingleInstanceService(identifier); if (!singleInstance.IsFirstInstance) { singleInstance.PassArgumentsToFirstInstance(args.Length == 0 ? args.Append(Constants.ParameterMultiplyInstance) : args); return; } singleInstance.ArgumentsReceived.Subscribe(SingleInstance_ArgumentsReceived); var app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; app.Exit += App_Exit; Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(@"##SyncfusionLicense##"); Global.LoadConfig(); I18NUtil.SetLanguage(Global.GuiConfig.LangName); ViewUtils.SetResource(app.Resources, @"../View/NotifyIconResources.xaml", 1); Global.Controller = new MainController(); // Logging Logging.DefaultOut = Console.Out; Logging.DefaultError = Console.Error; Utils.SetTls(); Global.ViewController = new MenuViewController(Global.Controller); SystemEvents.SessionEnding += Global.ViewController.Quit_Click; Global.Controller.Reload(); if (Global.GuiConfig.IsDefaultConfig()) { var res = MessageBox.Show( $@"{I18NUtil.GetAppStringValue(@"DefaultConfigMessage")}{Environment.NewLine}{I18NUtil.GetAppStringValue(@"DefaultConfigQuestion")}", Controller.HttpRequest.UpdateChecker.Name, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.OK); switch (res) { case MessageBoxResult.Yes: { Global.Controller.ShowConfigForm(); break; } case MessageBoxResult.No: { Global.Controller.ShowSubscribeWindow(); break; } default: { StopController(); return; } } } Reg.SetUrlProtocol(@"ssr"); Reg.SetUrlProtocol(@"sub"); singleInstance.ListenForArgumentsFromSuccessiveInstances(); app.Run(); }