Skip to content

Commit

Permalink
[UX] add tips for run & stop
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Jun 18, 2020
1 parent 0be671b commit 0ccf664
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 118 deletions.
3 changes: 3 additions & 0 deletions NaiveSharp/NaiveSharp.csproj
Expand Up @@ -106,6 +106,9 @@
<Compile Include="View\MainWindow.Designer.cs">
<DependentUpon>MainWindow.cs</DependentUpon>
</Compile>
<Compile Include="View\MainWindowsUtil.cs">
<SubType>Form</SubType>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
121 changes: 3 additions & 118 deletions NaiveSharp/View/MainWindow.cs
Expand Up @@ -6,7 +6,6 @@
using System.IO;
using System.Windows.Forms;
using NaiveSharp.ConstText;
using System.Data;

namespace NaiveSharp.View
{
Expand All @@ -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"))
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
}
131 changes: 131 additions & 0 deletions 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;
}
}
}
}

0 comments on commit 0ccf664

Please sign in to comment.