From 2a51fcb47daab64fe84ddff1b2c083e863578ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Sun, 8 Oct 2023 00:01:20 +0800 Subject: [PATCH] Add Proxy page --- Source/GrasscutterTools/App.config | 3 + Source/GrasscutterTools/Forms/FormMain.cs | 60 +++--- .../GrasscutterTools/GrasscutterTools.csproj | 9 + .../Pages/PageCustomCommands.cs | 12 +- .../Pages/PageOpenCommand.Designer.cs | 10 - .../GrasscutterTools/Pages/PageOpenCommand.cs | 45 +--- .../Pages/PageOpenCommand.resx | 51 ++--- .../Pages/PageProxy.Designer.cs | 196 ++++++++++++++++++ Source/GrasscutterTools/Pages/PageProxy.cs | 127 ++++++++++++ Source/GrasscutterTools/Pages/PageProxy.resx | 120 +++++++++++ .../Properties/Resources.Designer.cs | 18 ++ .../Properties/Resources.en-us.resx | 6 + .../Properties/Resources.resx | 6 + .../Properties/Resources.ru-ru.resx | 6 + .../Properties/Resources.zh-TW.resx | 6 + .../Properties/Settings.Designer.cs | 12 ++ .../Properties/Settings.settings | 3 + Source/GrasscutterTools/Utils/ProxyHelper.cs | 15 +- 18 files changed, 579 insertions(+), 126 deletions(-) create mode 100644 Source/GrasscutterTools/Pages/PageProxy.Designer.cs create mode 100644 Source/GrasscutterTools/Pages/PageProxy.cs create mode 100644 Source/GrasscutterTools/Pages/PageProxy.resx diff --git a/Source/GrasscutterTools/App.config b/Source/GrasscutterTools/App.config index e7ee5ad..420ed9f 100644 --- a/Source/GrasscutterTools/App.config +++ b/Source/GrasscutterTools/App.config @@ -79,6 +79,9 @@ True + + False + \ No newline at end of file diff --git a/Source/GrasscutterTools/Forms/FormMain.cs b/Source/GrasscutterTools/Forms/FormMain.cs index 4ed9467..a905114 100644 --- a/Source/GrasscutterTools/Forms/FormMain.cs +++ b/Source/GrasscutterTools/Forms/FormMain.cs @@ -30,15 +30,20 @@ using GrasscutterTools.Utils; namespace GrasscutterTools.Forms { - public partial class FormMain : Form + internal partial class FormMain : Form { - #region - 初始化 Init - + private const string TAG = nameof(FormMain); - private const string TAG = "FormMain"; + public static FormMain Instance { get; private set; } + + #region - 初始化 Init - public FormMain() { Logger.I(TAG, "FormMain ctor enter"); + + Instance = this; + InitializeComponent(); Icon = Resources.IconGrasscutter; @@ -110,21 +115,9 @@ namespace GrasscutterTools.Forms ph.OnLanguageChanged = () => FormMain_Load(this, EventArgs.Empty); var poc = CreatePage(); poc.ShowTipInRunButton = msg => ShowTip(msg, BtnInvokeOpenCommand); - var pcc = CreatePage(); - var phk = CreatePage(); - pcc.OnAddHotKey = tag => - { - phk.AddNewHotKey(tag); - // 跳转到快捷键界面 - for (var i = 0; i < TCMain.Controls.Count; i++) - { - if (TCMain.Controls[i].Controls[0] == phk) - { - ListPages.SelectedIndex = i; - break; - } - } - }; + CreatePage(); + CreatePage(); + CreatePage(); CreatePage(); CreatePage(); CreatePage(); @@ -156,6 +149,7 @@ namespace GrasscutterTools.Forms { Resources.PageHomeTitle, Resources.PageOpenCommandTitle, + Resources.PageProxyTitle, Resources.PageCustomCommandsTitle, Resources.PageHotKey, Resources.PageGetArtifactTitle, @@ -472,16 +466,7 @@ namespace GrasscutterTools.Forms if (Common.OC == null || !Common.OC.CanInvoke) { ShowTip(Resources.RequireOpenCommandTip, BtnInvokeOpenCommand); - //TCMain.SelectedTab = TPRemoteCall; - for (var i = 0; i < TCMain.Controls.Count; i++) - { - if (TCMain.Controls[i].Controls[0] is PageOpenCommand) - { - ListPages.SelectedIndex = i; - break; - } - } - + NavigateTo(); return false; } @@ -637,6 +622,25 @@ namespace GrasscutterTools.Forms TTip.Show(message, control, 0, control.Size.Height, 3000); } + /// + /// 导航到目标页面并返回该页面实例 + /// + /// 页面类型 + /// 如果导航到了则返回页面实例,否则返回空 + public TPage NavigateTo() where TPage : BasePage + { + for (var i = 0; i < TCMain.Controls.Count; i++) + { + if (TCMain.Controls[i].Controls[0] is TPage page) + { + ListPages.SelectedIndex = i; + return page; + } + } + + return null; + } + #endregion - 通用 General - } } \ No newline at end of file diff --git a/Source/GrasscutterTools/GrasscutterTools.csproj b/Source/GrasscutterTools/GrasscutterTools.csproj index 88c5e00..978d396 100644 --- a/Source/GrasscutterTools/GrasscutterTools.csproj +++ b/Source/GrasscutterTools/GrasscutterTools.csproj @@ -280,6 +280,12 @@ PageOpenCommand.cs + + UserControl + + + PageProxy.cs + UserControl @@ -590,6 +596,9 @@ PageOpenCommand.cs + + PageProxy.cs + PageQuest.cs diff --git a/Source/GrasscutterTools/Pages/PageCustomCommands.cs b/Source/GrasscutterTools/Pages/PageCustomCommands.cs index eb89211..f6fd0d7 100644 --- a/Source/GrasscutterTools/Pages/PageCustomCommands.cs +++ b/Source/GrasscutterTools/Pages/PageCustomCommands.cs @@ -21,7 +21,7 @@ using System; using System.IO; using System.Text; using System.Windows.Forms; - +using GrasscutterTools.Forms; using GrasscutterTools.Properties; using GrasscutterTools.Utils; @@ -249,8 +249,9 @@ namespace GrasscutterTools.Pages } } - public Action OnAddHotKey; - + /// + /// 点击添加快捷键时触发 + /// private void BtnAddHotKey_Click(object sender, EventArgs e) { var name = TxtCustomName.Text.Trim(); @@ -259,7 +260,10 @@ namespace GrasscutterTools.Pages MessageBox.Show(Resources.CommandTagCannotBeEmpty, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - OnAddHotKey?.Invoke(name); + + // 跳转到快捷键界面 + FormMain.Instance.NavigateTo()? + .AddNewHotKey(name); // 设置标签 } } } \ No newline at end of file diff --git a/Source/GrasscutterTools/Pages/PageOpenCommand.Designer.cs b/Source/GrasscutterTools/Pages/PageOpenCommand.Designer.cs index b444703..79285ab 100644 --- a/Source/GrasscutterTools/Pages/PageOpenCommand.Designer.cs +++ b/Source/GrasscutterTools/Pages/PageOpenCommand.Designer.cs @@ -60,7 +60,6 @@ this.TxtHost = new System.Windows.Forms.ComboBox(); this.BtnQueryServerStatus = new System.Windows.Forms.Button(); this.LblHost = new System.Windows.Forms.Label(); - this.BtnProxy = new System.Windows.Forms.Button(); this.GrpServerStatus.SuspendLayout(); this.GrpRemoteCommand.SuspendLayout(); this.TPOpenCommandCheck.SuspendLayout(); @@ -302,18 +301,10 @@ resources.ApplyResources(this.LblHost, "LblHost"); this.LblHost.Name = "LblHost"; // - // BtnProxy - // - resources.ApplyResources(this.BtnProxy, "BtnProxy"); - this.BtnProxy.Name = "BtnProxy"; - this.BtnProxy.UseVisualStyleBackColor = true; - this.BtnProxy.Click += new System.EventHandler(this.BtnProxy_Click); - // // PageOpenCommand // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.BtnProxy); this.Controls.Add(this.LnkLinks); this.Controls.Add(this.LnkGOODHelp); this.Controls.Add(this.LnkInventoryKamera); @@ -374,6 +365,5 @@ private System.Windows.Forms.ComboBox TxtHost; private System.Windows.Forms.Button BtnQueryServerStatus; private System.Windows.Forms.Label LblHost; - private System.Windows.Forms.Button BtnProxy; } } diff --git a/Source/GrasscutterTools/Pages/PageOpenCommand.cs b/Source/GrasscutterTools/Pages/PageOpenCommand.cs index 0b065bb..8ecc1c8 100644 --- a/Source/GrasscutterTools/Pages/PageOpenCommand.cs +++ b/Source/GrasscutterTools/Pages/PageOpenCommand.cs @@ -64,8 +64,6 @@ namespace GrasscutterTools.Pages TxtHost.Items.Add("http://127.0.0.1:443"); TxtHost.SelectedIndex = 0; } - - BtnProxy.Text = Resources.StartProxy; } #region - 服务器记录 - @@ -248,6 +246,8 @@ namespace GrasscutterTools.Pages return; } + Settings.Default.Host = host; + var isOcEnabled = false; try { @@ -275,8 +275,6 @@ namespace GrasscutterTools.Pages LblOpenCommandSupport.ForeColor = Color.Red; GrpRemoteCommand.Enabled = false; } - - BtnProxy.Enabled = true; } catch (Exception ex) { @@ -608,44 +606,5 @@ namespace GrasscutterTools.Pages } #endregion - 导入存档 GOOD - - - - #region - 代理 Porxy - - - /// - /// 点击代理按钮时触发 - /// - private void BtnProxy_Click(object sender, EventArgs e) - { - try - { - // 正在运行则关闭 - if (ProxyHelper.IsRunning) - { - ProxyHelper.StopProxy(); - BtnProxy.Text = Resources.StartProxy; - } - else - { - // 创建根证书并检查信任 - if (!ProxyHelper.CheckAndCreateCertifier()) - { - MessageBox.Show("必须先信任根证书才能继续", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - // 启动代理 - ProxyHelper.StartProxy(Common.OC.Host); - BtnProxy.Text = Resources.StopProxy; - } - } - catch (Exception ex) - { - Logger.E(TAG, "Start Proxy failed.", ex); - MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - #endregion } } \ No newline at end of file diff --git a/Source/GrasscutterTools/Pages/PageOpenCommand.resx b/Source/GrasscutterTools/Pages/PageOpenCommand.resx index a925056..211cf92 100644 --- a/Source/GrasscutterTools/Pages/PageOpenCommand.resx +++ b/Source/GrasscutterTools/Pages/PageOpenCommand.resx @@ -151,7 +151,7 @@ $this - 1 + 0 None @@ -184,7 +184,7 @@ $this - 2 + 1 None @@ -214,7 +214,7 @@ $this - 3 + 2 None @@ -244,7 +244,7 @@ $this - 4 + 3 None @@ -274,7 +274,7 @@ $this - 5 + 4 None @@ -307,7 +307,7 @@ $this - 6 + 5 None @@ -514,7 +514,7 @@ $this - 7 + 6 None @@ -923,7 +923,7 @@ $this - 8 + 7 None @@ -947,7 +947,7 @@ $this - 9 + 8 None @@ -959,7 +959,7 @@ 324, 34 - 50, 23 + 50, 25 3 @@ -977,7 +977,7 @@ $this - 10 + 9 None @@ -1010,34 +1010,7 @@ $this - 11 - - - False - - - 3, 3 - - - 120, 25 - - - 11 - - - 启动代理 - - - BtnProxy - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 + 10 True diff --git a/Source/GrasscutterTools/Pages/PageProxy.Designer.cs b/Source/GrasscutterTools/Pages/PageProxy.Designer.cs new file mode 100644 index 0000000..2c2f809 --- /dev/null +++ b/Source/GrasscutterTools/Pages/PageProxy.Designer.cs @@ -0,0 +1,196 @@ +namespace GrasscutterTools.Pages +{ + partial class PageProxy + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.TxtHost = new System.Windows.Forms.TextBox(); + this.LblServerAddress = new System.Windows.Forms.Label(); + this.BtnStartProxy = new System.Windows.Forms.Button(); + this.ChkAutoStart = new System.Windows.Forms.CheckBox(); + this.LblProxyIntroduction = new System.Windows.Forms.Label(); + this.BtnDestroyCert = new System.Windows.Forms.Button(); + this.LnkEavesdrop = new System.Windows.Forms.LinkLabel(); + this.LnkAbout = new System.Windows.Forms.LinkLabel(); + this.LblGcJarPath = new System.Windows.Forms.Label(); + this.TxtGcJarPath = new System.Windows.Forms.TextBox(); + this.BtnStartGc = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // TxtHost + // + this.TxtHost.Anchor = System.Windows.Forms.AnchorStyles.None; + this.TxtHost.Location = new System.Drawing.Point(227, 40); + this.TxtHost.Name = "TxtHost"; + this.TxtHost.Size = new System.Drawing.Size(160, 23); + this.TxtHost.TabIndex = 4; + this.TxtHost.Text = "http://127.0.0.1:443"; + // + // LblServerAddress + // + this.LblServerAddress.Anchor = System.Windows.Forms.AnchorStyles.None; + this.LblServerAddress.AutoSize = true; + this.LblServerAddress.Location = new System.Drawing.Point(84, 43); + this.LblServerAddress.Name = "LblServerAddress"; + this.LblServerAddress.Size = new System.Drawing.Size(137, 17); + this.LblServerAddress.TabIndex = 3; + this.LblServerAddress.Text = "目标 http(s) 服务器地址"; + // + // BtnStartProxy + // + this.BtnStartProxy.Anchor = System.Windows.Forms.AnchorStyles.None; + this.BtnStartProxy.Location = new System.Drawing.Point(393, 40); + this.BtnStartProxy.Name = "BtnStartProxy"; + this.BtnStartProxy.Size = new System.Drawing.Size(120, 25); + this.BtnStartProxy.TabIndex = 5; + this.BtnStartProxy.Text = "启动代理"; + this.BtnStartProxy.UseVisualStyleBackColor = true; + this.BtnStartProxy.Click += new System.EventHandler(this.BtnStartProxy_Click); + // + // ChkAutoStart + // + this.ChkAutoStart.Anchor = System.Windows.Forms.AnchorStyles.None; + this.ChkAutoStart.AutoSize = true; + this.ChkAutoStart.Location = new System.Drawing.Point(519, 42); + this.ChkAutoStart.Name = "ChkAutoStart"; + this.ChkAutoStart.Size = new System.Drawing.Size(75, 21); + this.ChkAutoStart.TabIndex = 6; + this.ChkAutoStart.Text = "自动开启"; + this.ChkAutoStart.UseVisualStyleBackColor = true; + this.ChkAutoStart.CheckedChanged += new System.EventHandler(this.ChkAutoStart_CheckedChanged); + // + // LblProxyIntroduction + // + this.LblProxyIntroduction.Anchor = System.Windows.Forms.AnchorStyles.None; + this.LblProxyIntroduction.Location = new System.Drawing.Point(48, 72); + this.LblProxyIntroduction.Name = "LblProxyIntroduction"; + this.LblProxyIntroduction.Size = new System.Drawing.Size(550, 120); + this.LblProxyIntroduction.TabIndex = 7; + this.LblProxyIntroduction.Text = " 启动代理需要信任本应用的临时根证书,该证书仅用于代理动漫游戏相关请求,有效期1月,你可以随时点击右下角卸载证书。\r\n 代理功能代码来自开源项目 Ea" + + "vesdrop,遵循MIT开源协议,经过魔改以匹配应用需求。\r\n 本代理通过大量过滤规则来规避非动漫游戏的请求经过应用,减小影响,欢迎体验!\r\n 程" + + "序退出时会自动关闭代理,放心使用 :)"; + // + // BtnDestroyCert + // + this.BtnDestroyCert.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.BtnDestroyCert.Location = new System.Drawing.Point(529, 207); + this.BtnDestroyCert.Name = "BtnDestroyCert"; + this.BtnDestroyCert.Size = new System.Drawing.Size(100, 25); + this.BtnDestroyCert.TabIndex = 10; + this.BtnDestroyCert.Text = "卸载证书"; + this.BtnDestroyCert.UseVisualStyleBackColor = true; + this.BtnDestroyCert.Click += new System.EventHandler(this.BtnDestroyCert_Click); + // + // LnkEavesdrop + // + this.LnkEavesdrop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.LnkEavesdrop.AutoSize = true; + this.LnkEavesdrop.Location = new System.Drawing.Point(15, 211); + this.LnkEavesdrop.Name = "LnkEavesdrop"; + this.LnkEavesdrop.Size = new System.Drawing.Size(70, 17); + this.LnkEavesdrop.TabIndex = 8; + this.LnkEavesdrop.TabStop = true; + this.LnkEavesdrop.Text = "Eavesdrop"; + this.LnkEavesdrop.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LnkEavesdrop_LinkClicked); + // + // LnkAbout + // + this.LnkAbout.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.LnkAbout.AutoSize = true; + this.LnkAbout.Location = new System.Drawing.Point(482, 211); + this.LnkAbout.Name = "LnkAbout"; + this.LnkAbout.Size = new System.Drawing.Size(32, 17); + this.LnkAbout.TabIndex = 9; + this.LnkAbout.TabStop = true; + this.LnkAbout.Text = "关于"; + this.LnkAbout.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LnkAbout_LinkClicked); + // + // LblGcJarPath + // + this.LblGcJarPath.AutoSize = true; + this.LblGcJarPath.Location = new System.Drawing.Point(102, 14); + this.LblGcJarPath.Name = "LblGcJarPath"; + this.LblGcJarPath.Size = new System.Drawing.Size(119, 17); + this.LblGcJarPath.TabIndex = 0; + this.LblGcJarPath.Text = "GrasscutterJar 路径"; + this.LblGcJarPath.Visible = false; + // + // TxtGcJarPath + // + this.TxtGcJarPath.Location = new System.Drawing.Point(227, 11); + this.TxtGcJarPath.Name = "TxtGcJarPath"; + this.TxtGcJarPath.Size = new System.Drawing.Size(160, 23); + this.TxtGcJarPath.TabIndex = 1; + this.TxtGcJarPath.Visible = false; + // + // BtnStartGc + // + this.BtnStartGc.Location = new System.Drawing.Point(393, 11); + this.BtnStartGc.Name = "BtnStartGc"; + this.BtnStartGc.Size = new System.Drawing.Size(120, 25); + this.BtnStartGc.TabIndex = 2; + this.BtnStartGc.Text = "启动服务器"; + this.BtnStartGc.UseVisualStyleBackColor = true; + this.BtnStartGc.Visible = false; + this.BtnStartGc.Click += new System.EventHandler(this.BtnStartGc_Click); + // + // PageProxy + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.BtnStartGc); + this.Controls.Add(this.TxtGcJarPath); + this.Controls.Add(this.LblGcJarPath); + this.Controls.Add(this.LnkAbout); + this.Controls.Add(this.LnkEavesdrop); + this.Controls.Add(this.BtnDestroyCert); + this.Controls.Add(this.LblProxyIntroduction); + this.Controls.Add(this.ChkAutoStart); + this.Controls.Add(this.BtnStartProxy); + this.Controls.Add(this.LblServerAddress); + this.Controls.Add(this.TxtHost); + this.Name = "PageProxy"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox TxtHost; + private System.Windows.Forms.Label LblServerAddress; + private System.Windows.Forms.Button BtnStartProxy; + private System.Windows.Forms.CheckBox ChkAutoStart; + private System.Windows.Forms.Label LblProxyIntroduction; + private System.Windows.Forms.Button BtnDestroyCert; + private System.Windows.Forms.LinkLabel LnkEavesdrop; + private System.Windows.Forms.LinkLabel LnkAbout; + private System.Windows.Forms.Label LblGcJarPath; + private System.Windows.Forms.TextBox TxtGcJarPath; + private System.Windows.Forms.Button BtnStartGc; + } +} diff --git a/Source/GrasscutterTools/Pages/PageProxy.cs b/Source/GrasscutterTools/Pages/PageProxy.cs new file mode 100644 index 0000000..6c35f44 --- /dev/null +++ b/Source/GrasscutterTools/Pages/PageProxy.cs @@ -0,0 +1,127 @@ +/** + * Grasscutter Tools + * Copyright (C) 2023 jie65535 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + **/ + +using System; +using System.Windows.Forms; +using GrasscutterTools.Forms; +using GrasscutterTools.Properties; +using GrasscutterTools.Utils; + +namespace GrasscutterTools.Pages +{ + internal partial class PageProxy : BasePage + { + private const string TAG = nameof(PageProxy); + public PageProxy() + { + InitializeComponent(); + } + + public override void OnLoad() + { + if (!string.IsNullOrEmpty(Settings.Default.Host)) + TxtHost.Text = Settings.Default.Host; + ChkAutoStart.Checked = Settings.Default.AutoStartProxy; + + if (Settings.Default.AutoStartProxy && !ProxyHelper.IsRunning) + { + Logger.I(TAG, "Auto start proxy!"); + BtnStartProxy_Click(BtnStartProxy, EventArgs.Empty); + } + } + + /// + /// 点击启动GC服务器时触发 + /// + private void BtnStartGc_Click(object sender, EventArgs e) + { + // TODO Run java -jar grasscutter.jar + } + + /// + /// 点击代理按钮时触发 + /// + private void BtnStartProxy_Click(object sender, EventArgs e) + { + try + { + // 正在运行则关闭 + if (ProxyHelper.IsRunning) + { + ProxyHelper.StopProxy(); + BtnStartProxy.Text = Resources.StartProxy; + TxtHost.Enabled = true; + } + else + { + // 创建根证书并检查信任 + if (!ProxyHelper.CheckAndCreateCertificate()) + { + MessageBox.Show(Resources.TrustedBeforeContinuing, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // 启动代理 + ProxyHelper.StartProxy(TxtHost.Text); + BtnStartProxy.Text = Resources.StopProxy; + TxtHost.Enabled = false; + } + } + catch (Exception ex) + { + Logger.E(TAG, "Start Proxy failed.", ex); + MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// 点击 Eavesdrop 标签时触发 + /// + private void LnkEavesdrop_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + UIUtil.OpenURL("https://github.com/ArachisH/Eavesdrop"); + } + + /// + /// 点击关于标签时触发 + /// + private void LnkAbout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + FormMain.Instance.NavigateTo(); + } + + /// + /// 点击卸载证书时触发 + /// + private void BtnDestroyCert_Click(object sender, EventArgs e) + { + Logger.I(TAG, "DestroyCertificate"); + ProxyHelper.DestroyCertificate(); + MessageBox.Show("OK", Resources.Tips); + } + + /// + /// 自动启动代理选项更改时触发 + /// + private void ChkAutoStart_CheckedChanged(object sender, EventArgs e) + { + Settings.Default.AutoStartProxy = ChkAutoStart.Checked; + } + } +} diff --git a/Source/GrasscutterTools/Pages/PageProxy.resx b/Source/GrasscutterTools/Pages/PageProxy.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Source/GrasscutterTools/Pages/PageProxy.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Source/GrasscutterTools/Properties/Resources.Designer.cs b/Source/GrasscutterTools/Properties/Resources.Designer.cs index d73bd89..4489ef6 100644 --- a/Source/GrasscutterTools/Properties/Resources.Designer.cs +++ b/Source/GrasscutterTools/Properties/Resources.Designer.cs @@ -1194,6 +1194,15 @@ namespace GrasscutterTools.Properties { } } + /// + /// 查找类似 代理 的本地化字符串。 + /// + internal static string PageProxyTitle { + get { + return ResourceManager.GetString("PageProxyTitle", resourceCulture); + } + } + /// /// 查找类似 任务 的本地化字符串。 /// @@ -1588,6 +1597,15 @@ namespace GrasscutterTools.Properties { } } + /// + /// 查找类似 必须先信任根证书才能继续! 的本地化字符串。 + /// + internal static string TrustedBeforeContinuing { + get { + return ResourceManager.GetString("TrustedBeforeContinuing", resourceCulture); + } + } + /// /// 查找类似 用户名不能为空! 的本地化字符串。 /// diff --git a/Source/GrasscutterTools/Properties/Resources.en-us.resx b/Source/GrasscutterTools/Properties/Resources.en-us.resx index 439d7d8..20a5a6e 100644 --- a/Source/GrasscutterTools/Properties/Resources.en-us.resx +++ b/Source/GrasscutterTools/Properties/Resources.en-us.resx @@ -375,4 +375,10 @@ Improvement suggestions have been submitted, please use caution to send emails t SceneTag + + The root certificate must be trusted before continuing! + + + Proxy + \ No newline at end of file diff --git a/Source/GrasscutterTools/Properties/Resources.resx b/Source/GrasscutterTools/Properties/Resources.resx index a6be29c..155e4e6 100644 --- a/Source/GrasscutterTools/Properties/Resources.resx +++ b/Source/GrasscutterTools/Properties/Resources.resx @@ -387,4 +387,10 @@ 场景项 + + 必须先信任根证书才能继续! + + + 代理 + \ No newline at end of file diff --git a/Source/GrasscutterTools/Properties/Resources.ru-ru.resx b/Source/GrasscutterTools/Properties/Resources.ru-ru.resx index 6b965bb..eae051e 100644 --- a/Source/GrasscutterTools/Properties/Resources.ru-ru.resx +++ b/Source/GrasscutterTools/Properties/Resources.ru-ru.resx @@ -363,4 +363,10 @@ Тег сцены + + Прежде чем продолжить, необходимо доверять корневому сертификату! + + + Прокси + \ No newline at end of file diff --git a/Source/GrasscutterTools/Properties/Resources.zh-TW.resx b/Source/GrasscutterTools/Properties/Resources.zh-TW.resx index 6c528fd..eac966a 100644 --- a/Source/GrasscutterTools/Properties/Resources.zh-TW.resx +++ b/Source/GrasscutterTools/Properties/Resources.zh-TW.resx @@ -369,4 +369,10 @@ 場景項 + + 必須先信任根憑證才能繼續! + + + 代理 + \ No newline at end of file diff --git a/Source/GrasscutterTools/Properties/Settings.Designer.cs b/Source/GrasscutterTools/Properties/Settings.Designer.cs index 89fd0e2..26ea288 100644 --- a/Source/GrasscutterTools/Properties/Settings.Designer.cs +++ b/Source/GrasscutterTools/Properties/Settings.Designer.cs @@ -298,5 +298,17 @@ namespace GrasscutterTools.Properties { this["IsHotkeyEenabled"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool AutoStartProxy { + get { + return ((bool)(this["AutoStartProxy"])); + } + set { + this["AutoStartProxy"] = value; + } + } } } diff --git a/Source/GrasscutterTools/Properties/Settings.settings b/Source/GrasscutterTools/Properties/Settings.settings index 617f771..d6d89d4 100644 --- a/Source/GrasscutterTools/Properties/Settings.settings +++ b/Source/GrasscutterTools/Properties/Settings.settings @@ -71,5 +71,8 @@ True + + False + \ No newline at end of file diff --git a/Source/GrasscutterTools/Utils/ProxyHelper.cs b/Source/GrasscutterTools/Utils/ProxyHelper.cs index 2bce984..22051f9 100644 --- a/Source/GrasscutterTools/Utils/ProxyHelper.cs +++ b/Source/GrasscutterTools/Utils/ProxyHelper.cs @@ -30,6 +30,11 @@ namespace GrasscutterTools.Utils { private const string TAG = "Proxy"; + static ProxyHelper() + { + Eavesdropper.Certifier = new Certifier("jie65535", "GrasscutterTools Root Certificate Authority"); + } + #region - Windows API - [DllImport("wininet.dll")] @@ -171,6 +176,8 @@ namespace GrasscutterTools.Utils private static string _gcDispatch; public static void StartProxy(string gcDispatch) { + // Check Url format + var _ = new Uri(gcDispatch); _gcDispatch = gcDispatch.TrimEnd('/'); Logger.I(TAG, "Start Proxy, redirect to " + _gcDispatch); StartGsProxyServer(ProxyServerPort); @@ -184,12 +191,16 @@ namespace GrasscutterTools.Utils StopGsProxyServer(); } - public static bool CheckAndCreateCertifier() + public static bool CheckAndCreateCertificate() { - Eavesdropper.Certifier = new Certifier("jie65535", "GrasscutterTools Root Certificate Authority"); return Eavesdropper.Certifier.CreateTrustedRootCertificate(); } + public static bool DestroyCertificate() + { + return Eavesdropper.Certifier.DestroyTrustedRootCertificate(); + } + public static bool IsRunning => Eavesdropper.IsRunning; } }