From f744ba992685aae7a8829bb015ea5a326ef28c07 Mon Sep 17 00:00:00 2001 From: callmeyan Date: Thu, 5 Sep 2024 16:05:28 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20ssl=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIProofread/Util/HttpUtil.cs | 4 ++ updater/Form1.Designer.cs | 65 ++++++++------------------------- updater/Form1.cs | 62 ++++++++++++++++++++++--------- updater/Properties/app.manifest | 2 +- 4 files changed, 65 insertions(+), 68 deletions(-) diff --git a/AIProofread/Util/HttpUtil.cs b/AIProofread/Util/HttpUtil.cs index d37ded7..462378c 100644 --- a/AIProofread/Util/HttpUtil.cs +++ b/AIProofread/Util/HttpUtil.cs @@ -15,6 +15,10 @@ namespace AIProofread.Util public static string GetHttpSource(string url) { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 + | SecurityProtocolType.Tls + | SecurityProtocolType.Tls11 + | SecurityProtocolType.Tls12; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); using (HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse()) { diff --git a/updater/Form1.Designer.cs b/updater/Form1.Designer.cs index 5ef2e1d..9fd6dec 100644 --- a/updater/Form1.Designer.cs +++ b/updater/Form1.Designer.cs @@ -30,71 +30,40 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.LabelLog = new System.Windows.Forms.Label(); - this.ButtonUpdate = new System.Windows.Forms.Button(); - this.LabelLocalVersion = new System.Windows.Forms.Label(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); - this.BtnCancel = new System.Windows.Forms.Button(); + this.ButtonProcess = new System.Windows.Forms.Button(); this.SuspendLayout(); // // LabelLog // this.LabelLog.BackColor = System.Drawing.SystemColors.ControlLight; this.LabelLog.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.LabelLog.Location = new System.Drawing.Point(52, 52); + this.LabelLog.Location = new System.Drawing.Point(52, 30); this.LabelLog.Name = "LabelLog"; - this.LabelLog.Size = new System.Drawing.Size(340, 100); + this.LabelLog.Size = new System.Drawing.Size(340, 169); this.LabelLog.TabIndex = 0; this.LabelLog.Text = "正在检测"; this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.LabelLog.Click += new System.EventHandler(this.LabelLog_Click); // - // ButtonUpdate - // - this.ButtonUpdate.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); - this.ButtonUpdate.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); - this.ButtonUpdate.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Blue; - this.ButtonUpdate.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); - this.ButtonUpdate.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.ButtonUpdate.ForeColor = System.Drawing.Color.White; - this.ButtonUpdate.Location = new System.Drawing.Point(228, 198); - this.ButtonUpdate.Name = "ButtonUpdate"; - this.ButtonUpdate.Size = new System.Drawing.Size(78, 31); - this.ButtonUpdate.TabIndex = 1; - this.ButtonUpdate.Text = "立即更新"; - this.ButtonUpdate.UseVisualStyleBackColor = false; - this.ButtonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); - // - // LabelLocalVersion - // - this.LabelLocalVersion.Location = new System.Drawing.Point(172, 232); - this.LabelLocalVersion.Name = "LabelLocalVersion"; - this.LabelLocalVersion.Size = new System.Drawing.Size(100, 23); - this.LabelLocalVersion.TabIndex = 2; - this.LabelLocalVersion.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // progressBar1 // - this.progressBar1.Location = new System.Drawing.Point(52, 159); + this.progressBar1.Location = new System.Drawing.Point(52, 210); this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(340, 10); this.progressBar1.TabIndex = 3; this.progressBar1.Visible = false; // - // BtnCancel + // ButtonProcess // - this.BtnCancel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); - this.BtnCancel.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); - this.BtnCancel.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Blue; - this.BtnCancel.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); - this.BtnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.BtnCancel.ForeColor = System.Drawing.Color.White; - this.BtnCancel.Location = new System.Drawing.Point(144, 198); - this.BtnCancel.Name = "BtnCancel"; - this.BtnCancel.Size = new System.Drawing.Size(78, 31); - this.BtnCancel.TabIndex = 4; - this.BtnCancel.Text = "取消更新"; - this.BtnCancel.UseVisualStyleBackColor = false; - this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click); + this.ButtonProcess.Location = new System.Drawing.Point(186, 228); + this.ButtonProcess.Name = "ButtonProcess"; + this.ButtonProcess.Size = new System.Drawing.Size(72, 33); + this.ButtonProcess.TabIndex = 4; + this.ButtonProcess.Text = "继续"; + this.ButtonProcess.UseVisualStyleBackColor = true; + this.ButtonProcess.Visible = false; + this.ButtonProcess.Click += new System.EventHandler(this.ButtonProcess_Click); // // Form1 // @@ -102,10 +71,8 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(438, 286); - this.Controls.Add(this.BtnCancel); + this.Controls.Add(this.ButtonProcess); this.Controls.Add(this.progressBar1); - this.Controls.Add(this.LabelLocalVersion); - this.Controls.Add(this.ButtonUpdate); this.Controls.Add(this.LabelLog); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; @@ -121,10 +88,8 @@ #endregion private System.Windows.Forms.Label LabelLog; - private System.Windows.Forms.Button ButtonUpdate; - private System.Windows.Forms.Label LabelLocalVersion; private System.Windows.Forms.ProgressBar progressBar1; - private System.Windows.Forms.Button BtnCancel; + private System.Windows.Forms.Button ButtonProcess; } } diff --git a/updater/Form1.cs b/updater/Form1.cs index 82d8125..1389695 100644 --- a/updater/Form1.cs +++ b/updater/Form1.cs @@ -8,6 +8,8 @@ using System.IO; using System.IO.Compression; using System.Net; using System.Text; +using System.Threading; +using System.Threading.Tasks; using System.Web.UI.Design.WebControls; using System.Windows.Forms; @@ -61,17 +63,21 @@ namespace updater { UpgradeModel local = JsonConvert.DeserializeObject(source); this.localVersion = local.Info; - LabelLocalVersion.Text = localVersion.Version; } } - private void ButtonUpdate_Click(object sender, System.EventArgs e) + private void StartUpgrade() { - if (CheckHostAppRunning()) + string runningApp = CheckHostAppRunning(); + if (!string.IsNullOrEmpty(runningApp)) { + MessageBox.Show(string.Format("检测到{0}正在运行中,请关闭{0}后继续执行更新操作",runningApp)); + ButtonProcess.Visible = true; + ButtonProcess.Text = "继续更新"; return; } + ButtonProcess.Visible = false; progressBar1.Visible = true; if (!Directory.Exists(UpgradeDir)) { @@ -87,23 +93,21 @@ namespace updater DownLoadFile(upgradeInfo.DownloadUrl, updateFileName); } - public bool CheckHostAppRunning() + public string CheckHostAppRunning() { Process[] array = Process.GetProcesses(); foreach (Process item2 in array) { if (item2.ProcessName.Equals("wps")) { - MessageBox.Show("检测到 WPS 正在运行中,请关闭后再执行更新操作"); - return true; + return "WPS"; } else if (item2.ProcessName.Equals("WINWORD")) { - MessageBox.Show("检测到 Word 正在运行中,请关闭后再执行更新操作"); - return true; + return "Word"; } } - return false; + return null; } private void LabelLog_Click(object sender, System.EventArgs e) @@ -115,6 +119,7 @@ namespace updater { try { + Thread.Sleep(1000); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version"); HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse(); // 获取响应内容 @@ -146,21 +151,27 @@ namespace updater if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version)) { - ButtonUpdate.Enabled = true; + StartUpgrade(); } else { - ButtonUpdate.Visible = false; - BtnCancel.Visible = false; - LabelLocalVersion.Text = "当前是最新版本"; + LabelLog.Text = "当前是最新版本"; + ButtonProcess.Text = "关闭"; + ButtonProcess.Visible = true; } } private void Form1_Load(object sender, EventArgs e) { - ButtonUpdate.Enabled = false; - CheckUpdate(); - + + Task t = new Task(() => + { + ButtonProcess.Invoke(new Action(() => + { + CheckUpdate(); + })); + }); + t.Start(); } public void DownLoadFile(string url, string filename) @@ -176,6 +187,8 @@ namespace updater } catch (Exception e) { + ButtonProcess.Visible = true; + ButtonProcess.Text = "重新更新"; MessageBox.Show(e.Message); } } @@ -221,7 +234,7 @@ namespace updater } } } - MessageBox.Show("更新完成"); + MessageBox.Show("更新完成, 您可以打开文档继续校对"); // 保存最新版本日志 File.WriteAllText(LocalVersionFilePath, updateSource); this.Close(); @@ -256,5 +269,20 @@ namespace updater this.Close(); Application.Exit(); } + + private void ButtonProcess_Click(object sender, EventArgs e) + { + switch (ButtonProcess.Text) + { + case "重新更新": + case "继续更新": + StartUpgrade(); + break; + case "关闭": + this.Close(); + break; + + } + } } } diff --git a/updater/Properties/app.manifest b/updater/Properties/app.manifest index 303298c..13e66c8 100644 --- a/updater/Properties/app.manifest +++ b/updater/Properties/app.manifest @@ -15,7 +15,7 @@ 如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此 元素。 --> - +