private void Application_Exit(object sender, ExitEventArgs e) { // save settings and fix autorun status. reduce startup time SettingManager.WriteFile(FileConfigXml, FilePreferenceXml); if (SettingManager.Configuration.IsAutorun) { SystemUtil.CheckOrCreateUserStartupShortcut(); } else { SystemUtil.DeleteUserStartupShortcuts(); } // shutdown service TransmitCtrl.StopServer(); TransmitCtrl.EnableTransmit(false); InterfaceCtrl.Dispose(); ServerManager.Dispose(); Model.IPAddress.IPInformation.Dispose(); // not important ProcPrivoxy.KillRunning(); ProcSS.KillRunning(); ProcV2Ray.KillRunning(); }
private void AddServerClipboard(object parameter) { List <V2RayVMess> serverList = V2RayVMess.ImportServers(Clipboard.GetText(TextDataFormat.Text)); if (serverList.Count > 0) { AddServer(serverList, out int added, out int updated); string notify; if (SettingManager.Configuration.IsReplaceOldServer) { notify = $"{added} {sr_server_x_added}, {updated} {sr_server_x_updated}"; } else { notify = $"{added} {sr_server_x_added}"; } InterfaceCtrl.ShowHomeNotify(notify); } else { InterfaceCtrl.ShowHomeNotify(sr_server_not_found); } }
private async void CheckPingSelected(object parameter) { // add task processing_check_ping = true; TaskView task = new TaskView { Name = sr_task_ping_server, StopAction = null }; InterfaceCtrl.AddHomeTask(task); // check selection items; IEnumerator<BaseServer> enumerator = (parameter as System.Collections.IList).Cast<BaseServer>().GetEnumerator(); List<BaseServer> selection = new List<BaseServer>(); while (enumerator.MoveNext()) { selection.Add(enumerator.Current); } for (int i = 0; i < selection.Count; ++i) { if (!processing_check_ping) { break; } await Task.Run(() => selection[i].UpdatePingDelay()).ConfigureAwait(true); task.Progress100 = i * 100 / selection.Count; } // done processing_check_ping = false; InterfaceCtrl.RemoveHomeTask(task); CommandManager.InvalidateRequerySuggested(); }
private void MenuItem_EnableTransmit(object sender, EventArgs e) { TransmitCtrl.EnableTransmit(!SettingManager.Configuration.IsTransmitEnabled); menuitemEnableTransmit.Checked = SettingManager.Configuration.IsTransmitEnabled; // update interface InterfaceCtrl.UpdateHomeTransmitStatue(); InterfaceCtrl.NotifyIcon.UpdateIcon(); }
private void ChangeServer(object parameter) { V2RayVMess server = (V2RayVMess)parameter; if (TransmitCtrl.ChangeTransmitServer(server)) { InterfaceCtrl.UpdateHomeTransmitStatue(); } }
private void AddServerQRCode(object parameter) { string ssBase64 = parameter as string; if (string.IsNullOrWhiteSpace(ssBase64)) { ZXing.Result result = QRCode.DecodeScreen(); if (result == null || string.IsNullOrWhiteSpace(result.Text)) { InterfaceCtrl.ShowHomeNotify(sr_server_not_found); InterfaceCtrl.NotifyIcon.ShowMessage(sr_server_not_found); return; } ssBase64 = result.Text; } if (V2RayVMess.FromVMessBase64(ssBase64) is V2RayVMess server) { AddServer(server, out int added, out int updated); string notify; if (SettingManager.Configuration.IsReplaceOldServer) { notify = added > 0 ? $"{added} {sr_server_x_added}" : $"{updated} {sr_server_x_updated}"; } else { notify = added > 0 ? $"{added} {sr_server_x_added}" : sr_server_already_exist; } if (Application.Current.MainWindow.IsActive) { InterfaceCtrl.ShowHomeNotify(notify); } else { InterfaceCtrl.NotifyIcon.ShowMessage(notify); } } else { if (Application.Current.MainWindow.IsActive) { InterfaceCtrl.ShowHomeNotify(sr_server_not_found); } else { InterfaceCtrl.NotifyIcon.ShowMessage(sr_server_not_found); } } }
private async void CheckPingAll(object parameter) { // add task processing_check_ping = true; TaskView task = new TaskView { Name = sr_task_ping_server, StopAction = () => { processing_check_ping = false; } }; InterfaceCtrl.AddHomeTask(task); // run IEnumerator<BaseServer> enumerator = Servers.GetEnumerator(); int count = Servers.Count(); int timeout = SettingManager.Configuration.TimeoutPing; using (Ping pingSender = new Ping()) { int complete = 0; enumerator.Reset(); while (enumerator.MoveNext()) { // isPingInProcess is also use to cancel task if (processing_check_ping == false) { break; } BaseServer server = enumerator.Current; try { PingReply reply = await pingSender.SendPingAsync(server.HostAddress, timeout).ConfigureAwait(true); server.PingDelay = (reply.Status == IPStatus.Success) ? reply.RoundtripTime : -1; } catch { server.PingDelay = -1; } task.Progress100 = ++complete * 100 / count; } enumerator.Dispose(); } // done processing_check_ping = false; InterfaceCtrl.RemoveHomeTask(task); CommandManager.InvalidateRequerySuggested(); }
private void AddServerFile(object parameter) { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog { InitialDirectory = App.DirectoryApplication, DefaultExt = "txt", Filter = "Text|*.txt", AddExtension = true }; string fileContent = null; if (openFileDialog.ShowDialog() == true) { try { fileContent = System.IO.File.ReadAllText(openFileDialog.FileName); } catch { } } if (string.IsNullOrWhiteSpace(fileContent)) { return; } List <V2RayVMess> serverList = V2RayVMess.ImportServers(fileContent); if (serverList.Count > 0) { AddServer(serverList, out int added, out int updated); string notify; if (SettingManager.Configuration.IsReplaceOldServer) { notify = $"{added} {sr_server_x_added}, {updated} {sr_server_x_updated}"; } else { notify = $"{added} {sr_server_x_added}"; } InterfaceCtrl.ShowHomeNotify(notify); } else { InterfaceCtrl.ShowHomeNotify(sr_server_not_found); } }
private void AddServerCreate(object parameter) { V2RayVMess server = new V2RayVMess(); new ServerConfigDialog(server, (bool resultOK) => { if (resultOK) { AddServer(server, out int added, out int updated); string notify; if (SettingManager.Configuration.IsReplaceOldServer) { notify = added > 0 ? $"{added} {sr_server_x_added}" : $"{updated} {sr_server_x_updated}"; } else { notify = added > 0 ? $"{added} {sr_server_x_added}" : sr_server_already_exist; } InterfaceCtrl.ShowHomeNotify(notify); }
private void MenuItem_Setting(object sender, EventArgs e) { InterfaceCtrl.ShowSetting(); }
private void MenuItem_AddServer_Clipboard(object sender, EventArgs e) { InterfaceCtrl.AddServerFromClipboard(); }
private void MenuItem_AddServer_ScanQRCode(object sender, EventArgs e) { InterfaceCtrl.AddServerByScanQRCode(); }
private void Application_Startup(object sender, StartupEventArgs e) { string dirData = "data"; string dirBin = "binary"; // to avoid loading WindowHome on startup fails StartupUri = new System.Uri("View/WindowShutdown.xaml", System.UriKind.Relative); // single instance if (SystemUtil.IsProcessExist("XTransmit")) { Shutdown(); return; } // init directory Name = (string)Current.FindResource("app_name"); //FileApplication = System.Reflection.Assembly.GetEntryAssembly().Location; FileApplication = System.Reflection.Assembly.GetExecutingAssembly().Location; DirectoryApplication = Path.GetDirectoryName(FileApplication); try { Directory.CreateDirectory($@"{DirectoryApplication}\{dirBin}"); Directory.CreateDirectory($@"{DirectoryApplication}\{dirData}"); } catch { string message = (string)FindResource("app_init_fail"); new View.DialogPrompt(Name, message).ShowDialog(); Shutdown(); return; } DirectoryPrivoxy = $@"{DirectoryApplication}\{dirBin}\privoxy"; DirectoryShadowsocks = $@"{DirectoryApplication}\{dirBin}\shadowsocks"; DirectoryV2Ray = $@"{DirectoryApplication}\{dirBin}\v2ray"; FilePreferenceXml = $@"{DirectoryApplication}\{dirData}\Preference.xml"; FileConfigXml = $@"{DirectoryApplication}\{dirData}\Config.xml"; FileIPAddressXml = $@"{DirectoryApplication}\{dirData}\IPAddress.xml"; //china ip optimized FileUserAgentXml = $@"{DirectoryApplication}\{dirData}\UserAgent.xml"; FileShadowsocksXml = $@"{DirectoryApplication}\{dirData}\ServerShadowsocks.xml"; FileV2RayXml = $@"{DirectoryApplication}\{dirData}\ServerV2Ray.xml"; // initialize binaries ProcPrivoxy.KillRunning(); ProcSS.KillRunning(); ProcV2Ray.KillRunning(); if (!ProcPrivoxy.Prepare() || !ProcSS.Prepare() || !ProcV2Ray.Prepare()) { string message = (string)FindResource("app_init_fail"); new View.DialogPrompt(Name, message).ShowDialog(); Shutdown(); return; } // load data ServerManager.Initialize(FileShadowsocksXml, FileV2RayXml); SettingManager.LoadFileOrDefault(FileConfigXml, FilePreferenceXml); // initialize interface and theme InterfaceCtrl.Initialize(); // initialize transmit if (!TransmitCtrl.StartServer()) { string message = (string)FindResource("app_service_fail"); new View.DialogPrompt(Name, message).ShowDialog(); Shutdown(); return; } TransmitCtrl.EnableTransmit(SettingManager.Configuration.IsTransmitEnabled); // done StartupUri = new System.Uri("View/WindowHome.xaml", System.UriKind.Relative); Exit += Application_Exit; }