Exemple #1
0
 private void CopyAddress_Click(object sender, EventArgs e)
 {
     try
     {
         IDataObject iData = Clipboard.GetDataObject();
         if (iData.GetDataPresent(DataFormats.Text))
         {
             List <string> urls = new List <string>();
             URL_Split((string)iData.GetData(DataFormats.Text), ref urls);
             int count = 0;
             foreach (string url in urls)
             {
                 if (controller.AddServerBySSURL(url))
                 {
                     ++count;
                 }
             }
             if (count > 0)
             {
                 ShowConfigForm(true);
             }
         }
     }
     catch
     {
     }
 }
 //************************************************************************************************
 //
 //
 //*************************************************************************************************
 private void AutoConfig_Click(object sender, EventArgs e)
 {
     System.Threading.Tasks.Task.Run(async() =>
     {
         var proxySockets = await new AutoNetProxy().GetProxiesByArukasCloud();
         controller.ClearServer();
         controller.AddServerBySSURL(proxySockets);
         ShowMessage("已经更新了代理");
     });
 }
        private void CopyAddress_Click(object sender, EventArgs e)
        {
            IDataObject iData = Clipboard.GetDataObject();

            if (iData.GetDataPresent(DataFormats.Text))
            {
                string[] urls = ((string)iData.GetData(DataFormats.Text)).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string url in urls)
                {
                    controller.AddServerBySSURL(url);
                }
                ShowConfigForm();
            }
        }
        private void ScanQRCodeItem_Click(object sender, EventArgs e)
        {
            var result = Utils.ScanQRCodeFromScreen();

            if (result != null)
            {
                if (result.ToLowerInvariant().StartsWith("http://") || result.ToLowerInvariant().StartsWith("https://"))
                {
                    _urlToOpen = result;
                    openURLFromQRCode();
                }
                else if (controller.AddServerBySSURL(result))
                {
                    ShowConfigForm();
                }
                else
                {
                    MessageBox.Show(I18N.GetString("Invalid QR Code content: {0}", result));
                }
                return;
            }
            else
            {
                MessageBox.Show(I18N.GetString("No QRCode found. Try to zoom in or move it to the center of the screen."));
            }
        }
Exemple #5
0
        public static void CopyAddress_Click(object sender, EventArgs e)
        {
            ShadowsocksController controller = new ShadowsocksController();

            Console.WriteLine("Import server!");
            try
            {
                IDataObject iData = Clipboard.GetDataObject();
                if (iData.GetDataPresent(DataFormats.Text))
                {
                    Console.WriteLine((string)iData.GetData(DataFormats.Text));
                    List <string> urls = new List <string>();
                    Utils.URL_Split((string)iData.GetData(DataFormats.Text), ref urls);
                    int count = 0;
                    Console.WriteLine(urls[0]);
                    foreach (string url in urls)
                    {
                        if (controller.AddServerBySSURL(url))
                        {
                            ++count;
                        }
                    }
                    if (count > 0)
                    {
                        Console.WriteLine("Import " + count.ToString() + " servers!");
                    }
                }
            }
            catch
            {
            }
        }
        private void ScanQRCodeItem_Click(object sender, EventArgs e)
        {
            foreach (Screen screen in Screen.AllScreens)
            {
                using (Bitmap fullImage = new Bitmap(screen.Bounds.Width,
                                                     screen.Bounds.Height))
                {
                    using (Graphics g = Graphics.FromImage(fullImage))
                    {
                        g.CopyFromScreen(screen.Bounds.X,
                                         screen.Bounds.Y,
                                         0, 0,
                                         fullImage.Size,
                                         CopyPixelOperation.SourceCopy);
                    }
                    int maxTry = 10;
                    for (int i = 0; i < maxTry; i++)
                    {
                        int       marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
                        int       marginTop  = (int)((double)fullImage.Height * i / 2.5 / maxTry);
                        Rectangle cropRect   = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
                        Bitmap    target     = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);

                        double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width;
                        using (Graphics g = Graphics.FromImage(target))
                        {
                            g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
                                        cropRect,
                                        GraphicsUnit.Pixel);
                        }
                        var          source = new BitmapLuminanceSource(target);
                        var          bitmap = new BinaryBitmap(new HybridBinarizer(source));
                        QRCodeReader reader = new QRCodeReader();
                        var          result = reader.decode(bitmap);
                        if (result != null)
                        {
                            var success             = controller.AddServerBySSURL(result.Text);
                            QRCodeSplashForm splash = new QRCodeSplashForm();
                            if (success)
                            {
                                splash.FormClosed += splash_FormClosed;
                            }
                            else if (result.Text.StartsWith("http://") || result.Text.StartsWith("https://"))
                            {
                                _urlToOpen         = result.Text;
                                splash.FormClosed += openURLFromQRCode;
                            }
                            else
                            {
                                MessageBox.Show(I18N.GetString("Failed to decode QRCode"));
                                return;
                            }
                            double minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0;
                            foreach (ResultPoint point in result.ResultPoints)
                            {
                                minX = Math.Min(minX, point.X);
                                minY = Math.Min(minY, point.Y);
                                maxX = Math.Max(maxX, point.X);
                                maxY = Math.Max(maxY, point.Y);
                            }
                            minX /= imageScale;
                            minY /= imageScale;
                            maxX /= imageScale;
                            maxY /= imageScale;
                            // make it 20% larger
                            double margin = (maxX - minX) * 0.20f;
                            minX           += -margin + marginLeft;
                            maxX           += margin + marginLeft;
                            minY           += -margin + marginTop;
                            maxY           += margin + marginTop;
                            splash.Location = new Point(screen.Bounds.X, screen.Bounds.Y);
                            // we need a panel because a window has a minimal size
                            // TODO: test on high DPI
                            splash.TargetRect = new Rectangle((int)minX + screen.Bounds.X, (int)minY + screen.Bounds.Y, (int)maxX - (int)minX, (int)maxY - (int)minY);
                            splash.Size       = new Size(fullImage.Width, fullImage.Height);
                            splash.Show();
                            return;
                        }
                    }
                }
            }
            MessageBox.Show(I18N.GetString("No QRCode found. Try to zoom in or move it to the center of the screen."));
        }
