From 5e8a10213111e8ea11179f3beeb24ceac1d432a4 Mon Sep 17 00:00:00 2001 From: wisdomwei201804 Date: Sun, 29 Apr 2018 23:11:03 +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 --- .../Form_About.Designer.cs | 81 +++++------ .../net.nutcore.aliddns/Form_About.cs | 129 ++++++++---------- 2 files changed, 98 insertions(+), 112 deletions(-) diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.Designer.cs index 952470b..8287eaf 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.Designer.cs @@ -38,11 +38,11 @@ this.personalWebsite = new System.Windows.Forms.LinkLabel(); this.textBox_updateInfo = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.label4 = new System.Windows.Forms.Label(); - this.label_currentVer = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.label_latestVer = new System.Windows.Forms.Label(); this.checkBox_autoCheckUpdate = new System.Windows.Forms.CheckBox(); + this.label_latestVer = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label_currentVer = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); this.authorInformation.SuspendLayout(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); @@ -145,42 +145,6 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "升级设置"; // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(6, 19); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(59, 12); - this.label4.TabIndex = 0; - this.label4.Text = "当前版本:"; - // - // label_currentVer - // - this.label_currentVer.AutoSize = true; - this.label_currentVer.Location = new System.Drawing.Point(71, 19); - this.label_currentVer.Name = "label_currentVer"; - this.label_currentVer.Size = new System.Drawing.Size(47, 12); - this.label_currentVer.TabIndex = 1; - this.label_currentVer.Text = "0.0.0.0"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(125, 19); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(59, 12); - this.label6.TabIndex = 2; - this.label6.Text = "最新版本:"; - // - // label_latestVer - // - this.label_latestVer.AutoSize = true; - this.label_latestVer.Location = new System.Drawing.Point(185, 19); - this.label_latestVer.Name = "label_latestVer"; - this.label_latestVer.Size = new System.Drawing.Size(47, 12); - this.label_latestVer.TabIndex = 3; - this.label_latestVer.Text = "0.0.0.0"; - // // checkBox_autoCheckUpdate // this.checkBox_autoCheckUpdate.AutoSize = true; @@ -194,6 +158,42 @@ this.checkBox_autoCheckUpdate.UseVisualStyleBackColor = true; this.checkBox_autoCheckUpdate.CheckedChanged += new System.EventHandler(this.checkBox_autoCheckUpdate_CheckedChanged); // + // label_latestVer + // + this.label_latestVer.AutoSize = true; + this.label_latestVer.Location = new System.Drawing.Point(185, 19); + this.label_latestVer.Name = "label_latestVer"; + this.label_latestVer.Size = new System.Drawing.Size(47, 12); + this.label_latestVer.TabIndex = 3; + this.label_latestVer.Text = "0.0.0.0"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(125, 19); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(59, 12); + this.label6.TabIndex = 2; + this.label6.Text = "最新版本:"; + // + // label_currentVer + // + this.label_currentVer.AutoSize = true; + this.label_currentVer.Location = new System.Drawing.Point(71, 19); + this.label_currentVer.Name = "label_currentVer"; + this.label_currentVer.Size = new System.Drawing.Size(47, 12); + this.label_currentVer.TabIndex = 1; + this.label_currentVer.Text = "0.0.0.0"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(6, 19); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(59, 12); + this.label4.TabIndex = 0; + this.label4.Text = "当前版本:"; + // // Form_About // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -206,6 +206,7 @@ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form_About"; this.Text = "关于"; + this.Load += new System.EventHandler(this.Form_About_Load); this.authorInformation.ResumeLayout(false); this.authorInformation.PerformLayout(); this.groupBox1.ResumeLayout(false); diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs index 9a0dee5..6d6911e 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_About.cs @@ -5,89 +5,18 @@ using System.Windows.Forms; using System.Xml; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; namespace net.nutcore.aliddns { public partial class Form_About : Form { - public static bool RemoteCertificateValidationCallback(Object sender, - X509Certificate certificate, - X509Chain chain, - SslPolicyErrors sslPolicyErrors) - { - return true; - } - private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) - { - return true; //总是接受 - } public Form_About() { InitializeComponent(); this.MinimizeBox = false; //取消窗口最小化按钮 this.MaximizeBox = false; //取消窗口最大化按钮 - label_currentVer.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //获取当前版本 - if (mainForm.checkUpdate == true) - { - checkBox_autoCheckUpdate.Checked = true; - //获取远程版本信息 - try - { - - string strUrl = "https://api.github.com/wisdomwei201804/AliDDNS/releases/latest"; //从控件获取WAN口IP查询网址,默认值为:"http://whatismyip.akamai.com/"; - Uri uri = new Uri(strUrl); - if (strUrl.StartsWith("https")) - System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; - WebRequest webreq = WebRequest.Create(uri); - Stream s = webreq.GetResponse().GetResponseStream(); - StreamReader sr = new StreamReader(s, Encoding.Default); - string all = sr.ReadToEnd(); - MessageBox.Show(all.ToString()); - } - /*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(); - HttpContent httpContent = new StringContent("Authorization: token 7e5aaa4649a6bdb9d5459abd221ef15ec484da79"); - httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); - httpContent.Headers.ContentType.CharSet = "utf-8"; - //httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); - - //httpContent.Headers.Add("token", "7e5aaa4649a6bdb9d5459abd221ef15ec484da79"); - // httpContent.Headers.Add("appId", appId); - //httpContent.Headers.Add("serviceURL", serviceURL); - - //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); - //httpClient..setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8"); - HttpResponseMessage response = httpClient.PostAsync(strUrl, httpContent).Result; - //statusCode = response.StatusCode.ToString(); - // if (response.IsSuccessStatusCode) - //{ - string result = response.Content.ReadAsStringAsync().Result; - MessageBox.Show(result.ToString()); - // return result; - //} - }*/ - catch( Exception error) - { - MessageBox.Show(error.ToString()); - } - - } - else checkBox_autoCheckUpdate.Checked = false; - textBox_updateInfo.ReadOnly = true; - string filePath = System.AppDomain.CurrentDomain.BaseDirectory; - string updateInfoFile = filePath + "updateinfo.txt"; - if (File.Exists(updateInfoFile)) - textBox_updateInfo.Text = File.ReadAllText(updateInfoFile, Encoding.Default); - else - textBox_updateInfo.Text = "软件运行目录下没有找到updateinfo.txt文件!"; + } private void PublishLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -163,5 +92,61 @@ namespace net.nutcore.aliddns config.Save(); */ } + + private void Form_About_Load(object sender, EventArgs e) + { + //读取updateinfo.txt文件 + textBox_updateInfo.ReadOnly = true; + string filePath = System.AppDomain.CurrentDomain.BaseDirectory; + string updateInfoFile = filePath + "updateinfo.txt"; + if (File.Exists(updateInfoFile)) + textBox_updateInfo.Text = File.ReadAllText(updateInfoFile, Encoding.Default); + else + textBox_updateInfo.Text = "软件运行目录下没有找到updateinfo.txt文件!"; + + //版本检查 + label_currentVer.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //获取当前版本 + if (mainForm.checkUpdate == true) + { + 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()); + } + + } + else checkBox_autoCheckUpdate.Checked = false; + } } }