From 7b9c64c5a5ce30b8b2832a20a68e9f3fd7ef7834 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 23 Apr 2023 15:06:51 +0800 Subject: [PATCH] remove export to server config --- v2rayN/v2rayN/Handler/MainFormHandler.cs | 119 ------------------ .../v2rayN/ViewModels/MainWindowViewModel.cs | 18 +-- v2rayN/v2rayN/Views/MainWindow.xaml | 4 - v2rayN/v2rayN/Views/MainWindow.xaml.cs | 1 - 4 files changed, 1 insertion(+), 141 deletions(-) diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index fde60793..916237ca 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -156,125 +156,6 @@ namespace v2rayN.Handler } } - public void Export2ServerConfig(ProfileItem item, Config config) - { - if (item == null) - { - return; - } - if (item.configType is not EConfigType.VMess and not EConfigType.VLESS) - { - UI.Show(ResUI.NonVmessService); - return; - } - - SaveFileDialog fileDialog = new() - { - Filter = "Config|*.json", - FilterIndex = 2, - RestoreDirectory = true - }; - if (fileDialog.ShowDialog() != true) - { - return; - } - string fileName = fileDialog.FileName; - if (Utils.IsNullOrEmpty(fileName)) - { - return; - } - //Config configCopy = Utils.DeepCopy(config); - //configCopy.index = index; - if (CoreConfigHandler.Export2ServerConfig(item, fileName, out string msg) != 0) - { - UI.Show(msg); - } - else - { - UI.ShowWarning(string.Format(ResUI.SaveServerConfigurationIn, fileName)); - } - } - - public void BackupGuiNConfig(Config config, bool auto = false) - { - string fileName = $"guiNConfig_{DateTime.Now:yyyy_MM_dd_HH_mm_ss_fff}.json"; - if (auto) - { - fileName = Utils.GetBackupPath(fileName); - } - else - { - SaveFileDialog fileDialog = new() - { - FileName = fileName, - Filter = "guiNConfig|*.json", - FilterIndex = 2, - RestoreDirectory = true - }; - if (fileDialog.ShowDialog() != true) - { - return; - } - fileName = fileDialog.FileName; - } - if (Utils.IsNullOrEmpty(fileName)) - { - return; - } - var ret = Utils.ToJsonFile(config, fileName); - if (!auto) - { - if (ret == 0) - { - UI.Show(ResUI.OperationSuccess); - } - else - { - UI.ShowWarning(ResUI.OperationFailed); - } - } - } - - public bool RestoreGuiNConfig(ref Config config) - { - var fileContent = string.Empty; - OpenFileDialog fileDialog = new(); - - fileDialog.InitialDirectory = Utils.GetBackupPath(""); - fileDialog.Filter = "guiNConfig|*.json|All|*.*"; - fileDialog.FilterIndex = 2; - fileDialog.RestoreDirectory = true; - - if (fileDialog.ShowDialog() == true) - { - fileContent = Utils.LoadResource(fileDialog.FileName); - } - else - { - return false; - } - - if (Utils.IsNullOrEmpty(fileContent)) - { - UI.ShowWarning(ResUI.OperationFailed); - return false; - } - - var resConfig = Utils.FromJson(fileContent); - if (resConfig == null) - { - UI.ShowWarning(ResUI.OperationFailed); - return false; - } - //backup first - BackupGuiNConfig(config, true); - - config = resConfig; - LazyConfig.Instance.SetConfig(config); - - return true; - } - public void UpdateTask(Config config, Action update) { Task.Run(() => UpdateTaskRunSubscription(config, update)); diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index ab5c9640..58d04456 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -121,7 +121,6 @@ namespace v2rayN.ViewModels //servers export public ReactiveCommand Export2ClientConfigCmd { get; } - public ReactiveCommand Export2ServerConfigCmd { get; } public ReactiveCommand Export2ShareUrlCmd { get; } public ReactiveCommand Export2SubContentCmd { get; } @@ -418,11 +417,7 @@ namespace v2rayN.ViewModels Export2ClientConfigCmd = ReactiveCommand.Create(() => { Export2ClientConfig(); - }, canEditRemove); - Export2ServerConfigCmd = ReactiveCommand.Create(() => - { - Export2ServerConfig(); - }, canEditRemove); + }, canEditRemove); Export2ShareUrlCmd = ReactiveCommand.Create(() => { Export2ShareUrl(); @@ -1247,17 +1242,6 @@ namespace v2rayN.ViewModels MainFormHandler.Instance.Export2ClientConfig(item, _config); } - private void Export2ServerConfig() - { - var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId); - if (item is null) - { - _noticeHandler?.Enqueue(ResUI.PleaseSelectServer); - return; - } - MainFormHandler.Instance.Export2ServerConfig(item, _config); - } - public void Export2ShareUrl() { if (GetProfileItems(out List lstSelecteds, true) < 0) diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index ea76bba8..f9161889 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -608,10 +608,6 @@ x:Name="menuExport2ClientConfig" Height="{StaticResource MenuItemHeight}" Header="{x:Static resx:ResUI.menuExport2ClientConfig}" /> - vm.Export2ClientConfigCmd, v => v.menuExport2ClientConfig).DisposeWith(disposables); - this.BindCommand(ViewModel, vm => vm.Export2ServerConfigCmd, v => v.menuExport2ServerConfig).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.Export2ShareUrlCmd, v => v.menuExport2ShareUrl).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.Export2SubContentCmd, v => v.menuExport2SubContent).DisposeWith(disposables);