diff --git a/README.md b/README.md index 5e0faf7..36bcada 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,7 @@ accessKeySecret</br> 实现Ngrok网络穿透,微信开发、APP开发、无公网IP实现外网访问利器。</br> # 程序界面 - </br> - +</br> +</br> +</br> +</br> diff --git a/images/aliddns1.png b/images/aliddns1.png new file mode 100644 index 0000000..6bd6700 Binary files /dev/null and b/images/aliddns1.png differ diff --git a/images/aliddns2.png b/images/aliddns2.png new file mode 100644 index 0000000..08cf11b Binary files /dev/null and b/images/aliddns2.png differ diff --git a/images/aliddns3.png b/images/aliddns3.png new file mode 100644 index 0000000..255f97d Binary files /dev/null and b/images/aliddns3.png differ diff --git a/images/aliddns4.png b/images/aliddns4.png new file mode 100644 index 0000000..e28a583 Binary files /dev/null and b/images/aliddns4.png differ diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/AppConfigHelper.cs b/net.nutcore.aliddns/net.nutcore.aliddns/AppConfigHelper.cs index 55b9b91..ee7cbf6 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/AppConfigHelper.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/AppConfigHelper.cs @@ -53,7 +53,7 @@ namespace net.nutcore.aliddns foreach (XmlNode node in oldNodes) { Console.WriteLine(node.Name.ToString() + " : " + node.InnerText.ToString()); - SaveAppSetting(node.Name.ToString(), node.InnerText.ToString()); + SetAppSetting(node.Name.ToString(), node.InnerText.ToString()); } } } @@ -111,9 +111,10 @@ namespace net.nutcore.aliddns new XElement("add", new XAttribute("key", "minimized"), new XAttribute("value", "Off")), new XElement("add", new XAttribute("key", "logautosave"), new XAttribute("value", "Off")), new XElement("add", new XAttribute("key", "TTL"), new XAttribute("value", "600")), - new XElement("add", new XAttribute("key", "autoCheckUpdate"), new XAttribute("value", "Off")), new XElement("add", new XAttribute("key", "ngrokauto"), new XAttribute("value", "Off")), - new XElement("add", new XAttribute("key", "ngrokexists"), new XAttribute("value", "Off")) + new XElement("add", new XAttribute("key", "ngrokexists"), new XAttribute("value", "Off")), + new XElement("add", new XAttribute("key", "autoUpgrade"), new XAttribute("value", "Off")), + new XElement("add", new XAttribute("key", "upgradeUrl"), new XAttribute("value", "")) ) ) ); @@ -123,8 +124,6 @@ namespace net.nutcore.aliddns xmlDoc.Indent = true; XmlWriter xw = XmlWriter.Create(configFilePath, xmlDoc); xElement.Save(xw);//写入文件 - //xw.Dispose(); - //xw.Flush(); xw.Close(); } @@ -144,11 +143,17 @@ namespace net.nutcore.aliddns /// </summary> /// <param name="key"></param> /// <param name="value"></param> - public void SaveAppSetting(string key, string value) + public void SetAppSetting(string key, string value) { - //在保存key值时必须先删除它,否则改key的值将出现两个,例如:value="oldvalue, newvalue" - configFile.AppSettings.Settings.Remove(key); - configFile.AppSettings.Settings.Add(key, value); + KeyValueConfigurationElement _key = configFile.AppSettings.Settings[key]; + if ( _key == null) + { + configFile.AppSettings.Settings.Add(key, value); + } + else + { + configFile.AppSettings.Settings[key].Value = value; + } configFile.Save(); } @@ -249,16 +254,17 @@ namespace net.nutcore.aliddns /// 判断appSettings中是否有指定键名 /// </summary> /// /// <param name="strKey">键名</param> - public bool AppSettingsKeyExists(string strKey) + public bool isKeyExists(string strKey) { - foreach (string key in ConfigurationManager.AppSettings.AllKeys) + KeyValueConfigurationElement _key = configFile.AppSettings.Settings[strKey]; + if ( _key == null ) { - if (key == strKey) - { - return true; - } + return false; + } + else + { + return true; } - return false; } /// <summary> diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs index 96b0622..0e4fa29 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.Designer.cs @@ -112,7 +112,10 @@ this.columnHeader_subdomain = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.tabPage_other = new System.Windows.Forms.TabPage(); this.groupBox4 = new System.Windows.Forms.GroupBox(); - this.checkBox_autoCheckUpdate = new System.Windows.Forms.CheckBox(); + this.textBox_upgradeUrl = new System.Windows.Forms.TextBox(); + this.label17 = new System.Windows.Forms.Label(); + this.button_updateTest = new System.Windows.Forms.Button(); + this.checkBox_autoUpgrade = new System.Windows.Forms.CheckBox(); this.label_latestVer = new System.Windows.Forms.Label(); this.label28 = new System.Windows.Forms.Label(); this.label_currentVer = new System.Windows.Forms.Label(); @@ -152,7 +155,7 @@ this.timeSetGroup.Location = new System.Drawing.Point(3, 3); this.timeSetGroup.Name = "timeSetGroup"; this.timeSetGroup.Size = new System.Drawing.Size(427, 85); - this.timeSetGroup.TabIndex = 4; + this.timeSetGroup.TabIndex = 0; this.timeSetGroup.TabStop = false; this.timeSetGroup.Text = "启动设置"; // @@ -162,7 +165,7 @@ this.checkBox_ngrokExists.Location = new System.Drawing.Point(9, 63); this.checkBox_ngrokExists.Name = "checkBox_ngrokExists"; this.checkBox_ngrokExists.Size = new System.Drawing.Size(150, 16); - this.checkBox_ngrokExists.TabIndex = 10; + this.checkBox_ngrokExists.TabIndex = 2; this.checkBox_ngrokExists.Text = "检测ngrok.exe是否存在"; this.checkBox_ngrokExists.UseVisualStyleBackColor = true; this.checkBox_ngrokExists.CheckedChanged += new System.EventHandler(this.checkBox_ngrokExists_CheckedChanged); @@ -173,7 +176,7 @@ this.checkBox_ngrokAuto.Location = new System.Drawing.Point(9, 41); this.checkBox_ngrokAuto.Name = "checkBox_ngrokAuto"; this.checkBox_ngrokAuto.Size = new System.Drawing.Size(102, 16); - this.checkBox_ngrokAuto.TabIndex = 9; + this.checkBox_ngrokAuto.TabIndex = 1; this.checkBox_ngrokAuto.Text = "自动启动ngrok"; this.checkBox_ngrokAuto.UseVisualStyleBackColor = true; this.checkBox_ngrokAuto.CheckedChanged += new System.EventHandler(this.checkBox_ngrokAuto_CheckedChanged); @@ -184,7 +187,7 @@ this.checkBox_logAutoSave.Location = new System.Drawing.Point(258, 41); this.checkBox_logAutoSave.Name = "checkBox_logAutoSave"; this.checkBox_logAutoSave.Size = new System.Drawing.Size(96, 16); - this.checkBox_logAutoSave.TabIndex = 8; + this.checkBox_logAutoSave.TabIndex = 4; this.checkBox_logAutoSave.Text = "日志自动转储"; this.checkBox_logAutoSave.UseVisualStyleBackColor = true; this.checkBox_logAutoSave.CheckedChanged += new System.EventHandler(this.checkBox_logAutoSave_CheckedChanged); @@ -195,7 +198,7 @@ this.checkBox_minimized.Location = new System.Drawing.Point(258, 19); this.checkBox_minimized.Name = "checkBox_minimized"; this.checkBox_minimized.Size = new System.Drawing.Size(96, 16); - this.checkBox_minimized.TabIndex = 7; + this.checkBox_minimized.TabIndex = 3; this.checkBox_minimized.Text = "启动时最小化"; this.checkBox_minimized.UseVisualStyleBackColor = true; this.checkBox_minimized.CheckedChanged += new System.EventHandler(this.checkBox_minimized_CheckedChanged); @@ -206,7 +209,7 @@ this.checkBox_autoBoot.Location = new System.Drawing.Point(9, 19); this.checkBox_autoBoot.Name = "checkBox_autoBoot"; this.checkBox_autoBoot.Size = new System.Drawing.Size(132, 16); - this.checkBox_autoBoot.TabIndex = 5; + this.checkBox_autoBoot.TabIndex = 0; this.checkBox_autoBoot.Text = "随系统启动自动运行"; this.checkBox_autoBoot.UseVisualStyleBackColor = true; this.checkBox_autoBoot.CheckedChanged += new System.EventHandler(this.checkBox_autoBoot_CheckedChanged); @@ -226,7 +229,7 @@ this.debugMessage.Location = new System.Drawing.Point(213, 46); this.debugMessage.Name = "debugMessage"; this.debugMessage.Size = new System.Drawing.Size(216, 79); - this.debugMessage.TabIndex = 5; + this.debugMessage.TabIndex = 3; this.debugMessage.TabStop = false; this.debugMessage.Text = "调试信息"; // @@ -237,7 +240,7 @@ this.label_TTL.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label_TTL.Name = "label_TTL"; this.label_TTL.Size = new System.Drawing.Size(41, 12); - this.label_TTL.TabIndex = 10; + this.label_TTL.TabIndex = 7; this.label_TTL.Text = "<null>"; // // label15 @@ -247,7 +250,7 @@ this.label15.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(29, 12); - this.label15.TabIndex = 9; + this.label15.TabIndex = 6; this.label15.Text = "TTL:"; // // textBox_recordId @@ -257,7 +260,7 @@ this.textBox_recordId.Name = "textBox_recordId"; this.textBox_recordId.ReadOnly = true; this.textBox_recordId.Size = new System.Drawing.Size(116, 21); - this.textBox_recordId.TabIndex = 8; + this.textBox_recordId.TabIndex = 1; this.textBox_recordId.Text = "<null>"; // // label_globalValue @@ -266,7 +269,7 @@ this.label_globalValue.Location = new System.Drawing.Point(45, 63); this.label_globalValue.Name = "label_globalValue"; this.label_globalValue.Size = new System.Drawing.Size(41, 12); - this.label_globalValue.TabIndex = 7; + this.label_globalValue.TabIndex = 9; this.label_globalValue.Text = "<null>"; // // label_globalDomainType @@ -275,7 +278,7 @@ this.label_globalDomainType.Location = new System.Drawing.Point(96, 44); this.label_globalDomainType.Name = "label_globalDomainType"; this.label_globalDomainType.Size = new System.Drawing.Size(41, 12); - this.label_globalDomainType.TabIndex = 6; + this.label_globalDomainType.TabIndex = 5; this.label_globalDomainType.Text = "<null>"; // // label12 @@ -284,7 +287,7 @@ this.label12.Location = new System.Drawing.Point(6, 62); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(41, 12); - this.label12.TabIndex = 5; + this.label12.TabIndex = 8; this.label12.Text = "Value:"; // // label11 @@ -339,7 +342,7 @@ this.globalSetGroup.Location = new System.Drawing.Point(213, 129); this.globalSetGroup.Name = "globalSetGroup"; this.globalSetGroup.Size = new System.Drawing.Size(216, 145); - this.globalSetGroup.TabIndex = 6; + this.globalSetGroup.TabIndex = 4; this.globalSetGroup.TabStop = false; this.globalSetGroup.Text = "阿里云账号"; // @@ -348,7 +351,7 @@ this.button_addNewDomain.Location = new System.Drawing.Point(145, 119); this.button_addNewDomain.Name = "button_addNewDomain"; this.button_addNewDomain.Size = new System.Drawing.Size(65, 23); - this.button_addNewDomain.TabIndex = 17; + this.button_addNewDomain.TabIndex = 10; this.button_addNewDomain.Text = "添加域名"; this.button_addNewDomain.UseVisualStyleBackColor = true; this.button_addNewDomain.Click += new System.EventHandler(this.button_addNewDomain_Click); @@ -360,7 +363,7 @@ this.label13.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(47, 12); - this.label13.TabIndex = 16; + this.label13.TabIndex = 6; this.label13.Text = "TTL(秒)"; // // textBox_TTL @@ -369,7 +372,7 @@ 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; + this.textBox_TTL.TabIndex = 7; this.textBox_TTL.Text = "600"; this.textBox_TTL.Leave += new System.EventHandler(this.textBox_TTL_Leave); // @@ -378,7 +381,7 @@ this.button_ShowHide.Location = new System.Drawing.Point(75, 119); this.button_ShowHide.Name = "button_ShowHide"; this.button_ShowHide.Size = new System.Drawing.Size(65, 23); - this.button_ShowHide.TabIndex = 14; + this.button_ShowHide.TabIndex = 9; this.button_ShowHide.Text = "显示录入"; this.button_ShowHide.UseVisualStyleBackColor = true; this.button_ShowHide.Click += new System.EventHandler(this.button_ShowHide_Click); @@ -388,7 +391,7 @@ this.button_checkAndSaveConfig.Location = new System.Drawing.Point(5, 119); this.button_checkAndSaveConfig.Name = "button_checkAndSaveConfig"; this.button_checkAndSaveConfig.Size = new System.Drawing.Size(65, 23); - this.button_checkAndSaveConfig.TabIndex = 10; + this.button_checkAndSaveConfig.TabIndex = 8; this.button_checkAndSaveConfig.Text = "测试连接"; this.button_checkAndSaveConfig.UseVisualStyleBackColor = true; this.button_checkAndSaveConfig.Click += new System.EventHandler(this.checkConfig_Click); @@ -399,7 +402,7 @@ this.label6.Location = new System.Drawing.Point(6, 73); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(53, 12); - this.label6.TabIndex = 5; + this.label6.TabIndex = 4; this.label6.Text = "完整域名"; // // textBox_fullDomainName @@ -407,7 +410,7 @@ this.textBox_fullDomainName.Location = new System.Drawing.Point(65, 69); this.textBox_fullDomainName.Name = "textBox_fullDomainName"; this.textBox_fullDomainName.Size = new System.Drawing.Size(145, 21); - this.textBox_fullDomainName.TabIndex = 4; + this.textBox_fullDomainName.TabIndex = 5; this.textBox_fullDomainName.Text = "www.xxx.com"; this.textBox_fullDomainName.Leave += new System.EventHandler(this.fullDomainName_Leave); // @@ -455,7 +458,7 @@ this.label8.Location = new System.Drawing.Point(106, 21); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(65, 12); - this.label8.TabIndex = 8; + this.label8.TabIndex = 2; this.label8.Text = "秒更新一次"; // // textBox_newSeconds @@ -463,7 +466,7 @@ this.textBox_newSeconds.Location = new System.Drawing.Point(40, 18); this.textBox_newSeconds.Name = "textBox_newSeconds"; this.textBox_newSeconds.Size = new System.Drawing.Size(60, 21); - this.textBox_newSeconds.TabIndex = 7; + this.textBox_newSeconds.TabIndex = 1; this.textBox_newSeconds.Text = "60"; this.textBox_newSeconds.Leave += new System.EventHandler(this.newSeconds_Leave); // @@ -473,7 +476,7 @@ this.label7.Location = new System.Drawing.Point(5, 21); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(29, 12); - this.label7.TabIndex = 6; + this.label7.TabIndex = 0; this.label7.Text = "每隔"; // // autoUpdateTimer @@ -511,7 +514,7 @@ this.ToolStripMenuItem_checkUpdate.Name = "ToolStripMenuItem_checkUpdate"; this.ToolStripMenuItem_checkUpdate.Size = new System.Drawing.Size(124, 22); this.ToolStripMenuItem_checkUpdate.Text = "检查升级"; - this.ToolStripMenuItem_checkUpdate.Click += new System.EventHandler(this.ToolStripMenuItem_checkUPdate_Click); + this.ToolStripMenuItem_checkUpdate.Click += new System.EventHandler(this.ToolStripMenuItem_checkUpgrade_Click); // // groupBox_netstate // @@ -524,7 +527,7 @@ this.groupBox_netstate.Location = new System.Drawing.Point(6, 6); this.groupBox_netstate.Name = "groupBox_netstate"; this.groupBox_netstate.Size = new System.Drawing.Size(423, 38); - this.groupBox_netstate.TabIndex = 9; + this.groupBox_netstate.TabIndex = 0; this.groupBox_netstate.TabStop = false; this.groupBox_netstate.Text = "网络状态"; // @@ -535,7 +538,7 @@ this.label_DomainIpStatus.Location = new System.Drawing.Point(371, 19); this.label_DomainIpStatus.Name = "label_DomainIpStatus"; this.label_DomainIpStatus.Size = new System.Drawing.Size(41, 12); - this.label_DomainIpStatus.TabIndex = 9; + this.label_DomainIpStatus.TabIndex = 5; this.label_DomainIpStatus.Text = "未绑定"; // // label_localIpStatus @@ -545,7 +548,7 @@ this.label_localIpStatus.Location = new System.Drawing.Point(156, 19); this.label_localIpStatus.Name = "label_localIpStatus"; this.label_localIpStatus.Size = new System.Drawing.Size(41, 12); - this.label_localIpStatus.TabIndex = 8; + this.label_localIpStatus.TabIndex = 2; this.label_localIpStatus.Text = "未连接"; // // label_domainIP @@ -554,7 +557,7 @@ this.label_domainIP.Location = new System.Drawing.Point(264, 19); this.label_domainIP.Name = "label_domainIP"; this.label_domainIP.Size = new System.Drawing.Size(47, 12); - this.label_domainIP.TabIndex = 7; + this.label_domainIP.TabIndex = 4; this.label_domainIP.Text = "0.0.0.0"; // // label2 @@ -563,7 +566,7 @@ this.label2.Location = new System.Drawing.Point(218, 19); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(47, 12); - this.label2.TabIndex = 6; + this.label2.TabIndex = 3; this.label2.Text = "域名IP:"; // // label_localIP @@ -572,7 +575,7 @@ this.label_localIP.Location = new System.Drawing.Point(57, 19); this.label_localIP.Name = "label_localIP"; this.label_localIP.Size = new System.Drawing.Size(47, 12); - this.label_localIP.TabIndex = 5; + this.label_localIP.TabIndex = 1; this.label_localIP.Text = "0.0.0.0"; // // label1 @@ -581,7 +584,7 @@ this.label1.Location = new System.Drawing.Point(5, 19); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(53, 12); - this.label1.TabIndex = 4; + this.label1.TabIndex = 0; this.label1.Text = "WAN口IP:"; // // groupBox_setWanIp @@ -595,7 +598,7 @@ this.groupBox_setWanIp.Location = new System.Drawing.Point(6, 46); this.groupBox_setWanIp.Name = "groupBox_setWanIp"; this.groupBox_setWanIp.Size = new System.Drawing.Size(201, 135); - this.groupBox_setWanIp.TabIndex = 10; + this.groupBox_setWanIp.TabIndex = 1; this.groupBox_setWanIp.TabStop = false; this.groupBox_setWanIp.Text = "WAN口IP设置"; // @@ -604,7 +607,7 @@ this.button_addUrl.Location = new System.Drawing.Point(105, 66); this.button_addUrl.Name = "button_addUrl"; this.button_addUrl.Size = new System.Drawing.Size(90, 23); - this.button_addUrl.TabIndex = 21; + this.button_addUrl.TabIndex = 3; this.button_addUrl.Text = "添加网址"; this.button_addUrl.UseVisualStyleBackColor = true; this.button_addUrl.Click += new System.EventHandler(this.button_addUrl_Click); @@ -616,14 +619,14 @@ this.maskedTextBox_setIP.Name = "maskedTextBox_setIP"; this.maskedTextBox_setIP.PromptChar = ' '; this.maskedTextBox_setIP.Size = new System.Drawing.Size(106, 21); - this.maskedTextBox_setIP.TabIndex = 20; + this.maskedTextBox_setIP.TabIndex = 4; // // button_setIP // this.button_setIP.Location = new System.Drawing.Point(119, 99); this.button_setIP.Name = "button_setIP"; this.button_setIP.Size = new System.Drawing.Size(76, 23); - this.button_setIP.TabIndex = 19; + this.button_setIP.TabIndex = 5; this.button_setIP.Text = "手工指定IP"; this.button_setIP.UseVisualStyleBackColor = true; this.button_setIP.Click += new System.EventHandler(this.button_setIP_Click); @@ -634,7 +637,7 @@ this.comboBox_whatIsUrl.Location = new System.Drawing.Point(6, 41); this.comboBox_whatIsUrl.Name = "comboBox_whatIsUrl"; this.comboBox_whatIsUrl.Size = new System.Drawing.Size(189, 20); - this.comboBox_whatIsUrl.TabIndex = 18; + this.comboBox_whatIsUrl.TabIndex = 1; this.comboBox_whatIsUrl.Leave += new System.EventHandler(this.comboBox_whatIsUrl_Leave); // // button_whatIsTest @@ -642,7 +645,7 @@ this.button_whatIsTest.Location = new System.Drawing.Point(6, 66); this.button_whatIsTest.Name = "button_whatIsTest"; this.button_whatIsTest.Size = new System.Drawing.Size(90, 23); - this.button_whatIsTest.TabIndex = 17; + this.button_whatIsTest.TabIndex = 2; this.button_whatIsTest.Text = "获取WAN口IP"; this.button_whatIsTest.UseVisualStyleBackColor = true; this.button_whatIsTest.Click += new System.EventHandler(this.button_whatIsTest_Click); @@ -653,7 +656,7 @@ this.label14.Location = new System.Drawing.Point(7, 22); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(59, 12); - this.label14.TabIndex = 16; + this.label14.TabIndex = 0; this.label14.Text = "查询网址:"; // // tabControl1 @@ -666,7 +669,7 @@ this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(441, 303); - this.tabControl1.TabIndex = 11; + this.tabControl1.TabIndex = 0; // // tabPage_ddns // @@ -695,7 +698,7 @@ this.groupBox6.Location = new System.Drawing.Point(6, 185); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(200, 89); - this.groupBox6.TabIndex = 11; + this.groupBox6.TabIndex = 2; this.groupBox6.TabStop = false; this.groupBox6.Text = "更新设置"; // @@ -705,7 +708,7 @@ this.checkBox_autoUpdate.Location = new System.Drawing.Point(7, 43); this.checkBox_autoUpdate.Name = "checkBox_autoUpdate"; this.checkBox_autoUpdate.Size = new System.Drawing.Size(72, 16); - this.checkBox_autoUpdate.TabIndex = 10; + this.checkBox_autoUpdate.TabIndex = 3; this.checkBox_autoUpdate.Text = "自动更新"; this.checkBox_autoUpdate.UseVisualStyleBackColor = true; // @@ -715,7 +718,7 @@ this.label3.Location = new System.Drawing.Point(114, 43); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(77, 12); - this.label3.TabIndex = 9; + this.label3.TabIndex = 5; this.label3.Text = "秒后更新记录"; // // label_nextUpdateSeconds @@ -724,7 +727,7 @@ this.label_nextUpdateSeconds.Location = new System.Drawing.Point(84, 44); this.label_nextUpdateSeconds.Name = "label_nextUpdateSeconds"; this.label_nextUpdateSeconds.Size = new System.Drawing.Size(30, 12); - this.label_nextUpdateSeconds.TabIndex = 8; + this.label_nextUpdateSeconds.TabIndex = 4; this.label_nextUpdateSeconds.Text = "60"; this.label_nextUpdateSeconds.TextAlign = System.Drawing.ContentAlignment.TopRight; // @@ -733,7 +736,7 @@ this.button_updateNow.Location = new System.Drawing.Point(6, 62); this.button_updateNow.Name = "button_updateNow"; this.button_updateNow.Size = new System.Drawing.Size(185, 23); - this.button_updateNow.TabIndex = 7; + this.button_updateNow.TabIndex = 6; this.button_updateNow.Text = "立即更新"; this.button_updateNow.UseVisualStyleBackColor = true; this.button_updateNow.Click += new System.EventHandler(this.updateNow_Click); @@ -768,7 +771,7 @@ this.groupBox1.Location = new System.Drawing.Point(238, 6); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(189, 48); - this.groupBox1.TabIndex = 0; + this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "认证令牌"; // @@ -795,7 +798,7 @@ this.groupBox2.Location = new System.Drawing.Point(6, 6); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(226, 48); - this.groupBox2.TabIndex = 1; + this.groupBox2.TabIndex = 0; this.groupBox2.TabStop = false; this.groupBox2.Text = "服务端Ngrokd"; // @@ -836,7 +839,7 @@ this.button_stop.Location = new System.Drawing.Point(360, 180); this.button_stop.Name = "button_stop"; this.button_stop.Size = new System.Drawing.Size(55, 25); - this.button_stop.TabIndex = 11; + this.button_stop.TabIndex = 6; this.button_stop.Text = "停止"; this.button_stop.UseVisualStyleBackColor = true; this.button_stop.Click += new System.EventHandler(this.button_stop_Click); @@ -846,7 +849,7 @@ this.button_edit.Location = new System.Drawing.Point(360, 51); this.button_edit.Name = "button_edit"; this.button_edit.Size = new System.Drawing.Size(55, 24); - this.button_edit.TabIndex = 10; + this.button_edit.TabIndex = 2; this.button_edit.Text = "编辑"; this.button_edit.UseVisualStyleBackColor = true; this.button_edit.Click += new System.EventHandler(this.button_edit_Click); @@ -856,7 +859,7 @@ this.button_ngrokSave.Location = new System.Drawing.Point(360, 112); this.button_ngrokSave.Name = "button_ngrokSave"; this.button_ngrokSave.Size = new System.Drawing.Size(55, 25); - this.button_ngrokSave.TabIndex = 9; + this.button_ngrokSave.TabIndex = 4; this.button_ngrokSave.Text = "保存"; this.button_ngrokSave.UseVisualStyleBackColor = true; this.button_ngrokSave.Click += new System.EventHandler(this.button_ngrokSave_Click); @@ -866,7 +869,7 @@ this.button_ngrokApply.Location = new System.Drawing.Point(360, 149); this.button_ngrokApply.Name = "button_ngrokApply"; this.button_ngrokApply.Size = new System.Drawing.Size(55, 25); - this.button_ngrokApply.TabIndex = 8; + this.button_ngrokApply.TabIndex = 5; this.button_ngrokApply.Text = "启动"; this.button_ngrokApply.UseVisualStyleBackColor = true; this.button_ngrokApply.Click += new System.EventHandler(this.button_ngrokApply_Click); @@ -876,7 +879,7 @@ this.button_delete.Location = new System.Drawing.Point(360, 81); this.button_delete.Name = "button_delete"; this.button_delete.Size = new System.Drawing.Size(55, 25); - this.button_delete.TabIndex = 7; + this.button_delete.TabIndex = 3; this.button_delete.Text = "删除"; this.button_delete.UseVisualStyleBackColor = true; this.button_delete.Click += new System.EventHandler(this.button_delete_Click); @@ -886,7 +889,7 @@ this.button_addnew.Location = new System.Drawing.Point(360, 20); this.button_addnew.Name = "button_addnew"; this.button_addnew.Size = new System.Drawing.Size(55, 25); - this.button_addnew.TabIndex = 6; + this.button_addnew.TabIndex = 1; this.button_addnew.Text = "增加"; this.button_addnew.UseVisualStyleBackColor = true; this.button_addnew.Click += new System.EventHandler(this.button_addnew_Click); @@ -905,7 +908,7 @@ this.listView_ngrok.Location = new System.Drawing.Point(6, 20); this.listView_ngrok.Name = "listView_ngrok"; this.listView_ngrok.Size = new System.Drawing.Size(348, 185); - this.listView_ngrok.TabIndex = 5; + this.listView_ngrok.TabIndex = 0; this.listView_ngrok.UseCompatibleStateImageBehavior = false; this.listView_ngrok.View = System.Windows.Forms.View.Details; this.listView_ngrok.DoubleClick += new System.EventHandler(this.button_edit_Click); @@ -956,28 +959,58 @@ // // groupBox4 // - this.groupBox4.Controls.Add(this.checkBox_autoCheckUpdate); + this.groupBox4.Controls.Add(this.textBox_upgradeUrl); + this.groupBox4.Controls.Add(this.label17); + this.groupBox4.Controls.Add(this.button_updateTest); + this.groupBox4.Controls.Add(this.checkBox_autoUpgrade); this.groupBox4.Controls.Add(this.label_latestVer); this.groupBox4.Controls.Add(this.label28); this.groupBox4.Controls.Add(this.label_currentVer); this.groupBox4.Controls.Add(this.label30); this.groupBox4.Location = new System.Drawing.Point(3, 94); this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(427, 42); - this.groupBox4.TabIndex = 11; + this.groupBox4.Size = new System.Drawing.Size(427, 72); + this.groupBox4.TabIndex = 1; this.groupBox4.TabStop = false; this.groupBox4.Text = "升级设置"; // - // checkBox_autoCheckUpdate + // textBox_upgradeUrl // - this.checkBox_autoCheckUpdate.AutoSize = true; - this.checkBox_autoCheckUpdate.Location = new System.Drawing.Point(258, 18); - this.checkBox_autoCheckUpdate.Name = "checkBox_autoCheckUpdate"; - this.checkBox_autoCheckUpdate.Size = new System.Drawing.Size(96, 16); - this.checkBox_autoCheckUpdate.TabIndex = 4; - this.checkBox_autoCheckUpdate.Text = "自动检测升级"; - this.checkBox_autoCheckUpdate.UseVisualStyleBackColor = true; - this.checkBox_autoCheckUpdate.CheckedChanged += new System.EventHandler(this.checkBox_autoCheckUpdate_CheckedChanged); + this.textBox_upgradeUrl.Location = new System.Drawing.Point(42, 43); + this.textBox_upgradeUrl.Name = "textBox_upgradeUrl"; + this.textBox_upgradeUrl.Size = new System.Drawing.Size(194, 21); + this.textBox_upgradeUrl.TabIndex = 7; + this.textBox_upgradeUrl.Leave += new System.EventHandler(this.textBox_upgradeUrl_Leave); + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(7, 46); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(35, 12); + this.label17.TabIndex = 6; + this.label17.Text = "地址:"; + // + // button_updateTest + // + this.button_updateTest.Location = new System.Drawing.Point(258, 40); + this.button_updateTest.Name = "button_updateTest"; + this.button_updateTest.Size = new System.Drawing.Size(96, 25); + this.button_updateTest.TabIndex = 5; + this.button_updateTest.Text = "立即检测升级"; + this.button_updateTest.UseVisualStyleBackColor = true; + this.button_updateTest.Click += new System.EventHandler(this.button_upgradeTest_Click); + // + // checkBox_autoUpgrade + // + this.checkBox_autoUpgrade.AutoSize = true; + this.checkBox_autoUpgrade.Location = new System.Drawing.Point(258, 18); + this.checkBox_autoUpgrade.Name = "checkBox_autoUpgrade"; + this.checkBox_autoUpgrade.Size = new System.Drawing.Size(96, 16); + this.checkBox_autoUpgrade.TabIndex = 4; + this.checkBox_autoUpgrade.Text = "自动检测升级"; + this.checkBox_autoUpgrade.UseVisualStyleBackColor = true; + this.checkBox_autoUpgrade.CheckedChanged += new System.EventHandler(this.checkBox_autoUpgrade_CheckedChanged); // // label_latestVer // @@ -1009,7 +1042,7 @@ // label30 // this.label30.AutoSize = true; - this.label30.Location = new System.Drawing.Point(6, 19); + this.label30.Location = new System.Drawing.Point(7, 19); this.label30.Name = "label30"; this.label30.Size = new System.Drawing.Size(59, 12); this.label30.TabIndex = 0; @@ -1033,7 +1066,7 @@ this.textBox_updateInfo.Name = "textBox_updateInfo"; this.textBox_updateInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.textBox_updateInfo.Size = new System.Drawing.Size(427, 211); - this.textBox_updateInfo.TabIndex = 9; + this.textBox_updateInfo.TabIndex = 1; // // groupBox5 // @@ -1042,7 +1075,7 @@ this.groupBox5.Location = new System.Drawing.Point(3, 3); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(427, 41); - this.groupBox5.TabIndex = 8; + this.groupBox5.TabIndex = 0; this.groupBox5.TabStop = false; this.groupBox5.Text = "著作信息"; // @@ -1052,7 +1085,7 @@ this.label31.Location = new System.Drawing.Point(6, 17); this.label31.Name = "label31"; this.label31.Size = new System.Drawing.Size(95, 12); - this.label31.TabIndex = 6; + this.label31.TabIndex = 0; this.label31.Text = "本程序发布地址:"; // // linkLabel2 @@ -1061,7 +1094,7 @@ this.linkLabel2.Location = new System.Drawing.Point(107, 17); this.linkLabel2.Name = "linkLabel2"; this.linkLabel2.Size = new System.Drawing.Size(125, 12); - this.linkLabel2.TabIndex = 2; + this.linkLabel2.TabIndex = 1; this.linkLabel2.TabStop = true; this.linkLabel2.Text = "AliDDNS 3.0 之后版本"; this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); @@ -1204,7 +1237,7 @@ private System.Windows.Forms.Label label_nextUpdateSeconds; private System.Windows.Forms.Button button_updateNow; private System.Windows.Forms.GroupBox groupBox4; - private System.Windows.Forms.CheckBox checkBox_autoCheckUpdate; + private System.Windows.Forms.CheckBox checkBox_autoUpgrade; private System.Windows.Forms.Label label_latestVer; private System.Windows.Forms.Label label28; private System.Windows.Forms.Label label_currentVer; @@ -1218,6 +1251,9 @@ private System.Windows.Forms.CheckBox checkBox_ngrokExists; private System.Windows.Forms.Button button_edit; private System.Windows.Forms.Button button_stop; + private System.Windows.Forms.TextBox textBox_upgradeUrl; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Button button_updateTest; } } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs index ed0c0d4..384e3a3 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_main.cs @@ -9,6 +9,7 @@ using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Windows.Forms; using static Aliyun.Acs.Alidns.Model.V20150109.DescribeSubDomainRecordsResponse; @@ -16,7 +17,7 @@ namespace net.nutcore.aliddns { public partial class Form_main : Form { - public static bool checkUpdate; + private delegate void ThreadNew();//代理异步线程->升级 static IClientProfile clientProfile; static DefaultAcsClient client; //初始化ngrok操作类 @@ -79,20 +80,6 @@ namespace net.nutcore.aliddns //读取设置文件aliddns_config.xml if (appConfig_Load()) { - string ExePath = System.AppDomain.CurrentDomain.BaseDirectory; - string updateExe = ExePath + "update.exe"; - if(checkUpdate == true) - { - if (File.Exists(updateExe)) - { - //执行update.exe - } - else - { - textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "版本检测程序update.exe未找到,跳过版本检测! " + "\r\n"); - } - } - //窗体根据参数判断是否最小化驻留系统托盘 if (checkBox_minimized.Checked == true) { @@ -129,18 +116,18 @@ namespace net.nutcore.aliddns textBox_updateInfo.Text = "软件运行目录下没有找到updateinfo.txt文件!"; } - //版本检查 - label_currentVer.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //获取当前版本 - if (Form_main.checkUpdate == true) - { - checkBox_autoCheckUpdate.Checked = true; - //获取远程版本信息 - string strVer = Form_main.verCheckUpdate(); - label_latestVer.Text = strVer.ToString(); + //获取当前版本 + label_currentVer.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + if ( checkBox_autoUpgrade.Checked == true ) + { + //执行upgrade + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "正在自动检测升级! " + "\r\n"); + Thread newThread = new Thread(new ParameterizedThreadStart(simpleUpgrade)); + newThread.Start(cfg.GetAppSetting("upgradeUrl")); } else { - checkBox_autoCheckUpdate.Checked = false; + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "自动检测升级未启用! " + "\r\n"); } //读取ngrok配置文件 ngrokConfig_Load(); @@ -161,9 +148,11 @@ namespace net.nutcore.aliddns textBox_recordId.Text = cfg.GetAppSetting("RecordID").ToString(); textBox_fullDomainName.Text = cfg.GetAppSetting("fullDomainName").ToString(); label_nextUpdateSeconds.Text = textBox_newSeconds.Text = cfg.GetAppSetting("WaitingTime").ToString(); + if (cfg.GetAppSetting("autoUpdate").ToString() == "On") checkBox_autoUpdate.Checked = true; else checkBox_autoUpdate.Checked = false; - if(cfg.GetAppSetting("whatIsUrl").ToString() != null) + + if (cfg.GetAppSetting("whatIsUrl").ToString() != null) { string[] arrayUrl = cfg.GetAppSetting("whatIsUrl").ToString().Split(','); foreach(string strUrl in arrayUrl) @@ -184,8 +173,8 @@ namespace net.nutcore.aliddns textBox_TTL.Text = cfg.GetAppSetting("TTL").ToString(); - if (cfg.GetAppSetting("autoCheckUpdate").ToString() == "On") checkUpdate = true; - else checkUpdate = false; + if (cfg.GetAppSetting("autoUpgrade").ToString() == "On") checkBox_autoUpgrade.Checked = true; + else checkBox_autoUpgrade.Checked = false; if (cfg.GetAppSetting("ngrokauto").ToString() == "On") checkBox_ngrokAuto.Checked = true; else checkBox_ngrokAuto.Checked = false; @@ -193,6 +182,16 @@ namespace net.nutcore.aliddns if (cfg.GetAppSetting("ngrokexists").ToString() == "On") checkBox_ngrokExists.Checked = true; else checkBox_ngrokExists.Checked = false; + if (cfg.isKeyExists("upgradeUrl")) + { + textBox_upgradeUrl.Text = cfg.GetAppSetting("upgradeUrl").ToString(); + } + else + { + cfg.SetAppSetting("upgradeUrl", "https://dev.51zyy.cn/aliddns/updater.xml"); + textBox_upgradeUrl.Text = cfg.GetAppSetting("upgradeUrl").ToString(); + } + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "设置文件读取成功!" + "\r\n"); return true; } @@ -246,7 +245,6 @@ namespace net.nutcore.aliddns textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "请检查配置文件查询网址设置!" + "\r\n"); return "0.0.0.0"; } - //return "0.0.0.0"; } catch (Exception error) { @@ -290,7 +288,7 @@ namespace net.nutcore.aliddns i++; textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "阿里云DNS服务返回RecordId:" + i.ToString() + " RecordId:" + record.RecordId + "\r\n"); textBox_recordId.Text = record.RecordId; - cfg.SaveAppSetting("RecordID", record.RecordId.ToString()); + cfg.SetAppSetting("RecordID", record.RecordId.ToString()); label_globalRR.Text = record.RR; label_globalDomainType.Text = record.Type; label_globalValue.Text = label_domainIP.Text = record.Value; @@ -342,7 +340,7 @@ namespace net.nutcore.aliddns textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "配置文件域名记录:" + textBox_recordId.Text.ToString() + " 对应域名为:" + textBox_fullDomainName.Text.ToString() + "\r\n"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "配置文件设置错误!可能原因是修改域名记录后未及时添加,已经自动修改配置文件与服务器记录一致!" + "\r\n"); textBox_fullDomainName.Text = fullDomain; - cfg.SaveAppSetting("fullDomainName", fullDomain); + cfg.SetAppSetting("fullDomainName", fullDomain); } textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "域名:" + response.RR + "." + response.DomainName + " 已经绑定IP:" + response.Value + "\r\n"); textBox_recordId.Text = response.RecordId; @@ -463,7 +461,7 @@ namespace net.nutcore.aliddns { textBox_log.AppendText(System.DateTime.Now.ToString() + " " + " 域名:" + textBox_fullDomainName.Text + "添加成功!" + "服务器返回RecordId:" + response.RecordId + "\r\n"); textBox_recordId.Text = response.RecordId.ToString(); - cfg.SaveAppSetting("RecordID", response.RecordId.ToString()); + cfg.SetAppSetting("RecordID", response.RecordId.ToString()); label_globalDomainType.Text = request.Type; label_globalRR.Text = request.RR; label_globalValue.Text = label_domainIP.Text = request.Value; @@ -643,7 +641,7 @@ namespace net.nutcore.aliddns Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); Rkey.SetValue("AliDDNS Tray", thisExecutablePath); Rkey.Close(); - cfg.SaveAppSetting("autoBoot", "On"); + cfg.SetAppSetting("autoBoot", "On"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "随系统启动自动运行设置成功!" + "\r\n"); } else @@ -651,7 +649,7 @@ namespace net.nutcore.aliddns Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Rkey.DeleteValue("AliDDNS Tray"); Rkey.Close(); - cfg.SaveAppSetting("autoBoot", "Off"); + cfg.SetAppSetting("autoBoot", "Off"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "随系统启动自动运行取消!" + "\r\n"); } } @@ -665,12 +663,12 @@ namespace net.nutcore.aliddns { if (checkBox_logAutoSave.Checked == true) { - cfg.SaveAppSetting("logautosave", "On"); + cfg.SetAppSetting("logautosave", "On"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "日志自动转储启用成功!日志超过1万行将自动转储。" + "\r\n"); } else { - cfg.SaveAppSetting("logautosave", "Off"); + cfg.SetAppSetting("logautosave", "Off"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "日志自动转储取消!" + "\r\n"); } } @@ -711,12 +709,12 @@ namespace net.nutcore.aliddns { if(checkBox_autoUpdate.Checked == true) { - cfg.SaveAppSetting("autoUpdate", "On"); + cfg.SetAppSetting("autoUpdate", "On"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "域名记录自动更新启用成功!" + "\r\n"); } else { - cfg.SaveAppSetting("autoUpdate", "Off"); + cfg.SetAppSetting("autoUpdate", "Off"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "域名记录自动更新取消!" + "\r\n"); } } @@ -725,12 +723,12 @@ namespace net.nutcore.aliddns { if (checkBox_minimized.Checked == true) { - cfg.SaveAppSetting("minimized", "On"); + cfg.SetAppSetting("minimized", "On"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "软件启动时驻留到系统托盘启用!" + "\r\n"); } else { - cfg.SaveAppSetting("minimized", "Off"); + cfg.SetAppSetting("minimized", "Off"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "软件启动时驻留到系统托盘取消!" + "\r\n"); } } @@ -786,15 +784,18 @@ namespace net.nutcore.aliddns /// 从github.com仓库检查软件最新release版本信息,返回版本号 /// </summary> /// <returns></returns> - public static string verCheckUpdate() + public string[] getRemoteVer(string strUrl) { - try + if (strUrl == null) { - string strUrl = "https://github.com/wisdomwei201804/AliDDNS/releases/latest"; - if (strUrl.StartsWith("https")) - { - ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls1.2 | SecurityProtocolType.Tls12; - } + strUrl = "https://github.com/wisdomwei201804/AliDDNS/releases/latest"; + } + if (strUrl.StartsWith("https")) + { + ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls1.2 | SecurityProtocolType.Tls12; + } + try + { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl); request.Method = "GET"; request.Accept = "application/json"; @@ -805,36 +806,31 @@ namespace net.nutcore.aliddns sr.Dispose(); if (response.StatusCode.ToString() == "OK" ) { - //MessageBox.Show(response.StatusCode.ToString()); - //MessageBox.Show(Regex.Match(result, @"""tag_name"":""([^""]*)""").Groups[1].Value); - return Regex.Match(result, @"""tag_name"":""([^""]*)""").Groups[1].Value; + string remoteVer = Regex.Match(result, @"""tag_name"":""([^""]*)""").Groups[1].Value; + return new string[] { "OK", remoteVer }; } else { - return null; + return new string[] { "NULL", null }; } } catch (Exception error) { - MessageBox.Show(error.ToString()); - return null; + return new string[] { "-1", error.Message.ToString() }; } } - private void ToolStripMenuItem_checkUPdate_Click(object sender, EventArgs e) + private void ToolStripMenuItem_checkUpgrade_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("没有新版本,无需升级!"); - } + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "正在检测升级! " + "\r\n"); + simpleUpgrade(textBox_upgradeUrl.Text); + + Version remoteVer = new Version(label_latestVer.Text); + Version localVer = new Version(label_currentVer.Text); + if (remoteVer > localVer) + MessageBox.Show("发现新版本: " + remoteVer); else - MessageBox.Show("获取新版本信息失败!"); + MessageBox.Show("没有新版本,无需升级!"); } private void checkBox_ngrokAuto_CheckedChanged(object sender, EventArgs e) @@ -842,7 +838,7 @@ namespace net.nutcore.aliddns if (checkBox_ngrokAuto.Checked == true) { - cfg.SaveAppSetting("ngrokauto", "On"); + cfg.SetAppSetting("ngrokauto", "On"); //检测ngrok.exe是否存在 if (ngrok.IsExists()) { @@ -856,7 +852,7 @@ namespace net.nutcore.aliddns } else { - cfg.SaveAppSetting("ngrokauto", "Off"); + cfg.SetAppSetting("ngrokauto", "Off"); ngrok.Stop(); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能关闭,再次启动将不会加载!" + "\r\n"); } @@ -866,7 +862,7 @@ namespace net.nutcore.aliddns { if (checkBox_ngrokExists.Checked == true) { - cfg.SaveAppSetting("ngrokexists", "On"); + cfg.SetAppSetting("ngrokexists", "On"); //检测ngrok.exe是否存在 if (ngrok.IsExists()) { @@ -879,7 +875,7 @@ namespace net.nutcore.aliddns } else { - cfg.SaveAppSetting("ngrokexists", "Off"); + cfg.SetAppSetting("ngrokexists", "Off"); ngrok.Stop(); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "启动时不再检测ngrok.exe是否存在。" + "\r\n"); } @@ -901,31 +897,31 @@ namespace net.nutcore.aliddns private void fullDomainName_Leave(object sender, EventArgs e) { - cfg.SaveAppSetting("fullDomainName", this.textBox_fullDomainName.Text.ToString()); + cfg.SetAppSetting("fullDomainName", this.textBox_fullDomainName.Text.ToString()); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "域名已经保存,点击测试连接将查询域名是否存在,当不存在时点击添加域名会创建新域名记录!" + "\r\n"); } private void accessKeyId_Leave(object sender, EventArgs e) { - cfg.SaveAppSetting("AccessKeyID", EncryptHelper.AESEncrypt(this.textBox_accessKeyId.Text.ToString())); + cfg.SetAppSetting("AccessKeyID", EncryptHelper.AESEncrypt(this.textBox_accessKeyId.Text.ToString())); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "accessKeyId已经保存,请完成设置录入后点击测试连接!" + "\r\n"); } private void accessKeySecret_Leave(object sender, EventArgs e) { - cfg.SaveAppSetting("AccessKeySecret", EncryptHelper.AESEncrypt(this.textBox_accessKeySecret.Text.ToString())); + cfg.SetAppSetting("AccessKeySecret", EncryptHelper.AESEncrypt(this.textBox_accessKeySecret.Text.ToString())); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "accessKeySecret已经保存,请完成设置录入后点击测试连接!" + "\r\n"); } private void textBox_TTL_Leave(object sender, EventArgs e) { - cfg.SaveAppSetting("TTL",this.textBox_TTL.Text.ToString()); + cfg.SetAppSetting("TTL",this.textBox_TTL.Text.ToString()); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "TTL设置修改保存成功!" + "\r\n"); } private void newSeconds_Leave(object sender, EventArgs e) { - cfg.SaveAppSetting("WaitingTime", this.textBox_newSeconds.Text.ToString()); + cfg.SetAppSetting("WaitingTime", this.textBox_newSeconds.Text.ToString()); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "自动更新倒计时设置修改保存成功!" + "\r\n"); } @@ -961,16 +957,16 @@ namespace net.nutcore.aliddns System.Diagnostics.Process.Start("explorer.exe", "https://github.com/wisdomwei201804/AliDDNS/"); } - private void checkBox_autoCheckUpdate_CheckedChanged(object sender, EventArgs e) + private void checkBox_autoUpgrade_CheckedChanged(object sender, EventArgs e) { - if (checkBox_autoCheckUpdate.Checked == true) + if (checkBox_autoUpgrade.Checked == true) { - cfg.SaveAppSetting("autoCheckUpdate", "On"); + cfg.SetAppSetting("autoUpgrade", "On"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "软件自动检测升级启用!" + "\r\n"); } else { - cfg.SaveAppSetting("autoCheckUpdate", "Off"); + cfg.SetAppSetting("autoUpgrade", "Off"); textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "软件自动检测升级关闭!" + "\r\n"); } } @@ -1160,5 +1156,74 @@ namespace net.nutcore.aliddns ngrok.Stop(); } } + + private void button_upgradeTest_Click(object sender, EventArgs e) + { + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "正在检测升级! " + "\r\n"); + simpleUpgrade(textBox_upgradeUrl.Text); + } + + private void textBox_upgradeUrl_Leave(object sender, EventArgs e) + { + cfg.SetAppSetting("upgradeUrl", this.textBox_upgradeUrl.Text.ToString()); + textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "升级地址修改成功!" + "\r\n"); + } + + private void simpleUpgrade(object str) + { + // 当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它 + if (textBox_log.InvokeRequired) + { + string[] remoteVer = this.getRemoteVer(str.ToString()); + if(remoteVer[0].ToString() == "OK") + { + Action<string> changeVer = delegate (string txt) + { + this.label_latestVer.Text = txt.ToString(); + }; + this.Invoke(changeVer, remoteVer[1].ToString()); + + Action<string> appendText = delegate (string txt) + { + this.textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "获取远程版本信息成功,远程版本: " + txt.ToString() + "\r\n"); + }; + this.Invoke(appendText, remoteVer[1].ToString()); + } + else if(remoteVer[0].ToString() == "NULL") + { + Action<string> appendText = delegate (string txt) + { + this.textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "未发现新版本" + "\r\n"); + }; + this.Invoke(appendText, null); + } + else + { + Action<string> appendText = delegate (string txt) + { + this.textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "获取远程版本信息出错:"+ txt.ToString() + "\r\n"); + }; + this.Invoke(appendText, remoteVer[1].ToString()); + } + + } + else + { + string[] remoteVer = this.getRemoteVer(str.ToString()); + if (remoteVer[0].ToString() == "OK") + { + this.label_latestVer.Text = remoteVer[1].ToString(); + this.textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "获取远程版本信息成功,远程版本: " + remoteVer[1].ToString() + "\r\n"); + } + else if (remoteVer[0].ToString() == "NULL") + { + this.textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "未发现新版本" + "\r\n"); + } + else + { + this.textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "获取远程版本信息出错:" + remoteVer[1].ToString() + "\r\n"); + } + } + } } } diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/Form_tunnelEdit.Designer.cs b/net.nutcore.aliddns/net.nutcore.aliddns/Form_tunnelEdit.Designer.cs index e1ce573..414dfe6 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/Form_tunnelEdit.Designer.cs +++ b/net.nutcore.aliddns/net.nutcore.aliddns/Form_tunnelEdit.Designer.cs @@ -62,7 +62,7 @@ this.label1.Location = new System.Drawing.Point(6, 17); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); - this.label1.TabIndex = 1; + this.label1.TabIndex = 5; this.label1.Text = "英文标识:"; // // label2 @@ -71,7 +71,7 @@ this.label2.Location = new System.Drawing.Point(6, 44); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(65, 12); - this.label2.TabIndex = 2; + this.label2.TabIndex = 6; this.label2.Text = "网络协议:"; // // label3 @@ -80,7 +80,7 @@ this.label3.Location = new System.Drawing.Point(6, 97); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(65, 12); - this.label3.TabIndex = 3; + this.label3.TabIndex = 8; this.label3.Text = "本地端口:"; // // label4 @@ -89,7 +89,7 @@ this.label4.Location = new System.Drawing.Point(6, 124); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(77, 12); - this.label4.TabIndex = 4; + this.label4.TabIndex = 9; this.label4.Text = "服务器端口:"; // // label5 @@ -98,7 +98,7 @@ this.label5.Location = new System.Drawing.Point(6, 70); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 12); - this.label5.TabIndex = 5; + this.label5.TabIndex = 7; this.label5.Text = "域名:"; // // textBox_localPort @@ -107,7 +107,7 @@ this.textBox_localPort.MaxLength = 5; this.textBox_localPort.Name = "textBox_localPort"; this.textBox_localPort.Size = new System.Drawing.Size(87, 21); - this.textBox_localPort.TabIndex = 6; + this.textBox_localPort.TabIndex = 3; // // comboBox_proto // @@ -120,7 +120,7 @@ this.comboBox_proto.Location = new System.Drawing.Point(77, 41); this.comboBox_proto.Name = "comboBox_proto"; this.comboBox_proto.Size = new System.Drawing.Size(87, 20); - this.comboBox_proto.TabIndex = 7; + this.comboBox_proto.TabIndex = 1; this.comboBox_proto.TextChanged += new System.EventHandler(this.comboBox_proto_TextChanged); // // textBox_serverPort @@ -129,7 +129,7 @@ this.textBox_serverPort.MaxLength = 5; this.textBox_serverPort.Name = "textBox_serverPort"; this.textBox_serverPort.Size = new System.Drawing.Size(87, 21); - this.textBox_serverPort.TabIndex = 8; + this.textBox_serverPort.TabIndex = 4; // // textBox_subdomain // @@ -137,7 +137,7 @@ this.textBox_subdomain.MaxLength = 10; this.textBox_subdomain.Name = "textBox_subdomain"; this.textBox_subdomain.Size = new System.Drawing.Size(87, 21); - this.textBox_subdomain.TabIndex = 9; + this.textBox_subdomain.TabIndex = 2; // // label6 // @@ -194,7 +194,7 @@ this.groupBox_tunnel.Location = new System.Drawing.Point(5, 7); this.groupBox_tunnel.Name = "groupBox_tunnel"; this.groupBox_tunnel.Size = new System.Drawing.Size(244, 149); - this.groupBox_tunnel.TabIndex = 14; + this.groupBox_tunnel.TabIndex = 0; this.groupBox_tunnel.TabStop = false; this.groupBox_tunnel.Text = "Tunnel"; // @@ -203,7 +203,7 @@ this.button_confirm.Location = new System.Drawing.Point(139, 162); this.button_confirm.Name = "button_confirm"; this.button_confirm.Size = new System.Drawing.Size(58, 25); - this.button_confirm.TabIndex = 15; + this.button_confirm.TabIndex = 0; this.button_confirm.Text = "确定"; this.button_confirm.UseVisualStyleBackColor = true; this.button_confirm.Click += new System.EventHandler(this.button_confirm_Click); @@ -213,7 +213,7 @@ this.button_cancel.Location = new System.Drawing.Point(57, 162); this.button_cancel.Name = "button_cancel"; this.button_cancel.Size = new System.Drawing.Size(59, 25); - this.button_cancel.TabIndex = 16; + this.button_cancel.TabIndex = 1; this.button_cancel.Text = "取消"; this.button_cancel.UseVisualStyleBackColor = true; this.button_cancel.Click += new System.EventHandler(this.button_cancel_Click); diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/aliyun-net-sdk-Core.dll b/net.nutcore.aliddns/net.nutcore.aliddns/aliyun-net-sdk-Core.dll new file mode 100644 index 0000000..3fb3a0c Binary files /dev/null and b/net.nutcore.aliddns/net.nutcore.aliddns/aliyun-net-sdk-Core.dll differ diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj b/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj index 50df90c..18f7e47 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj +++ b/net.nutcore.aliddns/net.nutcore.aliddns/net.nutcore.aliddns.csproj @@ -62,8 +62,8 @@ <SpecificVersion>False</SpecificVersion> <HintPath>.\aliyun-net-sdk-Core.dll</HintPath> </Reference> - <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath> + <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="PresentationCore" /> @@ -82,8 +82,8 @@ <Reference Include="UIAutomationProvider" /> <Reference Include="WindowsBase" /> <Reference Include="WindowsFormsIntegration" /> - <Reference Include="YamlDotNet, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\YamlDotNet.5.0.1\lib\net35\YamlDotNet.dll</HintPath> + <Reference Include="YamlDotNet, Version=7.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL"> + <HintPath>..\packages\YamlDotNet.7.0.0\lib\net35\YamlDotNet.dll</HintPath> <Private>True</Private> </Reference> </ItemGroup> diff --git a/net.nutcore.aliddns/net.nutcore.aliddns/packages.config b/net.nutcore.aliddns/net.nutcore.aliddns/packages.config index 512c716..4f5d8bd 100644 --- a/net.nutcore.aliddns/net.nutcore.aliddns/packages.config +++ b/net.nutcore.aliddns/net.nutcore.aliddns/packages.config @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net40" /> - <package id="YamlDotNet" version="5.0.1" targetFramework="net40" /> + <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net40" /> + <package id="YamlDotNet" version="7.0.0" targetFramework="net40" /> </packages> \ No newline at end of file