Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0be671b
commit 0ccf664
Showing
3 changed files
with
137 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |