Skip to content

Commit 1b5069a

Browse files
committed
Code clean
1 parent 18ea6fd commit 1b5069a

23 files changed

Lines changed: 102 additions & 102 deletions

v2rayN/v2rayN/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class App : Application
99

1010
public App()
1111
{
12-
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
12+
DispatcherUnhandledException += App_DispatcherUnhandledException;
1313
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
1414
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
1515
}
@@ -23,7 +23,7 @@ protected override void OnStartup(StartupEventArgs e)
2323
var exePathKey = Utils.GetMd5(Utils.GetExePath());
2424

2525
var rebootas = (e.Args ?? Array.Empty<string>()).Any(t => t == Global.RebootAs);
26-
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out bool bCreatedNew);
26+
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out var bCreatedNew);
2727
if (!rebootas && !bCreatedNew)
2828
{
2929
ProgramStarted.Set();

v2rayN/v2rayN/Common/UI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.Win32;
22

3-
namespace v2rayN;
3+
namespace v2rayN.Common;
44

55
internal class UI
66
{

v2rayN/v2rayN/Common/WindowsUtils.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Windows.Media.Imaging;
44
using Microsoft.Win32;
55

6-
namespace v2rayN;
6+
namespace v2rayN.Common;
77

88
internal static class WindowsUtils
99
{
@@ -40,13 +40,13 @@ public static void SetClipboardData(string strData)
4040
}
4141

4242
[DllImport("dwmapi.dll")]
43-
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attribute, ref int attributeValue, uint attributeSize);
43+
public static extern int DwmSetWindowAttribute(nint hwnd, DWMWINDOWATTRIBUTE attribute, ref int attributeValue, uint attributeSize);
4444

4545
public static ImageSource IconToImageSource(Icon icon)
4646
{
4747
return Imaging.CreateBitmapSourceFromHIcon(
4848
icon.Handle,
49-
new System.Windows.Int32Rect(0, 0, icon.Width, icon.Height),
49+
new Int32Rect(0, 0, icon.Width, icon.Height),
5050
BitmapSizeOptions.FromEmptyOptions());
5151
}
5252

@@ -65,9 +65,9 @@ public static void SetDarkBorder(Window window, string? theme)
6565
private static void SetDarkBorder(Window window, bool dark)
6666
{
6767
// Make sure the handle is created before the window is shown
68-
IntPtr hWnd = new WindowInteropHelper(window).EnsureHandle();
69-
int attribute = dark ? 1 : 0;
70-
uint attributeSize = (uint)Marshal.SizeOf(attribute);
68+
var hWnd = new WindowInteropHelper(window).EnsureHandle();
69+
var attribute = dark ? 1 : 0;
70+
var attributeSize = (uint)Marshal.SizeOf(attribute);
7171
DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, ref attribute, attributeSize);
7272
DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref attribute, attributeSize);
7373
}

v2rayN/v2rayN/Manager/HotkeyManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void Init()
4343
modifiers |= KeyModifiers.Alt;
4444
}
4545

