Refactor naming

This commit is contained in:
ChsBuffer
2021-06-28 02:22:51 +08:00
parent c0452552ec
commit 29b003bacd
34 changed files with 74 additions and 76 deletions

View File

@@ -7,8 +7,8 @@ using System.ServiceProcess;
using Netch.Interfaces;
using Netch.Interops;
using Netch.Models;
using Netch.Servers;
using Netch.Servers.Shadowsocks;
using Netch.Servers.Socks5;
using Netch.Utils;
using Serilog;
using static Netch.Interops.Redirector;

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
using Netch.Forms;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.Socks5;
using Netch.Servers;
using Netch.Utils;
namespace Netch.Controllers

View File

@@ -8,7 +8,7 @@ using Netch.Enums;
using Netch.Interfaces;
using Netch.Interops;
using Netch.Models;
using Netch.Servers.Socks5;
using Netch.Servers;
using Netch.Utils;
using Serilog;
using static Netch.Interops.tun2socks;

View File

@@ -11,7 +11,7 @@ using System.Windows.Forms;
using Microsoft.Win32;
using Netch.Controllers;
using Netch.Enums;
using Netch.Forms.Mode;
using Netch.Forms.ModeForms;
using Netch.Interfaces;
using Netch.Models;
using Netch.Properties;
@@ -246,14 +246,14 @@ namespace Netch.Forms
private void CreateProcessModeToolStripButton_Click(object sender, EventArgs e)
{
Hide();
new Process().ShowDialog();
new ProcessForm().ShowDialog();
Show();
}
private void createRouteTableModeToolStripMenuItem_Click(object sender, EventArgs e)
{
Hide();
new Route().ShowDialog();
new RouteForm().ShowDialog();
Show();
}
@@ -479,7 +479,7 @@ namespace Netch.Forms
return;
}
if (ModeComboBox.SelectedItem is not Models.Mode mode)
if (ModeComboBox.SelectedItem is not Mode mode)
{
MessageBoxX.Show(i18N.Translate("Please select a mode first"));
return;
@@ -707,7 +707,7 @@ namespace Netch.Forms
{
try
{
Global.Settings.ModeComboBoxSelectedIndex = Global.Modes.IndexOf((Models.Mode)ModeComboBox.SelectedItem);
Global.Settings.ModeComboBoxSelectedIndex = Global.Modes.IndexOf((Mode)ModeComboBox.SelectedItem);
}
catch
{
@@ -724,7 +724,7 @@ namespace Netch.Forms
return;
}
var mode = (Models.Mode)ModeComboBox.SelectedItem;
var mode = (Mode)ModeComboBox.SelectedItem;
if (ModifierKeys == Keys.Control)
{
Utils.Utils.Open(ModeHelper.GetFullPath(mode.RelativePath!));
@@ -735,13 +735,13 @@ namespace Netch.Forms
{
case ModeType.Process:
Hide();
new Process(mode).ShowDialog();
new ProcessForm(mode).ShowDialog();
Show();
break;
case ModeType.ProxyRuleIPs:
case ModeType.BypassRuleIPs:
Hide();
new Route(mode).ShowDialog();
new RouteForm(mode).ShowDialog();
Show();
break;
default:
@@ -759,7 +759,7 @@ namespace Netch.Forms
return;
}
ModeHelper.Delete((Models.Mode)ModeComboBox.SelectedItem);
ModeHelper.Delete((Mode)ModeComboBox.SelectedItem);
SelectLastMode();
}
@@ -837,7 +837,7 @@ namespace Netch.Forms
ProfileNameText.Text = profile.ProfileName;
var server = ServerComboBox.Items.Cast<Server>().FirstOrDefault(s => s.Remark.Equals(profile.ServerRemark));
var mode = ModeComboBox.Items.Cast<Models.Mode>().FirstOrDefault(m => m.Remark.Equals(profile.ModeRemark));
var mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Equals(profile.ModeRemark));
if (server == null)
throw new Exception("Server not found.");
@@ -852,7 +852,7 @@ namespace Netch.Forms
private Profile CreateProfileAtIndex(int index)
{
var server = (Server)ServerComboBox.SelectedItem;
var mode = (Models.Mode)ModeComboBox.SelectedItem;
var mode = (Mode)ModeComboBox.SelectedItem;
var name = ProfileNameText.Text;
Profile? profile;
@@ -1418,7 +1418,7 @@ namespace Netch.Forms
break;
}
case Models.Mode item:
case Mode item:
{
// 绘制 模式Box 底色
e.Graphics.FillRectangle(Brushes.Gray, _numberBoxX, e.Bounds.Y, _numberBoxWidth, e.Bounds.Height);

View File

@@ -1,7 +1,7 @@
using System.IO;
using System.Text;
namespace Netch.Forms.Mode
namespace Netch.Forms.ModeForms
{
public static class ModeEditorUtils
{

View File

@@ -1,9 +1,9 @@
using System;
using System.Windows.Forms;
namespace Netch.Forms.Mode
namespace Netch.Forms.ModeForms
{
partial class Process
partial class ProcessForm
{
/// <summary>
/// Required designer variable.
@@ -180,7 +180,7 @@ namespace Netch.Forms.Mode
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false;
this.Name = "Process";
this.Name = "ProcessForm";
this.Padding = new System.Windows.Forms.Padding(12, 5, 12, 5);
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Process Mode";

View File

@@ -10,20 +10,20 @@ using System.Linq;
using System.Windows.Forms;
using Netch.Enums;
namespace Netch.Forms.Mode
namespace Netch.Forms.ModeForms
{
public partial class Process : Form
public partial class ProcessForm : Form
{
/// <summary>
/// 被编辑的模式
/// </summary>
private readonly Models.Mode? _mode;
private readonly Mode? _mode;
/// <summary>
/// 编辑模式
/// </summary>
/// <param name="mode">模式</param>
public Process(Models.Mode? mode = null)
public ProcessForm(Mode? mode = null)
{
if (mode != null && mode.Type is not ModeType.Process)
throw new ArgumentOutOfRangeException();
@@ -133,7 +133,7 @@ namespace Netch.Forms.Mode
return;
}
var mode = new Models.Mode(fullName)
var mode = new Mode(fullName)
{
Type = ModeType.Process,
Remark = RemarkTextBox.Text

View File

@@ -1,9 +1,9 @@
using System.ComponentModel;
using Netch.Properties;
namespace Netch.Forms.Mode
namespace Netch.Forms.ModeForms
{
partial class Route
partial class RouteForm
{
/// <summary>
/// Required designer variable.
@@ -166,7 +166,7 @@ namespace Netch.Forms.Mode
this.ClientSize = new System.Drawing.Size(356, 419);
this.Controls.Add(this.ConfigurationGroupBox);
this.Controls.Add(this.ControlButton);
this.Name = "Route";
this.Name = "RouteForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Route Table Rule";
this.Load += new System.EventHandler(this.Route_Load);

View File

@@ -6,16 +6,16 @@ using System.IO;
using System.Windows.Forms;
using Netch.Enums;
namespace Netch.Forms.Mode
namespace Netch.Forms.ModeForms
{
public partial class Route : Form
public partial class RouteForm : Form
{
private readonly TagItem<ModeType>[] _items =
{ new(ModeType.ProxyRuleIPs, "Proxy Rule IPs"), new(ModeType.BypassRuleIPs, "Bypass Rule IPs") };
private readonly Models.Mode? _mode;
private readonly Mode? _mode;
public Route(Models.Mode? mode = null)
public RouteForm(Mode? mode = null)
{
if (mode != null && mode.Type is not (ModeType.ProxyRuleIPs or ModeType.BypassRuleIPs))
throw new ArgumentOutOfRangeException();
@@ -79,7 +79,7 @@ namespace Netch.Forms.Mode
return;
}
var mode = new Models.Mode(fullName)
var mode = new Mode(fullName)
{
Type = (ModeType)comboBox1.SelectedValue,
Remark = RemarkTextBox.Text

View File

@@ -1,5 +1,5 @@
using Netch.Models;
using Netch.Servers.Socks5;
using Netch.Servers;
namespace Netch.Interfaces
{

View File

@@ -72,7 +72,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Update="Forms\Mode\Route.cs" />
<Compile Update="Forms\Mode\RouteForm.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -21,7 +21,7 @@ namespace Netch.Servers.Shadowsocks
public string? LocalAddress { get; set; }
public Socks5.Socks5 Start(in Server s)
public Socks5 Start(in Server s)
{
var server = (Shadowsocks)s;
@@ -39,7 +39,7 @@ namespace Netch.Servers.Shadowsocks
};
StartGuard(command.ToString());
return new Socks5.Socks5(this.LocalAddress(), this.Socks5LocalPort());
return new Socks5(this.LocalAddress(), this.Socks5LocalPort());
}
[Verb]

View File

@@ -21,7 +21,7 @@ namespace Netch.Servers.ShadowsocksR
public string? LocalAddress { get; set; }
public Socks5.Socks5 Start(in Server s)
public Socks5 Start(in Server s)
{
var server = (ShadowsocksR)s;
@@ -42,7 +42,7 @@ namespace Netch.Servers.ShadowsocksR
};
StartGuard(command.ToString());
return new Socks5.Socks5(this.LocalAddress(), this.Socks5LocalPort());
return new Socks5(this.LocalAddress(), this.Socks5LocalPort());
}
[Verb]

View File

@@ -1,6 +1,6 @@
using Netch.Forms;
namespace Netch.Servers.Socks5.Form
namespace Netch.Servers
{
public class Socks5Form : ServerForm
{

View File

@@ -1,7 +1,7 @@
using Netch.Models;
using Netch.Servers.V2ray;
using Netch.Servers;
namespace Netch.Servers.Socks5
namespace Netch.Servers
{
public class S5Controller : V2rayController
{

View File

@@ -3,9 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.Socks5.Form;
namespace Netch.Servers.Socks5
namespace Netch.Servers
{
public class S5Util : IServerUtil
{

View File

@@ -1,6 +1,6 @@
using Netch.Models;
namespace Netch.Servers.Socks5
namespace Netch.Servers
{
public class Socks5 : Server
{

View File

@@ -1,6 +1,6 @@
using Netch.Forms;
namespace Netch.Servers.Trojan.Form
namespace Netch.Servers.Form
{
public class TrojanForm : ServerForm
{

View File

@@ -1,7 +1,7 @@
#nullable disable
using System.Collections.Generic;
namespace Netch.Servers.Trojan.Models
namespace Netch.Servers.Models
{
public class TrojanConfig
{

View File

@@ -1,6 +1,6 @@
using Netch.Models;
namespace Netch.Servers.Trojan
namespace Netch.Servers
{
public class Trojan : Server
{

View File

@@ -4,9 +4,9 @@ using System.Text.Json;
using Netch.Controllers;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.Trojan.Models;
using Netch.Servers.Models;
namespace Netch.Servers.Trojan
namespace Netch.Servers
{
public class TrojanController : Guard, IServerController
{
@@ -24,7 +24,7 @@ namespace Netch.Servers.Trojan
public string? LocalAddress { get; set; }
public Socks5.Socks5 Start(in Server s)
public Socks5 Start(in Server s)
{
var server = (Trojan)s;
var trojanConfig = new TrojanConfig
@@ -48,7 +48,7 @@ namespace Netch.Servers.Trojan
File.WriteAllBytes(Constants.TempConfig, JsonSerializer.SerializeToUtf8Bytes(trojanConfig, Global.NewDefaultJsonSerializerOptions));
StartGuard("-c ..\\data\\last.json");
return new Socks5.Socks5(this.LocalAddress(), this.Socks5LocalPort());
return new Socks5(this.LocalAddress(), this.Socks5LocalPort());
}
}
}

View File

@@ -4,9 +4,9 @@ using System.Text.RegularExpressions;
using System.Web;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.Trojan.Form;
using Netch.Servers.Form;
namespace Netch.Servers.Trojan
namespace Netch.Servers
{
public class TrojanUtil : IServerUtil
{

View File

@@ -1,7 +1,7 @@
#nullable disable
using System.Collections.Generic;
namespace Netch.Servers.V2ray.Models
namespace Netch.Servers.Models
{
public class V2rayConfig
{

View File

@@ -1,4 +1,4 @@
namespace Netch.Servers.V2ray.Models
namespace Netch.Servers.Models
{
/// <summary>
/// 使用 v2rayN 定义的 VMess 链接格式

View File

@@ -2,10 +2,10 @@
using System.Linq;
using System.Text.Json;
using Netch.Models;
using Netch.Servers.V2ray.Models;
using V2rayConfig = Netch.Servers.V2ray.Models.V2rayConfig;
using Netch.Servers.Models;
using V2rayConfig = Netch.Servers.Models.V2rayConfig;
namespace Netch.Servers.V2ray.Utils
namespace Netch.Servers.Utils
{
public static class V2rayConfigUtils
{
@@ -105,7 +105,7 @@ namespace Netch.Servers.V2ray.Utils
switch (server)
{
case Socks5.Socks5 socks5:
case Socks5 socks5:
{
outbound.settings.servers = new List<ServersItem>
{
@@ -132,7 +132,7 @@ namespace Netch.Servers.V2ray.Utils
outbound.protocol = "socks";
break;
}
case VLESS.VLESS vless:
case VLESS vless:
{
var vnextItem = new VnextItem
{

View File

@@ -3,9 +3,9 @@ using System.IO;
using Netch.Controllers;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.V2ray.Utils;
using Netch.Servers.Utils;
namespace Netch.Servers.V2ray
namespace Netch.Servers
{
public class V2rayController : Guard, IServerController
{
@@ -25,11 +25,11 @@ namespace Netch.Servers.V2ray
public string? LocalAddress { get; set; }
public virtual Socks5.Socks5 Start(in Server s)
public virtual Socks5 Start(in Server s)
{
File.WriteAllText(Constants.TempConfig, V2rayConfigUtils.GenerateClientConfig(s));
StartGuard("-config ..\\data\\last.json");
return new Socks5.Socks5(this.LocalAddress(), this.Socks5LocalPort());
return new Socks5(this.LocalAddress(), this.Socks5LocalPort());
}
}
}

View File

@@ -6,14 +6,14 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
namespace Netch.Servers.V2ray
namespace Netch.Servers
{
public static class V2rayUtils
{
public static IEnumerable<Server> ParseVUri(string text)
{
var scheme = ShareLink.GetUriScheme(text).ToLower();
var server = scheme switch { "vmess" => new VMess.VMess(), "vless" => new VLESS.VLESS(), _ => throw new ArgumentOutOfRangeException() };
var server = scheme switch { "vmess" => new VMess.VMess(), "vless" => new VLESS(), _ => throw new ArgumentOutOfRangeException() };
if (text.Contains("#"))
{
server.Remark = Uri.UnescapeDataString(text.Split('#')[1]);
@@ -54,7 +54,7 @@ namespace Netch.Servers.V2ray
{
server.Host = parameter.Get("sni") ?? "";
if (server.TLSSecureType == "xtls")
((VLESS.VLESS)server).Flow = parameter.Get("flow") ?? "";
((VLESS)server).Flow = parameter.Get("flow") ?? "";
}
}
@@ -127,7 +127,7 @@ namespace Netch.Servers.V2ray
if (server.TLSSecureType == "xtls")
{
var flow = ((VLESS.VLESS)server).Flow;
var flow = ((VLESS)server).Flow;
if (!flow.IsNullOrWhiteSpace())
parameter.Add("flow", flow!.Replace("-udp443", ""));
}

View File

@@ -1,7 +1,7 @@
using Netch.Servers.VMess;
using System.Collections.Generic;
namespace Netch.Servers.VLESS
namespace Netch.Servers
{
public class VLESS : VMess.VMess
{

View File

@@ -1,7 +1,7 @@
using Netch.Forms;
using System.Collections.Generic;
namespace Netch.Servers.VLESS.VLESSForm
namespace Netch.Servers.VLESSForm
{
internal class VLESSForm : ServerForm
{

View File

@@ -2,9 +2,9 @@ using System;
using System.Collections.Generic;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.V2ray;
using Netch.Servers;
namespace Netch.Servers.VLESS
namespace Netch.Servers
{
public class VLESSUtil : IServerUtil
{

View File

@@ -5,8 +5,8 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers.V2ray;
using Netch.Servers.V2ray.Models;
using Netch.Servers;
using Netch.Servers.Models;
using Netch.Servers.VMess.Form;
using Netch.Utils;

View File

@@ -4,11 +4,10 @@ using System.Linq;
using System.Reactive.Linq;
using Netch.Controllers;
using Netch.Enums;
using Netch.Forms;
using Netch.Interfaces;
using Netch.Models;
using Netch.Servers;
using Netch.Servers.Shadowsocks;
using Netch.Servers.Socks5;
using Serilog;
namespace Netch.Utils