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.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);

View File

@ -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;
}

View File

@ -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);
// }
//}
}
}

View File

@ -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;
}

View File

@ -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<ProfileItem> lstSelecteds, false) < 0)
if (GetProfileItems(out List<ProfileItem> 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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();