diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs
index ea618040..ec9f90f8 100644
--- a/Netch/Controllers/MainController.cs
+++ b/Netch/Controllers/MainController.cs
@@ -190,7 +190,7 @@ namespace Netch.Controllers
string fileName;
try
{
- fileName = p.MainModule!.FileName;
+ fileName = p.MainModule?.FileName ?? throw new Exception(); // TODO what's this exception?
}
catch (Exception e)
{
diff --git a/Netch/Forms/LogForm.cs b/Netch/Forms/LogForm.cs
index 8afb72d5..38329d74 100644
--- a/Netch/Forms/LogForm.cs
+++ b/Netch/Forms/LogForm.cs
@@ -16,13 +16,13 @@ namespace Netch.Forms
_parent = parent;
}
- protected override void OnLoad(EventArgs e)
+ protected override void OnLoad(EventArgs? e)
{
base.OnLoad(e);
Parent_Move(null!, null!);
}
- private void Parent_Move(object sender, EventArgs e)
+ private void Parent_Move(object? sender, EventArgs? e)
{
var cl = Location;
var fl = _parent.Location;
@@ -32,7 +32,7 @@ namespace Netch.Forms
Location = cl;
}
- private void Parent_Activated(object sender, EventArgs e)
+ private void Parent_Activated(object? sender, EventArgs? e)
{
SetWindowPos(Handle,
HWND.HWND_TOPMOST,
@@ -51,7 +51,7 @@ namespace Netch.Forms
SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_SHOWWINDOW);
}
- private void richTextBox1_TextChanged(object sender, System.EventArgs e)
+ private void richTextBox1_TextChanged(object? sender, EventArgs? e)
{
if (!checkBox1.Checked)
return;
@@ -60,19 +60,19 @@ namespace Netch.Forms
richTextBox1.ScrollToCaret();
}
- private void Notifycation_Load(object sender, EventArgs e)
+ private void Notifycation_Load(object? sender, EventArgs? e)
{
_parent.LocationChanged += Parent_Move;
_parent.SizeChanged += Parent_Move;
_parent.Activated += Parent_Activated;
}
- protected override void OnClosing(CancelEventArgs e)
+ protected override void OnClosing(CancelEventArgs? e)
{
_parent.Activated -= Parent_Activated;
_parent.LocationChanged -= Parent_Move;
_parent.SizeChanged -= Parent_Move;
- base.OnClosing(e);
+ base.OnClosing(e!);
}
}
}
\ No newline at end of file
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index 4af55046..63e7ef01 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.IO;
using System.Linq;
@@ -234,8 +235,12 @@ namespace Netch.Forms
}
}
- private void AddServerToolStripMenuItem_Click(object sender, EventArgs e)
+ private void AddServerToolStripMenuItem_Click([NotNull] object? sender, EventArgs? e)
{
+ if (sender == null)
+ throw new ArgumentNullException(nameof(sender));
+
+ // TODO get Util from Tag
var s = ((ToolStripMenuItem) sender).Text;
var start = s.IndexOf("[", StringComparison.Ordinal) + 1;
@@ -321,12 +326,12 @@ namespace Netch.Forms
{
Task.Run(() =>
{
- void OnNewVersionNotFound(object o, EventArgs args)
+ void OnNewVersionNotFound(object? o, EventArgs? args)
{
NotifyTip(i18N.Translate("Already latest version"));
}
- void OnNewVersionFoundFailed(object o, EventArgs args)
+ void OnNewVersionFoundFailed(object? o, EventArgs? args)
{
NotifyTip(i18N.Translate("New version found failed"), info: false);
}
@@ -661,7 +666,7 @@ namespace Netch.Forms
ServerHelper.DelayTestHelper.TestDelayFinished += OnTestDelayFinished;
_ = Task.Run(ServerHelper.DelayTestHelper.TestAllDelay);
- void OnTestDelayFinished(object o1, EventArgs e1)
+ void OnTestDelayFinished(object? o1, EventArgs? e1)
{
Refresh();
@@ -900,8 +905,11 @@ namespace Netch.Forms
return profile;
}
- private async void ProfileButton_Click(object sender, EventArgs e)
+ private async void ProfileButton_Click([NotNull] object? sender, EventArgs? e)
{
+ if (sender == null)
+ throw new ArgumentNullException(nameof(sender));
+
var profileButton = (Button) sender;
var profile = (Profile?) profileButton.Tag;
var index = ProfileTable.Controls.IndexOf(profileButton);
@@ -1317,7 +1325,7 @@ namespace Netch.Forms
UpdateChecker.NewVersionFound -= OnUpdateCheckerOnNewVersionFound;
}
- void OnUpdateCheckerOnNewVersionFound(object o, EventArgs eventArgs)
+ void OnUpdateCheckerOnNewVersionFound(object? o, EventArgs? eventArgs)
{
NotifyTip($"{i18N.Translate(@"New version available", ": ")}{UpdateChecker.LatestVersionNumber}");
NewVersionLabel.Text = i18N.Translate("New version available");
diff --git a/Netch/Forms/Mode/Process.cs b/Netch/Forms/Mode/Process.cs
index c22d4fea..832718ed 100644
--- a/Netch/Forms/Mode/Process.cs
+++ b/Netch/Forms/Mode/Process.cs
@@ -149,7 +149,7 @@ namespace Netch.Forms.Mode
Close();
}
- private void RemarkTextBox_TextChanged(object sender, EventArgs e)
+ private void RemarkTextBox_TextChanged(object? sender, EventArgs? e)
{
BeginInvoke(new Action(() =>
{
@@ -195,7 +195,8 @@ namespace Netch.Forms.Mode
foreach (string dir in Directory.GetDirectories(directory))
ScanDirectory(dir, list, maxCount);
- list.AddRange(Directory.GetFiles(directory).Select(Path.GetFileName).Where(s => s.EndsWith(".exe")).Select(s => s.ToRegexString()));
+ list.AddRange(
+ Directory.GetFiles(directory).Select(s => Path.GetFileName(s)).Where(s => s.EndsWith(".exe")).Select(s => s.ToRegexString()));
if (maxCount != 0 && list.Count > maxCount)
throw new Exception("The number of results is greater than maxCount");
diff --git a/Netch/Forms/Mode/Process.resx b/Netch/Forms/Mode/Process.resx
new file mode 100644
index 00000000..1af7de15
--- /dev/null
+++ b/Netch/Forms/Mode/Process.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Netch/Forms/Mode/Route.cs b/Netch/Forms/Mode/Route.cs
index b99195cc..7a6dd087 100644
--- a/Netch/Forms/Mode/Route.cs
+++ b/Netch/Forms/Mode/Route.cs
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Windows.Forms;
+using Netch.Models;
using Netch.Properties;
using Netch.Utils;
@@ -8,26 +9,7 @@ namespace Netch.Forms.Mode
{
public partial class Route : Form
{
- class Item
- {
- private string _text;
-
- public Item(int value, string text)
- {
- _text = text;
- Value = value;
- }
-
- public string Text
- {
- get => i18N.Translate(_text);
- set => _text = value;
- }
-
- public int Value { get; set; }
- }
-
- private readonly Item[] _items = {new(1, "Proxy Rule IPs"), new(2, "Bypass Rule IPs")};
+ private readonly TagItem[] _items = {new(1, "Proxy Rule IPs"), new(2, "Bypass Rule IPs")};
private readonly Models.Mode? _mode;
@@ -41,8 +23,8 @@ namespace Netch.Forms.Mode
InitializeComponent();
Icon = Resources.icon;
comboBox1.DataSource = _items;
- comboBox1.ValueMember = "Value";
- comboBox1.DisplayMember = "Text";
+ comboBox1.ValueMember = nameof(TagItem.Value);
+ comboBox1.DisplayMember = nameof(TagItem.Text);
}
private void Route_Load(object sender, EventArgs e)
@@ -110,12 +92,9 @@ namespace Netch.Forms.Mode
Close();
}
- private void RemarkTextBox_TextChanged(object sender, EventArgs e)
+ private void RemarkTextBox_TextChanged(object? sender, EventArgs? e)
{
- BeginInvoke(new Action(() =>
- {
- FilenameTextBox.Text = ModeEditorUtils.GetCustomModeRelativePath(RemarkTextBox.Text);
- }));
+ BeginInvoke(new Action(() => { FilenameTextBox.Text = ModeEditorUtils.GetCustomModeRelativePath(RemarkTextBox.Text); }));
}
}
}
\ No newline at end of file
diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs
index 93d85868..12502953 100644
--- a/Netch/Forms/SettingForm.cs
+++ b/Netch/Forms/SettingForm.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
+using Netch.Models;
using Netch.Properties;
using Netch.Utils;
@@ -99,10 +100,7 @@ namespace Netch.Forms
BindTextBox(AclAddrTextBox, s => true, s => Global.Settings.ACL = s, Global.Settings.ACL);
- BindListComboBox(LanguageComboBox,
- o => Global.Settings.Language = o.ToString(),
- i18N.GetTranslateList().Cast