private static void Main(string[] args) { Directory.SetCurrentDirectory(Path.GetDirectoryName(Utils.GetExecutablePath()) ?? throw new InvalidOperationException()); if (args.Contains(Constants.ParameterSetautorun)) { if (!AutoStartup.Switch()) { Environment.ExitCode = 1; } return; } var identifier = $@"Global\{UpdateChecker.Name}_{Directory.GetCurrentDirectory().GetDeterministicHashCode()}"; using var singleInstance = new SingleInstance(identifier); if (!singleInstance.IsFirstInstance) { singleInstance.PassArgumentsToFirstInstance(args.Length == 0 ? args.Append(Constants.ParameterMultiplyInstance) : args); return; } singleInstance.ArgumentsReceived += 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##"); I18NUtil.SetLanguage(Configuration.Load().LangName); ViewUtils.SetResource(app.Resources, @"../View/NotifyIconResources.xaml", 1); _controller = new ShadowsocksController(); // Logging Logging.DefaultOut = Console.Out; Logging.DefaultError = Console.Error; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12; _viewController = new MenuViewController(_controller); SystemEvents.SessionEnding += _viewController.Quit_Click; _controller.Reload(); if (_controller.IsDefaultConfig()) { var res = MessageBox.Show( $@"{I18NUtil.GetAppStringValue(@"DefaultConfigMessage")}{Environment.NewLine}{I18NUtil.GetAppStringValue(@"DefaultConfigQuestion")}", UpdateChecker.Name, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.OK); switch (res) { case MessageBoxResult.Yes: { _controller.ShowConfigForm(); break; } case MessageBoxResult.No: { _controller.ShowSubscribeWindow(); break; } default: { StopController(); return; } } } #if !DEBUG Reg.SetUrlProtocol(@"ssr"); Reg.SetUrlProtocol(@"sub"); #endif singleInstance.ListenForArgumentsFromSuccessiveInstances(); app.Run(); }