46-
key = key << 16 | (int)modifiers;
46+
key = (key << 16) | (int)modifiers;
4747
if (!_hotkeyTriggerDic.ContainsKey(key))
4848
{
4949
_hotkeyTriggerDic.Add(key, new() { item.EGlobalHotkey });
@@ -103,7 +103,7 @@ public void ReLoad()
103103
private (int fsModifiers, int vKey, string hotkeyStr, List<string> Names) GetHotkeyInfo(int hotkeyCode)
104104
{
105105
var fsModifiers = hotkeyCode & 0xffff;
106-
var vKey = hotkeyCode >> 16 & 0xffff;
106+
var vKey = (hotkeyCode >> 16) & 0xffff;
107107
var hotkeyStr = new StringBuilder();
108108
var names = new List<string>();
109109

v2rayN/v2rayN/Manager/WindowsManager.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,26 @@ public System.Windows.Media.ImageSource GetAppIcon(Config config)
6060
return null;
6161
}
6262

63-
Color color = ColorTranslator.FromHtml("#3399CC");
64-
int index = (int)config.SystemProxyItem.SysProxyType;
63+
var color = ColorTranslator.FromHtml("#3399CC");
64+
var index = (int)config.SystemProxyItem.SysProxyType;
6565
if (index > 0)
6666
{
6767
color = (new[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1];
6868
}
6969

70-
int width = 128;
71-
int height = 128;
70+
var width = 128;
71+
var height = 128;
7272

7373
Bitmap bitmap = new(width, height);
74-
Graphics graphics = Graphics.FromImage(bitmap);
74+
var graphics = Graphics.FromImage(bitmap);
7575
SolidBrush drawBrush = new(color);
7676

7777
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
7878
//graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
7979
graphics.DrawImage(new Bitmap(item.CustomIcon), 0, 0, width, height);
8080
graphics.FillEllipse(drawBrush, width / 2, width / 2, width / 2, width / 2);
8181

82-
Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());
82+
var createdIcon = Icon.FromHandle(bitmap.GetHicon());
8383

8484
drawBrush.Dispose();
8585
graphics.Dispose();

v2rayN/v2rayN/Views/AddGroupServerWindow.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public AddGroupServerWindow(ProfileItem profileItem)
66
{
77
InitializeComponent();
88

9-
this.Owner = Application.Current.MainWindow;
10-
this.Loaded += Window_Loaded;
11-
this.PreviewKeyDown += AddGroupServerWindow_PreviewKeyDown;
9+
Owner = Application.Current.MainWindow;
10+
Loaded += Window_Loaded;
11+
PreviewKeyDown += AddGroupServerWindow_PreviewKeyDown;
1212
lstChild.SelectionChanged += LstChild_SelectionChanged;
1313
menuSelectAllChild.Click += MenuSelectAllChild_Click;
1414

@@ -27,11 +27,11 @@ public AddGroupServerWindow(ProfileItem profileItem)
2727
switch (profileItem.ConfigType)
2828
{
2929
case EConfigType.PolicyGroup:
30-
this.Title = ResUI.TbConfigTypePolicyGroup;
30+
Title = ResUI.TbConfigTypePolicyGroup;
3131
break;
3232

3333
case EConfigType.ProxyChain:
34-
this.Title = ResUI.TbConfigTypeProxyChain;
34+
Title = ResUI.TbConfigTypeProxyChain;
3535
gridPolicyGroup.Visibility = Visibility.Collapsed;
3636
break;
3737
}
@@ -61,7 +61,7 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
6161
switch (action)
6262
{
6363
case EViewAction.CloseWindow:
64-
this.DialogResult = true;
64+
DialogResult = true;
6565
break;
6666
}
6767
return await Task.FromResult(true);

v2rayN/v2rayN/Views/AddServer2Window.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public AddServer2Window(ProfileItem profileItem)
66
{
77
InitializeComponent();
88

9-
this.Owner = Application.Current.MainWindow;
10-
this.Loaded += Window_Loaded;
9+
Owner = Application.Current.MainWindow;
10+
Loaded += Window_Loaded;
1111
ViewModel = new AddServer2ViewModel(profileItem, UpdateViewHandler);
1212

1313
cmbCoreType.ItemsSource = Utils.GetEnumNames<ECoreType>().Where(t => t != ECoreType.v2rayN.ToString()).ToList().AppendEmpty();
@@ -32,11 +32,11 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
3232
switch (action)
3333
{
3434
case EViewAction.CloseWindow:
35-
this.DialogResult = true;
35+
DialogResult = true;
3636
break;
3737

3838
case EViewAction.BrowseServer:
39-
if (UI.OpenFileDialog(out string fileName, "Config|*.json|YAML|*.yaml;*.yml|All|*.*") != true)
39+
if (UI.OpenFileDialog(out var fileName, "Config|*.json|YAML|*.yaml;*.yml|All|*.*") != true)
4040
{
4141
return false;
4242
}

v2rayN/v2rayN/Views/AddServerWindow.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public AddServerWindow(ProfileItem profileItem)
88
{
99
InitializeComponent();
1010

11-
this.Owner = Application.Current.MainWindow;
12-
this.Loaded += Window_Loaded;
11+
Owner = Application.Current.MainWindow;
12+
Loaded += Window_Loaded;
1313
cmbNetwork.SelectionChanged += CmbNetwork_SelectionChanged;
1414
cmbStreamSecurity.SelectionChanged += CmbStreamSecurity_SelectionChanged;
1515
btnGUID.Click += btnGUID_Click;
@@ -191,7 +191,7 @@ public AddServerWindow(ProfileItem profileItem)
191191
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
192192
});
193193

194-
this.Title = $"{profileItem.ConfigType}";
194+
Title = $"{profileItem.ConfigType}";
195195
WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme);
196196
}
197197

@@ -200,7 +200,7 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
200200
switch (action)
201201
{
202202
case EViewAction.CloseWindow:
203-
this.DialogResult = true;
203+
DialogResult = true;
204204
break;
205205
}
206206
return await Task.FromResult(true);

v2rayN/v2rayN/Views/BackupAndRestoreView.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public BackupAndRestoreView()
2828

2929
private void MenuLocalBackup_Click(object sender, RoutedEventArgs e)
3030
{
31-
if (UI.SaveFileDialog(out string fileName, "Zip|*.zip") != true)
31+
if (UI.SaveFileDialog(out var fileName, "Zip|*.zip") != true)
3232
{
3333
return;
3434
}
@@ -37,7 +37,7 @@ private void MenuLocalBackup_Click(object sender, RoutedEventArgs e)
3737

3838
private void MenuLocalRestore_Click(object sender, RoutedEventArgs e)
3939
{
40-
if (UI.OpenFileDialog(out string fileName, "Zip|*.zip|All|*.*") != true)
40+
if (UI.OpenFileDialog(out var fileName, "Zip|*.zip|All|*.*") != true)
4141
{
4242
return;
4343
}

v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public DNSSettingWindow()
88
{
99
InitializeComponent();
1010

11-
this.Owner = Application.Current.MainWindow;
11+
Owner = Application.Current.MainWindow;
1212
_config = AppManager.Instance.Config;
1313

1414
ViewModel = new DNSSettingViewModel(UpdateViewHandler);
@@ -78,7 +78,7 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
7878
switch (action)
7979
{
8080
case EViewAction.CloseWindow:
81-
this.DialogResult = true;
81+
DialogResult = true;
8282
break;
8383
}
8484
return await Task.FromResult(true);

0 commit comments

Comments
 (0)