mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
Start Profile, Refactor Save LastSelectedServer/Mode
This commit is contained in:
4
Netch/Forms/MainForm.Designer.cs
generated
4
Netch/Forms/MainForm.Designer.cs
generated
@@ -423,7 +423,7 @@
|
||||
this.ModeComboBox.Size = new System.Drawing.Size(546, 24);
|
||||
this.ModeComboBox.TabIndex = 2;
|
||||
this.ModeComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem);
|
||||
this.ModeComboBox.SelectedIndexChanged += new System.EventHandler(this.ModeComboBox_SelectedIndexChanged);
|
||||
this.ModeComboBox.SelectionChangeCommitted += new System.EventHandler(this.ModeComboBox_SelectionChangeCommitted);
|
||||
//
|
||||
// ServerComboBox
|
||||
//
|
||||
@@ -438,7 +438,7 @@
|
||||
this.ServerComboBox.Size = new System.Drawing.Size(546, 24);
|
||||
this.ServerComboBox.TabIndex = 1;
|
||||
this.ServerComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBox_DrawItem);
|
||||
this.ServerComboBox.SelectedIndexChanged += new System.EventHandler(this.ServerComboBox_SelectedIndexChanged);
|
||||
this.ServerComboBox.SelectionChangeCommitted += new System.EventHandler(this.ServerComboBox_SelectionChangeCommitted);
|
||||
//
|
||||
// tableLayoutPanel2
|
||||
//
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace Netch.Forms
|
||||
|
||||
private readonly Dictionary<string, object> _mainFormText = new();
|
||||
|
||||
private bool _comboBoxInitialized;
|
||||
private bool _textRecorded;
|
||||
|
||||
public MainForm()
|
||||
@@ -85,6 +84,8 @@ namespace Netch.Forms
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
Netch.TimePoint("MainForm ctor (Pre MainForm Load)");
|
||||
|
||||
// 计算 ComboBox绘制 目标宽度
|
||||
RecordSize();
|
||||
|
||||
@@ -93,7 +94,6 @@ namespace Netch.Forms
|
||||
|
||||
ModeHelper.Load();
|
||||
LoadModes();
|
||||
_comboBoxInitialized = true;
|
||||
|
||||
// 加载翻译
|
||||
TranslateControls();
|
||||
@@ -121,6 +121,8 @@ namespace Netch.Forms
|
||||
if (Global.Settings.StartWhenOpened)
|
||||
ControlButton_Click(null, null);
|
||||
});
|
||||
|
||||
Netch.TimePoint("Post Form Load", false);
|
||||
}
|
||||
|
||||
private void RecordSize()
|
||||
@@ -735,13 +737,9 @@ namespace Netch.Forms
|
||||
|
||||
private void LoadServers()
|
||||
{
|
||||
var comboBoxInitialized = _comboBoxInitialized;
|
||||
_comboBoxInitialized = false;
|
||||
|
||||
ServerComboBox.Items.Clear();
|
||||
ServerComboBox.Items.AddRange(Global.Settings.Server.ToArray());
|
||||
SelectLastServer();
|
||||
_comboBoxInitialized = comboBoxInitialized;
|
||||
}
|
||||
|
||||
public void SelectLastServer()
|
||||
@@ -756,11 +754,8 @@ namespace Netch.Forms
|
||||
// 如果当前 ServerComboBox 中没元素,不做处理
|
||||
}
|
||||
|
||||
private void ServerComboBox_SelectedIndexChanged(object sender, EventArgs o)
|
||||
private void ServerComboBox_SelectionChangeCommitted(object sender, EventArgs o)
|
||||
{
|
||||
if (!_comboBoxInitialized)
|
||||
return;
|
||||
|
||||
Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex;
|
||||
}
|
||||
|
||||
@@ -859,14 +854,10 @@ namespace Netch.Forms
|
||||
|
||||
public void LoadModes()
|
||||
{
|
||||
var comboBoxInitialized = _comboBoxInitialized;
|
||||
_comboBoxInitialized = false;
|
||||
|
||||
ModeComboBox.Items.Clear();
|
||||
ModeComboBox.Items.AddRange(Global.Modes.ToArray());
|
||||
ModeComboBox.Items.AddRange(Global.Modes.Cast<object>().ToArray());
|
||||
ModeComboBox.Tag = null;
|
||||
SelectLastMode();
|
||||
_comboBoxInitialized = comboBoxInitialized;
|
||||
}
|
||||
|
||||
public void SelectLastMode()
|
||||
@@ -881,11 +872,8 @@ namespace Netch.Forms
|
||||
// 如果当前 ModeComboBox 中没元素,不做处理
|
||||
}
|
||||
|
||||
private void ModeComboBox_SelectedIndexChanged(object sender, EventArgs o)
|
||||
private void ModeComboBox_SelectionChangeCommitted(object sender, EventArgs o)
|
||||
{
|
||||
if (!_comboBoxInitialized)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Global.Settings.ModeComboBoxSelectedIndex = Global.Modes.IndexOf((Models.Mode) ModeComboBox.SelectedItem);
|
||||
|
||||
@@ -16,6 +16,28 @@ namespace Netch
|
||||
{
|
||||
public static class Netch
|
||||
{
|
||||
private static readonly Stopwatch Stopwatch = new();
|
||||
|
||||
public static void StartStopwatch(string name)
|
||||
{
|
||||
if (Stopwatch.IsRunning)
|
||||
throw new Exception();
|
||||
|
||||
Stopwatch.Start();
|
||||
Console.WriteLine($"Start {name} Stopwatch");
|
||||
}
|
||||
|
||||
public static void TimePoint(string name, bool restart = true)
|
||||
{
|
||||
if (!Stopwatch.IsRunning)
|
||||
throw new Exception();
|
||||
|
||||
Stopwatch.Stop();
|
||||
Console.WriteLine($"{name} Stopwatch: {Stopwatch.ElapsedMilliseconds}");
|
||||
if (restart)
|
||||
Stopwatch.Restart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点
|
||||
/// </summary>
|
||||
@@ -28,6 +50,7 @@ namespace Netch
|
||||
if (args.Contains("-console"))
|
||||
AttachConsole();
|
||||
#endif
|
||||
StartStopwatch("Netch");
|
||||
|
||||
// 设置当前目录
|
||||
Directory.SetCurrentDirectory(Global.NetchDir);
|
||||
@@ -43,9 +66,11 @@ namespace Netch
|
||||
if (!Directory.Exists(item))
|
||||
Directory.CreateDirectory(item);
|
||||
|
||||
TimePoint("Clean Old, Create Directory");
|
||||
// 加载配置
|
||||
Configuration.Load();
|
||||
|
||||
TimePoint("Load Configuration");
|
||||
// 检查是否已经运行
|
||||
if (!Global.Mutex.WaitOne(0, false))
|
||||
{
|
||||
@@ -79,6 +104,8 @@ namespace Netch
|
||||
Logging.Info($"版本: {UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}");
|
||||
Task.Run(() => { Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Global.NetchExecutable)}"); });
|
||||
|
||||
TimePoint("Get Info, Pre-Form");
|
||||
|
||||
// 绑定错误捕获
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
Application.ThreadException += Application_OnException;
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Netch.Utils
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Unsupported Server Type
|
||||
return JsonSerializer.Deserialize<Server>(jsonElement.GetRawText(), new JsonSerializerOptions())!;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user