From d570085ec83ed967019132a270d3cd2d005bdeb7 Mon Sep 17 00:00:00 2001 From: wisdomwei201804 Date: Mon, 30 Apr 2018 11:29:53 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.3.0=20=20=E5=BC=80=E5=8F=91=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=B8=AD...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net.nutcore.aliddns/Form_About.cs | 39 +------------ .../net.nutcore.aliddns/Program.cs | 3 - .../net.nutcore.aliddns/main.Designer.cs | 18 ++++-- .../net.nutcore.aliddns/main.cs | 58 +++++++++++++++++++ 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs index 6d6911e..1ad5e74 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs @@ -3,8 +3,6 @@ using System.Text; using System.IO; using System.Windows.Forms; using System.Xml; -using System.Net; -using System.Net.Http; namespace net.nutcore.aliddns { @@ -110,41 +108,8 @@ namespace net.nutcore.aliddns { checkBox_autoCheckUpdate.Checked = true; //获取远程版本信息 - try - { - string strUrl = "https://github.com/wisdomwei201804/AliDDNS/releases/latest"; - if (strUrl.StartsWith("https")) - System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls1.2 | SecurityProtocolType.Tls12; - HttpClient httpClient = new HttpClient( - new HttpClientHandler - { - //CookieContainer = cookies, - AutomaticDecompression = DecompressionMethods.GZip //防止返回的json乱码 - | DecompressionMethods.Deflate - }); - httpClient.DefaultRequestHeaders.Add("UserAgent", "Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1)"); - httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4"); - httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, sdch"); - httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/x-www-form-urlencoded,application/xhtml+xml,application/json,application/xml;q=0.9,image/webp,*/*;q=0.8"); - httpClient.DefaultRequestHeaders.Accept.Clear(); - httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - httpClient.DefaultRequestHeaders.AcceptCharset.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("UTF-8")); - HttpResponseMessage response = httpClient.GetAsync(strUrl).Result; - //var statusCode = response.StatusCode.ToString(); - if (response.IsSuccessStatusCode) - { - string result = response.Content.ReadAsStringAsync().Result; - string ver = System.Text.RegularExpressions.Regex.Match(result, @"""tag_name"":""([^""]*)""").Groups[1].Value; - label_latestVer.Text = ver.ToString(); - //MessageBox.Show(ver); - //return result; - } - } - catch (Exception error) - { - MessageBox.Show(error.ToString()); - } - + string strVer = mainForm.verCheckUpdate(); + label_latestVer.Text = strVer.ToString(); } else checkBox_autoCheckUpdate.Checked = false; } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Program.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Program.cs index 758e850..85ae51e 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Program.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Program.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Threading.Tasks; using System.Windows.Forms; namespace net.nutcore.aliddns diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/main.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/main.Designer.cs index 0a87446..ca16fbe 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/main.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/main.Designer.cs @@ -82,6 +82,7 @@ this.comboBox_whatIsUrl = new System.Windows.Forms.ComboBox(); this.button_whatIsTest = new System.Windows.Forms.Button(); this.label14 = new System.Windows.Forms.Label(); + this.ToolStripMenuItem_checkUpdate = new System.Windows.Forms.ToolStripMenuItem(); this.timeSetGroup.SuspendLayout(); this.debugMessage.SuspendLayout(); this.globalSetGroup.SuspendLayout(); @@ -326,7 +327,7 @@ // textBox_TTL // this.textBox_TTL.Location = new System.Drawing.Point(65, 121); - this.textBox_TTL.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox_TTL.Margin = new System.Windows.Forms.Padding(2); this.textBox_TTL.Name = "textBox_TTL"; this.textBox_TTL.Size = new System.Drawing.Size(37, 21); this.textBox_TTL.TabIndex = 15; @@ -451,21 +452,22 @@ this.contextMenuStrip_sysTrayMenu.ImageScalingSize = new System.Drawing.Size(24, 24); this.contextMenuStrip_sysTrayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem_Exit, + this.ToolStripMenuItem_checkUpdate, this.ToolStripMenuItem_About}); this.contextMenuStrip_sysTrayMenu.Name = "contextMenuStrip1"; - this.contextMenuStrip_sysTrayMenu.Size = new System.Drawing.Size(101, 48); + this.contextMenuStrip_sysTrayMenu.Size = new System.Drawing.Size(153, 92); // // toolStripMenuItem_Exit // this.toolStripMenuItem_Exit.Name = "toolStripMenuItem_Exit"; - this.toolStripMenuItem_Exit.Size = new System.Drawing.Size(100, 22); + this.toolStripMenuItem_Exit.Size = new System.Drawing.Size(152, 22); this.toolStripMenuItem_Exit.Text = "退出"; this.toolStripMenuItem_Exit.Click += new System.EventHandler(this.toolStripMenuItem1_Click); // // ToolStripMenuItem_About // this.ToolStripMenuItem_About.Name = "ToolStripMenuItem_About"; - this.ToolStripMenuItem_About.Size = new System.Drawing.Size(100, 22); + this.ToolStripMenuItem_About.Size = new System.Drawing.Size(152, 22); this.ToolStripMenuItem_About.Text = "关于"; this.ToolStripMenuItem_About.Click += new System.EventHandler(this.ToolStripMenuItem_About_Click); // @@ -614,6 +616,13 @@ this.label14.TabIndex = 16; this.label14.Text = "查询网址:"; // + // ToolStripMenuItem_checkUpdate + // + this.ToolStripMenuItem_checkUpdate.Name = "ToolStripMenuItem_checkUpdate"; + this.ToolStripMenuItem_checkUpdate.Size = new System.Drawing.Size(152, 22); + this.ToolStripMenuItem_checkUpdate.Text = "检查升级"; + this.ToolStripMenuItem_checkUpdate.Click += new System.EventHandler(this.ToolStripMenuItem_checkUPdate_Click); + // // mainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -700,6 +709,7 @@ private System.Windows.Forms.Label label15; private System.Windows.Forms.Label label13; private System.Windows.Forms.TextBox textBox_TTL; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_checkUpdate; } } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/main.cs b/net.nutcore.aliddns/net.nutcore.aliddns/main.cs index bba48bd..9444613 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/main.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/main.cs @@ -794,6 +794,64 @@ namespace net.nutcore.aliddns } } + + public static string verCheckUpdate() + { + try + { + string strUrl = "https://github.com/wisdomwei201804/AliDDNS/releases/latest"; + if (strUrl.StartsWith("https")) + System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls1.2 | SecurityProtocolType.Tls12; + System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient( + new System.Net.Http.HttpClientHandler + { + //CookieContainer = cookies, + AutomaticDecompression = DecompressionMethods.GZip //防止返回的json乱码 + | DecompressionMethods.Deflate + }); + httpClient.DefaultRequestHeaders.Add("UserAgent", "Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1)"); + httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4"); + httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, sdch"); + httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/x-www-form-urlencoded,application/xhtml+xml,application/json,application/xml;q=0.9,image/webp,*/*;q=0.8"); + httpClient.DefaultRequestHeaders.Accept.Clear(); + httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + httpClient.DefaultRequestHeaders.AcceptCharset.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("UTF-8")); + System.Net.Http.HttpResponseMessage response = httpClient.GetAsync(strUrl).Result; + //var statusCode = response.StatusCode.ToString(); + if (response.IsSuccessStatusCode) + { + string result = response.Content.ReadAsStringAsync().Result; + string ver = System.Text.RegularExpressions.Regex.Match(result, @"""tag_name"":""([^""]*)""").Groups[1].Value; + //MessageBox.Show(ver); + return ver.ToString(); + } + else + return null; + httpClient.Dispose(); + response.Dispose(); + } + catch (Exception error) + { + MessageBox.Show(error.ToString()); + return null; + } + } + + private void ToolStripMenuItem_checkUPdate_Click(object sender, EventArgs e) + { + string strVer = verCheckUpdate(); + if (strVer != null) + { + Version remoteVer = new Version(strVer); + Version localVer = new Version(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); + if (remoteVer > localVer) + MessageBox.Show("发现新版本: " + remoteVer); + else + MessageBox.Show("没有新版本,无需升级!"); + } + else + MessageBox.Show("获取新版本信息失败!"); + } } ///