public SubscribeWindow(MainController controller, UpdateSubscribeManager updateSubscribeManager, UpdateNode updateNodeChecker) { InitializeComponent(); I18NUtil.SetLanguage(Resources, @"SubscribeWindow"); Closed += (o, e) => { controller.ConfigChanged -= controller_ConfigChanged; SubscribeWindowViewModel.SubscribesChanged -= SubscribeWindowViewModel_SubscribesChanged; }; _controller = controller; _updateSubscribeManager = updateSubscribeManager; _updateNodeChecker = updateNodeChecker; _controller.ConfigChanged += controller_ConfigChanged; LoadCurrentConfiguration(); SubscribeWindowViewModel.SubscribesChanged += SubscribeWindowViewModel_SubscribesChanged; }
public NewMainForm(ShadowsocksController controller) { this.Font = System.Drawing.SystemFonts.MessageBoxFont; InitializeComponent(); this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); this.controller = controller; LoadCurrentConfiguration(); UpdateTexts(); LoadServer(); updateChecker = new UpdateChecker(); //Thread t = new Thread(new ThreadStart(show_ping_start)); //t.Start(); controller.ConfigChanged += controller_ConfigChanged; updateFreeNodeChecker = new UpdateFreeNode(); updateFreeNodeChecker.NewFreeNodeFound += updateFreeNodeChecker_NewFreeNodeFound; updateSubscribeManager = new UpdateSubscribeManager(); _notifyIcon = new NotifyIcon(); }
public ApiForm(ShadowsocksController controller) { this.Font = System.Drawing.SystemFonts.MessageBoxFont; InitializeComponent(); this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); this.controller = controller; LoadCurrentConfiguration(); UpdateTexts(); updateSubscribeManager = new UpdateSubscribeManager(); backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.DoWork += backgroundWorker_DoWork; backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged; backgroundWorker.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted; //backgroundWorker.CancelAsync(); }
public MenuViewController(ShadowsocksController controller) { this.controller = controller; LoadMenu(); controller.ToggleModeChanged += controller_ToggleModeChanged; controller.ToggleRuleModeChanged += controller_ToggleRuleModeChanged; controller.ConfigChanged += controller_ConfigChanged; controller.Errored += controller_Errored; _notifyIcon = new NotifyIcon(); UpdateTrayIcon(); _notifyIcon.Visible = true; _notifyIcon.ContextMenu = contextMenu1; _notifyIcon.MouseClick += notifyIcon1_Click; updateNodeChecker = new UpdateNode(); updateNodeChecker.NewNodeFound += updateNodeChecker_NewNodeFound; updateSubscribeManager = new UpdateSubscribeManager(); updateChinaIPChecker = new UpdateChinaIP(); updateChinaIPChecker.NewChinaIPFound += updateChinaIPChecker_NewChinaIPFound; updateChinaIPManager = new UpdateChinaIPManager(); LoadCurrentConfiguration(); Configuration config = controller.GetCurrentConfiguration(); if (config.nodeFeedAutoUpdate) { updateSubscribeManager.CreateTask(config, updateNodeChecker); } timerDelayCheckUpdate = new System.Timers.Timer(1000.0 * 10); timerDelayCheckUpdate.Elapsed += timer_Elapsed; timerDelayCheckUpdate.Start(); }
public static int updateServerFromSSRURL(ShadowsocksController controller, UpdateSubscribeManager updateSubscribeManager, string result) { //Console.WriteLine(result); int count = 0; //string result = result; //updateFreeNodeChecker.FreeNodeResult = result; //MessageBox.Show(result); if (!String.IsNullOrEmpty(result)) { List <string> urls = new List <string>(); int max_node_num = 0; Configuration config = controller.GetCurrentConfiguration(); //Console.WriteLine("config.configs.Count->" + config.configs.Count); Server selected_server = null; if (config.index >= 0 && config.index < config.configs.Count) { selected_server = config.configs[config.index]; } //Console.WriteLine("result:"+result); Utils.URL_Split(result, ref urls); for (int i = urls.Count - 1; i >= 0; --i) { //Console.WriteLine(urls[i]); if (!urls[i].StartsWith("ssr")) { urls.RemoveAt(i); } } if (urls.Count > 0) { bool keep_selected_server = false; // set 'false' if import all nodes 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); if (!config.isDefaultConfig()) { keep_selected_server = true; } } string lastGroup = null; string curGroup = null; foreach (string url in urls) { try // try get group name { Server server = new Server(url, null); if (!String.IsNullOrEmpty(server.group)) { curGroup = server.group; break; } } catch { } } //MessageBox.Show(curGroup + "||1"); string subscribeURL = updateSubscribeManager.URL; //MessageBox.Show(subscribeURL + "||2"); if (String.IsNullOrEmpty(curGroup)) { curGroup = subscribeURL; } //MessageBox.Show(curGroup + "||3"); for (int i = 0; i < config.serverSubscribes.Count; ++i) { if (subscribeURL == config.serverSubscribes[i].URL) { lastGroup = config.serverSubscribes[i].Group; //MessageBox.Show(lastGroup); config.serverSubscribes[i].Group = curGroup; break; } } if (lastGroup == null) { lastGroup = curGroup; } if (keep_selected_server && selected_server.group == curGroup) { bool match = false; for (int i = 0; i < urls.Count; ++i) { try { Server server = new Server(urls[i], null); if (selected_server.isMatchServer(server)) { match = true; break; } } catch { } } if (!match) { urls.RemoveAt(0); urls.Add(selected_server.GetSSRLinkForServer()); } } // import all, find difference { Dictionary <string, Server> old_servers = new Dictionary <string, Server>(); if (!String.IsNullOrEmpty(lastGroup)) { for (int i = config.configs.Count - 1; i >= 0; --i) { if (lastGroup == config.configs[i].group) { old_servers[config.configs[i].id] = config.configs[i]; } } } foreach (string url in urls) { try { Server server = new Server(url, curGroup); bool match = false; foreach (KeyValuePair <string, Server> pair in old_servers) { if (server.isMatchServer(pair.Value)) { match = true; old_servers.Remove(pair.Key); pair.Value.CopyServerInfo(server); ++count; break; } } if (!match) { config.configs.Add(server); ++count; } } catch { } } foreach (KeyValuePair <string, Server> pair in old_servers) { for (int i = config.configs.Count - 1; i >= 0; --i) { if (config.configs[i].id == pair.Key) { config.configs.RemoveAt(i); break; } } } controller.SaveServersConfig(config); } // 重新获取config 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) { Configuration config = controller.GetCurrentConfiguration(); // 删除默认无效服务器 if (config.configs[0].server == Configuration.GetDefaultServer().server) { config.configs.RemoveAt(0); controller.SaveServersConfig(config); } } return(count); }