mirror of https://github.com/2dust/v2rayN
Optimize code
parent
6762f35ade
commit
3c4703ad85
|
@ -2,15 +2,19 @@
|
||||||
using QRCoder.Xaml;
|
using QRCoder.Xaml;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace v2rayN.Handler
|
namespace v2rayN
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 含有QR码的描述类和包装编码和渲染
|
/// 含有QR码的描述类和包装编码和渲染
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QRCodeHelper
|
public class QRCodeHelper
|
||||||
{
|
{
|
||||||
public static DrawingImage? GetQRCode(string strContent)
|
public static DrawingImage? GetQRCode(string? strContent)
|
||||||
{
|
{
|
||||||
|
if (strContent is null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QRCodeGenerator qrGenerator = new();
|
QRCodeGenerator qrGenerator = new();
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Windows;
|
using Microsoft.Win32;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace v2rayN
|
namespace v2rayN
|
||||||
{
|
{
|
||||||
|
@ -20,5 +21,24 @@ namespace v2rayN
|
||||||
{
|
{
|
||||||
return MessageBox.Show(msg, caption, MessageBoxButton.YesNo, MessageBoxImage.Question);
|
return MessageBox.Show(msg, caption, MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool? OpenFileDialog(out string fileName, string filter)
|
||||||
|
{
|
||||||
|
fileName = string.Empty;
|
||||||
|
|
||||||
|
var fileDialog = new OpenFileDialog
|
||||||
|
{
|
||||||
|
Multiselect = false,
|
||||||
|
Filter = filter
|
||||||
|
};
|
||||||
|
|
||||||
|
if (fileDialog.ShowDialog() != true)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fileName = fileDialog.FileName;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
using Microsoft.Win32;
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
using ReactiveUI.Validation.Helpers;
|
using ReactiveUI.Validation.Helpers;
|
||||||
|
@ -104,20 +103,16 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
UI.Show(ResUI.CustomServerTips);
|
UI.Show(ResUI.CustomServerTips);
|
||||||
|
|
||||||
OpenFileDialog fileDialog = new()
|
if (UI.OpenFileDialog(out string fileName,
|
||||||
{
|
"Config|*.json|YAML|*.yaml;*.yml|All|*.*") != true)
|
||||||
Multiselect = false,
|
|
||||||
Filter = "Config|*.json|YAML|*.yaml;*.yml|All|*.*"
|
|
||||||
};
|
|
||||||
if (fileDialog.ShowDialog() != true)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string fileName = fileDialog.FileName;
|
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (Utils.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = LazyConfig.Instance.GetProfileItem(SelectedSource.indexId);
|
var item = LazyConfig.Instance.GetProfileItem(SelectedSource.indexId);
|
||||||
item ??= SelectedSource;
|
item ??= SelectedSource;
|
||||||
item.address = fileName;
|
item.address = fileName;
|
||||||
|
|
|
@ -3,7 +3,6 @@ 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;
|
||||||
|
@ -1397,16 +1396,11 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
private void ImportOldGuiConfig()
|
private void ImportOldGuiConfig()
|
||||||
{
|
{
|
||||||
OpenFileDialog fileDialog = new()
|
if (UI.OpenFileDialog(out string fileName,
|
||||||
{
|
"guiNConfig|*.json|All|*.*") != true)
|
||||||
Multiselect = false,
|
|
||||||
Filter = "guiNConfig|*.json|All|*.*"
|
|
||||||
};
|
|
||||||
if (fileDialog.ShowDialog() != true)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string fileName = fileDialog.FileName;
|
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (Utils.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
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;
|
||||||
|
@ -264,20 +263,16 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
private void ImportRulesFromFile()
|
private void ImportRulesFromFile()
|
||||||
{
|
{
|
||||||
OpenFileDialog fileDialog = new OpenFileDialog
|
if (UI.OpenFileDialog(out string fileName,
|
||||||
{
|
"Rules|*.json|All|*.*") != true)
|
||||||
Multiselect = false,
|
|
||||||
Filter = "Rules|*.json|All|*.*"
|
|
||||||
};
|
|
||||||
if (fileDialog.ShowDialog() != true)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string fileName = fileDialog.FileName;
|
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (Utils.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string result = Utils.LoadResource(fileName);
|
string result = Utils.LoadResource(fileName);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (Utils.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using Microsoft.Win32;
|
using ReactiveUI;
|
||||||
using ReactiveUI;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
@ -205,13 +204,5 @@ namespace v2rayN.Views
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnBrowse_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
var openFileDialog1 = new OpenFileDialog();
|
|
||||||
openFileDialog1.Filter = "tunConfig|*.json|All|*.*";
|
|
||||||
openFileDialog1.ShowDialog();
|
|
||||||
|
|
||||||
// txtCustomTemplate.Text = openFileDialog1.FileName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using Microsoft.Win32;
|
using ReactiveUI;
|
||||||
using ReactiveUI;
|
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
@ -131,11 +130,13 @@ 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 OpenFileDialog();
|
if (UI.OpenFileDialog(out string fileName,
|
||||||
openFileDialog1.Filter = "PNG,ICO|*.png;*.ico";
|
"PNG,ICO|*.png;*.ico") != true)
|
||||||
openFileDialog1.ShowDialog();
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
txtCustomIcon.Text = openFileDialog1.FileName;
|
txtCustomIcon.Text = fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue