Exemple #1
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.EnableStatusChanged       += controller_EnableStatusChanged;
            controller.ConfigChanged             += controller_ConfigChanged;
            controller.PACFileReadyToOpen        += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen   += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
            controller.EnableGlobalChanged       += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible           = true;
            _notifyIcon.ContextMenu       = contextMenu1;
            _notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            this.updateChecker             = new UpdateChecker();
            updateChecker.NewVersionFound += updateChecker_NewVersionFound;

            LoadCurrentConfiguration();

            updateChecker.CheckUpdate(controller.GetConfiguration());

            if (controller.GetConfiguration().isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
        }
Exemple #2
0
 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     updateChecker.CheckUpdate(controller.GetConfiguration());
     if (timerDelayCheckUpdate != null)
     {
         timerDelayCheckUpdate.Elapsed -= timer_Elapsed;
         timerDelayCheckUpdate.Stop();
         timerDelayCheckUpdate          = new System.Timers.Timer(1000.0 * 60 * 60 * 2);
         timerDelayCheckUpdate.Elapsed += timer_Elapsed;
         timerDelayCheckUpdate.Start();
     }
 }
Exemple #3
0
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            Bitmap icon = null;

            if (dpi < 97)
            {
                // dpi = 96;
                icon = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon = Resources.ss20;
            }
            else
            {
                icon = Resources.ss24;
            }
            Configuration config  = controller.GetConfiguration();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            if (!enabled)
            {
                Bitmap iconCopy = new Bitmap(icon);
                for (int x = 0; x < iconCopy.Width; x++)
                {
                    for (int y = 0; y < iconCopy.Height; y++)
                    {
                        Color color = icon.GetPixel(x, y);
                        iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B));
                    }
                }
                icon = iconCopy;
            }
            _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());

            // we want to show more details but notify icon title is limited to 63 characters
            string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
                          (enabled ?
                           I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
                           String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running
                          + "\n" + config.GetCurrentServer().FriendlyName();

            _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
        }
Exemple #4
0
        public MenuViewController(ShadowsocksController controller)
        {
            LoadMenu();
            LoadTrayIcon();

            this.controller = controller;
            controller.EnableStatusChanged       += controller_EnableStatusChanged;
            controller.ConfigChanged             += controller_ConfigChanged;
            controller.PACFileReadyToOpen        += controller_PACFileReadyToOpen;
            controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
            controller.EnableGlobalChanged       += controller_EnableGlobalChanged;

            this.updateChecker             = new UpdateChecker();
            updateChecker.NewVersionFound += updateChecker_NewVersionFound;

            LoadCurrentConfiguration();

            updateChecker.CheckUpdate();

            if (controller.GetConfiguration().isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = _controller.GetConfiguration();
     ServerViewModel.ReadConfig(_modifiedConfiguration);
     SetServerListSelectedIndex(_modifiedConfiguration.index);
     ApplyButton.IsEnabled = false;
 }
        private void LoadCurrentConfiguration()
        {
            _modifiedConfiguration = _controller.GetConfiguration();
            SubscribeWindowViewModel.ReadConfig(_modifiedConfiguration);

            ApplyButton.IsEnabled = false;
        }
Exemple #7
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox1.Text.Trim()))
            {
                MessageBox.Show("请先在文本中输入一个IP!");
                return;
            }
            var s   = webBrowser1.Document.Body.InnerHtml;;
            var reg = new System.Text.RegularExpressions.Regex("<tbody>(.*)<\\/tbody>");

            foreach (Match m in reg.Matches(s))
            {
                var xx = m.ToString();
                if (xx.Contains(textBox1.Text))
                {
                    Console.WriteLine(m);
                    var sbOut = new System.Text.StringBuilder();
                    sbOut.AppendLine(@"<html>");
                    sbOut.AppendLine("<table>" + m.ToString() + "</table>");
                    sbOut.AppendLine("</html");
                    var sFileTemplate = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "1.html");
                    var sOut          = System.IO.File.ReadAllText(sFileTemplate);
                    sOut = sOut.Replace("${SSTABLE}", "<table>" + m.ToString() + "</table>");
                    var sFileOut = getFilePath("2.html");
                    System.IO.File.WriteAllText(sFileOut, sOut);
                    ToSSRJson();

                    var _config = Configuration.Load();
                    Configuration.Save(_config);
                    controller.GetConfiguration();
                }
            }
            Console.WriteLine(s);
        }
