mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2025-10-22 20:09:46 +08:00
Add Proxy page
This commit is contained in:
127
Source/GrasscutterTools/Pages/PageProxy.cs
Normal file
127
Source/GrasscutterTools/Pages/PageProxy.cs
Normal file
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
**/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击启动GC服务器时触发
|
||||
/// </summary>
|
||||
private void BtnStartGc_Click(object sender, EventArgs e)
|
||||
{
|
||||
// TODO Run java -jar grasscutter.jar
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击代理按钮时触发
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击 Eavesdrop 标签时触发
|
||||
/// </summary>
|
||||
private void LnkEavesdrop_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||
{
|
||||
UIUtil.OpenURL("https://github.com/ArachisH/Eavesdrop");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击关于标签时触发
|
||||
/// </summary>
|
||||
private void LnkAbout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||
{
|
||||
FormMain.Instance.NavigateTo<PageAbout>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击卸载证书时触发
|
||||
/// </summary>
|
||||
private void BtnDestroyCert_Click(object sender, EventArgs e)
|
||||
{
|
||||
Logger.I(TAG, "DestroyCertificate");
|
||||
ProxyHelper.DestroyCertificate();
|
||||
MessageBox.Show("OK", Resources.Tips);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动启动代理选项更改时触发
|
||||
/// </summary>
|
||||
private void ChkAutoStart_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Settings.Default.AutoStartProxy = ChkAutoStart.Checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user