Exemple #7
0
        void updateFreeNodeChecker_NewFreeNodeFound(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(updateFreeNodeChecker.FreeNodeResult))
            {
                List <string> urls = new List <string>();
                updateFreeNodeChecker.FreeNodeResult.TrimEnd('\r', '\n', ' ');
                Configuration config          = controller.GetCurrentConfiguration();
                Server        selected_server = null;
                if (config.index >= 0 && config.index < config.configs.Count)
                {
                    selected_server = config.configs[config.index];
                }
                try
                {
                    updateFreeNodeChecker.FreeNodeResult = Util.Base64.DecodeBase64(updateFreeNodeChecker.FreeNodeResult);
                }
                catch
                {
                }
                int max_node_num = 0;

                Match match_maxnum = Regex.Match(updateFreeNodeChecker.FreeNodeResult, "^MAX=([0-9]+)");
                if (match_maxnum.Success)
                {
                    try
                    {
                        max_node_num = Convert.ToInt32(match_maxnum.Groups[1].Value, 10);
                    }
                    catch
                    {
                    }
                }
                URL_Split(updateFreeNodeChecker.FreeNodeResult, ref urls);
                int count = 0;
                for (int i = urls.Count - 1; i >= 0; --i)
                {
                    if (!urls[i].StartsWith("ss"))
                    {
                        urls.RemoveAt(i);
                    }
                }
                if (urls.Count > 0)
                {
                    if (max_node_num <= 0 || max_node_num >= urls.Count)
                    {
                        urls.Reverse();
                    }
                    else
                    {
                        Random r = new Random();
                        Util.Utils.Shuffle(urls, r);
                        urls.RemoveRange(max_node_num, urls.Count - max_node_num);
                    }
                    foreach (string url in urls)
                    {
                        try // try get group name
                        {
                            Server server = new Server(url, null);
                            if (!String.IsNullOrEmpty(server.group))
                            {
                                config.nodeFeedGroup = server.group;
                                break;
                            }
                        }
                        catch
                        { }
                    }
                    if (String.IsNullOrEmpty(config.nodeFeedGroup))
                    {
                        config.nodeFeedGroup = config.nodeFeedURL;
                    }

                    for (int i = config.configs.Count - 1; i >= 0; --i)
                    {
                        if (config.configs[i].id == selected_server.id && config.nodeFeedGroup == selected_server.group)
                        {
                            bool match = false;
                            for (int j = 0; j < urls.Count; ++j)
                            {
                                try // try get group name
                                {
                                    Server server = new Server(urls[j], null);
                                    {
                                        if (selected_server.isMatchServer(server))
                                        {
                                            match = true;
                                            urls.RemoveAt(j);
                                            break;
                                        }
                                    }
                                }
                                catch
                                { }
                            }
                            if (match)
                            {
                                config.configs.RemoveAt(i);
                                config.configs.Add(selected_server);
                            }
                            else
                            {
                                urls.RemoveAt(0);
                            }
                        }
                        if (config.configs[i].id != selected_server.id && config.configs[i].group == config.nodeFeedGroup)
                        {
                            config.configs.RemoveAt(i);
                        }
                    }
                    controller.SaveServersConfig(config);
                    foreach (string url in urls)
                    {
                        if (controller.AddServerBySSURL(url, config.nodeFeedGroup, true))
                        {
                            ++count;
                        }
                    }
                    config = controller.GetCurrentConfiguration();
                    if (selected_server != null)
                    {
                        bool match = false;
                        for (int i = config.configs.Count - 1; i >= 0; --i)
                        {
                            if (config.configs[i].id == selected_server.id)
                            {
                                config.index = i;
                                match        = true;
                                break;
                            }
                            else if (config.configs[i].group == selected_server.group)
                            {
                                if (config.configs[i].isMatchServer(selected_server))
                                {
                                    config.index = i;
                                    match        = true;
                                    break;
                                }
                            }
                        }
                        if (!match)
                        {
                            config.index = config.configs.Count - 1;
                        }
                    }
                    else
                    {
                        config.index = config.configs.Count - 1;
                    }
                    controller.SaveServersConfig(config);

                    if (count > 0)
                    {
                        ShowBalloonTip(I18N.GetString("Success"),
                                       I18N.GetString("Update subscribe SSR node success"), ToolTipIcon.Info, 10000);
                        return;
                    }
                }
            }
            ShowBalloonTip(I18N.GetString("Error"),
                           I18N.GetString("Update subscribe SSR node failure"), ToolTipIcon.Info, 10000);
        }