Exemple #8
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfiguration();
     LoadConfiguration(_modifiedConfiguration);
     SetServerListSelectedIndex(_modifiedConfiguration.index);
     LoadSelectedServer();
 }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfiguration();
     LoadConfiguration(_modifiedConfiguration);
     _oldSelectedIndex            = _modifiedConfiguration.index;
     ServersListBox.SelectedIndex = _modifiedConfiguration.index;
     LoadSelectedServer();
 }
        private void GetIPAddress(int svc, out string addr, out string stat, out float speed)
        {
            var currentIndex = controller.GetConfiguration().index;

            controller.SelectServerIndexTemp(svc);
            var webClient = new SocksWebClient {
                ProxyDetails = new ProxyDetails(controller.GetConfiguration().localPort)
            };

            try
            {
                //get location
                var regx1    = new Regex(@"\d+\.\d+\.\d+\.\d+");
                var regx2    = new Regex(@"来自:(.*?)\<");
                var response = webClient.DownloadString(@"http://1111.ip138.com/ic.asp");

                var mc1 = regx1.Match(response);
                addr = mc1.Success ? mc1.Value : I18N.GetString("Unknow");

                var mc2 = regx2.Match(response);
                stat = mc2.Success ? mc2.Groups[1].Value : I18N.GetString("…(⊙_⊙;)…");
            }
            catch
            {
                addr = I18N.GetString("Unknow");
                stat = I18N.GetString("…(⊙_⊙;)…");
            }

            try
            {
                //speed test
                var sw = System.Diagnostics.Stopwatch.StartNew();
                var dl = webClient.DownloadData("https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B7B1E2CBF-95F1-5FDD-C836-E5930E3E51CD%7D%26lang%3Den%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26installdataindex%3Ddefaultbrowser/update2/installers/ChromeSetup.exe");//http://dl.google.com/googletalk/googletalk-setup.exe
                sw.Stop();
                var len = dl.Length / 1024f;
                var sec = sw.Elapsed.Milliseconds / 1000f;
                speed = len / sec;
            }
            catch
            {
                speed = 0;
            }
            webClient.Dispose();
            controller.SelectServerIndexTemp(currentIndex);
        }
Exemple #11
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = _controller.GetConfiguration();
     LoadConfiguration();
     _allowSave = false;
     SetServerListSelectedIndex(_modifiedConfiguration.index);
     _allowSave = true;
     LoadSelectedServer();
 }
        private void LogForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var config = _controller.GetConfiguration().logViewer;

            config.Font        = logTextBox.Font;
            config.AlwaysOnTop = TopMost;
            config.WrapText    = logTextBox.WordWrap;

            _controller.SaveLogViewerConfig(config);
        }
Exemple #13
0
        private void LoadCurrentConfiguration(bool scrollToSelectedItem)
        {
            _modifiedConfiguration = _controller.GetConfiguration();
            ServerViewModel.ReadServers(_modifiedConfiguration.configs);

            if (scrollToSelectedItem)
            {
                MoveToSelectedItem(_modifiedConfiguration.index);
            }

            ApplyButton.IsEnabled = false;
        }
Exemple #14
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfiguration();
     LoadAllSettings();
     if (listServerSubscribe.Items.Count == 0)
     {
         textBoxURL.Enabled = false;
     }
     else
     {
         textBoxURL.Enabled = true;
     }
 }
