Exemple #1
0
 private static void Application_ApplicationExit(object sender, EventArgs e)
 {
     if (_controller != null)
     {
         _controller.Stop();
         _controller = null;
     }
 }
Exemple #2
0
        public void Test111()
        {
            var c  = new NewShadowsocksController();
            var b  = "iVBORw0KGgoAAAANSUhEUgAAASgAAAEoAQAAAADDfFG0AAAACXBIWXMAAAsSAAALEgHS3X78AAABKklEQVRoge3Wy7KCIQwD4Lz/S9cRklIK3nYugkfGA183mdZfxDcLVlZWVv+pMNdWhHJq1ZSi44fnHdap1aHyHDLr1OqVGn/jbfWTirB6q7TnNxvqqVVTvGsvVVg1pTWiRD+16mokygST1V8hVpsiDLVe5ORuY22Vm264qRBWdzUfnoB6MLuQBVZVCYI4MuXeq1az3wJqxTm/PFGsVruK4Kwia+SsTsU+RDaiLKO1OhXAB2gwXfSnglUqaFTr5K6+tNrV/G+2YNlD0mpXHFFphRpHF1pxg2Z0VkUOsdVFaaEUrJStulKEK1jwtc221T66fDhEmWJYXdXsO7SKy2xbFTXyJGA3qsjqouYdbzXJVhdFK8ls2ZhWXWWCR/vVbzkrBfppWVlZWf2fegBh5wyM6RfsfwAAAABJRU5ErkJggg==";
            var by = c.Base64ToBytes(b);
            var d  = c.QRDecode(by);

            d = d.Substring("ss://".Length);
            var aaa = d.PadRight(d.Length + (4 - d.Length % 4) % 4, '=');
            var a   = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(aaa));


            var s = new Shadowsocks.Model.Server(d);
        }
Exemple #3
0
        static void Main()
        {
            // Check OS since we are using dual-mode socket
            if (!Utils.IsWinVistaOrHigher())
            {
                MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."),
                                "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Utils.ReleaseMemory(true);
            using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode()))
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.ApplicationExit   += Application_ApplicationExit;
                SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ApplicationExit += (sender, args) => HotKeys.Destroy();

                if (!mutex.WaitOne(0, false))
                {
                    Process[] oldProcesses = Process.GetProcessesByName("Shadowsocks");
                    if (oldProcesses.Length > 0)
                    {
                        Process oldProcess = oldProcesses[0];
                    }
                    MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + "\n" +
                                    I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."),
                                    I18N.GetString("Shadowsocks is already running."));
                    return;
                }

                /**
                 * 当前用户是管理员的时候,直接启动应用程序
                 * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行
                 */
                //获得当前登录的Windows用户标示
                System.Security.Principal.WindowsIdentity  identity  = System.Security.Principal.WindowsIdentity.GetCurrent();
                System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
                //判断当前登录用户是否为管理员
                if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                {
                    var process  = System.Diagnostics.Process.GetCurrentProcess();
                    var filename = process.MainModule.FileName;
                    //创建启动对象
                    var p = new System.Diagnostics.Process();
                    p.StartInfo.UseShellExecute  = true;
                    p.StartInfo.WorkingDirectory = new FileInfo(filename).DirectoryName;
                    p.StartInfo.FileName         = filename;
                    //设置启动动作,确保以管理员身份运行
                    p.StartInfo.Verb = "runas";
                    try { p.Start(); } catch { }
                    //退出
                    Environment.Exit(0);
                }

                Directory.SetCurrentDirectory(Application.StartupPath);
#if DEBUG
                Logging.OpenLogFile();

                // truncate privoxy log file while debugging
                string privoxyLogFilename = Utils.GetTempPath("privoxy.log");
                if (File.Exists(privoxyLogFilename))
                {
                    using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { }
                }
#else
                Logging.OpenLogFile();
#endif
                _controller     = new NewShadowsocksController();
                _viewController = new NewMenuViewController(_controller);
                HotKeys.Init();
                _controller.Start();
                Application.Run();
            }
        }