diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 1e96bd8f..c20b3514 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -1,7 +1,7 @@  +using Microsoft.Win32; using System.Drawing; using System.IO; -using System.Windows.Forms; using System.Windows.Media.Imaging; using v2rayN.Mode; using v2rayN.Resx; @@ -142,7 +142,7 @@ namespace v2rayN.Handler FilterIndex = 2, RestoreDirectory = true }; - if (fileDialog.ShowDialog() != DialogResult.OK) + if (fileDialog.ShowDialog() != true) { return; } @@ -181,7 +181,7 @@ namespace v2rayN.Handler FilterIndex = 2, RestoreDirectory = true }; - if (fileDialog.ShowDialog() != DialogResult.OK) + if (fileDialog.ShowDialog() != true) { return; } @@ -218,7 +218,7 @@ namespace v2rayN.Handler FilterIndex = 2, RestoreDirectory = true }; - if (fileDialog.ShowDialog() != DialogResult.OK) + if (fileDialog.ShowDialog() != true) { return; } @@ -246,22 +246,22 @@ namespace v2rayN.Handler public bool RestoreGuiNConfig(ref Config config) { var fileContent = string.Empty; - using (OpenFileDialog fileDialog = new()) - { - fileDialog.InitialDirectory = Utils.GetBackupPath(""); - fileDialog.Filter = "guiNConfig|*.json|All|*.*"; - fileDialog.FilterIndex = 2; - fileDialog.RestoreDirectory = true; + OpenFileDialog fileDialog = new(); - if (fileDialog.ShowDialog() == DialogResult.OK) - { - fileContent = Utils.LoadResource(fileDialog.FileName); - } - else - { - return false; - } + 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); diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs index 12f11e73..7db31e41 100644 --- a/v2rayN/v2rayN/Handler/UpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.IO; using System.Text; using System.Text.RegularExpressions; -using System.Windows.Forms; +using System.Windows; using v2rayN.Base; using v2rayN.Mode; using v2rayN.Resx; @@ -479,7 +479,7 @@ namespace v2rayN.Handler bool blDownload = false; if (blAsk) { - if (UI.ShowYesNo(string.Format(ResUI.DownloadYesNo, url)) == DialogResult.Yes) + if (UI.ShowYesNo(string.Format(ResUI.DownloadYesNo, url)) == MessageBoxResult.Yes) { blDownload = true; } diff --git a/v2rayN/v2rayN/Tool/UI.cs b/v2rayN/v2rayN/Tool/UI.cs index f2cabf75..c51236e1 100644 --- a/v2rayN/v2rayN/Tool/UI.cs +++ b/v2rayN/v2rayN/Tool/UI.cs @@ -1,45 +1,22 @@ -using System.Windows.Forms; +using System.Windows; namespace v2rayN { class UI { + private readonly static string caption = "v2rayN"; + public static void Show(string msg) { - MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(msg, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); } public static void ShowWarning(string msg) { - MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Warning); + MessageBox.Show(msg, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); } - public static void ShowError(string msg) + public static MessageBoxResult ShowYesNo(string msg) { - MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Error); + return MessageBox.Show(msg, caption, MessageBoxButton.YesNo, MessageBoxImage.Question); } - - public static DialogResult ShowYesNo(string msg) - { - return MessageBox.Show(msg, "v2rayN", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - } - - //public static string GetResourseString(string key) - //{ - // CultureInfo cultureInfo = null; - // try - // { - // string languageCode = this.LanguageCode; - // cultureInfo = new CultureInfo(languageCode); - // return Common.ResourceManager.GetString(key, cultureInfo); - // } - // catch (Exception) - // { - // //默认读取英文的多语言 - // cultureInfo = new CultureInfo(MKey.kDefaultLanguageCode); - // return Common.ResourceManager.GetString(key, cultureInfo); - // } - //} - } - - } diff --git a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs index 6d739108..b0663c5a 100644 --- a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs @@ -1,3 +1,4 @@ +using Microsoft.Win32; using ReactiveUI; using ReactiveUI.Fody.Helpers; using ReactiveUI.Validation.Helpers; @@ -5,7 +6,6 @@ using Splat; using System.IO; using System.Reactive; using System.Windows; -using System.Windows.Forms; using v2rayN.Base; using v2rayN.Handler; using v2rayN.Mode; @@ -111,7 +111,7 @@ namespace v2rayN.ViewModels Multiselect = false, Filter = "Config|*.json|YAML|*.yaml;*.yml|All|*.*" }; - if (fileDialog.ShowDialog() != DialogResult.OK) + if (fileDialog.ShowDialog() != true) { return; } diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 86255d79..51445289 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -3,6 +3,7 @@ using DynamicData.Binding; using MaterialDesignColors; using MaterialDesignColors.ColorManipulation; using MaterialDesignThemes.Wpf; +using Microsoft.Win32; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Splat; @@ -12,7 +13,6 @@ using System.Reactive; using System.Reactive.Linq; using System.Text; using System.Windows; -using System.Windows.Forms; using System.Windows.Media; using v2rayN.Base; using v2rayN.Handler; @@ -953,7 +953,7 @@ namespace v2rayN.ViewModels return; } - if (UI.ShowYesNo(ResUI.RemoveServer) == DialogResult.No) + if (UI.ShowYesNo(ResUI.RemoveServer) == MessageBoxResult.No) { return; } @@ -1110,7 +1110,7 @@ namespace v2rayN.ViewModels return; } - if (GetProfileItems(out List lstSelecteds, false) < 0) + if (GetProfileItems(out List lstSelecteds, true) < 0) { return; } @@ -1302,7 +1302,7 @@ namespace v2rayN.ViewModels Multiselect = false, Filter = "guiNConfig|*.json|All|*.*" }; - if (fileDialog.ShowDialog() != DialogResult.OK) + if (fileDialog.ShowDialog() != true) { return; } diff --git a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs index f1bc5ebf..6dc2fb06 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs @@ -1,10 +1,10 @@ using DynamicData.Binding; +using Microsoft.Win32; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Splat; using System.Reactive; using System.Windows; -using System.Windows.Forms; using v2rayN.Base; using v2rayN.Handler; using v2rayN.Mode; @@ -173,7 +173,7 @@ namespace v2rayN.ViewModels UI.Show(ResUI.PleaseSelectRules); return; } - if (UI.ShowYesNo(ResUI.RemoveRules) == DialogResult.No) + if (UI.ShowYesNo(ResUI.RemoveRules) == MessageBoxResult.No) { return; } @@ -268,7 +268,7 @@ namespace v2rayN.ViewModels Multiselect = false, Filter = "Rules|*.json|All|*.*" }; - if (fileDialog.ShowDialog() != DialogResult.OK) + if (fileDialog.ShowDialog() != true) { return; } @@ -322,7 +322,7 @@ namespace v2rayN.ViewModels private int AddBatchRoutingRules(RoutingItem routingItem, string clipboardData) { bool blReplace = false; - if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == DialogResult.No) + if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == MessageBoxResult.No) { blReplace = true; } diff --git a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs index 01b27ff2..4c3729f2 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingSettingViewModel.cs @@ -4,7 +4,6 @@ using ReactiveUI.Fody.Helpers; using Splat; using System.Reactive; using System.Windows; -using System.Windows.Forms; using v2rayN.Base; using v2rayN.Handler; using v2rayN.Mode; @@ -244,7 +243,7 @@ namespace v2rayN.ViewModels UI.Show(ResUI.PleaseSelectRules); return; } - if (UI.ShowYesNo(ResUI.RemoveRules) == DialogResult.No) + if (UI.ShowYesNo(ResUI.RemoveRules) == MessageBoxResult.No) { return; } diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index 142ee53e..922b0adb 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -139,7 +139,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.SelectedSource.fingerprint, v => v.cmbFingerprint.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.alpn, v => v.cmbAlpn.Text).DisposeWith(disposables); //reality - this.Bind(ViewModel, vm => vm.SelectedSource.sni, v => v.txtSNI2.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.sni, v => v.txtSNI2.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.fingerprint, v => v.cmbFingerprint2.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.publicKey, v => v.txtPublicKey.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.shortId, v => v.txtShortId.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 2cd8c05a..94f19d52 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -1,4 +1,5 @@ -using ReactiveUI; +using Microsoft.Win32; +using ReactiveUI; using System.Globalization; using System.IO; using System.Reactive.Disposables; @@ -210,7 +211,7 @@ namespace v2rayN.Views } private void btnBrowse_Click(object sender, System.Windows.RoutedEventArgs e) { - var openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + var openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "tunConfig|*.json|All|*.*"; openFileDialog1.ShowDialog(); diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index 0e82607e..15b26132 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -1,4 +1,5 @@ -using ReactiveUI; +using Microsoft.Win32; +using ReactiveUI; using System.Reactive.Disposables; using System.Windows; using System.Windows.Input; @@ -108,7 +109,7 @@ namespace v2rayN.Views private void btnBrowse_Click(object sender, System.Windows.RoutedEventArgs e) { - var openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + var openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "PNG|*.png"; openFileDialog1.ShowDialog();