Exemple #15
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = _controller.GetConfiguration();
     LoadAllSettings();
     if (listServerSubscribe.Items.Count == 0)
     {
         buttonModify.Enabled = false;
         buttonDel.Enabled    = false;
     }
     else
     {
         buttonModify.Enabled = true;
         buttonDel.Enabled    = true;
     }
 }
Exemple #16
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = _controller.GetConfiguration();
     LoadConfiguration(_modifiedConfiguration);
     SetServerListSelectedIndex(_modifiedConfiguration.index);
     LoadSelectedServer();
     if (ServersListBox.Items.Count == 0)
     {
         LoadDefaultServer();
         ModifyButton.Enabled = false;
         DeleteButton.Enabled = false;
         UpButton.Enabled     = false;
         DownButton.Enabled   = false;
     }
 }
 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (timerDelayCheckUpdate != null)
     {
         if (timerDelayCheckUpdate.Interval <= 1000.0 * 30)
         {
             timerDelayCheckUpdate.Interval = 1000.0 * 60 * 5;
         }
         else
         {
             timerDelayCheckUpdate.Interval = 1000.0 * 60 * 60 * 2;
         }
     }
     updateChecker.CheckUpdate(controller.GetConfiguration());
 }
        public PingForm(ShadowsocksController sc)
        {
            InitializeComponent();

            var qqwryPath = Environment.CurrentDirectory + "\\qqwry.dat";

            if (Util.Utils.qqwry == null && File.Exists(qqwryPath))
            {
                Util.Utils.qqwry = new QQWry(qqwryPath);
            }

            controller = sc;

            Font = Util.Utils.GetFont();

            PerformLayout();

            UpdateTexts();

            Icon = Icon.FromHandle(Resources.ssw128.GetHicon());

            LoadConfiguration(controller.GetConfiguration());

            if (dgvMain.Rows.Count <= 5)
            {
                foreach (var row in dgvMain.Rows)
                {
                    var t = new Thread(Ping)
                    {
                        IsBackground = true
                    };
                    t.Start(row);
                }
            }
            else
            {
                ChangeStatus(I18N.GetString("DoSomething"));
                var t = new Thread(Go)
                {
                    IsBackground = true
                };
                t.Start(dgvMain.Rows);
            }
        }
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.EnableStatusChanged     += controller_EnableStatusChanged;
            controller.ConfigChanged           += controller_ConfigChanged;
            controller.PACFileReadyToOpen      += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
            //controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
            //controller.SelectRandomStatusChanged += controller_SelectRandomStatusChanged;
            controller.EnableGlobalChanged           += controller_EnableGlobalChanged;
            controller.Errored                       += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;
            controller.ShowConfigFormEvent           += Config_Click;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible     = true;
            _notifyIcon.ContextMenu = contextMenu1;
            _notifyIcon.MouseClick += notifyIcon1_Click;
            //_notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            this.updateChecker             = new UpdateChecker();
            updateChecker.NewVersionFound += updateChecker_NewVersionFound;

            LoadCurrentConfiguration();

            if (controller.GetConfiguration().isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }

            timerDelayCheckUpdate          = new System.Timers.Timer(1000 * 10.0);
            timerDelayCheckUpdate.Elapsed += timer_Elapsed;
            timerDelayCheckUpdate.Start();
        }
Exemple #20
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.ToggleModeChanged       += controller_ToggleModeChanged;
            controller.ToggleRuleModeChanged   += controller_ToggleRuleModeChanged;
            controller.ConfigChanged           += controller_ConfigChanged;
            controller.PACFileReadyToOpen      += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;
            controller.ShowConfigFormEvent           += Config_Click;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible     = true;
            _notifyIcon.ContextMenu = contextMenu1;
            _notifyIcon.MouseClick += notifyIcon1_Click;
            //_notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            updateChecker = new UpdateChecker();
            updateChecker.NewVersionFound += updateChecker_NewVersionFound;

            LoadCurrentConfiguration();

            Configuration cfg = controller.GetConfiguration();

            if (cfg.isDefaultConfig())
            {
                ShowConfigForm(false);
            }

            timerDelayCheckUpdate          = new System.Timers.Timer(1000.0 * 10);
            timerDelayCheckUpdate.Elapsed += timer_Elapsed;
            timerDelayCheckUpdate.Start();
        }
