Remove some System.Windows.Forms references

pull/3611/head
2dust 2023-04-04 10:22:13 +08:00
parent b98da3a5dc
commit e61368a26e
10 changed files with 45 additions and 67 deletions

View File

@ -1,7 +1,7 @@
 
using Microsoft.Win32;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Windows.Forms;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using v2rayN.Mode; using v2rayN.Mode;
using v2rayN.Resx; using v2rayN.Resx;
@ -142,7 +142,7 @@ namespace v2rayN.Handler
FilterIndex = 2, FilterIndex = 2,
RestoreDirectory = true RestoreDirectory = true
}; };
if (fileDialog.ShowDialog() != DialogResult.OK) if (fileDialog.ShowDialog() != true)
{ {
return; return;
} }
@ -181,7 +181,7 @@ namespace v2rayN.Handler
FilterIndex = 2, FilterIndex = 2,
RestoreDirectory = true RestoreDirectory = true
}; };
if (fileDialog.ShowDialog() != DialogResult.OK) if (fileDialog.ShowDialog() != true)
{ {
return; return;
} }
@ -218,7 +218,7 @@ namespace v2rayN.Handler
FilterIndex = 2, FilterIndex = 2,
RestoreDirectory = true RestoreDirectory = true
}; };
if (fileDialog.ShowDialog() != DialogResult.OK) if (fileDialog.ShowDialog() != true)
{ {
return; return;
} }
@ -246,22 +246,22 @@ namespace v2rayN.Handler
public bool RestoreGuiNConfig(ref Config config) public bool RestoreGuiNConfig(ref Config config)
{ {
var fileContent = string.Empty; var fileContent = string.Empty;
using (OpenFileDialog fileDialog = new()) OpenFileDialog fileDialog = new();
{
fileDialog.InitialDirectory = Utils.GetBackupPath("");
fileDialog.Filter = "guiNConfig|*.json|All|*.*";
fileDialog.FilterIndex = 2;
fileDialog.RestoreDirectory = true;
if (fileDialog.ShowDialog() == DialogResult.OK) fileDialog.InitialDirectory = Utils.GetBackupPath("");
{ fileDialog.Filter = "guiNConfig|*.json|All|*.*";
fileContent = Utils.LoadResource(fileDialog.FileName); fileDialog.FilterIndex = 2;
} fileDialog.RestoreDirectory = true;
else
{ if (fileDialog.ShowDialog() == true)
return false; {
} fileContent = Utils.LoadResource(fileDialog.FileName);
} }
else
{
return false;
}
if (Utils.IsNullOrEmpty(fileContent)) if (Utils.IsNullOrEmpty(fileContent))
{ {
UI.ShowWarning(ResUI.OperationFailed); UI.ShowWarning(ResUI.OperationFailed);

View File

@ -3,7 +3,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows;
using v2rayN.Base; using v2rayN.Base;
using v2rayN.Mode; using v2rayN.Mode;
using v2rayN.Resx; using v2rayN.Resx;
@ -479,7 +479,7 @@ namespace v2rayN.Handler
bool blDownload = false; bool blDownload = false;
if (blAsk) if (blAsk)
{ {
if (UI.ShowYesNo(string.Format(ResUI.DownloadYesNo, url)) == DialogResult.Yes) if (UI.ShowYesNo(string.Format(ResUI.DownloadYesNo, url)) == MessageBoxResult.Yes)
{ {
blDownload = true; blDownload = true;
} }

View File

@ -1,45 +1,22 @@
using System.Windows.Forms; using System.Windows;
namespace v2rayN namespace v2rayN
{ {
class UI class UI
{ {
private readonly static string caption = "v2rayN";
public static void Show(string msg) 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) 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);
// }
//}
} }
} }

View File

@ -1,3 +1,4 @@
using Microsoft.Win32;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using ReactiveUI.Validation.Helpers; using ReactiveUI.Validation.Helpers;
@ -5,7 +6,6 @@ using Splat;
using System.IO; using System.IO;
using System.Reactive; using System.Reactive;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using v2rayN.Base; using v2rayN.Base;
using v2rayN.Handler; using v2rayN.Handler;
using v2rayN.Mode; using v2rayN.Mode;
@ -111,7 +111,7 @@ namespace v2rayN.ViewModels
Multiselect = false, Multiselect = false,
Filter = "Config|*.json|YAML|*.yaml;*.yml|All|*.*" Filter = "Config|*.json|YAML|*.yaml;*.yml|All|*.*"
}; };
if (fileDialog.ShowDialog() != DialogResult.OK) if (fileDialog.ShowDialog() != true)
{ {
return; return;
} }

View File

@ -3,6 +3,7 @@ using DynamicData.Binding;
using MaterialDesignColors; using MaterialDesignColors;
using MaterialDesignColors.ColorManipulation; using MaterialDesignColors.ColorManipulation;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat; using Splat;
@ -12,7 +13,6 @@ using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using System.Windows.Media; using System.Windows.Media;
using v2rayN.Base; using v2rayN.Base;
using v2rayN.Handler; using v2rayN.Handler;
@ -953,7 +953,7 @@ namespace v2rayN.ViewModels
return; return;
} }
if (UI.ShowYesNo(ResUI.RemoveServer) == DialogResult.No) if (UI.ShowYesNo(ResUI.RemoveServer) == MessageBoxResult.No)
{ {
return; return;
} }
@ -1110,7 +1110,7 @@ namespace v2rayN.ViewModels
return; return;
} }
if (GetProfileItems(out List<ProfileItem> lstSelecteds, false) < 0) if (GetProfileItems(out List<ProfileItem> lstSelecteds, true) < 0)
{ {
return; return;
} }
@ -1302,7 +1302,7 @@ namespace v2rayN.ViewModels
Multiselect = false, Multiselect = false,
Filter = "guiNConfig|*.json|All|*.*" Filter = "guiNConfig|*.json|All|*.*"
}; };
if (fileDialog.ShowDialog() != DialogResult.OK) if (fileDialog.ShowDialog() != true)
{ {
return; return;
} }

