Skip to content

Commit bf44a2b

Browse files
committed
v1.0.3
1 parent 194c10d commit bf44a2b

File tree

10 files changed

+65
-93
lines changed

10 files changed

+65
-93
lines changed

PortProxyGUI - NET/NewProxy.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PortProxyGUI - NET/NewProxy.cs

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ namespace PortProxyGUI
99
public partial class NewProxy : Form
1010
{
1111
public readonly PortProxyGUI PortProxyGUI;
12+
private string AutoString { get; }
1213

1314
public NewProxy(PortProxyGUI portProxyGUI)
1415
{
1516
PortProxyGUI = portProxyGUI;
16-
1717
InitializeComponent();
18+
AutoString = comboBox_type.Text = comboBox_type.Items.OfType<string>().First();
1819
}
1920

2021
private void AddPortProxy(string type, string listenOn, string listenPort, string connectTo, string connectPort)
@@ -25,13 +26,18 @@ private void AddPortProxy(string type, string listenOn, string listenPort, strin
2526

2627
private bool IsIPv4(string ip)
2728
{
28-
if (ip == "localhost" || ip == "*") return true;
29-
else return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
29+
return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
3030
}
3131
private bool IsIPv6(string ip)
3232
{
33-
if (ip == "localhost" || ip == "*") return true;
34-
else return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
33+
return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
34+
}
35+
36+
private string GetPassType(string listenOn, string connectTo)
37+
{
38+
var from = IsIPv6(listenOn) ? "v6" : "v4";
39+
var to = IsIPv6(connectTo) ? "v6" : "v4";
40+
return $"{from}to{to}";
3541
}
3642

3743
private void button1_Click(object sender, EventArgs e)
@@ -54,37 +60,11 @@ private void button1_Click(object sender, EventArgs e)
5460
return;
5561
}
5662

57-
if (string.IsNullOrEmpty(type))
58-
{
59-
if (IsIPv4(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v4tov4";
60-
else if (IsIPv4(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v4tov6";
61-
else if (IsIPv6(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v6tov4";
62-
else if (IsIPv6(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v6tov6";
63-
else
64-
{
65-
MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
66-
return;
67-
}
68-
}
69-
else if (new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
70-
{
71-
bool invalid = false;
72-
switch (type)
73-
{
74-
case "v4tov4": if (!IsIPv4(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
75-
case "v4tov6": if (!IsIPv4(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
76-
case "v6tov4": if (!IsIPv6(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
77-
case "v6tov6": if (!IsIPv6(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
78-
}
79-
if (invalid)
80-
{
81-
MessageBox.Show($"The type ({type}) is invalid for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
82-
return;
83-
}
84-
}
85-
else
63+
if (type == AutoString) type = GetPassType(listenOn, connectTo);
64+
65+
if (!new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
8666
{
87-
MessageBox.Show($"Unknow type ({type}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
67+
MessageBox.Show($"Unknow type for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8868
return;
8969
}
9070

@@ -93,7 +73,6 @@ private void button1_Click(object sender, EventArgs e)
9373

9474
private void NewProxy_Load(object sender, EventArgs e)
9575
{
96-
9776
}
9877

9978
private void NewProxy_FormClosing(object sender, FormClosingEventArgs e)

PortProxyGUI - NET/NewProxy.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,18 @@
394394
<value>Popup</value>
395395
</data>
396396
<data name="comboBox_type.Items" xml:space="preserve">
397-
<value>v4tov4</value>
397+
<value>(Auto)</value>
398398
</data>
399399
<data name="comboBox_type.Items1" xml:space="preserve">
400-
<value>v4tov6</value>
400+
<value>v4tov4</value>
401401
</data>
402402
<data name="comboBox_type.Items2" xml:space="preserve">
403-
<value>v6tov4</value>
403+
<value>v4tov6</value>
404404
</data>
405405
<data name="comboBox_type.Items3" xml:space="preserve">
406+
<value>v6tov4</value>
407+
</data>
408+
<data name="comboBox_type.Items4" xml:space="preserve">
406409
<value>v6tov6</value>
407410
</data>
408411
<data name="comboBox_type.Location" type="System.Drawing.Point, System.Drawing">

PortProxyGUI - NET/NewProxy.zh-CN.resx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,16 @@
258258
<data name="&gt;&gt;textBox_listenPort.ZOrder" xml:space="preserve">
259259
<value>1</value>
260260
</data>
261-
<data name="comboBox_type.Items" xml:space="preserve">
261+
<data name="comboBox_type.Items1" xml:space="preserve">
262262
<value>v4tov4</value>
263263
</data>
264-
<data name="comboBox_type.Items1" xml:space="preserve">
264+
<data name="comboBox_type.Items2" xml:space="preserve">
265265
<value>v4tov6</value>
266266
</data>
267-
<data name="comboBox_type.Items2" xml:space="preserve">
267+
<data name="comboBox_type.Items3" xml:space="preserve">
268268
<value>v6tov4</value>
269269
</data>
270-
<data name="comboBox_type.Items3" xml:space="preserve">
270+
<data name="comboBox_type.Items4" xml:space="preserve">
271271
<value>v6tov6</value>
272272
</data>
273273
<data name="&gt;&gt;comboBox_type.Name" xml:space="preserve">
@@ -453,4 +453,7 @@
453453
<data name="textBox_listenPort.TextAlign" type="System.Windows.Forms.HorizontalAlignment, System.Windows.Forms">
454454
<value>Center</value>
455455
</data>
456+
<data name="comboBox_type.Items" xml:space="preserve">
457+
<value>(自动)</value>
458+
</data>
456459
</root>

PortProxyGUI - NET/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
[assembly: AssemblyTitle("PortProxyGUI - NET")]
88
[assembly: AssemblyDescription("")]
99
[assembly: AssemblyConfiguration("")]
10-
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyCompany("nstandard.net")]
1111
[assembly: AssemblyProduct("PortProxyGUI - NET")]
12-
[assembly: AssemblyCopyright("Copyright © 2020")]
12+
[assembly: AssemblyCopyright("Copyright © nstandard.net 2020")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.2.0")]
35-
[assembly: AssemblyFileVersion("1.0.2.0")]
34+
[assembly: AssemblyVersion("1.0.3.0")]
35+
[assembly: AssemblyFileVersion("1.0.3.0")]

PortProxyGUI/NewProxy.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PortProxyGUI/NewProxy.cs

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ namespace PortProxyGUI
99
public partial class NewProxy : Form
1010
{
1111
public readonly PortProxyGUI PortProxyGUI;
12+
private string AutoString { get; }
1213

1314
public NewProxy(PortProxyGUI portProxyGUI)
1415
{
1516
PortProxyGUI = portProxyGUI;
16-
1717
InitializeComponent();
18+
AutoString = comboBox_type.Text = comboBox_type.Items.OfType<string>().First();
1819
}
1920

2021
private void AddPortProxy(string type, string listenOn, string listenPort, string connectTo, string connectPort)
@@ -25,13 +26,18 @@ private void AddPortProxy(string type, string listenOn, string listenPort, strin
2526

2627
private bool IsIPv4(string ip)
2728
{
28-
if (ip == "localhost" || ip == "*") return true;
29-
else return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
29+
return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
3030
}
3131
private bool IsIPv6(string ip)
3232
{
33-
if (ip == "localhost" || ip == "*") return true;
34-
else return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
33+
return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
34+
}
35+
36+
private string GetPassType(string listenOn, string connectTo)
37+
{
38+
var from = IsIPv6(listenOn) ? "v6" : "v4";
39+
var to = IsIPv6(connectTo) ? "v6" : "v4";
40+
return $"{from}to{to}";
3541
}
3642

3743
private void button1_Click(object sender, EventArgs e)
@@ -54,37 +60,11 @@ private void button1_Click(object sender, EventArgs e)
5460
return;
5561
}
5662

57-
if (string.IsNullOrEmpty(type))
58-
{
59-
if (IsIPv4(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v4tov4";
60-
else if (IsIPv4(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v4tov6";
61-
else if (IsIPv6(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v6tov4";
62-
else if (IsIPv6(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v6tov6";
63-
else
64-
{
65-
MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
66-
return;
67-
}
68-
}
69-
else if (new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
70-
{
71-
bool invalid = false;
72-
switch (type)
73-
{
74-
case "v4tov4": if (!IsIPv4(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
75-
case "v4tov6": if (!IsIPv4(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
76-
case "v6tov4": if (!IsIPv6(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
77-
case "v6tov6": if (!IsIPv6(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
78-
}
79-
if (invalid)
80-
{
81-
MessageBox.Show($"The type ({type}) is invalid for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
82-
return;
83-
}
84-
}
85-
else
63+
if (type == AutoString) type = GetPassType(listenOn, connectTo);
64+
65+
if (!new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
8666
{
87-
MessageBox.Show($"Unknow type ({type}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
67+
MessageBox.Show($"Unknow type for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8868
return;
8969
}
9070

@@ -93,7 +73,6 @@ private void button1_Click(object sender, EventArgs e)
9373

9474
private void NewProxy_Load(object sender, EventArgs e)
9575
{
96-
9776
}
9877

9978
private void NewProxy_FormClosing(object sender, FormClosingEventArgs e)

PortProxyGUI/NewProxy.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,18 @@
394394
<value>Popup</value>
395395
</data>
396396
<data name="comboBox_type.Items" xml:space="preserve">
397-
<value>v4tov4</value>
397+
<value>(Auto)</value>
398398
</data>
399399
<data name="comboBox_type.Items1" xml:space="preserve">
400-
<value>v4tov6</value>
400+
<value>v4tov4</value>
401401
</data>
402402
<data name="comboBox_type.Items2" xml:space="preserve">
403-
<value>v6tov4</value>
403+
<value>v4tov6</value>
404404
</data>
405405
<data name="comboBox_type.Items3" xml:space="preserve">
406+
<value>v6tov4</value>
407+
</data>
408+
<data name="comboBox_type.Items4" xml:space="preserve">
406409
<value>v6tov6</value>
407410
</data>
408411
<data name="comboBox_type.Location" type="System.Drawing.Point, System.Drawing">

PortProxyGUI/NewProxy.zh-CN.resx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,16 @@
258258
<data name="&gt;&gt;textBox_listenPort.ZOrder" xml:space="preserve">
259259
<value>1</value>
260260
</data>
261-
<data name="comboBox_type.Items" xml:space="preserve">
261+
<data name="comboBox_type.Items1" xml:space="preserve">
262262
<value>v4tov4</value>
263263
</data>
264-
<data name="comboBox_type.Items1" xml:space="preserve">
264+
<data name="comboBox_type.Items2" xml:space="preserve">
265265
<value>v4tov6</value>
266266
</data>
267-
<data name="comboBox_type.Items2" xml:space="preserve">
267+
<data name="comboBox_type.Items3" xml:space="preserve">
268268
<value>v6tov4</value>
269269
</data>
270-
<data name="comboBox_type.Items3" xml:space="preserve">
270+
<data name="comboBox_type.Items4" xml:space="preserve">
271271
<value>v6tov6</value>
272272
</data>
273273
<data name="&gt;&gt;comboBox_type.Name" xml:space="preserve">
@@ -453,4 +453,7 @@
453453
<data name="textBox_listenPort.TextAlign" type="System.Windows.Forms.HorizontalAlignment, System.Windows.Forms">
454454
<value>Center</value>
455455
</data>
456+
<data name="comboBox_type.Items" xml:space="preserve">
457+
<value>(自动)</value>
458+
</data>
456459
</root>

PortProxyGUI/PortProxyGUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageTags>portproxy TCP/IP redirector</PackageTags>
1515
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
1616
<Copyright>Copyright © nstandard.net 2020</Copyright>
17-
<Version>1.0.2</Version>
17+
<Version>1.0.3</Version>
1818
<ApplicationIcon>icon.ico</ApplicationIcon>
1919
</PropertyGroup>
2020

0 commit comments

Comments
 (0)