From 0d511b032598cce80575003bdd511c78b7ac38b9 Mon Sep 17 00:00:00 2001
From: LovelyWei <16489620+LovelyWei@users.noreply.github.com>
Date: Tue, 18 Feb 2020 15:22:32 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E6=9C=BA=E8=87=AA?=
=?UTF-8?q?=E5=90=AF=E9=80=89=E9=A1=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Netch/Forms/SettingForm.Designer.cs | 15 +++++++++++-
Netch/Forms/SettingForm.cs | 38 +++++++++++++++++++++++++++++
Netch/Models/Setting.cs | 5 ++++
Netch/Netch.csproj | 12 +++++++++
Netch/Resources/zh-CN | 1 +
5 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs
index a72ef5ec..5e23daee 100644
--- a/Netch/Forms/SettingForm.Designer.cs
+++ b/Netch/Forms/SettingForm.Designer.cs
@@ -50,6 +50,7 @@
this.ControlButton = new System.Windows.Forms.Button();
this.GlobalBypassIPsButton = new System.Windows.Forms.Button();
this.BehaviorGroupBox = new System.Windows.Forms.GroupBox();
+ this.RunAtStartup = new System.Windows.Forms.CheckBox();
this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox();
this.ProfileCount_Label = new System.Windows.Forms.Label();
this.ProfileCount_TextBox = new System.Windows.Forms.TextBox();
@@ -261,6 +262,7 @@
//
// BehaviorGroupBox
//
+ this.BehaviorGroupBox.Controls.Add(this.RunAtStartup);
this.BehaviorGroupBox.Controls.Add(this.MinimizeWhenStartedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_Label);
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_TextBox);
@@ -275,6 +277,16 @@
this.BehaviorGroupBox.TabStop = false;
this.BehaviorGroupBox.Text = "Behavior";
//
+ // RunAtStartup
+ //
+ this.RunAtStartup.AutoSize = true;
+ this.RunAtStartup.Location = new System.Drawing.Point(120, 130);
+ this.RunAtStartup.Name = "RunAtStartup";
+ this.RunAtStartup.Size = new System.Drawing.Size(109, 21);
+ this.RunAtStartup.TabIndex = 11;
+ this.RunAtStartup.Text = "Run at startup";
+ this.RunAtStartup.UseVisualStyleBackColor = true;
+ //
// MinimizeWhenStartedCheckBox
//
this.MinimizeWhenStartedCheckBox.AutoSize = true;
@@ -305,7 +317,7 @@
// CheckUpdateWhenOpenedCheckBox
//
this.CheckUpdateWhenOpenedCheckBox.AutoSize = true;
- this.CheckUpdateWhenOpenedCheckBox.Location = new System.Drawing.Point(120, 130);
+ this.CheckUpdateWhenOpenedCheckBox.Location = new System.Drawing.Point(120, 157);
this.CheckUpdateWhenOpenedCheckBox.Name = "CheckUpdateWhenOpenedCheckBox";
this.CheckUpdateWhenOpenedCheckBox.Size = new System.Drawing.Size(190, 21);
this.CheckUpdateWhenOpenedCheckBox.TabIndex = 8;
@@ -406,5 +418,6 @@
private System.Windows.Forms.Label ProfileCount_Label;
private System.Windows.Forms.TextBox ProfileCount_TextBox;
private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox;
+ private System.Windows.Forms.CheckBox RunAtStartup;
}
}
\ No newline at end of file
diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs
index 59408626..3ee47e91 100644
--- a/Netch/Forms/SettingForm.cs
+++ b/Netch/Forms/SettingForm.cs
@@ -1,6 +1,8 @@
using System;
+using System.Collections;
using System.Net;
using System.Windows.Forms;
+using TaskScheduler;
namespace Netch.Forms
{
@@ -58,6 +60,7 @@ namespace Netch.Forms
StartWhenOpenedCheckBox.Checked = Global.Settings.StartWhenOpened;
CheckUpdateWhenOpenedCheckBox.Checked = Global.Settings.CheckUpdateWhenOpened;
MinimizeWhenStartedCheckBox.Checked = Global.Settings.MinimizeWhenStarted;
+ RunAtStartup.Checked = Global.Settings.RunAtStartup;
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
@@ -74,6 +77,7 @@ namespace Netch.Forms
StopWhenExitedCheckBox.Text = Utils.i18N.Translate(StopWhenExitedCheckBox.Text);
StartWhenOpenedCheckBox.Text = Utils.i18N.Translate(StartWhenOpenedCheckBox.Text);
MinimizeWhenStartedCheckBox.Text = Utils.i18N.Translate(MinimizeWhenStartedCheckBox.Text);
+ RunAtStartup.Text = Utils.i18N.Translate(RunAtStartup.Text);
CheckUpdateWhenOpenedCheckBox.Text = Utils.i18N.Translate(CheckUpdateWhenOpenedCheckBox.Text);
ProfileCount_Label.Text = Utils.i18N.Translate(ProfileCount_Label.Text);
@@ -136,6 +140,40 @@ namespace Netch.Forms
Global.Settings.StartWhenOpened = StartWhenOpenedCheckBox.Checked;
Global.Settings.CheckUpdateWhenOpened = CheckUpdateWhenOpenedCheckBox.Checked;
Global.Settings.MinimizeWhenStarted = MinimizeWhenStartedCheckBox.Checked;
+ Global.Settings.RunAtStartup = RunAtStartup.Checked;
+
+ // 开机自启判断
+ TaskSchedulerClass scheduler = new TaskSchedulerClass();
+ scheduler.Connect(null, null, null, null);
+ ITaskFolder folder = scheduler.GetFolder("\\");
+ IRegisteredTaskCollection tasks_exists = folder.GetTasks(1);
+
+ if (RunAtStartup.Checked)
+ {
+ if (((IList)tasks_exists).Contains("Netch Startup"))
+ folder.DeleteTask("Netch Startup", 0);
+
+ ITaskDefinition task = scheduler.NewTask(0);
+ task.RegistrationInfo.Author = "Netch";
+ task.RegistrationInfo.Description = "Netch run at startup.";
+ task.Principal.RunLevel = _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST;
+
+ task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON);
+ IExecAction action = (IExecAction)task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
+ action.Path = System.Windows.Forms.Application.ExecutablePath;
+
+
+ task.Settings.ExecutionTimeLimit = "PT0S";
+ task.Settings.DisallowStartIfOnBatteries = false;
+ task.Settings.RunOnlyIfIdle = false;
+
+ folder.RegisterTaskDefinition("Netch Startup", task, (int)_TASK_CREATION.TASK_CREATE, null, null, _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, "");
+ }
+ else
+ {
+ if (((IList)tasks_exists).Contains("Netch Startup"))
+ folder.DeleteTask("Netch Startup", 0);
+ }
try
{
diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs
index cd74666b..4488f0bc 100644
--- a/Netch/Models/Setting.cs
+++ b/Netch/Models/Setting.cs
@@ -68,6 +68,11 @@ namespace Netch.Models
///
public bool MinimizeWhenStarted = false;
+ ///
+ /// 是否开机启动软件
+ ///
+ public bool RunAtStartup = false;
+
///
/// 是否打开软件时检查更新
///
diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj
index 7990343a..56858fbb 100644
--- a/Netch/Netch.csproj
+++ b/Netch/Netch.csproj
@@ -52,6 +52,18 @@
+
+
+ e34cb9f1-c7f7-424c-be29-027dcc09363a
+ 1
+ 0
+ tlbimp
+ 0
+ false
+ false
+
+
+
diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN
index d5e27f32..701284ae 100644
--- a/Netch/Resources/zh-CN
+++ b/Netch/Resources/zh-CN
@@ -120,6 +120,7 @@
"Settings": "设置",
"Start when opened": "打开软件时启动加速",
"Minimize when started": "启动加速后隐藏",
+ "Run at startup": "开机自动启动",
"Local Port": "本地端口",
"Allow other Devices to connect": "允许其他设备连入",
"Netmask": "子网掩码",