View File

@ -1,10 +1,10 @@
using DynamicData.Binding; using DynamicData.Binding;
using Microsoft.Win32;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using Splat; using Splat;
using System.Reactive; using System.Reactive;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using v2rayN.Base; using v2rayN.Base;
using v2rayN.Handler; using v2rayN.Handler;
using v2rayN.Mode; using v2rayN.Mode;
@ -173,7 +173,7 @@ namespace v2rayN.ViewModels
UI.Show(ResUI.PleaseSelectRules); UI.Show(ResUI.PleaseSelectRules);
return; return;
} }
if (UI.ShowYesNo(ResUI.RemoveRules) == DialogResult.No) if (UI.ShowYesNo(ResUI.RemoveRules) == MessageBoxResult.No)
{ {
return; return;
} }
@ -268,7 +268,7 @@ namespace v2rayN.ViewModels
Multiselect = false, Multiselect = false,
Filter = "Rules|*.json|All|*.*" Filter = "Rules|*.json|All|*.*"
}; };
if (fileDialog.ShowDialog() != DialogResult.OK) if (fileDialog.ShowDialog() != true)
{ {
return; return;
} }
@ -322,7 +322,7 @@ namespace v2rayN.ViewModels
private int AddBatchRoutingRules(RoutingItem routingItem, string clipboardData) private int AddBatchRoutingRules(RoutingItem routingItem, string clipboardData)
{ {
bool blReplace = false; bool blReplace = false;
if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == DialogResult.No) if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == MessageBoxResult.No)
{ {
blReplace = true; blReplace = true;
} }

View File

@ -4,7 +4,6 @@ using ReactiveUI.Fody.Helpers;
using Splat; using Splat;
using System.Reactive; using System.Reactive;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using v2rayN.Base; using v2rayN.Base;
using v2rayN.Handler; using v2rayN.Handler;
using v2rayN.Mode; using v2rayN.Mode;
@ -244,7 +243,7 @@ namespace v2rayN.ViewModels
UI.Show(ResUI.PleaseSelectRules); UI.Show(ResUI.PleaseSelectRules);
return; return;
} }
if (UI.ShowYesNo(ResUI.RemoveRules) == DialogResult.No) if (UI.ShowYesNo(ResUI.RemoveRules) == MessageBoxResult.No)
{ {
return; return;
} }

View File

@ -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.fingerprint, v => v.cmbFingerprint.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.alpn, v => v.cmbAlpn.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.alpn, v => v.cmbAlpn.Text).DisposeWith(disposables);
//reality //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.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.publicKey, v => v.txtPublicKey.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.shortId, v => v.txtShortId.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.shortId, v => v.txtShortId.Text).DisposeWith(disposables);

View File

@ -1,4 +1,5 @@
using ReactiveUI; using Microsoft.Win32;
using ReactiveUI;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Reactive.Disposables; using System.Reactive.Disposables;
@ -210,7 +211,7 @@ namespace v2rayN.Views
} }
private void btnBrowse_Click(object sender, System.Windows.RoutedEventArgs e) 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.Filter = "tunConfig|*.json|All|*.*";
openFileDialog1.ShowDialog(); openFileDialog1.ShowDialog();

View File

@ -1,4 +1,5 @@
using ReactiveUI; using Microsoft.Win32;
using ReactiveUI;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
@ -108,7 +109,7 @@ namespace v2rayN.Views
private void btnBrowse_Click(object sender, System.Windows.RoutedEventArgs e) 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.Filter = "PNG|*.png";
openFileDialog1.ShowDialog(); openFileDialog1.ShowDialog();