A simple profile UI which enables you to swtich to different profiles quickly.

1. It will enable the UI sooner after you click the "Stop" button, allowing you to switch mode/server much sooner.

2. Adds a Profile UI which allows you to Ctrl+Click to save a profile and Click to switch to a profile.
This commit is contained in:
henning
2020-01-01 20:08:57 +08:00
parent b57fb5c77a
commit 6eca1085b2
5 changed files with 279 additions and 34 deletions

View File

@@ -50,6 +50,8 @@
this.AboutToolStripButton = new System.Windows.Forms.ToolStripButton();
this.VersionLabel = new System.Windows.Forms.ToolStripLabel();
this.ConfigurationGroupBox = new System.Windows.Forms.GroupBox();
this.ProfileNameText = new System.Windows.Forms.TextBox();
this.ProfileLabel = new System.Windows.Forms.Label();
this.SpeedPictureBox = new System.Windows.Forms.PictureBox();
this.DeletePictureBox = new System.Windows.Forms.PictureBox();
this.EditPictureBox = new System.Windows.Forms.PictureBox();
@@ -68,6 +70,8 @@
this.ShowMainFormToolStripButton = new System.Windows.Forms.ToolStripMenuItem();
this.ExitToolStripButton = new System.Windows.Forms.ToolStripMenuItem();
this.SettingsButton = new System.Windows.Forms.Button();
this.ProfileGroupBox = new System.Windows.Forms.GroupBox();
this.ProfileTable = new System.Windows.Forms.TableLayoutPanel();
this.MenuStrip.SuspendLayout();
this.ConfigurationGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.SpeedPictureBox)).BeginInit();
@@ -75,6 +79,7 @@
((System.ComponentModel.ISupportInitialize)(this.EditPictureBox)).BeginInit();
this.StatusStrip.SuspendLayout();
this.NotifyMenu.SuspendLayout();
this.ProfileGroupBox.SuspendLayout();
this.SuspendLayout();
//
// MenuStrip
@@ -91,7 +96,7 @@
this.MenuStrip.Location = new System.Drawing.Point(0, 0);
this.MenuStrip.Name = "MenuStrip";
this.MenuStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
this.MenuStrip.Size = new System.Drawing.Size(608, 26);
this.MenuStrip.Size = new System.Drawing.Size(608, 24);
this.MenuStrip.TabIndex = 0;
//
// ServerToolStripMenuItem
@@ -104,41 +109,41 @@
this.AddVMessServerToolStripMenuItem});
this.ServerToolStripMenuItem.Margin = new System.Windows.Forms.Padding(3, 0, 0, 1);
this.ServerToolStripMenuItem.Name = "ServerToolStripMenuItem";
this.ServerToolStripMenuItem.Size = new System.Drawing.Size(57, 21);
this.ServerToolStripMenuItem.Size = new System.Drawing.Size(51, 19);
this.ServerToolStripMenuItem.Text = "Server";
//
// ImportServersFromClipboardToolStripMenuItem
//
this.ImportServersFromClipboardToolStripMenuItem.Name = "ImportServersFromClipboardToolStripMenuItem";
this.ImportServersFromClipboardToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.ImportServersFromClipboardToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.ImportServersFromClipboardToolStripMenuItem.Text = "Import Servers From Clipboard";
this.ImportServersFromClipboardToolStripMenuItem.Click += new System.EventHandler(this.ImportServersFromClipboardToolStripMenuItem_Click);
//
// AddSocks5ServerToolStripMenuItem
//
this.AddSocks5ServerToolStripMenuItem.Name = "AddSocks5ServerToolStripMenuItem";
this.AddSocks5ServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddSocks5ServerToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.AddSocks5ServerToolStripMenuItem.Text = "Add [Socks5] Server";
this.AddSocks5ServerToolStripMenuItem.Click += new System.EventHandler(this.AddSocks5ServerToolStripMenuItem_Click);
//
// AddShadowsocksServerToolStripMenuItem
//
this.AddShadowsocksServerToolStripMenuItem.Name = "AddShadowsocksServerToolStripMenuItem";
this.AddShadowsocksServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddShadowsocksServerToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.AddShadowsocksServerToolStripMenuItem.Text = "Add [Shadowsocks] Server";
this.AddShadowsocksServerToolStripMenuItem.Click += new System.EventHandler(this.AddShadowsocksServerToolStripMenuItem_Click);
//
// AddShadowsocksRServerToolStripMenuItem
//
this.AddShadowsocksRServerToolStripMenuItem.Name = "AddShadowsocksRServerToolStripMenuItem";
this.AddShadowsocksRServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddShadowsocksRServerToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.AddShadowsocksRServerToolStripMenuItem.Text = "Add [ShadowsocksR] Server";
this.AddShadowsocksRServerToolStripMenuItem.Click += new System.EventHandler(this.AddShadowsocksRServerToolStripMenuItem_Click);
//
// AddVMessServerToolStripMenuItem
//
this.AddVMessServerToolStripMenuItem.Name = "AddVMessServerToolStripMenuItem";
this.AddVMessServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddVMessServerToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.AddVMessServerToolStripMenuItem.Text = "Add [VMess] Server";
this.AddVMessServerToolStripMenuItem.Click += new System.EventHandler(this.AddVMessServerToolStripMenuItem_Click);
//
@@ -148,13 +153,13 @@
this.CreateProcessModeToolStripMenuItem});
this.ModeToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1);
this.ModeToolStripMenuItem.Name = "ModeToolStripMenuItem";
this.ModeToolStripMenuItem.Size = new System.Drawing.Size(55, 21);
this.ModeToolStripMenuItem.Size = new System.Drawing.Size(50, 19);
this.ModeToolStripMenuItem.Text = "Mode";
//
// CreateProcessModeToolStripMenuItem
//
this.CreateProcessModeToolStripMenuItem.Name = "CreateProcessModeToolStripMenuItem";
this.CreateProcessModeToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.CreateProcessModeToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.CreateProcessModeToolStripMenuItem.Text = "Create Process Mode";
this.CreateProcessModeToolStripMenuItem.Click += new System.EventHandler(this.CreateProcessModeToolStripButton_Click);
//
@@ -165,20 +170,20 @@
this.UpdateServersFromSubscribeLinksToolStripMenuItem});
this.SubscribeToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1);
this.SubscribeToolStripMenuItem.Name = "SubscribeToolStripMenuItem";
this.SubscribeToolStripMenuItem.Size = new System.Drawing.Size(77, 21);
this.SubscribeToolStripMenuItem.Size = new System.Drawing.Size(70, 19);
this.SubscribeToolStripMenuItem.Text = "Subscribe";
//
// ManageSubscribeLinksToolStripMenuItem
//
this.ManageSubscribeLinksToolStripMenuItem.Name = "ManageSubscribeLinksToolStripMenuItem";
this.ManageSubscribeLinksToolStripMenuItem.Size = new System.Drawing.Size(294, 22);
this.ManageSubscribeLinksToolStripMenuItem.Size = new System.Drawing.Size(267, 22);
this.ManageSubscribeLinksToolStripMenuItem.Text = "Manage Subscribe Links";
this.ManageSubscribeLinksToolStripMenuItem.Click += new System.EventHandler(this.ManageSubscribeLinksToolStripMenuItem_Click);
//
// UpdateServersFromSubscribeLinksToolStripMenuItem
//
this.UpdateServersFromSubscribeLinksToolStripMenuItem.Name = "UpdateServersFromSubscribeLinksToolStripMenuItem";
this.UpdateServersFromSubscribeLinksToolStripMenuItem.Size = new System.Drawing.Size(294, 22);
this.UpdateServersFromSubscribeLinksToolStripMenuItem.Size = new System.Drawing.Size(267, 22);
this.UpdateServersFromSubscribeLinksToolStripMenuItem.Text = "Update Servers From Subscribe Links";
this.UpdateServersFromSubscribeLinksToolStripMenuItem.Click += new System.EventHandler(this.UpdateServersFromSubscribeLinksToolStripMenuItem_Click);
//
@@ -191,34 +196,34 @@
this.CleanDNSCacheToolStripMenuItem});
this.OptionsToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1);
this.OptionsToolStripMenuItem.Name = "OptionsToolStripMenuItem";
this.OptionsToolStripMenuItem.Size = new System.Drawing.Size(66, 21);
this.OptionsToolStripMenuItem.Size = new System.Drawing.Size(61, 19);
this.OptionsToolStripMenuItem.Text = "Options";
//
// ReloadModesToolStripMenuItem
//
this.ReloadModesToolStripMenuItem.Name = "ReloadModesToolStripMenuItem";
this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.ReloadModesToolStripMenuItem.Text = "Reload Modes";
this.ReloadModesToolStripMenuItem.Click += new System.EventHandler(this.ReloadModesToolStripMenuItem_Click);
//
// RestartServiceToolStripMenuItem
//
this.RestartServiceToolStripMenuItem.Name = "RestartServiceToolStripMenuItem";
this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.RestartServiceToolStripMenuItem.Text = "Restart Service";
this.RestartServiceToolStripMenuItem.Click += new System.EventHandler(this.RestartServiceToolStripMenuItem_Click);
//
// UninstallServiceToolStripMenuItem
//
this.UninstallServiceToolStripMenuItem.Name = "UninstallServiceToolStripMenuItem";
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.UninstallServiceToolStripMenuItem.Text = "Uninstall Service";
this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click);
//
// CleanDNSCacheToolStripMenuItem
//
this.CleanDNSCacheToolStripMenuItem.Name = "CleanDNSCacheToolStripMenuItem";
this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.CleanDNSCacheToolStripMenuItem.Text = "Clean DNS Cache";
this.CleanDNSCacheToolStripMenuItem.Click += new System.EventHandler(this.CleanDNSCacheToolStripMenuItem_Click);
//
@@ -228,7 +233,7 @@
this.AboutToolStripButton.AutoToolTip = false;
this.AboutToolStripButton.Margin = new System.Windows.Forms.Padding(0, 0, 3, 1);
this.AboutToolStripButton.Name = "AboutToolStripButton";
this.AboutToolStripButton.Size = new System.Drawing.Size(47, 21);
this.AboutToolStripButton.Size = new System.Drawing.Size(44, 19);
this.AboutToolStripButton.Text = "About";
this.AboutToolStripButton.Click += new System.EventHandler(this.AboutToolStripButton_Click);
//
@@ -240,12 +245,14 @@
this.VersionLabel.IsLink = true;
this.VersionLabel.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
this.VersionLabel.Name = "VersionLabel";
this.VersionLabel.Size = new System.Drawing.Size(35, 19);
this.VersionLabel.Size = new System.Drawing.Size(31, 17);
this.VersionLabel.Text = "x.x.x";
this.VersionLabel.Click += new System.EventHandler(this.VersionLabel_Click);
//
// ConfigurationGroupBox
//
this.ConfigurationGroupBox.Controls.Add(this.ProfileNameText);
this.ConfigurationGroupBox.Controls.Add(this.ProfileLabel);
this.ConfigurationGroupBox.Controls.Add(this.SpeedPictureBox);
this.ConfigurationGroupBox.Controls.Add(this.DeletePictureBox);
this.ConfigurationGroupBox.Controls.Add(this.EditPictureBox);
@@ -255,11 +262,27 @@
this.ConfigurationGroupBox.Controls.Add(this.ServerLabel);
this.ConfigurationGroupBox.Location = new System.Drawing.Point(12, 28);
this.ConfigurationGroupBox.Name = "ConfigurationGroupBox";
this.ConfigurationGroupBox.Size = new System.Drawing.Size(584, 86);
this.ConfigurationGroupBox.Size = new System.Drawing.Size(584, 116);
this.ConfigurationGroupBox.TabIndex = 1;
this.ConfigurationGroupBox.TabStop = false;
this.ConfigurationGroupBox.Text = "Configuration";
//
// ProfileNameText
//
this.ProfileNameText.Location = new System.Drawing.Point(96, 88);
this.ProfileNameText.Name = "ProfileNameText";
this.ProfileNameText.Size = new System.Drawing.Size(415, 23);
this.ProfileNameText.TabIndex = 11;
//
// label1
//
this.ProfileLabel.AutoSize = true;
this.ProfileLabel.Location = new System.Drawing.Point(6, 89);
this.ProfileLabel.Name = "label1";
this.ProfileLabel.Size = new System.Drawing.Size(84, 17);
this.ProfileLabel.TabIndex = 10;
this.ProfileLabel.Text = "Profile Name";
//
// SpeedPictureBox
//
this.SpeedPictureBox.Cursor = System.Windows.Forms.Cursors.Hand;
@@ -344,7 +367,7 @@
this.UsedBandwidthLabel,
this.DownloadSpeedLabel,
this.UploadSpeedLabel});
this.StatusStrip.Location = new System.Drawing.Point(0, 154);
this.StatusStrip.Location = new System.Drawing.Point(0, 235);
this.StatusStrip.Name = "StatusStrip";
this.StatusStrip.Size = new System.Drawing.Size(608, 22);
this.StatusStrip.SizingGrip = false;
@@ -354,33 +377,33 @@
//
this.StatusLabel.BackColor = System.Drawing.Color.Transparent;
this.StatusLabel.Name = "StatusLabel";
this.StatusLabel.Size = new System.Drawing.Size(177, 17);
this.StatusLabel.Size = new System.Drawing.Size(162, 17);
this.StatusLabel.Text = "Status: Waiting for command";
//
// UsedBandwidthLabel
//
this.UsedBandwidthLabel.Name = "UsedBandwidthLabel";
this.UsedBandwidthLabel.Size = new System.Drawing.Size(72, 17);
this.UsedBandwidthLabel.Size = new System.Drawing.Size(62, 17);
this.UsedBandwidthLabel.Text = "Used: 0 KB";
this.UsedBandwidthLabel.Visible = false;
//
// DownloadSpeedLabel
//
this.DownloadSpeedLabel.Name = "DownloadSpeedLabel";
this.DownloadSpeedLabel.Size = new System.Drawing.Size(59, 17);
this.DownloadSpeedLabel.Size = new System.Drawing.Size(52, 17);
this.DownloadSpeedLabel.Text = "↓: 0 KB/s";
this.DownloadSpeedLabel.Visible = false;
//
// UploadSpeedLabel
//
this.UploadSpeedLabel.Name = "UploadSpeedLabel";
this.UploadSpeedLabel.Size = new System.Drawing.Size(59, 17);
this.UploadSpeedLabel.Size = new System.Drawing.Size(52, 17);
this.UploadSpeedLabel.Text = "↑: 0 KB/s";
this.UploadSpeedLabel.Visible = false;
//
// ControlButton
//
this.ControlButton.Location = new System.Drawing.Point(521, 120);
this.ControlButton.Location = new System.Drawing.Point(521, 205);
this.ControlButton.Name = "ControlButton";
this.ControlButton.Size = new System.Drawing.Size(75, 27);
this.ControlButton.TabIndex = 3;
@@ -404,25 +427,25 @@
this.ExitToolStripButton});
this.NotifyMenu.Name = "NotifyMenu";
this.NotifyMenu.ShowItemToolTips = false;
this.NotifyMenu.Size = new System.Drawing.Size(108, 48);
this.NotifyMenu.Size = new System.Drawing.Size(104, 48);
//
// ShowMainFormToolStripButton
//
this.ShowMainFormToolStripButton.Name = "ShowMainFormToolStripButton";
this.ShowMainFormToolStripButton.Size = new System.Drawing.Size(107, 22);
this.ShowMainFormToolStripButton.Size = new System.Drawing.Size(103, 22);
this.ShowMainFormToolStripButton.Text = "Show";
this.ShowMainFormToolStripButton.Click += new System.EventHandler(this.ShowMainFormToolStripButton_Click);
//
// ExitToolStripButton
//
this.ExitToolStripButton.Name = "ExitToolStripButton";
this.ExitToolStripButton.Size = new System.Drawing.Size(107, 22);
this.ExitToolStripButton.Size = new System.Drawing.Size(103, 22);
this.ExitToolStripButton.Text = "Exit";
this.ExitToolStripButton.Click += new System.EventHandler(this.ExitToolStripButton_Click);
//
// SettingsButton
//
this.SettingsButton.Location = new System.Drawing.Point(12, 120);
this.SettingsButton.Location = new System.Drawing.Point(12, 205);
this.SettingsButton.Name = "SettingsButton";
this.SettingsButton.Size = new System.Drawing.Size(72, 24);
this.SettingsButton.TabIndex = 4;
@@ -430,17 +453,44 @@
this.SettingsButton.UseVisualStyleBackColor = true;
this.SettingsButton.Click += new System.EventHandler(this.SettingsButton_Click);
//
// profileGroupBox
//
this.ProfileGroupBox.Controls.Add(this.ProfileTable);
this.ProfileGroupBox.Location = new System.Drawing.Point(12, 145);
this.ProfileGroupBox.Name = "profileGroupBox";
this.ProfileGroupBox.Size = new System.Drawing.Size(584, 61);
this.ProfileGroupBox.TabIndex = 13;
this.ProfileGroupBox.TabStop = false;
this.ProfileGroupBox.Text = "Profiles";
//
// profileTable
//
this.ProfileTable.AutoSize = true;
this.ProfileTable.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ProfileTable.ColumnCount = 2;
this.ProfileTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ProfileTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ProfileTable.Dock = System.Windows.Forms.DockStyle.Fill;
this.ProfileTable.Location = new System.Drawing.Point(3, 19);
this.ProfileTable.Name = "profileTable";
this.ProfileTable.RowCount = 1;
this.ProfileTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ProfileTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ProfileTable.Size = new System.Drawing.Size(578, 39);
this.ProfileTable.TabIndex = 0;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(608, 176);
this.ClientSize = new System.Drawing.Size(608, 257);
this.Controls.Add(this.ProfileGroupBox);
this.Controls.Add(this.SettingsButton);
this.Controls.Add(this.ControlButton);
this.Controls.Add(this.StatusStrip);
this.Controls.Add(this.ConfigurationGroupBox);
this.Controls.Add(this.MenuStrip);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Font = new System.Drawing.Font("Microsoft YaHei", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
@@ -460,6 +510,8 @@
this.StatusStrip.ResumeLayout(false);
this.StatusStrip.PerformLayout();
this.NotifyMenu.ResumeLayout(false);
this.ProfileGroupBox.ResumeLayout(false);
this.ProfileGroupBox.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -505,5 +557,9 @@
private System.Windows.Forms.ToolStripStatusLabel UploadSpeedLabel;
private System.Windows.Forms.ToolStripStatusLabel DownloadSpeedLabel;
private System.Windows.Forms.ToolStripMenuItem CleanDNSCacheToolStripMenuItem;
private System.Windows.Forms.Label ProfileLabel;
private System.Windows.Forms.TextBox ProfileNameText;
private System.Windows.Forms.GroupBox ProfileGroupBox;
private System.Windows.Forms.TableLayoutPanel ProfileTable;
}
}

