예제 #1
0
 public static void SetUrlProtocol(string link)
 {
     try
     {
         var service = new URISchemeService(link, @"URL:ShadowsocksR Link", Utils.GetExecutablePath());
         service.Set();
     }
     catch
     {
         // ignored
     }
 }
예제 #2
0
 public static void SetUrlProtocol(string link)
 {
     try
     {
         var path = Utils.GetExecutablePath();
         using var runKey = Utils.OpenRegKey(@"Software\Classes", true);
         using var ssr    = runKey?.CreateSubKey(link);
         if (ssr != null)
         {
             ssr.SetValue(null, @"URL:ShadowsocksR Link");
             ssr.SetValue(@"URL Protocol", @"");
             using var command = ssr.CreateSubKey(@"Shell\Open\Command");
             command?.SetValue(null, $@"""{path}"" ""%1""");
         }
     }
     catch
     {
         // ignored
     }
 }
예제 #3
0
        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();
        }