diff --git a/ProxySU_Core/Models/Host.cs b/ProxySU_Core/Models/Host.cs new file mode 100644 index 0000000..c4d3fc8 --- /dev/null +++ b/ProxySU_Core/Models/Host.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySU_Core.Models +{ + public class Host + { + + + public Host() + { + Proxy = new LocalProxy(); + } + + + public string Tag { get; set; } + + public string Address { get; set; } + + public string UserName { get; set; } + + public string Password { get; set; } + + public int Port { get; set; } = 22; + + public string PrivateKeyPath { get; set; } + + public LocalProxy Proxy { get; set; } + + public LoginSecretType SecretType { get; set; } + } +} diff --git a/ProxySU_Core/Models/LocalProxy.cs b/ProxySU_Core/Models/LocalProxy.cs new file mode 100644 index 0000000..7e71c8b --- /dev/null +++ b/ProxySU_Core/Models/LocalProxy.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ProxySU_Core.Models +{ + public class LocalProxy + { + public string Address { get; set; } = "127.0.0.1"; + + public int Port { get; set; } = 1080; + + public LocalProxyType Type { get; set; } + + public string UserName { get; set; } + + public string Password { get; set; } + + } +} diff --git a/ProxySU_Core/ViewModels/LocalProxyType.cs b/ProxySU_Core/Models/LocalProxyType.cs similarity index 92% rename from ProxySU_Core/ViewModels/LocalProxyType.cs rename to ProxySU_Core/Models/LocalProxyType.cs index df6f158..c74da49 100644 --- a/ProxySU_Core/ViewModels/LocalProxyType.cs +++ b/ProxySU_Core/Models/LocalProxyType.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace ProxySU_Core.ViewModels +namespace ProxySU_Core.Models { public enum LocalProxyType { diff --git a/ProxySU_Core/ViewModels/LoginSecretType.cs b/ProxySU_Core/Models/LoginSecretType.cs similarity index 82% rename from ProxySU_Core/ViewModels/LoginSecretType.cs rename to ProxySU_Core/Models/LoginSecretType.cs index e897261..66c2602 100644 --- a/ProxySU_Core/ViewModels/LoginSecretType.cs +++ b/ProxySU_Core/Models/LoginSecretType.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace ProxySU_Core.ViewModels +namespace ProxySU_Core.Models { public enum LoginSecretType { diff --git a/ProxySU_Core/Models/Record.cs b/ProxySU_Core/Models/Record.cs new file mode 100644 index 0000000..091ac2f --- /dev/null +++ b/ProxySU_Core/Models/Record.cs @@ -0,0 +1,24 @@ +using ProxySU_Core.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ProxySU_Core.Models +{ + public class Record + { + public Record() + { + + } + + public Record(Host host) + { + this.Host = host; + } + + public Host Host { get; set; } = new Host(); + + public XraySettings Settings { get; set; } = new XraySettings(); + } +} diff --git a/ProxySU_Core/ViewModels/Developers/XrayParameters.cs b/ProxySU_Core/Models/XraySettings.cs similarity index 56% rename from ProxySU_Core/ViewModels/Developers/XrayParameters.cs rename to ProxySU_Core/Models/XraySettings.cs index 4c47c32..683b278 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayParameters.cs +++ b/ProxySU_Core/Models/XraySettings.cs @@ -1,11 +1,28 @@ -using System; +using ProxySU_Core.ViewModels.Developers; +using System; using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading.Tasks; -namespace ProxySU_Core.ViewModels.Developers +namespace ProxySU_Core.Models { - public class XrayParameters : IParameters + public class XraySettings : IParameters { + + public XraySettings() + { + Port = 443; + UUID = Guid.NewGuid().ToString(); + Types = new List { XrayType.VLESS_TCP_XTLS }; + VLESS_WS_Path = "/vlessws"; + VLESS_TCP_Path = "/vlesstcp"; + VMESS_WS_Path = "/vmessws"; + VMESS_TCP_Path = "/vmesstcp"; + Trojan_TCP_Path = "/trojan"; + TrojanPassword = Guid.NewGuid().ToString(); + } + /// /// 访问端口 /// @@ -19,27 +36,27 @@ namespace ProxySU_Core.ViewModels.Developers /// /// vless ws路径 /// - public string VlessWsPath { get; set; } + public string VLESS_WS_Path { get; set; } /// /// vless tcp路径 /// - public string VlessTcpPath { get; set; } + public string VLESS_TCP_Path { get; set; } /// /// vmess ws路径 /// - public string VmessWsPath { get; set; } + public string VMESS_WS_Path { get; set; } /// /// vmess tcp路径 /// - public string VmessTcpPath { get; set; } + public string VMESS_TCP_Path { get; set; } /// /// trojan tcp路径 /// - public string TrojanTcpPath { get; set; } + public string Trojan_TCP_Path { get; set; } /// /// trojan密码 @@ -59,25 +76,25 @@ namespace ProxySU_Core.ViewModels.Developers /// /// 安装类型 /// - public XrayType Type { get; set; } + public List Types { get; set; } - public string GetPath() + public string GetPath(XrayType type) { - switch (Type) + switch (type) { case XrayType.VLESS_TCP_TLS: - return VlessTcpPath; + return VLESS_TCP_Path; case XrayType.VLESS_TCP_XTLS: - return VlessTcpPath; + return VLESS_TCP_Path; case XrayType.VLESS_WS_TLS: - return VlessWsPath; + return VLESS_WS_Path; case XrayType.VMESS_TCP_TLS: - return VmessTcpPath; + return VMESS_TCP_Path; case XrayType.VMESS_WS_TLS: - return VmessWsPath; + return VMESS_WS_Path; case XrayType.Trojan_TCP_TLS: - return TrojanTcpPath; + return Trojan_TCP_Path; default: return string.Empty; } diff --git a/ProxySU_Core/ProxySU_Core.csproj b/ProxySU_Core/ProxySU_Core.csproj index f40e48b..167bf91 100644 --- a/ProxySU_Core/ProxySU_Core.csproj +++ b/ProxySU_Core/ProxySU_Core.csproj @@ -182,35 +182,36 @@ App.xaml Code + + + + - + - - - - - - + + + + + + - - HostEditorWindow.xaml - + MainWindow.xaml + + RecordEditorWindow.xaml + TerminalWindow.xaml - - XrayWindow.xaml - - Code @@ -282,22 +283,18 @@ MSBuild:Compile Designer - - MSBuild:Compile - Designer - MSBuild:Compile Designer + + Designer + MSBuild:Compile + MSBuild:Compile Designer - - Designer - MSBuild:Compile - diff --git a/ProxySU_Core/Resources/Languages/en.xaml b/ProxySU_Core/Resources/Languages/en.xaml index 47fb3c3..5058372 100644 --- a/ProxySU_Core/Resources/Languages/en.xaml +++ b/ProxySU_Core/Resources/Languages/en.xaml @@ -10,6 +10,7 @@ Actions Connect Edit + Edit Xray Delete Install Save diff --git a/ProxySU_Core/Resources/Languages/zh_cn.xaml b/ProxySU_Core/Resources/Languages/zh_cn.xaml index 505c9aa..7031dfd 100644 --- a/ProxySU_Core/Resources/Languages/zh_cn.xaml +++ b/ProxySU_Core/Resources/Languages/zh_cn.xaml @@ -11,6 +11,7 @@ 连接 安装 编辑 + 编辑模板 删除 保存 消息 diff --git a/ProxySU_Core/Tools/Extensions.cs b/ProxySU_Core/Tools/Extensions.cs new file mode 100644 index 0000000..1c4af48 --- /dev/null +++ b/ProxySU_Core/Tools/Extensions.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Threading.Tasks; + +namespace System +{ + public static class Extensions + { + // Deep clone + public static T DeepClone(this T obj) + { + if (obj == null) + throw new ArgumentNullException("Object cannot be null"); + return (T)Process(obj); + } + + static object Process(object obj) + { + if (obj == null) + return null; + Type type = obj.GetType(); + if (type.IsValueType || type == typeof(string)) + { + return obj; + } + else if (type.IsArray) + { + Type elementType = Type.GetType( + type.FullName.Replace("[]", string.Empty)); + var array = obj as Array; + Array copied = Array.CreateInstance(elementType, array.Length); + for (int i = 0; i < array.Length; i++) + { + copied.SetValue(Process(array.GetValue(i)), i); + } + return Convert.ChangeType(copied, obj.GetType()); + } + else if (type.IsClass) + { + object toret = Activator.CreateInstance(obj.GetType()); + FieldInfo[] fields = type.GetFields(BindingFlags.Public | + BindingFlags.NonPublic | BindingFlags.Instance); + foreach (FieldInfo field in fields) + { + object fieldValue = field.GetValue(obj); + if (fieldValue == null) + continue; + field.SetValue(toret, Process(fieldValue)); + } + return toret; + } + else + throw new ArgumentException("Unknown type"); + } + + } +} diff --git a/ProxySU_Core/ViewModels/BaseModel.cs b/ProxySU_Core/ViewModels/BaseViewModel.cs similarity index 87% rename from ProxySU_Core/ViewModels/BaseModel.cs rename to ProxySU_Core/ViewModels/BaseViewModel.cs index 88d3837..1aa2f1c 100644 --- a/ProxySU_Core/ViewModels/BaseModel.cs +++ b/ProxySU_Core/ViewModels/BaseViewModel.cs @@ -5,7 +5,7 @@ using System.Text; namespace ProxySU_Core.ViewModels { - public abstract class BaseModel : INotifyPropertyChanged + public abstract class BaseViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; diff --git a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs index 6bc02f8..1e954dd 100644 --- a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs +++ b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using ProxySU_Core.Models; using System; using System.Collections.Generic; using System.IO; @@ -57,11 +58,9 @@ namespace ProxySU_Core.ViewModels.Developers stats = statsObj["stats"], reverse = reverseObj["reverse"] }; - - } - public static string BuildCaddyConfig(XrayParameters parameters) + public static string BuildCaddyConfig(XraySettings parameters) { var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile")); caddyStr.Replace("##domain##", parameters.Domain); @@ -77,11 +76,11 @@ namespace ProxySU_Core.ViewModels.Developers return caddyStr; } - public static string BuildXrayConfig(XrayParameters parameters) + public static string BuildXrayConfig(XraySettings parameters) { var xrayConfig = LoadXrayConfig(); var baseBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VLESS_TCP_XTLS.json")); - baseBound["port"] = VLESS_TCP_Port; + baseBound["port"] = parameters.Port; baseBound["settings"]["fallbacks"].Add(new { dest = 80, @@ -89,64 +88,69 @@ namespace ProxySU_Core.ViewModels.Developers }); xrayConfig["inbounds"].Add(baseBound); - switch (parameters.Type) + if (parameters.Types.Contains(XrayType.VLESS_TCP_XTLS)) { - case XrayType.VLESS_TCP_TLS: - case XrayType.VLESS_TCP_XTLS: - baseBound["settings"]["clients"][0]["id"] = parameters.UUID; - break; - case XrayType.VLESS_WS_TLS: - var wsInbound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VLESS_WS_TLS.json")); - wsInbound["port"] = VLESS_WS_Port; - wsInbound["settings"]["clients"][0]["id"] = parameters.UUID; - wsInbound["streamSettings"]["wsSettings"]["path"] = parameters.VlessWsPath; - baseBound["settings"]["fallbacks"].Add(new - { - dest = VLESS_WS_Port, - path = parameters.VlessWsPath, - xver = 1, - }); - xrayConfig["inbounds"].Add(wsInbound); - break; - case XrayType.VMESS_TCP_TLS: - var mtcpBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VMESS_TCP_TLS.json")); - mtcpBound["port"] = VMESS_TCP_Port; - mtcpBound["settings"]["clients"][0]["id"] = parameters.UUID; - mtcpBound["streamSettings"]["tcpSettings"]["header"]["request"]["path"] = parameters.VmessTcpPath; - baseBound["settings"]["fallbacks"].Add(new - { - dest = VMESS_TCP_Port, - path = parameters.VmessTcpPath, - xver = 1, - }); - xrayConfig["inbounds"].Add(mtcpBound); - break; - case XrayType.VMESS_WS_TLS: - var mwsBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VMESS_WS_TLS.json")); - mwsBound["port"] = VMESS_WS_Port; - mwsBound["settings"]["clients"][0]["id"] = parameters.UUID; - mwsBound["streamSettings"]["wsSettings"]["path"] = parameters.VmessWsPath; - baseBound["settings"]["fallbacks"].Add(new - { - dest = VMESS_WS_Port, - path = parameters.VmessWsPath, - xver = 1, - }); - xrayConfig["inbounds"].Add(mwsBound); - break; - case XrayType.Trojan_TCP_TLS: - var trojanTcpBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "Trojan_TCP_TLS.json")); - trojanTcpBound["port"] = Trojan_TCP_Port; - trojanTcpBound["settings"]["clients"][0]["password"] = parameters.TrojanPassword; - baseBound["settings"]["fallbacks"][0] = new - { - dest = Trojan_TCP_Port, - xver = 1, - }; - xrayConfig["inbounds"].Add(trojanTcpBound); - break; - default: - break; + baseBound["settings"]["clients"][0]["id"] = parameters.UUID; + } + + if (parameters.Types.Contains(XrayType.VLESS_WS_TLS)) + { + baseBound["settings"]["clients"][0]["id"] = parameters.UUID; + + var wsInbound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VLESS_WS_TLS.json")); + wsInbound["port"] = VLESS_WS_Port; + wsInbound["settings"]["clients"][0]["id"] = parameters.UUID; + wsInbound["streamSettings"]["wsSettings"]["path"] = parameters.VLESS_WS_Path; + baseBound["settings"]["fallbacks"].Add(new + { + dest = VLESS_WS_Port, + path = parameters.VLESS_WS_Path, + xver = 1, + }); + xrayConfig["inbounds"].Add(wsInbound); + } + + if (parameters.Types.Contains(XrayType.VMESS_TCP_TLS)) + { + var mtcpBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VMESS_TCP_TLS.json")); + mtcpBound["port"] = VMESS_TCP_Port; + mtcpBound["settings"]["clients"][0]["id"] = parameters.UUID; + mtcpBound["streamSettings"]["tcpSettings"]["header"]["request"]["path"] = parameters.VMESS_TCP_Path; + baseBound["settings"]["fallbacks"].Add(new + { + dest = VMESS_TCP_Port, + path = parameters.VMESS_TCP_Path, + xver = 1, + }); + xrayConfig["inbounds"].Add(mtcpBound); + } + + if (parameters.Types.Contains(XrayType.VMESS_WS_TLS)) + { + var mwsBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VMESS_WS_TLS.json")); + mwsBound["port"] = VMESS_WS_Port; + mwsBound["settings"]["clients"][0]["id"] = parameters.UUID; + mwsBound["streamSettings"]["wsSettings"]["path"] = parameters.VMESS_WS_Path; + baseBound["settings"]["fallbacks"].Add(new + { + dest = VMESS_WS_Port, + path = parameters.VMESS_WS_Path, + xver = 1, + }); + xrayConfig["inbounds"].Add(mwsBound); + } + + if (parameters.Types.Contains(XrayType.Trojan_TCP_TLS)) + { + var trojanTcpBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "Trojan_TCP_TLS.json")); + trojanTcpBound["port"] = Trojan_TCP_Port; + trojanTcpBound["settings"]["clients"][0]["password"] = parameters.TrojanPassword; + baseBound["settings"]["fallbacks"][0] = new + { + dest = Trojan_TCP_Port, + xver = 1, + }; + xrayConfig["inbounds"].Add(trojanTcpBound); } return JsonConvert.SerializeObject(xrayConfig, Formatting.Indented); diff --git a/ProxySU_Core/ViewModels/Developers/Project.cs b/ProxySU_Core/ViewModels/Developers/Project.cs index de90a6a..60e6cae 100644 --- a/ProxySU_Core/ViewModels/Developers/Project.cs +++ b/ProxySU_Core/ViewModels/Developers/Project.cs @@ -19,7 +19,7 @@ namespace ProxySU_Core.ViewModels.Developers Yum } - public abstract class Project : BaseModel where TParameters : IParameters + public abstract class Project : BaseViewModel where TParameters : IParameters { private SshClient _sshClient; diff --git a/ProxySU_Core/ViewModels/Developers/XrayProject.cs b/ProxySU_Core/ViewModels/Developers/XrayProject.cs index 34359d5..1c3e0fc 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayProject.cs +++ b/ProxySU_Core/ViewModels/Developers/XrayProject.cs @@ -6,10 +6,11 @@ using System.Text; using System.Windows; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using ProxySU_Core.Models; namespace ProxySU_Core.ViewModels.Developers { - public class XrayProject : Project + public class XrayProject : Project { private const string ServerLogDir = @"Templates\xray\server\00_log"; @@ -24,7 +25,7 @@ namespace ProxySU_Core.ViewModels.Developers private const string ServerReverseDir = @"Templates\xray\server\09_reverse"; private const string CaddyFileDir = @"Templates\xray\caddy"; - public XrayProject(SshClient sshClient, XrayParameters parameters, Action writeOutput) : base(sshClient, parameters, writeOutput) + public XrayProject(SshClient sshClient, XraySettings parameters, Action writeOutput) : base(sshClient, parameters, writeOutput) { } diff --git a/ProxySU_Core/ViewModels/Host.cs b/ProxySU_Core/ViewModels/HostViewModel.cs similarity index 68% rename from ProxySU_Core/ViewModels/Host.cs rename to ProxySU_Core/ViewModels/HostViewModel.cs index d2af885..1d06af0 100644 --- a/ProxySU_Core/ViewModels/Host.cs +++ b/ProxySU_Core/ViewModels/HostViewModel.cs @@ -1,5 +1,6 @@ using Microsoft.Win32; using Newtonsoft.Json; +using ProxySU_Core.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -8,66 +9,79 @@ using System.Windows.Input; namespace ProxySU_Core.ViewModels { - public class Host : BaseModel + public class HostViewModel : BaseViewModel { - private LoginSecretType _secretType; - private string tag = string.Empty; - private string _address; - private LocalProxy proxy; + public Host host; + private readonly ICommand _selectKeyCommand; - public Host() + public HostViewModel(Host host) { _selectKeyCommand = new BaseCommand(obj => OpenFileDialog(obj)); - Proxy = new LocalProxy(); + this.host = host; } public string Tag { - get => tag; set + get => host.Tag; + set { - tag = value; + host.Tag = value; Notify("Tag"); } } public string Address { - get => _address; + get => host.Address; set { - _address = value; + host.Address = value; Notify("Address"); } } - public string UserName { get; set; } + public string UserName + { + get => host.UserName; + set => host.UserName = value; + } - public string Password { get; set; } + public string Password + { + get => host.Password; + set => host.Password = value; + } - public int Port { get; set; } = 22; + public int Port + { + get => host.Port; + set => host.Port = value; + } - public string PrivateKeyPath { get; set; } + public string PrivateKeyPath + { + get => host.PrivateKeyPath; + set => host.PrivateKeyPath = value; + } public LocalProxy Proxy { - get => proxy; set + get => host.Proxy; + set { - proxy = value; + host.Proxy = value; Notify("Proxy"); } } public LoginSecretType SecretType { - get - { - return _secretType; - } + get => host.SecretType; set { - _secretType = value; + host.SecretType = value; Notify("SecretType"); Notify("KeyUploaderVisiblity"); Notify("PasswordVisiblity"); diff --git a/ProxySU_Core/ViewModels/LocalProxy.cs b/ProxySU_Core/ViewModels/LocalProxy.cs deleted file mode 100644 index c6984ca..0000000 --- a/ProxySU_Core/ViewModels/LocalProxy.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ProxySU_Core.ViewModels -{ - public class LocalProxy : BaseModel - { - private LocalProxyType type = LocalProxyType.None; - - public string Address { get; set; } = "127.0.0.1"; - - public int Port { get; set; } = 1080; - - public LocalProxyType Type - { - get => type; set - { - type = value; - Notify("Type"); - } - - } - - public string UserName { get; set; } - - public string Password { get; set; } - - } - - -} diff --git a/ProxySU_Core/ViewModels/Record.cs b/ProxySU_Core/ViewModels/Record.cs deleted file mode 100644 index 9f6af0d..0000000 --- a/ProxySU_Core/ViewModels/Record.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ProxySU_Core.ViewModels -{ - public class Record - { - public Host Host { get; set; } - - } -} diff --git a/ProxySU_Core/ViewModels/RecordViewModel.cs b/ProxySU_Core/ViewModels/RecordViewModel.cs new file mode 100644 index 0000000..717a5f6 --- /dev/null +++ b/ProxySU_Core/ViewModels/RecordViewModel.cs @@ -0,0 +1,40 @@ +using ProxySU_Core.Models; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySU_Core.ViewModels +{ + public class RecordViewModel : BaseViewModel + { + public Record record; + + public RecordViewModel(Record record) + { + this.record = record; + } + + public Host Host + { + get => record.Host; + set + { + record.Host = value; + Notify("Host"); + } + } + + public XraySettings Settings + { + get => record.Settings; + set + { + record.Settings = value; + Notify("Settings"); + } + } + } +} diff --git a/ProxySU_Core/ViewModels/Terminal.cs b/ProxySU_Core/ViewModels/Terminal.cs index 63a2cad..4c5028b 100644 --- a/ProxySU_Core/ViewModels/Terminal.cs +++ b/ProxySU_Core/ViewModels/Terminal.cs @@ -1,11 +1,12 @@ -using System; +using ProxySU_Core.Models; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; namespace ProxySU_Core.ViewModels { - public class Terminal : BaseModel + public class Terminal : BaseViewModel { private string outputText; diff --git a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs new file mode 100644 index 0000000..daa09aa --- /dev/null +++ b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs @@ -0,0 +1,237 @@ +using ProxySU_Core.Models; +using ProxySU_Core.ViewModels.Developers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySU_Core.ViewModels +{ + public class XraySettingsViewModel : BaseViewModel + { + private XraySettings p; + + public XraySettingsViewModel(XraySettings parameters) + { + this.p = parameters; + } + + public string UUID + { + get => p.UUID; + set => p.UUID = value; + } + + public string Domain + { + get => p.Domain; + set => p.Domain = value; + } + + public string MaskDomain + { + get => p.MaskDomain; + set => p.MaskDomain = value; + } + + public string VLESS_TCP_Path + { + get => p.VLESS_TCP_Path; + set => p.VLESS_TCP_Path = value; + } + + public string VLESS_WS_Path + { + get => p.VLESS_WS_Path; + set => p.VLESS_WS_Path = value; + } + + public string VMESS_TCP_Path + { + get => p.VMESS_TCP_Path; + set => p.VMESS_TCP_Path = value; + } + + public string VMESS_WS_Path + { + get => p.VMESS_WS_Path; + set => p.VMESS_WS_Path = value; + } + + public string Trojan_TCP_Path + { + get => p.Trojan_TCP_Path; + set => p.Trojan_TCP_Path = value; + } + + public string TrojanPassword + { + get => p.TrojanPassword; + set => p.TrojanPassword = value; + } + + public bool Checked_VLESS_TCP + { + get + { + return p.Types.Contains(XrayType.VLESS_TCP_TLS); + } + set + { + if (value == true) + { + p.Types.Add(XrayType.VLESS_TCP_TLS); + } + else + { + p.Types.Remove(XrayType.VLESS_TCP_TLS); + } + Notify("Checked_VLESS_TCP"); + Notify("VLESS_TCP_Path_Visibility"); + } + } + + public bool Checked_VLESS_XTLS + { + get + { + return p.Types.Contains(XrayType.VLESS_TCP_XTLS); + } + set + { + if (value == true) + { + p.Types.Add(XrayType.VLESS_TCP_XTLS); + } + else + { + p.Types.Remove(XrayType.VLESS_TCP_XTLS); + } + Notify("Checked_VLESS_XTLS"); + } + } + + public bool Checked_VLESS_WS + { + get + { + return p.Types.Contains(XrayType.VLESS_WS_TLS); + } + set + { + if (value == true) + { + p.Types.Add(XrayType.VLESS_WS_TLS); + } + else + { + p.Types.Remove(XrayType.VLESS_WS_TLS); + } + Notify("Checked_VLESS_WS"); + Notify("VLESS_WS_Path_Visibility"); + } + } + + public bool Checked_VMESS_TCP + { + get + { + return p.Types.Contains(XrayType.VMESS_TCP_TLS); + } + set + { + if (value == true) + { + p.Types.Add(XrayType.VMESS_TCP_TLS); + } + else + { + p.Types.Remove(XrayType.VMESS_TCP_TLS); + } + Notify("Checked_VMESS_TCP"); + Notify("VMESS_TCP_Path_Visibility"); + } + } + + public bool Checked_VMESS_WS + { + get + { + return p.Types.Contains(XrayType.VMESS_WS_TLS); + } + set + { + if (value == true) + { + p.Types.Add(XrayType.VMESS_WS_TLS); + } + else + { + p.Types.Remove(XrayType.VMESS_WS_TLS); + } + Notify("Checked_VMESS_WS"); + Notify("VMESS_WS_Path_Visibility"); + } + } + + public bool Checked_Trojan_TCP + { + get + { + return p.Types.Contains(XrayType.Trojan_TCP_TLS); + } + set + { + if (value == true) + { + p.Types.Add(XrayType.Trojan_TCP_TLS); + } + else + { + p.Types.Remove(XrayType.Trojan_TCP_TLS); + } + Notify("Checked_Trojan_TCP"); + Notify("Trojan_TCP_Path_Visibility"); + } + } + + public Visibility VLESS_TCP_Path_Visibility + { + get + { + return Checked_VLESS_TCP ? Visibility.Visible : Visibility.Hidden; + } + } + public Visibility VLESS_WS_Path_Visibility + { + get + { + return Checked_VLESS_WS ? Visibility.Visible : Visibility.Hidden; + } + } + public Visibility VMESS_TCP_Path_Visibility + { + get + { + return Checked_VMESS_TCP ? Visibility.Visible : Visibility.Hidden; + } + } + public Visibility VMESS_WS_Path_Visibility + { + get + { + return Checked_VMESS_WS ? Visibility.Visible : Visibility.Hidden; + } + } + public Visibility Trojan_TCP_Path_Visibility + { + get + { + return Checked_Trojan_TCP ? Visibility.Visible : Visibility.Hidden; + } + } + + } +} diff --git a/ProxySU_Core/Views/HostEditorWindow.xaml b/ProxySU_Core/Views/HostEditorWindow.xaml deleted file mode 100644 index d343726..0000000 --- a/ProxySU_Core/Views/HostEditorWindow.xaml +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/ProxySU_Core/Views/RecordEditorWindow.xaml.cs b/ProxySU_Core/Views/RecordEditorWindow.xaml.cs new file mode 100644 index 0000000..e9cd021 --- /dev/null +++ b/ProxySU_Core/Views/RecordEditorWindow.xaml.cs @@ -0,0 +1,42 @@ +using ProxySU_Core.Models; +using ProxySU_Core.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace ProxySU_Core.Views +{ + /// + /// RecordEditorWindow.xaml 的交互逻辑 + /// + public partial class RecordEditorWindow + { + public Record Record { get; set; } + + public HostViewModel Host { get; set; } + + public XraySettingsViewModel Settings { get; set; } + + public RecordEditorWindow(Record record) + { + InitializeComponent(); + ResizeMode = ResizeMode.NoResize; + WindowStartupLocation = WindowStartupLocation.CenterScreen; + + this.Record = record; + Host = new HostViewModel(record.Host.DeepClone()); + Settings = new XraySettingsViewModel(record.Settings.DeepClone()); + this.DataContext = this; + } + } +} diff --git a/ProxySU_Core/Views/TerminalWindow.xaml.cs b/ProxySU_Core/Views/TerminalWindow.xaml.cs index 828f95b..748fb8e 100644 --- a/ProxySU_Core/Views/TerminalWindow.xaml.cs +++ b/ProxySU_Core/Views/TerminalWindow.xaml.cs @@ -1,4 +1,5 @@ using MahApps.Metro.Controls.Dialogs; +using ProxySU_Core.Models; using ProxySU_Core.ViewModels; using ProxySU_Core.ViewModels.Developers; using ProxySU_Core.Views; @@ -30,6 +31,8 @@ namespace ProxySU_Core public TerminalWindow(Record project) { InitializeComponent(); + ResizeMode = ResizeMode.NoResize; + WindowStartupLocation = WindowStartupLocation.CenterScreen; _vm = new Terminal(project.Host); DataContext = _vm; @@ -107,9 +110,6 @@ namespace ProxySU_Core private void Install(object sender, RoutedEventArgs e) { - var xrayWindow = new XrayWindow(); - xrayWindow.ShowDialog(); - } diff --git a/ProxySU_Core/Views/XrayWindow.xaml b/ProxySU_Core/Views/XrayWindow.xaml deleted file mode 100644 index 348aeb9..0000000 --- a/ProxySU_Core/Views/XrayWindow.xaml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - diff --git a/ProxySU_Core/Views/XrayWindow.xaml.cs b/ProxySU_Core/Views/XrayWindow.xaml.cs deleted file mode 100644 index 51acdcb..0000000 --- a/ProxySU_Core/Views/XrayWindow.xaml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace ProxySU_Core.Views -{ - /// - /// XrayWindow.xaml 的交互逻辑 - /// - public partial class XrayWindow - { - public XrayWindow() - { - InitializeComponent(); - } - } -}