PortProxyGUI.1.3.3
This commit is contained in:
parent
1756d32c79
commit
e8da3c5055
|
@ -63,7 +63,7 @@ namespace PortProxyGUI
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var rule = ParseRule(item);
|
var rule = ParseRule(item);
|
||||||
CmdUtil.AddOrUpdateProxy(rule);
|
PortProxyUtil.AddOrUpdateProxy(rule);
|
||||||
}
|
}
|
||||||
catch (NotSupportedException ex)
|
catch (NotSupportedException ex)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,7 @@ namespace PortProxyGUI
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var rule = ParseRule(item);
|
var rule = ParseRule(item);
|
||||||
CmdUtil.DeleteProxy(rule);
|
PortProxyUtil.DeleteProxy(rule);
|
||||||
}
|
}
|
||||||
catch (NotSupportedException ex)
|
catch (NotSupportedException ex)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ namespace PortProxyGUI
|
||||||
|
|
||||||
public void RefreshProxyList()
|
public void RefreshProxyList()
|
||||||
{
|
{
|
||||||
var proxies = CmdUtil.GetProxies();
|
var proxies = PortProxyUtil.GetProxies();
|
||||||
var rules = Program.SqliteDbScope.Rules.ToArray();
|
var rules = Program.SqliteDbScope.Rules.ToArray();
|
||||||
foreach (var proxy in proxies)
|
foreach (var proxy in proxies)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,4 +42,4 @@
|
||||||
<PackageReference Include="SQLib.Sqlite" Version="0.8.6" />
|
<PackageReference Include="SQLib.Sqlite" Version="0.8.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -116,17 +116,17 @@ namespace PortProxyGUI
|
||||||
if (_updateMode)
|
if (_updateMode)
|
||||||
{
|
{
|
||||||
var oldRule = Program.SqliteDbScope.GetRule(_itemRule.Type, _itemRule.ListenOn, _itemRule.ListenPort);
|
var oldRule = Program.SqliteDbScope.GetRule(_itemRule.Type, _itemRule.ListenOn, _itemRule.ListenPort);
|
||||||
CmdUtil.DeleteProxy(oldRule);
|
PortProxyUtil.DeleteProxy(oldRule);
|
||||||
Program.SqliteDbScope.Remove(oldRule);
|
Program.SqliteDbScope.Remove(oldRule);
|
||||||
|
|
||||||
CmdUtil.AddOrUpdateProxy(rule);
|
PortProxyUtil.AddOrUpdateProxy(rule);
|
||||||
Program.SqliteDbScope.Add(rule);
|
Program.SqliteDbScope.Add(rule);
|
||||||
|
|
||||||
ParentWindow.UpdateListViewItem(_listViewItem, rule, 1);
|
ParentWindow.UpdateListViewItem(_listViewItem, rule, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CmdUtil.AddOrUpdateProxy(rule);
|
PortProxyUtil.AddOrUpdateProxy(rule);
|
||||||
Program.SqliteDbScope.Add(rule);
|
Program.SqliteDbScope.Add(rule);
|
||||||
|
|
||||||
ParentWindow.RefreshProxyList();
|
ParentWindow.RefreshProxyList();
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
using System.Diagnostics;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace PortProxyGUI
|
namespace PortProxyGUI
|
||||||
{
|
{
|
||||||
|
[Obsolete("The method of creating a new process is no longer used.")]
|
||||||
public static class CmdRunner
|
public static class CmdRunner
|
||||||
{
|
{
|
||||||
public static string Execute(string cmd)
|
public static string Execute(string cmd)
|
||||||
|
|
|
@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace PortProxyGUI
|
namespace PortProxyGUI
|
||||||
{
|
{
|
||||||
|
[Obsolete("The method of creating a new process is no longer used.", true)]
|
||||||
public static class CmdUtil
|
public static class CmdUtil
|
||||||
{
|
{
|
||||||
private static Regex GetRegex(string fromType, string toType)
|
private static Regex GetRegex(string fromType, string toType)
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using PortProxyGUI.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace PortProxyGUI
|
||||||
|
{
|
||||||
|
public static class PortProxyUtil
|
||||||
|
{
|
||||||
|
private static InvalidOperationException InvalidPortProxyType(string type) => new($"Invalid port proxy type ({type}).");
|
||||||
|
private static readonly string[] ProxyTypes = new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" };
|
||||||
|
|
||||||
|
public static Rule[] GetProxies()
|
||||||
|
{
|
||||||
|
var ruleList = new List<Rule>();
|
||||||
|
foreach (var type in ProxyTypes)
|
||||||
|
{
|
||||||
|
var keyName = $@"SYSTEM\ControlSet001\Services\PortProxy\{type}\tcp";
|
||||||
|
var key = Registry.LocalMachine.OpenSubKey(keyName);
|
||||||
|
|
||||||
|
if (key is not null)
|
||||||
|
{
|
||||||
|
foreach (var name in key.GetValueNames())
|
||||||
|
{
|
||||||
|
var listenParts = name.Split('/');
|
||||||
|
var listenOn = listenParts[0];
|
||||||
|
if (!int.TryParse(listenParts[1], out var listenPort)) continue;
|
||||||
|
|
||||||
|
var connectParts = key.GetValue(name).ToString().Split('/');
|
||||||
|
var connectTo = connectParts[0];
|
||||||
|
if (!int.TryParse(connectParts[1], out var connectPort)) continue;
|
||||||
|
|
||||||
|
ruleList.Add(new Rule
|
||||||
|
{
|
||||||
|
Type = type,
|
||||||
|
ListenOn = listenOn,
|
||||||
|
ListenPort = listenPort,
|
||||||
|
ConnectTo = connectTo,
|
||||||
|
ConnectPort = connectPort,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ruleList.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddOrUpdateProxy(Rule rule)
|
||||||
|
{
|
||||||
|
if (!ProxyTypes.Contains(rule.Type)) throw InvalidPortProxyType(rule.Type);
|
||||||
|
|
||||||
|
var keyName = $@"SYSTEM\ControlSet001\Services\PortProxy\{rule.Type}\tcp";
|
||||||
|
var key = Registry.LocalMachine.OpenSubKey(keyName, true);
|
||||||
|
var valueName = $"{rule.ListenOn}/{rule.ListenPort}";
|
||||||
|
var value = $"{rule.ConnectTo}/{rule.ConnectPort}";
|
||||||
|
|
||||||
|
key.SetValue(valueName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteProxy(Rule rule)
|
||||||
|
{
|
||||||
|
if (!ProxyTypes.Contains(rule.Type)) throw InvalidPortProxyType(rule.Type);
|
||||||
|
|
||||||
|
var keyName = $@"SYSTEM\ControlSet001\Services\PortProxy\{rule.Type}\tcp";
|
||||||
|
var key = Registry.LocalMachine.OpenSubKey(keyName, true);
|
||||||
|
var valueName = $"{rule.ListenOn}/{rule.ListenPort}";
|
||||||
|
|
||||||
|
key.DeleteValue(valueName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue