From 0ccf664a9fba39fd1937937ca3bc4aa992496d2a Mon Sep 17 00:00:00 2001 From: KevinZonda <33132228+KevinZonda@users.noreply.github.com> Date: Thu, 18 Jun 2020 19:12:51 +0800 Subject: [PATCH] [UX] add tips for run & stop --- NaiveSharp/NaiveSharp.csproj | 3 + NaiveSharp/View/MainWindow.cs | 121 +------------------------- NaiveSharp/View/MainWindowsUtil.cs | 131 +++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 118 deletions(-) create mode 100644 NaiveSharp/View/MainWindowsUtil.cs diff --git a/NaiveSharp/NaiveSharp.csproj b/NaiveSharp/NaiveSharp.csproj index 90e1f5d..ed4a8b4 100644 --- a/NaiveSharp/NaiveSharp.csproj +++ b/NaiveSharp/NaiveSharp.csproj @@ -106,6 +106,9 @@ MainWindow.cs + + Form + ResXFileCodeGenerator Resources.Designer.cs diff --git a/NaiveSharp/View/MainWindow.cs b/NaiveSharp/View/MainWindow.cs index 4c7d451..fc075f4 100644 --- a/NaiveSharp/View/MainWindow.cs +++ b/NaiveSharp/View/MainWindow.cs @@ -6,7 +6,6 @@ using System.IO; using System.Windows.Forms; using NaiveSharp.ConstText; -using System.Data; namespace NaiveSharp.View { @@ -29,65 +28,6 @@ public MainWindow() } } - public void LoadFromNs(string ns) - { - if (string.IsNullOrWhiteSpace(ns)) - { - return; - } - - var x = ns.Trim().Split(' '); - if (x.Length != 2) - { - return; - } - - x[0] = x[0].FromBase64(); - - var uri = new Uri(x[0]); - - switch (uri.Scheme) - { - case "https": - rdoHttps.Checked = true; - rdoQuic.Checked = false; - break; - default: - rdoHttps.Checked = false; - rdoQuic.Checked = true; - break; - } - - chkPadding.Checked = bool.Parse(x[1]); - txtHost.Text = uri.Host; - string userinfo = uri.UserInfo.Trim(); - if (string.IsNullOrWhiteSpace(userinfo)) - { - txtPassword.Text = - txtUsername.Text = ""; - } - else - { - var vv = userinfo.Split(':'); - switch (vv.Length) - { - case 1: - txtUsername.Text = vv[0]; - break; - case 2: - txtUsername.Text = vv[0].FromUrlEncode(); - txtPassword.Text = vv[1].FromUrlEncode(); - break; - default: - throw new DataException(); - } - } - if (uri.Port > 0) - { - txtHost.Text += ":" + uri.Port; - } - } - private void MainWindows_Load(object sender, EventArgs e) { if (System.IO.File.Exists("DEBUG")) @@ -137,62 +77,12 @@ private void lblSave_Click(object sender, EventArgs e) private void btnRun_Click(object sender, EventArgs e) { - /* - * 0 -> Ok - * 1 -> 1080 - * 2 -> 1081 - * 3 -> 1080 & 1081 - */ - int status = 0; - - if (Net.IsPortUsed(1080)) - { - status = 1; - } - - if (Net.IsPortUsed(1081)) - { - if (status == 1) - { - status = 3; - } - else - { - status = 2; - } - } - - DialogResult result = DialogResult.OK; - switch (status) - { - case 1: - result = MessageBox.Show("Port 1080 is in used! NaiveProxy may not work normally!\n" + - "Do you still want to continue?", "Port is in used", - MessageBoxButtons.YesNo, - MessageBoxIcon.Warning); - break; - case 2: - result = MessageBox.Show("Port 1081 is in used! HTTP proxy and padding may not work normally!\n" + - "Do you still want to continue?", "Port is in used", - MessageBoxButtons.YesNo, - MessageBoxIcon.Warning); - break; - case 3: - result = MessageBox.Show("Port 1080 is in used! NaiveProxy may not work normally!\n" + - "Port 1081 is in used! HTTP proxy and padding may not work normally!\n" + - "Do you still want to continue?", "Port is in used", - MessageBoxButtons.YesNo, - MessageBoxIcon.Warning); - break; - } - - if (result == DialogResult.No) + if (CheckPortStatus() == DialogResult.No) { return; } Operation.Run(); - MessageBox.Show("NaiveProxy runs successfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } @@ -257,11 +147,13 @@ private void smiExit_Click(object sender, EventArgs e) private void smiStop_Click(object sender, EventArgs e) { Operation.Stop(); + icnNotify.ShowBalloonTip(500, "Naive #", "NaiveProxy stopped successfully.", ToolTipIcon.Info); } private void smiRun_Click(object sender, EventArgs e) { Operation.Run(); + icnNotify.ShowBalloonTip(500, "Naive #", "NaiveProxy is running.", ToolTipIcon.Info); } private void smiAbout_Click(object sender, EventArgs e) @@ -349,12 +241,5 @@ private void tsmGeoIP_Click(object sender, EventArgs e) tsmGFWList.Checked = tsmGFWList.Checked = false; SyncModeToSMI(); } - - private void SyncModeToSMI() - { - tsmGlobal.Checked = rdoGlobal.Checked; - tsmGeoIP.Checked = rdoGeoIP.Checked; - tsmGFWList.Checked = rdoGfwlist.Checked; - } } } \ No newline at end of file diff --git a/NaiveSharp/View/MainWindowsUtil.cs b/NaiveSharp/View/MainWindowsUtil.cs new file mode 100644 index 0000000..b907600 --- /dev/null +++ b/NaiveSharp/View/MainWindowsUtil.cs @@ -0,0 +1,131 @@ +using NaiveSharp.Controller; +using NaiveSharp.Controller.Extension; + +using System; +using System.Data; +using System.Windows.Forms; + +namespace NaiveSharp.View +{ + public partial class MainWindow + { + private void SyncModeToSMI() + { + tsmGlobal.Checked = rdoGlobal.Checked; + tsmGeoIP.Checked = rdoGeoIP.Checked; + tsmGFWList.Checked = rdoGfwlist.Checked; + } + + private DialogResult CheckPortStatus() + { + /* + * 0 -> Ok + * 1 -> 1080 + * 2 -> 1081 + * 3 -> 1080 & 1081 + */ + int status = 0; + + if (Net.IsPortUsed(1080)) + { + status = 1; + } + + if (Net.IsPortUsed(1081)) + { + if (status == 1) + { + status = 3; + } + else + { + status = 2; + } + } + + DialogResult result = DialogResult.OK; + switch (status) + { + case 1: + result = MessageBox.Show("Port 1080 is in used! NaiveProxy may not work normally!\n" + + "Do you still want to continue?", "Port is in used", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning); + break; + case 2: + result = MessageBox.Show("Port 1081 is in used! HTTP proxy and padding may not work normally!\n" + + "Do you still want to continue?", "Port is in used", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning); + break; + case 3: + result = MessageBox.Show("Port 1080 is in used! NaiveProxy may not work normally!\n" + + "Port 1081 is in used! HTTP proxy and padding may not work normally!\n" + + "Do you still want to continue?", "Port is in used", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning); + break; + } + + return result; + } + + public void LoadFromNs(string ns) + { + if (string.IsNullOrWhiteSpace(ns)) + { + return; + } + + var x = ns.Trim().Split(' '); + if (x.Length != 2) + { + return; + } + + x[0] = x[0].FromBase64(); + + var uri = new Uri(x[0]); + + switch (uri.Scheme) + { + case "https": + rdoHttps.Checked = true; + rdoQuic.Checked = false; + break; + default: + rdoHttps.Checked = false; + rdoQuic.Checked = true; + break; + } + + chkPadding.Checked = bool.Parse(x[1]); + txtHost.Text = uri.Host; + string userinfo = uri.UserInfo.Trim(); + if (string.IsNullOrWhiteSpace(userinfo)) + { + txtPassword.Text = txtUsername.Text = ""; + } + else + { + var vv = userinfo.Split(':'); + switch (vv.Length) + { + case 1: + txtUsername.Text = vv[0]; + break; + case 2: + txtUsername.Text = vv[0].FromUrlEncode(); + txtPassword.Text = vv[1].FromUrlEncode(); + break; + default: + throw new DataException(); + } + } + if (uri.Port > 0) + { + txtHost.Text += ":" + uri.Port; + } + } + } +}