fixed ssl获取数据异常

This commit is contained in:
LittleBoy 2024-09-05 16:05:28 +08:00
parent 99e0792772
commit f744ba9926
4 changed files with 65 additions and 68 deletions

View File

@ -15,6 +15,10 @@ namespace AIProofread.Util
public static string GetHttpSource(string url) public static string GetHttpSource(string url)
{ {
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
| SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse()) using (HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse())
{ {

View File

@ -30,71 +30,40 @@
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.LabelLog = new System.Windows.Forms.Label(); 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.progressBar1 = new System.Windows.Forms.ProgressBar();
this.BtnCancel = new System.Windows.Forms.Button(); this.ButtonProcess = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// LabelLog // LabelLog
// //
this.LabelLog.BackColor = System.Drawing.SystemColors.ControlLight; 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.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.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.TabIndex = 0;
this.LabelLog.Text = "正在检测"; this.LabelLog.Text = "正在检测";
this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.LabelLog.Click += new System.EventHandler(this.LabelLog_Click); 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 // 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.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(340, 10); this.progressBar1.Size = new System.Drawing.Size(340, 10);
this.progressBar1.TabIndex = 3; this.progressBar1.TabIndex = 3;
this.progressBar1.Visible = false; this.progressBar1.Visible = false;
// //
// BtnCancel // ButtonProcess
// //
this.BtnCancel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); this.ButtonProcess.Location = new System.Drawing.Point(186, 228);
this.BtnCancel.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); this.ButtonProcess.Name = "ButtonProcess";
this.BtnCancel.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Blue; this.ButtonProcess.Size = new System.Drawing.Size(72, 33);
this.BtnCancel.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(100)))), ((int)(((byte)(215))))); this.ButtonProcess.TabIndex = 4;
this.BtnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; this.ButtonProcess.Text = "继续";
this.BtnCancel.ForeColor = System.Drawing.Color.White; this.ButtonProcess.UseVisualStyleBackColor = true;
this.BtnCancel.Location = new System.Drawing.Point(144, 198); this.ButtonProcess.Visible = false;
this.BtnCancel.Name = "BtnCancel"; this.ButtonProcess.Click += new System.EventHandler(this.ButtonProcess_Click);
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);
// //
// Form1 // Form1
// //
@ -102,10 +71,8 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(438, 286); 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.progressBar1);
this.Controls.Add(this.LabelLocalVersion);
this.Controls.Add(this.ButtonUpdate);
this.Controls.Add(this.LabelLog); this.Controls.Add(this.LabelLog);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false; this.MaximizeBox = false;
@ -121,10 +88,8 @@
#endregion #endregion
private System.Windows.Forms.Label LabelLog; 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.ProgressBar progressBar1;
private System.Windows.Forms.Button BtnCancel; private System.Windows.Forms.Button ButtonProcess;
} }
} }

View File

@ -8,6 +8,8 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.Design.WebControls; using System.Web.UI.Design.WebControls;
using System.Windows.Forms; using System.Windows.Forms;
@ -61,17 +63,21 @@ namespace updater
{ {
UpgradeModel local = JsonConvert.DeserializeObject<UpgradeModel>(source); UpgradeModel local = JsonConvert.DeserializeObject<UpgradeModel>(source);
this.localVersion = local.Info; 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; return;
} }
ButtonProcess.Visible = false;
progressBar1.Visible = true; progressBar1.Visible = true;
if (!Directory.Exists(UpgradeDir)) if (!Directory.Exists(UpgradeDir))
{ {
@ -87,23 +93,21 @@ namespace updater
DownLoadFile(upgradeInfo.DownloadUrl, updateFileName); DownLoadFile(upgradeInfo.DownloadUrl, updateFileName);
} }
public bool CheckHostAppRunning() public string CheckHostAppRunning()
{ {
Process[] array = Process.GetProcesses(); Process[] array = Process.GetProcesses();
foreach (Process item2 in array) foreach (Process item2 in array)
{ {
if (item2.ProcessName.Equals("wps")) if (item2.ProcessName.Equals("wps"))
{ {
MessageBox.Show("检测到 WPS 正在运行中,请关闭后再执行更新操作"); return "WPS";
return true;
} }
else if (item2.ProcessName.Equals("WINWORD")) else if (item2.ProcessName.Equals("WINWORD"))
{ {
MessageBox.Show("检测到 Word 正在运行中,请关闭后再执行更新操作"); return "Word";
return true;
} }
} }
return false; return null;
} }
private void LabelLog_Click(object sender, System.EventArgs e) private void LabelLog_Click(object sender, System.EventArgs e)
@ -115,6 +119,7 @@ namespace updater
{ {
try try
{ {
Thread.Sleep(1000);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version"); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version");
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse(); HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
// 获取响应内容 // 获取响应内容
@ -146,21 +151,27 @@ namespace updater
if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version)) if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version))
{ {
ButtonUpdate.Enabled = true; StartUpgrade();
} }
else else
{ {
ButtonUpdate.Visible = false; LabelLog.Text = "当前是最新版本";
BtnCancel.Visible = false; ButtonProcess.Text = "关闭";
LabelLocalVersion.Text = "当前是最新版本"; ButtonProcess.Visible = true;
} }
} }
private void Form1_Load(object sender, EventArgs e) 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) public void DownLoadFile(string url, string filename)
@ -176,6 +187,8 @@ namespace updater
} }
catch (Exception e) catch (Exception e)
{ {
ButtonProcess.Visible = true;
ButtonProcess.Text = "重新更新";
MessageBox.Show(e.Message); MessageBox.Show(e.Message);
} }
} }
@ -221,7 +234,7 @@ namespace updater
} }
} }
} }
MessageBox.Show("更新完成"); MessageBox.Show("更新完成, 您可以打开文档继续校对");
// 保存最新版本日志 // 保存最新版本日志
File.WriteAllText(LocalVersionFilePath, updateSource); File.WriteAllText(LocalVersionFilePath, updateSource);
this.Close(); this.Close();
@ -256,5 +269,20 @@ namespace updater
this.Close(); this.Close();
Application.Exit(); Application.Exit();
} }
private void ButtonProcess_Click(object sender, EventArgs e)
{
switch (ButtonProcess.Text)
{
case "重新更新":
case "继续更新":
StartUpgrade();
break;
case "关闭":
this.Close();
break;
}
}
} }
} }