Example #1
0
        private void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Global.Settings.UseProxyToUpdateSubscription)
            {
                // 当前 ServerComboBox 中至少有一项
                if (ServerComboBox.SelectedIndex == -1)
                {
                    MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                MenuStrip.Enabled  = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
                ControlButton.Text = "...";
            }

            if (Global.Settings.SubscribeLink.Count > 0)
            {
                DeletePictureBox.Enabled = false;

                Task.Run(() =>
                {
                    if (Global.Settings.UseProxyToUpdateSubscription)
                    {
                        var mode = new Models.Mode()
                        {
                            Remark = "ProxyUpdate",
                            Type   = 5
                        };
                        MainController = new MainController();
                        MainController.Start(ServerComboBox.SelectedItem as Models.Server, mode);
                    }
                    foreach (var item in Global.Settings.SubscribeLink)
                    {
                        using (var client = new Override.WebClient())
                        {
                            try
                            {
                                if (!String.IsNullOrEmpty(item.UserAgent))
                                {
                                    client.Headers.Add("User-Agent", item.UserAgent);
                                }
                                else
                                {
                                    client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36");
                                }

                                if (Global.Settings.UseProxyToUpdateSubscription)
                                {
                                    client.Proxy = new System.Net.WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
                                }

                                var response = client.DownloadString(item.Link);

                                try
                                {
                                    response = Utils.ShareLink.URLSafeBase64Decode(response);
                                }
                                catch (Exception)
                                {
                                    // 跳过
                                }

                                var list = new List <Models.Server>();
                                foreach (var server in Global.Settings.Server)
                                {
                                    if (server.Group != item.Remark)
                                    {
                                        list.Add(server);
                                    }
                                }
                                Global.Settings.Server = list;

                                using (var sr = new StringReader(response))
                                {
                                    string text;

                                    while ((text = sr.ReadLine()) != null)
                                    {
                                        var result = Utils.ShareLink.Parse(text);

                                        if (result != null)
                                        {
                                            foreach (var x in result)
                                            {
                                                x.Group = item.Remark;
                                            }

                                            Global.Settings.Server.AddRange(result);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }

                    InitServer();
                    DeletePictureBox.Enabled = true;
                    if (Global.Settings.UseProxyToUpdateSubscription)
                    {
                        MenuStrip.Enabled  = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
                        ControlButton.Text = Utils.i18N.Translate("Start");
                        MainController.Stop();
                    }
                    MessageBox.Show(this, Utils.i18N.Translate("Update completed"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Utils.Configuration.Save();
                });

                MessageBox.Show(Utils.i18N.Translate("Updating in the background"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(Utils.i18N.Translate("No subscription link"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
        private void SubscribeLinksButton_Click(object sender, EventArgs e)
        {
            var number              = new int[] { 0, 0, 0 };
            var v2rayProxies        = new List <Objects.Server.v2ray>();
            var ShadowsocksProxies  = new List <Objects.Server.Shadowsocks>();
            var ShadowsocksRProxies = new List <Objects.Server.ShadowsocksR>();

            foreach (string link in Global.SubscriptionLinks)
            {
                using (var client = new Override.WebClient())
                {
                    try
                    {
                        var response = client.DownloadString(link);
                        if (response != "")
                        {
                            if (response.Length % 4 != 0)
                            {
                                for (var i = 0; i < response.Length % 4; i++)
                                {
                                    response += "=";
                                }
                            }

                            response = Encoding.UTF8.GetString(Convert.FromBase64String(response));

                            using (var sr = new StringReader(response))
                            {
                                string text;

                                while ((text = sr.ReadLine()) != null)
                                {
                                    number[0]++;

                                    if (text.StartsWith("vmess://"))
                                    {
                                        v2rayProxies.Add(Utils.Parse.v2ray(text));
                                    }
                                    else if (text.StartsWith("ss://"))
                                    {
                                        ShadowsocksProxies.Add(Utils.Parse.Shadowsocks(text));
                                    }
                                    else if (text.StartsWith("ssr://"))
                                    {
                                        ShadowsocksRProxies.Add(Utils.Parse.ShadowsocksR(text));
                                    }
                                    else
                                    {
                                        number[2]++;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        number[1]++;

                        if (MessageBox.Show(string.Format("在处理订阅链接:\"{0}\" 时发生错误:{1}\n\n是否终止导入?", link, ex), "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        {
                            continue;
                        }
                    }
                }
            }

            Global.V2RayProxies        = v2rayProxies;
            Global.ShadowsocksProxies  = ShadowsocksProxies;
            Global.ShadowsocksRProxies = ShadowsocksRProxies;
            Global.Views.MainForm.InitProxies();
            MessageBox.Show(String.Format("总共 {0} 条\n成功导入 {1} 条\n导入失败 {2} 条\n无法处理 {3} 条", number[0], number[0] - number[1] - number[2], number[1], number[2]), "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #3
0
        private void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Global.Settings.SubscribeLink.Count > 0)
            {
                DeletePictureBox.Enabled = false;
                Task.Run(() =>
                {
                    foreach (var item in Global.Settings.SubscribeLink)
                    {
                        using (var client = new Override.WebClient())
                        {
                            try
                            {
                                if (!String.IsNullOrEmpty(item.UserAgent))
                                {
                                    client.Headers.Add("User-Agent", item.UserAgent);
                                }
                                else
                                {
                                    client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36");
                                }
                                var response = client.DownloadString(item.Link);

                                try
                                {
                                    response = Utils.ShareLink.URLSafeBase64Decode(response);
                                }
                                catch (Exception)
                                {
                                    // 跳过
                                }

                                var list = new List <Models.Server>();
                                foreach (var server in Global.Settings.Server)
                                {
                                    if (server.Group != item.Remark)
                                    {
                                        list.Add(server);
                                    }
                                }
                                Global.Settings.Server = list;

                                using (var sr = new StringReader(response))
                                {
                                    string text;

                                    while ((text = sr.ReadLine()) != null)
                                    {
                                        var result = Utils.ShareLink.Parse(text);

                                        if (result != null)
                                        {
                                            if (item.Link.Contains("n3ro"))
                                            {
                                                foreach (var x in result)
                                                {
                                                    x.Remark = x.Remark.Split('#')[0].Trim();
                                                }
                                            }

                                            foreach (var x in result)
                                            {
                                                x.Group = item.Remark;
                                            }

                                            Global.Settings.Server.AddRange(result);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }

                    InitServer();
                    DeletePictureBox.Enabled = true;
                    MessageBox.Show(this, Utils.i18N.Translate("Update completed"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                });

                MessageBox.Show(Utils.i18N.Translate("Updating in the background"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(Utils.i18N.Translate("No subscription link"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #4
0
        private void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Global.SubscribeLink.Count > 0)
            {
                DeletePictureBox.Enabled = false;
                Task.Run(() =>
                {
                    foreach (var item in Global.SubscribeLink)
                    {
                        using (var client = new Override.WebClient())
                        {
                            try
                            {
                                var response = client.DownloadString(item.Link);

                                try
                                {
                                    response = Utils.ShareLink.URLSafeBase64Decode(response);
                                }
                                catch (Exception)
                                {
                                    // 跳过
                                }

                                var list = new List <Objects.Server>();
                                foreach (var server in Global.Server)
                                {
                                    if (server.Group != item.Remark)
                                    {
                                        list.Add(server);
                                    }
                                }
                                Global.Server = list;

                                using (var sr = new StringReader(response))
                                {
                                    string text;

                                    while ((text = sr.ReadLine()) != null)
                                    {
                                        var result = Utils.ShareLink.Parse(text);

                                        if (result != null)
                                        {
                                            if (item.Link.Contains("n3ro"))
                                            {
                                                foreach (var x in result)
                                                {
                                                    x.Remark = x.Remark.Split('#')[0].Trim();
                                                }
                                            }

                                            foreach (var x in result)
                                            {
                                                x.Group = item.Remark;
                                            }

                                            Global.Server.AddRange(result);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }

                    InitServer();
                    DeletePictureBox.Enabled = true;
                    MessageBox.Show(Utils.i18N.Translate("Update completed"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                });

                MessageBox.Show(Utils.i18N.Translate("Updating in the background"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(Utils.i18N.Translate("No subscription link"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #5
0
        private void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Global.Settings.UseProxyToUpdateSubscription)
            {
                // 当前 ServerComboBox 中至少有一项
                if (ServerComboBox.SelectedIndex == -1)
                {
                    MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                MenuStrip.Enabled  = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
                ControlButton.Text = "...";
            }

            if (Global.Settings.SubscribeLink.Count > 0)
            {
                DeletePictureBox.Enabled = false;

                UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false;
                Task.Run(() =>
                {
                    if (Global.Settings.UseProxyToUpdateSubscription)
                    {
                        var mode = new Models.Mode
                        {
                            Remark = "ProxyUpdate",
                            Type   = 5
                        };
                        MainController = new MainController();
                        MainController.Start(ServerComboBox.SelectedItem as Models.Server, mode);
                    }
                    foreach (var item in Global.Settings.SubscribeLink)
                    {
                        using var client = new Override.WebClient();
                        try
                        {
                            if (!string.IsNullOrEmpty(item.UserAgent))
                            {
                                client.Headers.Add("User-Agent", item.UserAgent);
                            }
                            else
                            {
                                client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36");
                            }

                            if (Global.Settings.UseProxyToUpdateSubscription)
                            {
                                client.Proxy = new System.Net.WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
                            }

                            var response = client.DownloadString(item.Link);

                            try
                            {
                                response = Utils.ShareLink.URLSafeBase64Decode(response);
                            }
                            catch (Exception)
                            {
                                // 跳过
                            }

                            Global.Settings.Server = Global.Settings.Server.Where(server => server.Group != item.Remark).ToList();
                            var result             = Utils.ShareLink.Parse(response);

                            if (result != null)
                            {
                                foreach (var x in result)
                                {
                                    x.Group = item.Remark;
                                }
                                Global.Settings.Server.AddRange(result);
                                NotifyIcon.ShowBalloonTip(5,
                                                          UpdateChecker.Name,
                                                          string.Format(Utils.i18N.Translate("Update {1} server(s) from {0}"), item.Remark, result.Count),
                                                          ToolTipIcon.Info);
                            }
                            else
                            {
                                NotifyIcon.ShowBalloonTip(5,
                                                          UpdateChecker.Name,
                                                          string.Format(Utils.i18N.Translate("Update servers error from {0}"), item.Remark),
                                                          ToolTipIcon.Error);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    InitServer();
                    DeletePictureBox.Enabled = true;
                    if (Global.Settings.UseProxyToUpdateSubscription)
                    {
                        MenuStrip.Enabled  = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
                        ControlButton.Text = Utils.i18N.Translate("Start");
                        MainController.Stop();
                        NatTypeStatusLabel.Text = "";
                    }
                    Utils.Configuration.Save();
                }).ContinueWith(task =>
                {
                    BeginInvoke(new Action(() =>
                    {
                        UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = true;
                    }));
                });

                NotifyIcon.ShowBalloonTip(5,
                                          UpdateChecker.Name,
                                          Utils.i18N.Translate("Updating in the background"),
                                          ToolTipIcon.Info);
            }
            else
            {
                MessageBox.Show(Utils.i18N.Translate("No subscription link"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }