private void ButtonSwitch_Click(object sender, RoutedEventArgs e) { try { Task.Run(() => SnakeBarMessage(I18N.GetString("PleaseWait"))); if (V2Ray.IsRunning()) { Task.Run(() => V2Ray.Stop()); } else { Task.Run(() => V2Ray.Start()); } Task.Run(() => UpgradeStatus(true)); } catch (Exception ex) { MessageBox.Show(ex.Message, name, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void ButtonRoute_Click(object sender, RoutedEventArgs e) { try { if (listBoxNode.SelectedItem != null) { Task.Run(() => SnakeBarMessage(I18N.GetString("PleaseWait"))); var name = listBoxNode.SelectedItem.ToString(); Task.Run(() => V2Ray.ChangeRoute(name)); Task.Run(() => UpgradeStatus(true)); } else { throw new Exception(I18N.GetString("NodeNotSelect")); } } catch (Exception ex) { MessageBox.Show(ex.Message, name, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Complete(long tick) { Dispatcher.Invoke(new Action(() => { if (tick == -2) { labelUpgrade.Content = I18N.GetString("NoSubscription"); Task.Run(() => SnakeBarMessage(I18N.GetString("NoSubscription"))); } else if (tick == -1) { labelUpgrade.Content = I18N.GetString("UpgradeNodeError"); Task.Run(() => SnakeBarMessage(I18N.GetString("UpgradeNodeError"))); } else { var dateTime = new DateTime(Configuration.Config.UpgradeTime); labelUpgrade.Content = $"{I18N.GetString("Upgrade")}: " + $"{dateTime:yyyy.MM.dd HH:mm:ss}"; if ((DateTime.Now - dateTime).TotalSeconds < 2) { Task.Run(() => SnakeBarMessage(I18N.GetString("UpgradeCompleted"))); } } listBoxNode.Items.Clear(); var vmesses = Node.vmesses.Select(x => x.Name).OrderBy(y => y).ToList(); foreach (var item in vmesses) { listBoxNode.Items.Add(item); } if (listBoxNode.Items.Count != 0) { listBoxNode.SelectedItem = V2Ray.SelectNode(); listBoxNode.ScrollIntoView(listBoxNode.SelectedItem); listBoxNode.Focus(); } })); }
private void UpgradeStatus(bool isWait) { Dispatcher.Invoke(new Action(() => { buttonSwitch.IsEnabled = false; buttonRoute.IsEnabled = false; buttonNode.IsEnabled = false; buttonListen.IsEnabled = false; labelStatus.Content = $"{I18N.GetString("Waiting")}"; labelStatus.Foreground = labelUpgrade.Foreground; })); if (isWait) { Task.Delay(2000).Wait(); } Dispatcher.Invoke(new Action(() => { var isRunning = V2Ray.IsRunning(); var isUsingRoute = V2Ray.IsUsingRoute(); var isListenHostOnly = V2Ray.IsListenHostOnly(); if (isRunning) { buttonSwitch.Content = I18N.GetString("Stop"); } else { buttonSwitch.Content = I18N.GetString("Start"); } if (isUsingRoute) { buttonRoute.Content = I18N.GetString("Global"); } else { buttonRoute.Content = I18N.GetString("Route"); } if (isListenHostOnly) { buttonListen.Content = I18N.GetString("AllowAny"); } else { buttonListen.Content = I18N.GetString("HostOnly"); } if (isRunning) { if (isUsingRoute && isListenHostOnly) { labelStatus.Content = $"{I18N.GetString("RunningStatus")}: " + $"{I18N.GetString("Route")}, {I18N.GetString("HostOnly")}"; labelStatus.Foreground = Brushes.DarkCyan; } else if (isUsingRoute && !isListenHostOnly) { labelStatus.Content = $"{I18N.GetString("RunningStatus")}: " + $"{I18N.GetString("Route")}, {I18N.GetString("AllowAny")}"; labelStatus.Foreground = Brushes.DarkCyan; } else if (!isUsingRoute && isListenHostOnly) { labelStatus.Content = $"{I18N.GetString("RunningStatus")}: " + $"{I18N.GetString("Global")}, {I18N.GetString("HostOnly")}"; labelStatus.Foreground = Brushes.DeepPink; } else { labelStatus.Content = $"{I18N.GetString("RunningStatus")}: " + $"{I18N.GetString("Global")}, {I18N.GetString("AllowAny")}"; labelStatus.Foreground = Brushes.DeepPink; } } else { labelStatus.Content = $"{I18N.GetString("RunningStatus")}: " + $"{I18N.GetString("Stoped")}"; labelStatus.Foreground = labelUpgrade.Foreground; } buttonSwitch.IsEnabled = true; buttonRoute.IsEnabled = true; buttonNode.IsEnabled = true; buttonListen.IsEnabled = true; })); }
private void Application_Startup(object sender, StartupEventArgs e) { try { var isSingle = SingleInstance.IsSingle(); if (!isSingle) { SingleInstance.SetForeground(); return; } var isTrueDirectory = DirectoryCheck.IsTrueDirectory(); if (!isTrueDirectory) { throw new Exception(I18N.GetString("FileNotFound")); } var isAdmin = Administrator.IsAdmin(); if (e.Args.Length == 0 && isAdmin) { switch (MessageBox.Show($"{I18N.GetString("Setup")}", name, MessageBoxButton.YesNoCancel, MessageBoxImage.Information)) { case MessageBoxResult.Yes: Autorun.Add(); DesktopMenu.Add(); break; case MessageBoxResult.No: Autorun.Remove(); DesktopMenu.Remove(); V2Ray.Stop(); break; default: break; } } else if (e.Args.Length == 0 && !isAdmin) { throw new Exception(I18N.GetString("PermissionDenied")); } else if (e.Args[0] == "-start") { V2Ray.Start(); } else if (e.Args[0] == "-stop") { V2Ray.Stop(); } else if (e.Args[0] == "-config") { var window = new MainWindow(); window.ShowDialog(); } else { throw new ArgumentException(); } } catch (Exception ex) { MessageBox.Show(ex.Message, name, MessageBoxButton.OK, MessageBoxImage.Error); } finally { Environment.Exit(Environment.ExitCode); } }
public void Start(Configuration configuration) { if (_process != null) { return; } KillAll(); var config = Utils.GetTempPath(_uniqueConfigFile); File.WriteAllText(config, V2Ray.GenerateVNextConf(configuration.GetCurrentServer(), configuration.corePort, configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1")); _process = new Process { StartInfo = { FileName = V2Ray.V2RAY_CORE, Arguments = $"-config {config}", WorkingDirectory = Global.AppPath, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true, CreateNoWindow = true } }; _process.Start(); _v2rayJob.AddProcess(_process.Handle); }