View File

@@ -38,6 +38,8 @@ namespace Netch.Forms
/// </summary>
public bool IsFirstOpened = true;
public List<Button> ProfileButtons = new List<Button>();
public MainForm()
{
InitializeComponent();
@@ -299,6 +301,8 @@ namespace Netch.Forms
ShowMainFormToolStripButton.Text = Utils.i18N.Translate("Show");
ExitToolStripButton.Text = Utils.i18N.Translate("Exit");
InitProfile();
// 自动检测延迟
Task.Run(() =>
{
@@ -821,6 +825,10 @@ namespace Netch.Forms
StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Stopping")}";
State = Models.State.Stopping;
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = SettingsButton.Enabled = true;
ProfileGroupBox.Enabled = false;
Task.Run(() =>
{
var server = ServerComboBox.SelectedItem as Models.Server;
@@ -838,7 +846,9 @@ namespace Netch.Forms
UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = false;
}
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
ControlButton.Enabled = true;
ProfileGroupBox.Enabled = true;
ControlButton.Text = Utils.i18N.Translate("Start");
StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Stopped")}";
State = Models.State.Stopped;
@@ -930,5 +940,147 @@ namespace Netch.Forms
LastDownloadBandwidth = download;
Refresh();
}
private void ProfileButton_Click(object sender, EventArgs e)
{
int index = ProfileButtons.IndexOf((Button)sender);
//Utils.Logging.Info(String.Format("Button no.{0} clicked", index));
if (Control.ModifierKeys == Keys.Control)
{
SaveProfile(index);
ProfileButtons[index].Text = ProfileNameText.Text;
}
else
{
try
{
ProfileNameText.Text = LoadProfile(index);
// start the profile
bool need2ndStart = true;
if (State == Models.State.Waiting || State == Models.State.Stopped)
{
need2ndStart = false;
}
ControlButton.PerformClick();
if (need2ndStart)
{
Task.Run(() =>
{
while (State != Models.State.Stopped)
{
Thread.Sleep(200);
}
ControlButton.PerformClick();
});
}
}
catch (Exception ee)
{
Utils.Logging.Info(ee.Message);
ProfileButtons[index].Text = "Error";
}
}
}
public void InitProfile()
{
int num_profile = 4;
ProfileTable.ColumnCount = num_profile;
while (Global.Settings.profiles.Count < num_profile)
{
Global.Settings.profiles.Add(new Models.Profile());
}
// buttons
for (int i = 0; i < num_profile; ++i)
{
var b = new Button();
ProfileTable.Controls.Add(b,i,0);
b.Location = new Point(i * 100, 0);
b.Click += new EventHandler(ProfileButton_Click);
b.Dock = DockStyle.Fill;
ProfileButtons.Add(b);
if (!Global.Settings.profiles[i].IsDummy)
{
b.Text = Global.Settings.profiles[i].ProfileName;
}
else
{
b.Text = "None";
}
}
// equal column
this.ProfileTable.ColumnStyles.Clear();
for (int i = 1; i <= this.ProfileTable.RowCount; i++)
{
ProfileTable.RowStyles.Add(new RowStyle(SizeType.Percent, 1));
}
for (int i = 1; i <= this.ProfileTable.ColumnCount; i++)
{
ProfileTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1));
}
}
private String LoadProfile(int index)
{
Models.Profile p = Global.Settings.profiles[index];
if (p.IsDummy)
throw new Exception("Profile not found.");
bool result = false;
foreach(Models.Server server in ServerComboBox.Items)
{
if (server.Remark.Equals(p.ServerRemark))
{
ServerComboBox.SelectedItem = server;
result = true;
break;
}
}
if (!result)
throw new Exception("Server not found.");
result = false;
foreach (Models.Mode mode in ModeComboBox.Items)
{
if (mode.Remark.Equals(p.ModeRemark))
{
ModeComboBox.SelectedItem = mode;
result = true;
break;
}
}
if (!result)
throw new Exception("Mode not found.");
return p.ProfileName;
}
private void SaveProfile(int index)
{
var selectedServer = (Models.Server)ServerComboBox.SelectedItem;
var selectedMode = (Models.Mode)ModeComboBox.SelectedItem;
String name = ProfileNameText.Text;
Global.Settings.profiles[index] = new Models.Profile(selectedServer, selectedMode, name);
}
}
}

30
Netch/Models/Profile.cs Normal file
View File

@@ -0,0 +1,30 @@
using System;
namespace Netch.Models
{
public class Profile
{
public String ServerRemark;
public String ModeRemark;
public String ProfileName;
public bool IsDummy = true;
public Profile(Server server, Mode mode, String name)
{
ServerRemark = server.Remark;
ModeRemark = mode.Remark;
ProfileName = name;
IsDummy = false;
}
/// <summary>
/// Return a dummy one.
/// </summary>
public Profile()
{
}
}
}

View File

@@ -118,5 +118,11 @@ namespace Netch.Models
/// 全局绕过 IP 列表
/// </summary>
public List<string> BypassIPs = new List<string>();
/// <summary>
/// Saved profiles
/// </summary>
public List<Profile> profiles = new List<Profile>();
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@@ -294,6 +294,7 @@
<Compile Include="Models\GitHubRelease\VersionUtil.cs" />
<Compile Include="Models\LegacyServer.cs" />
<Compile Include="Models\LegacySetting.cs" />
<Compile Include="Models\Profile.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="Netch.cs" />
<Compile Include="Models\Information\VMess.cs" />