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; I18NUtil.SetLanguage(app.Resources, @"App"); ViewUtils.SetResource(app.Resources, @"../View/NotifyIconResources.xaml", 1); SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; app.Exit += App_Exit; var tryTimes = 0; while (Configuration.Load() == null) { if (tryTimes >= 5) { return; } var dlg = new InputPasswordWindow(); if (dlg.ShowDialog() == true) { Configuration.SetPassword(dlg.Password); } else { return; } tryTimes += 1; } _controller = new ShadowsocksController(); HostMap.Instance().LoadHostFile(); // Logging Logging.DefaultOut = Console.Out; Logging.DefaultError = Console.Error; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; _viewController = new MenuViewController(_controller); SystemEvents.SessionEnding += _viewController.Quit_Click; _controller.Start(); Reg.SetUrlProtocol(@"ssr"); Reg.SetUrlProtocol(@"sub"); singleInstance.ListenForArgumentsFromSuccessiveInstances(); app.Run(); }
private static void Main(string[] args) { Directory.SetCurrentDirectory(Path.GetDirectoryName(Utils.GetExecutablePath()) ?? throw new InvalidOperationException()); if (args.Any(arg => arg == @"--setautorun")) { if (!AutoStartup.Switch()) { Environment.ExitCode = 1; } return; } using var mutex = new Mutex(false, $@"Global\ShadowsocksR_{Directory.GetCurrentDirectory().GetDeterministicHashCode()}"); if (!mutex.WaitOne(0, false)) { MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + Environment.NewLine + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."), I18N.GetString("ShadowsocksR is already running.")); return; } var app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; app.Exit += App_Exit; var tryTimes = 0; while (Configuration.Load() == null) { if (tryTimes >= 5) { return; } var dlg = new InputPasswordWindow(); if (dlg.ShowDialog() == true) { Configuration.SetPassword(dlg.Password); } else { return; } tryTimes += 1; } _controller = new ShadowsocksController(); HostMap.Instance().LoadHostFile(); // Logging Logging.DefaultOut = Console.Out; Logging.DefaultError = Console.Error; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; _viewController = new MenuViewController(_controller); SystemEvents.SessionEnding += _viewController.Quit_Click; _controller.Start(); app.Run(); }