mirror of
https://github.com/netchx/netch.git
synced 2026-04-03 19:35:10 +08:00
ComboBox 绑定数据
This commit is contained in:
@@ -68,8 +68,8 @@ namespace Netch.Forms
|
||||
while (State == State.Started)
|
||||
{
|
||||
server.Test();
|
||||
// 重载服务器列表
|
||||
InitServer();
|
||||
// 重绘 ServerComboBox
|
||||
ServerComboBox.Invalidate();
|
||||
|
||||
Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000);
|
||||
}
|
||||
|
||||
2
Netch/Forms/MainForm.Designer.cs
generated
2
Netch/Forms/MainForm.Designer.cs
generated
@@ -764,7 +764,7 @@ namespace Netch.Forms
|
||||
private System.Windows.Forms.ToolStripMenuItem ImportServersFromClipboardToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem ManageSubscribeLinksToolStripMenuItem;
|
||||
private System.Windows.Forms.MenuStrip MenuStrip;
|
||||
private System.Windows.Forms.SearchComboBox ModeComboBox;
|
||||
public System.Windows.Forms.SearchComboBox ModeComboBox;
|
||||
private System.Windows.Forms.Label ModeLabel;
|
||||
private System.Windows.Forms.ToolStripMenuItem ModeToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem HelpToolStripMenuItem;
|
||||
|
||||
@@ -35,14 +35,16 @@ namespace Netch.Forms
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
Global.Settings.Server.AddRange(result);
|
||||
foreach (var server in result)
|
||||
{
|
||||
Global.Settings.Server.Add(server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("Import servers error!"), LogLevel.ERROR);
|
||||
}
|
||||
|
||||
InitServer();
|
||||
Configuration.Save();
|
||||
}
|
||||
}
|
||||
@@ -61,6 +63,7 @@ namespace Netch.Forms
|
||||
|
||||
Hide();
|
||||
form?.ShowDialog();
|
||||
Configuration.Save();
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -75,16 +78,12 @@ namespace Netch.Forms
|
||||
Show();
|
||||
}
|
||||
|
||||
private async void ReloadModesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void ReloadModesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Enabled = false;
|
||||
try
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
SaveConfigs();
|
||||
InitMode();
|
||||
});
|
||||
Modes.Load();
|
||||
NotifyTip(i18N.Translate("Modes have been reload"));
|
||||
}
|
||||
catch (Exception)
|
||||
@@ -105,7 +104,6 @@ namespace Netch.Forms
|
||||
{
|
||||
Hide();
|
||||
new SubscribeForm().ShowDialog();
|
||||
InitServer();
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -170,13 +168,19 @@ namespace Netch.Forms
|
||||
|
||||
lock (serverLock)
|
||||
{
|
||||
Global.Settings.Server = Global.Settings.Server.Where(server => server.Group != item.Remark).ToList();
|
||||
foreach (var server in Global.Settings.Server.Where(server => server.Group == item.Remark))
|
||||
{
|
||||
Global.Settings.Server.Remove(server);
|
||||
}
|
||||
|
||||
var result = ShareLink.Parse(str);
|
||||
if (result != null)
|
||||
{
|
||||
foreach (var x in result) x.Group = item.Remark;
|
||||
|
||||
Global.Settings.Server.AddRange(result);
|
||||
foreach (var server in result)
|
||||
{
|
||||
server.Group = item.Remark;
|
||||
Global.Settings.Server.Add(server);
|
||||
}
|
||||
}
|
||||
|
||||
NotifyTip(i18N.TranslateFormat("Update {1} server(s) from {0}", item.Remark, result?.Count ?? 0));
|
||||
@@ -193,7 +197,6 @@ namespace Netch.Forms
|
||||
})).ToArray());
|
||||
|
||||
Configuration.Save();
|
||||
await Task.Run(InitServer);
|
||||
StatusText(i18N.Translate("Subscription updated"));
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
@@ -29,11 +29,8 @@ namespace Netch.Forms
|
||||
}
|
||||
}
|
||||
|
||||
public void InitServer()
|
||||
public void SelectLastServer()
|
||||
{
|
||||
ServerComboBox.Items.Clear();
|
||||
ServerComboBox.Items.AddRange(Global.Settings.Server.ToArray());
|
||||
|
||||
// 如果值合法,选中该位置
|
||||
if (Global.Settings.ServerComboBoxSelectedIndex > 0 &&
|
||||
Global.Settings.ServerComboBoxSelectedIndex < ServerComboBox.Items.Count)
|
||||
@@ -53,18 +50,7 @@ namespace Netch.Forms
|
||||
|
||||
#region Mode
|
||||
|
||||
public void InitMode()
|
||||
{
|
||||
ModeComboBox.Items.Clear();
|
||||
|
||||
Modes.Load();
|
||||
|
||||
ModeComboBox.Items.AddRange(Global.Modes.ToArray());
|
||||
|
||||
SelectLastMode();
|
||||
}
|
||||
|
||||
private void SelectLastMode()
|
||||
public void SelectLastMode()
|
||||
{
|
||||
// 如果值合法,选中该位置
|
||||
if (Global.Settings.ModeComboBoxSelectedIndex > 0 &&
|
||||
@@ -81,17 +67,6 @@ namespace Netch.Forms
|
||||
// 如果当前 ModeComboBox 中没元素,不做处理
|
||||
}
|
||||
|
||||
public void AddMode(Models.Mode mode)
|
||||
{
|
||||
ModeComboBox.Items.Clear();
|
||||
Global.Modes.Add(mode);
|
||||
var array = Global.Modes.ToArray();
|
||||
Array.Sort(array, (a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
|
||||
ModeComboBox.Items.AddRange(array);
|
||||
|
||||
SelectLastMode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,35 +31,18 @@ namespace Netch.Forms
|
||||
CheckForIllegalCrossThreadCalls = false;
|
||||
}
|
||||
|
||||
private void SaveConfigs()
|
||||
{
|
||||
Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex;
|
||||
if (ModeComboBox.Items.Count != 0 && ModeComboBox.SelectedItem != null)
|
||||
{
|
||||
if (ModeComboBox.Tag is object[] list)
|
||||
{
|
||||
Global.Settings.ModeComboBoxSelectedIndex = list.ToList().IndexOf(ModeComboBox.SelectedItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.Settings.ModeComboBoxSelectedIndex = ModeComboBox.Items.IndexOf(ModeComboBox.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
OnlyInstance.Called += OnCalled;
|
||||
// 计算 ComboBox绘制 目标宽度
|
||||
_eWidth = ServerComboBox.Width / 10;
|
||||
|
||||
// 加载服务器
|
||||
InitServer();
|
||||
Modes.Load();
|
||||
ServerComboBox.DataSource = Global.Settings.Server;
|
||||
|
||||
// 加载模式
|
||||
InitMode();
|
||||
SaveSelectIndex = true;
|
||||
SelectLastMode();
|
||||
SelectLastServer();
|
||||
|
||||
// 加载翻译
|
||||
InitText();
|
||||
@@ -250,7 +233,7 @@ namespace Netch.Forms
|
||||
ControlFun();
|
||||
}
|
||||
|
||||
SaveConfigs();
|
||||
Configuration.Save();
|
||||
State = State.Terminating;
|
||||
}
|
||||
|
||||
@@ -282,28 +265,26 @@ namespace Netch.Forms
|
||||
|
||||
private void EditServerPictureBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveConfigs();
|
||||
// 当前ServerComboBox中至少有一项
|
||||
if (ServerComboBox.SelectedIndex != -1)
|
||||
{
|
||||
Form server = Global.Settings.Server[ServerComboBox.SelectedIndex].Type switch
|
||||
{
|
||||
"Socks5" => new Socks5(ServerComboBox.SelectedIndex),
|
||||
"SS" => new Shadowsocks(ServerComboBox.SelectedIndex),
|
||||
"SSR" => new ShadowsocksR(ServerComboBox.SelectedIndex),
|
||||
"VMess" => new VMess(ServerComboBox.SelectedIndex),
|
||||
"Trojan" => new Trojan(ServerComboBox.SelectedIndex),
|
||||
_ => null
|
||||
};
|
||||
Hide();
|
||||
server?.ShowDialog();
|
||||
InitServer();
|
||||
Show();
|
||||
}
|
||||
else
|
||||
if (ServerComboBox.SelectedIndex == -1)
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("Please select a server first"));
|
||||
return;
|
||||
}
|
||||
|
||||
Form server = Global.Settings.Server[ServerComboBox.SelectedIndex].Type switch
|
||||
{
|
||||
"Socks5" => new Socks5(Global.Settings.Server[ServerComboBox.SelectedIndex]),
|
||||
"SS" => new Shadowsocks(Global.Settings.Server[ServerComboBox.SelectedIndex]),
|
||||
"SSR" => new ShadowsocksR(Global.Settings.Server[ServerComboBox.SelectedIndex]),
|
||||
"VMess" => new VMess(Global.Settings.Server[ServerComboBox.SelectedIndex]),
|
||||
"Trojan" => new Trojan(Global.Settings.Server[ServerComboBox.SelectedIndex]),
|
||||
_ => null
|
||||
};
|
||||
Hide();
|
||||
server?.ShowDialog();
|
||||
Configuration.Save();
|
||||
Show();
|
||||
}
|
||||
|
||||
private async void SpeedPictureBox_Click(object sender, EventArgs e)
|
||||
@@ -332,20 +313,14 @@ namespace Netch.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
SaveConfigs();
|
||||
var selectedMode = (Models.Mode) ModeComboBox.SelectedItem;
|
||||
switch (selectedMode.Type)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
var process = new Process(selectedMode);
|
||||
process.Show();
|
||||
Hide();
|
||||
process.FormClosed += (o, args) =>
|
||||
{
|
||||
InitMode();
|
||||
Show();
|
||||
};
|
||||
new Process(selectedMode).ShowDialog();
|
||||
Show();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -359,70 +334,56 @@ namespace Netch.Forms
|
||||
private void DeleteModePictureBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 当前ModeComboBox中至少有一项
|
||||
if (ModeComboBox.Items.Count > 0 && ModeComboBox.SelectedIndex != -1)
|
||||
{
|
||||
var selectedMode = (Models.Mode) ModeComboBox.SelectedItem;
|
||||
|
||||
//删除模式文件
|
||||
selectedMode.DeleteFile("mode");
|
||||
|
||||
ModeComboBox.Items.Clear();
|
||||
Global.Modes.Remove(selectedMode);
|
||||
var array = Global.Modes.ToArray();
|
||||
Array.Sort(array, (a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
|
||||
ModeComboBox.Items.AddRange(array);
|
||||
|
||||
SelectLastMode();
|
||||
Configuration.Save();
|
||||
}
|
||||
else
|
||||
if (ModeComboBox.Items.Count <= 0 || ModeComboBox.SelectedIndex == -1)
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("Please select a mode first"));
|
||||
return;
|
||||
}
|
||||
|
||||
Modes.Delete(ModeComboBox.SelectedItem as Models.Mode);
|
||||
|
||||
SelectLastMode();
|
||||
}
|
||||
|
||||
private void CopyLinkPictureBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 当前ServerComboBox中至少有一项
|
||||
if (ServerComboBox.SelectedIndex != -1)
|
||||
{
|
||||
var selectedMode = (Models.Server) ServerComboBox.SelectedItem;
|
||||
try
|
||||
{
|
||||
//听说巨硬BUG经常会炸,所以Catch一下 :D
|
||||
Clipboard.SetText(ShareLink.GetShareLink(selectedMode));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
else
|
||||
if (ServerComboBox.SelectedIndex == -1)
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("Please select a server first"));
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedMode = (Models.Server) ServerComboBox.SelectedItem;
|
||||
try
|
||||
{
|
||||
//听说巨硬BUG经常会炸,所以Catch一下 :D
|
||||
Clipboard.SetText(ShareLink.GetShareLink(selectedMode));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteServerPictureBox_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 当前 ServerComboBox 中至少有一项
|
||||
if (ServerComboBox.SelectedIndex != -1)
|
||||
{
|
||||
var index = ServerComboBox.SelectedIndex;
|
||||
|
||||
Global.Settings.Server.Remove(ServerComboBox.SelectedItem as Models.Server);
|
||||
ServerComboBox.Items.RemoveAt(index);
|
||||
|
||||
if (ServerComboBox.Items.Count > 0)
|
||||
{
|
||||
ServerComboBox.SelectedIndex = index != 0 ? index - 1 : index;
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
}
|
||||
else
|
||||
if (ServerComboBox.SelectedIndex == -1)
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("Please select a server first"));
|
||||
return;
|
||||
}
|
||||
|
||||
var index = ServerComboBox.SelectedIndex;
|
||||
|
||||
Global.Settings.Server.Remove(ServerComboBox.SelectedItem as Models.Server);
|
||||
|
||||
Configuration.Save();
|
||||
|
||||
if (ServerComboBox.Items.Count > 0)
|
||||
{
|
||||
ServerComboBox.SelectedIndex = index != 0 ? index - 1 : index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,13 +431,17 @@ namespace Netch.Forms
|
||||
|
||||
#endregion
|
||||
|
||||
private bool SaveSelectIndex = false;
|
||||
|
||||
private void ModeComboBox_SelectedIndexChanged(object sender, EventArgs o)
|
||||
{
|
||||
if (!SaveSelectIndex) return;
|
||||
Global.Settings.ModeComboBoxSelectedIndex = ModeComboBox.SelectedIndex;
|
||||
}
|
||||
|
||||
private void ServerComboBox_SelectedIndexChanged(object sender, EventArgs o)
|
||||
{
|
||||
if (!SaveSelectIndex) return;
|
||||
Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ namespace Netch.Forms.Mode
|
||||
|
||||
MessageBoxX.Show(i18N.Translate("Mode added successfully"));
|
||||
|
||||
Global.MainForm.AddMode(mode);
|
||||
Modes.Add(mode);
|
||||
Close();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -9,17 +9,11 @@ namespace Netch.Forms.Server
|
||||
{
|
||||
private readonly Models.Server _server;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="index">需要编辑的索引</param>
|
||||
public Shadowsocks(int index = -1)
|
||||
public Shadowsocks(Models.Server server = default)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_server = index != -1
|
||||
? Global.Settings.Server[index]
|
||||
: new Models.Server {EncryptMethod = Global.EncryptMethods.SS[0]};
|
||||
_server = server ?? new Models.Server {EncryptMethod = Global.EncryptMethods.SS[0]};
|
||||
}
|
||||
|
||||
private void Shadowsocks_Load(object sender, EventArgs e)
|
||||
@@ -96,9 +90,7 @@ namespace Netch.Forms.Server
|
||||
Global.Settings.Server.Add(_server);
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
MessageBoxX.Show(i18N.Translate("Saved"));
|
||||
Global.MainForm.InitServer();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,11 @@ namespace Netch.Forms.Server
|
||||
{
|
||||
private readonly Models.Server _server;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="index">需要编辑的索引</param>
|
||||
public ShadowsocksR(int index = -1)
|
||||
public ShadowsocksR(Models.Server server = default)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_server = index != -1
|
||||
? Global.Settings.Server[index]
|
||||
: new Models.Server {EncryptMethod = Global.EncryptMethods.SSR[0]};
|
||||
_server = server ?? new Models.Server {EncryptMethod = Global.EncryptMethods.SSR[0]};
|
||||
}
|
||||
|
||||
private void ShadowsocksR_Load(object sender, EventArgs e)
|
||||
@@ -44,7 +38,6 @@ namespace Netch.Forms.Server
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
RemarkTextBox.Text = _server.Remark;
|
||||
AddressTextBox.Text = _server.Hostname;
|
||||
PortTextBox.Text = _server.Port.ToString();
|
||||
@@ -106,9 +99,7 @@ namespace Netch.Forms.Server
|
||||
Global.Settings.Server.Add(_server);
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
MessageBoxX.Show(i18N.Translate("Saved"));
|
||||
Global.MainForm.InitServer();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,11 @@ namespace Netch.Forms.Server
|
||||
{
|
||||
private readonly Models.Server _server;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="index">需要编辑的索引</param>
|
||||
public Socks5(int index = -1)
|
||||
public Socks5(Models.Server server = default)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_server = index != -1
|
||||
? Global.Settings.Server[index]
|
||||
: new Models.Server();
|
||||
_server = server ?? new Models.Server();
|
||||
}
|
||||
|
||||
private void Shadowsocks_Load(object sender, EventArgs e)
|
||||
@@ -88,9 +82,7 @@ namespace Netch.Forms.Server
|
||||
Global.Settings.Server.Add(_server);
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
MessageBoxX.Show(i18N.Translate("Saved"));
|
||||
Global.MainForm.InitServer();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,11 @@ namespace Netch.Forms.Server
|
||||
{
|
||||
private readonly Models.Server _server;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="index">需要编辑的索引</param>
|
||||
public Trojan(int index = -1)
|
||||
public Trojan(Models.Server server = default)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
_server = index != -1
|
||||
? Global.Settings.Server[index]
|
||||
: new Models.Server();
|
||||
_server = server ?? new Models.Server();
|
||||
}
|
||||
|
||||
private void Trojan_Load(object sender, EventArgs e)
|
||||
@@ -83,9 +76,7 @@ namespace Netch.Forms.Server
|
||||
Global.Settings.Server.Add(_server);
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
MessageBoxX.Show(i18N.Translate("Saved"));
|
||||
Global.MainForm.InitServer();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,13 @@ namespace Netch.Forms.Server
|
||||
{
|
||||
public partial class VMess : Form
|
||||
{
|
||||
private static Models.Server server;
|
||||
private static Models.Server _server;
|
||||
|
||||
public VMess(int index = -1)
|
||||
public VMess(Models.Server server = default)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
server = index != -1
|
||||
? Global.Settings.Server[index]
|
||||
: new Models.Server {EncryptMethod = Global.EncryptMethods.VMess[0]};
|
||||
_server = server ?? new Models.Server {EncryptMethod = Global.EncryptMethods.VMess[0]};
|
||||
}
|
||||
|
||||
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
|
||||
@@ -71,20 +69,20 @@ namespace Netch.Forms.Server
|
||||
|
||||
#endregion
|
||||
|
||||
RemarkTextBox.Text = server.Remark;
|
||||
AddressTextBox.Text = server.Hostname;
|
||||
PortTextBox.Text = server.Port.ToString();
|
||||
UserIDTextBox.Text = server.UserID;
|
||||
AlterIDTextBox.Text = server.AlterID.ToString();
|
||||
EncryptMethodComboBox.SelectedIndex = Global.EncryptMethods.VMess.IndexOf(server.EncryptMethod);
|
||||
TransferProtocolComboBox.SelectedIndex = Global.TransferProtocols.IndexOf(server.TransferProtocol);
|
||||
FakeTypeComboBox.SelectedIndex = Global.FakeTypes.IndexOf(server.FakeType);
|
||||
HostTextBox.Text = server.Host;
|
||||
PathTextBox.Text = server.Path;
|
||||
QUICSecurityComboBox.SelectedIndex = Global.EncryptMethods.VMessQUIC.IndexOf(server.QUICSecure);
|
||||
QUICSecretTextBox.Text = server.QUICSecret;
|
||||
TLSSecureCheckBox.Checked = server.TLSSecure;
|
||||
UseMuxCheckBox.Checked = server.UseMux;
|
||||
RemarkTextBox.Text = _server.Remark;
|
||||
AddressTextBox.Text = _server.Hostname;
|
||||
PortTextBox.Text = _server.Port.ToString();
|
||||
UserIDTextBox.Text = _server.UserID;
|
||||
AlterIDTextBox.Text = _server.AlterID.ToString();
|
||||
EncryptMethodComboBox.SelectedIndex = Global.EncryptMethods.VMess.IndexOf(_server.EncryptMethod);
|
||||
TransferProtocolComboBox.SelectedIndex = Global.TransferProtocols.IndexOf(_server.TransferProtocol);
|
||||
FakeTypeComboBox.SelectedIndex = Global.FakeTypes.IndexOf(_server.FakeType);
|
||||
HostTextBox.Text = _server.Host;
|
||||
PathTextBox.Text = _server.Path;
|
||||
QUICSecurityComboBox.SelectedIndex = Global.EncryptMethods.VMessQUIC.IndexOf(_server.QUICSecure);
|
||||
QUICSecretTextBox.Text = _server.QUICSecret;
|
||||
TLSSecureCheckBox.Checked = _server.TLSSecure;
|
||||
UseMuxCheckBox.Checked = _server.UseMux;
|
||||
}
|
||||
|
||||
private void ControlButton_Click(object sender, EventArgs e)
|
||||
@@ -105,31 +103,29 @@ namespace Netch.Forms.Server
|
||||
return;
|
||||
}
|
||||
|
||||
server.Remark = RemarkTextBox.Text;
|
||||
server.Type = "VMess";
|
||||
server.Hostname = AddressTextBox.Text;
|
||||
server.Port = port;
|
||||
server.UserID = UserIDTextBox.Text;
|
||||
server.AlterID = afterId;
|
||||
server.EncryptMethod = EncryptMethodComboBox.Text;
|
||||
server.TransferProtocol = TransferProtocolComboBox.Text;
|
||||
server.FakeType = FakeTypeComboBox.Text;
|
||||
server.Host = HostTextBox.Text;
|
||||
server.Path = PathTextBox.Text;
|
||||
server.QUICSecure = QUICSecurityComboBox.Text;
|
||||
server.QUICSecret = QUICSecretTextBox.Text;
|
||||
server.TLSSecure = TLSSecureCheckBox.Checked;
|
||||
server.UseMux = UseMuxCheckBox.Checked;
|
||||
server.Country = null;
|
||||
_server.Remark = RemarkTextBox.Text;
|
||||
_server.Type = "VMess";
|
||||
_server.Hostname = AddressTextBox.Text;
|
||||
_server.Port = port;
|
||||
_server.UserID = UserIDTextBox.Text;
|
||||
_server.AlterID = afterId;
|
||||
_server.EncryptMethod = EncryptMethodComboBox.Text;
|
||||
_server.TransferProtocol = TransferProtocolComboBox.Text;
|
||||
_server.FakeType = FakeTypeComboBox.Text;
|
||||
_server.Host = HostTextBox.Text;
|
||||
_server.Path = PathTextBox.Text;
|
||||
_server.QUICSecure = QUICSecurityComboBox.Text;
|
||||
_server.QUICSecret = QUICSecretTextBox.Text;
|
||||
_server.TLSSecure = TLSSecureCheckBox.Checked;
|
||||
_server.UseMux = UseMuxCheckBox.Checked;
|
||||
_server.Country = null;
|
||||
|
||||
if (Global.Settings.Server.IndexOf(server) == -1)
|
||||
if (Global.Settings.Server.IndexOf(_server) == -1)
|
||||
{
|
||||
Global.Settings.Server.Add(server);
|
||||
Global.Settings.Server.Add(_server);
|
||||
}
|
||||
|
||||
Configuration.Save();
|
||||
MessageBoxX.Show(i18N.Translate("Saved"));
|
||||
Global.MainForm.InitServer();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +92,6 @@ namespace Netch.Forms
|
||||
Global.Settings.SubscribeLink.RemoveAt(item.Index);
|
||||
SubscribeLinkListView.Items.Remove(item);
|
||||
ResetEditingGroup();
|
||||
|
||||
Global.MainForm.InitServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,18 +185,21 @@ namespace Netch.Forms
|
||||
|
||||
private static void DeleteServersInGroup(string group)
|
||||
{
|
||||
Global.Settings.Server = Global.Settings.Server.Where(server => !server.Group.Equals(group)).ToList();
|
||||
foreach (var server in Global.Settings.Server.ToList().Where(server => server.Group.Equals(group)))
|
||||
{
|
||||
Global.Settings.Server.Remove(server);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RenameServersGroup(string oldGroup, string newGroup)
|
||||
{
|
||||
Global.Settings.Server.ForEach(server =>
|
||||
foreach (var server in Global.Settings.Server)
|
||||
{
|
||||
if (server.Group == oldGroup)
|
||||
{
|
||||
server.Group = newGroup;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -203,6 +203,6 @@ namespace Netch
|
||||
/// <summary>
|
||||
/// 用于存储模式
|
||||
/// </summary>
|
||||
public static readonly List<Models.Mode> Modes = new List<Models.Mode>();
|
||||
public static readonly SortableBindingList<Models.Mode> Modes = new SortableBindingList<Models.Mode>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Netch.Utils;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
@@ -118,15 +120,12 @@ namespace Netch.Models
|
||||
/// <summary>
|
||||
/// 删除模式文件
|
||||
/// </summary>
|
||||
public void DeleteFile(string Dir)
|
||||
public void DeleteFile()
|
||||
{
|
||||
if (System.IO.Directory.Exists(Dir))
|
||||
var fullPath = Path.Combine(Modes.ModeDirectory, RelativePath);
|
||||
if (File.Exists(fullPath))
|
||||
{
|
||||
var NewPath = System.IO.Path.Combine(Dir, FileName);
|
||||
if (System.IO.File.Exists(NewPath + ".txt"))
|
||||
{
|
||||
System.IO.File.Delete(NewPath + ".txt");
|
||||
}
|
||||
File.Delete(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Netch.Models
|
||||
{
|
||||
@@ -87,7 +88,7 @@ namespace Netch.Models
|
||||
/// 是否打开软件时检查更新
|
||||
/// </summary>
|
||||
public bool CheckUpdateWhenOpened = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否检查 Beta 更新
|
||||
/// </summary>
|
||||
@@ -146,7 +147,7 @@ namespace Netch.Models
|
||||
/// <summary>
|
||||
/// 服务器列表
|
||||
/// </summary>
|
||||
public List<Server> Server = new List<Server>();
|
||||
public readonly BindingList<Server> Server = new BindingList<Server>();
|
||||
|
||||
/// <summary>
|
||||
/// 全局绕过 IP 列表
|
||||
@@ -198,4 +199,4 @@ namespace Netch.Models
|
||||
/// </summary>
|
||||
public string Language = "System";
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Netch/Override/SortableBindingList.cs
Normal file
47
Netch/Override/SortableBindingList.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
public class SortableBindingList<T> : BindingList<T>
|
||||
{
|
||||
public SortableBindingList(IList<T> list) : base(list)
|
||||
{
|
||||
}
|
||||
|
||||
public SortableBindingList()
|
||||
{
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
Sort(null, null);
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
Sort(comparer, null);
|
||||
}
|
||||
|
||||
public void Sort(Comparison<T> comparison)
|
||||
{
|
||||
Sort(null, comparison);
|
||||
}
|
||||
|
||||
private void Sort(IComparer<T> comparer, Comparison<T> comparison)
|
||||
{
|
||||
// if (typeof(T).GetInterface(nameof(IComparable)) == null) return;
|
||||
var raiseListChangedEvents = this.RaiseListChangedEvents;
|
||||
this.RaiseListChangedEvents = false;
|
||||
try
|
||||
{
|
||||
var items = (List<T>) this.Items;
|
||||
if (comparison != null) items.Sort(comparison);
|
||||
else items.Sort(comparer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.RaiseListChangedEvents = raiseListChangedEvents;
|
||||
ResetBindings();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace Netch.Utils
|
||||
/// <summary>
|
||||
/// 数据目录
|
||||
/// </summary>
|
||||
public static readonly string DATA_DIR = "data";
|
||||
public const string DATA_DIR = "data";
|
||||
|
||||
/// <summary>
|
||||
/// 设置
|
||||
|
||||
@@ -8,15 +8,25 @@ namespace Netch.Utils
|
||||
{
|
||||
public static class Modes
|
||||
{
|
||||
private static readonly string ModeDirectory = Path.Combine(Global.NetchDir, "mode\\");
|
||||
private const string MODE_DIR = "mode";
|
||||
|
||||
public static readonly string ModeDirectory = Path.Combine(Global.NetchDir, $"{MODE_DIR}\\");
|
||||
|
||||
/// <summary>
|
||||
/// 从模式文件夹读取模式并为 <see cref="Forms.MainForm.ModeComboBox"/> 绑定数据
|
||||
/// </summary>
|
||||
public static void Load()
|
||||
{
|
||||
var raiseListChangedEvents = Global.Modes.RaiseListChangedEvents;
|
||||
|
||||
Global.Modes.RaiseListChangedEvents = false;
|
||||
Global.MainForm.ModeComboBox.DataSource = null;
|
||||
Global.Modes.Clear();
|
||||
if (!Directory.Exists("mode")) return;
|
||||
|
||||
if (!Directory.Exists(MODE_DIR)) return;
|
||||
|
||||
var stack = new Stack<string>();
|
||||
stack.Push("mode");
|
||||
stack.Push(MODE_DIR);
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
var dirInfo = new DirectoryInfo(stack.Pop());
|
||||
@@ -34,7 +44,9 @@ namespace Netch.Utils
|
||||
}
|
||||
}
|
||||
|
||||
Global.Modes.Sort((a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
|
||||
Sort();
|
||||
Global.MainForm.ModeComboBox.DataSource = Global.Modes;
|
||||
Global.Modes.RaiseListChangedEvents = raiseListChangedEvents;
|
||||
}
|
||||
|
||||
private static void LoadModeFile(string path)
|
||||
@@ -81,5 +93,22 @@ namespace Netch.Utils
|
||||
|
||||
Global.Modes.Add(mode);
|
||||
}
|
||||
|
||||
private static void Sort()
|
||||
{
|
||||
Global.Modes.Sort((a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
public static void Add(Mode mode)
|
||||
{
|
||||
Global.Modes.Add(mode);
|
||||
Sort();
|
||||
}
|
||||
|
||||
public static void Delete(Mode mode)
|
||||
{
|
||||
mode.DeleteFile();
|
||||
Global.Modes.Remove(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user