Exemple #21
0
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            Bitmap icon = null;

            if (dpi < 97)
            {
                // dpi = 96;
                icon = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon = Resources.ss20;
            }
            else
            {
                icon = Resources.ss24;
            }
            bool enabled = controller.GetConfiguration().enabled;

            if (!enabled)
            {
                Bitmap iconCopy = new Bitmap(icon);
                for (int x = 0; x < iconCopy.Width; x++)
                {
                    for (int y = 0; y < iconCopy.Height; y++)
                    {
                        Color color = icon.GetPixel(x, y);
                        iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B));
                    }
                }
                icon = iconCopy;
            }
            _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());

            string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" + (enabled ? I18N.GetString("Enabled") : I18N.GetString("Disabled")) + "\n" + controller.GetCurrentServer().FriendlyName();

            _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
        }
Exemple #22
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfiguration();
 }
Exemple #23
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfiguration();
     LoadConfiguration(_modifiedConfiguration);
     LoadSelectedServer();
 }
Exemple #24
0
 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     updateChecker.CheckUpdate(controller.GetConfiguration());
     timerDelayCheckUpdate.Elapsed -= timer_Elapsed;
     timerDelayCheckUpdate.Stop();
     timerDelayCheckUpdate = null;
 }
Exemple #25
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = _controller.GetConfiguration();
     LoadAllSettings();
     UrlTextBox.IsEnabled = ServerSubscribeListBox.Items.Count != 0;
 }
Exemple #26
0
 private void controller_EnableStatusChanged(object sender, EventArgs e)
 {
     enableItem.Checked = controller.GetConfiguration().enabled;
 }
Exemple #27
0
        static void Main(string[] args)
        {
#if !_CONSOLE
            foreach (string arg in args)
            {
                if (arg == "--setautorun")
                {
                    if (!Controller.AutoStartup.Switch())
                    {
                        Environment.ExitCode = 1;
                    }
                    return;
                }
            }
            using (Mutex mutex = new Mutex(false, "Global\\ShadowsocksR_" + Application.StartupPath.GetHashCode()))
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.EnableVisualStyles();
                Application.ApplicationExit += Application_ApplicationExit;
                SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
                Application.SetCompatibleTextRenderingDefault(false);

                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;
                }
#endif
                Directory.SetCurrentDirectory(Application.StartupPath);

#if !_CONSOLE
                int try_times = 0;
                while (Configuration.Load() == null)
                {
                    if (try_times >= 5)
                        return;
                    using (InputPassword dlg = new InputPassword())
                    {
                        if (dlg.ShowDialog() == DialogResult.OK)
                            Configuration.SetPassword(dlg.password);
                        else
                            return;
                    }
                    try_times += 1;
                }
#endif

                _controller = new ShadowsocksController();
                HostMap.Instance().LoadHostFile();

                // Logging
                Configuration cfg = _controller.GetConfiguration();
                Logging.save_to_file = cfg.logEnable;

                //#if !DEBUG
                if (try_times > 0)
                    Logging.save_to_file = false;
                Logging.OpenLogFile();
                //#endif

#if _DOTNET_4_0
                // Enable Modern TLS when .NET 4.5+ installed.
                if (Util.EnvCheck.CheckDotNet45())
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
#endif
#if !_CONSOLE
                _viewController = new MenuViewController(_controller);
#endif

                _controller.Start();

#if !_CONSOLE
                //Util.Utils.ReleaseMemory();

                Application.Run();
            }
#else
            Console.ReadLine();
            _controller.Stop();
#endif
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = _controller.GetConfiguration();
     LoadSettings();
 }