Эх сурвалжийг харах

修改通过FTP获取文件

callm 2 өдөр өмнө
parent
commit
2f8cc04311

+ 43 - 36
UAS_AutoUpdate/CheckUpdateWindow.cs

@@ -27,69 +27,76 @@ namespace UAS_AutoUpdate
 
         private void CheckUpdateWindow_Load(object sender, EventArgs e)
         {
+            //使用WebClient从指定位置下载文件,然后进行解压缩覆盖
             try
             {
-                FileInfo fileInfo = new FileInfo(ConfigFile);
-                if (fileInfo.Length == 0)
+                FileInfo info = new FileInfo(ConfigFile);
+                if (info.Length == 0)
                 {
-                    XmlDocument xmlDocument = new XmlDocument();
-                    XmlNode newChild = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", "");
-                    xmlDocument.AppendChild(newChild);
-                    XmlElement newChild2 = xmlDocument.CreateElement("cacheInfo");
-                    xmlDocument.AppendChild(newChild2);
-                    xmlDocument.Save(ConfigFile);
+                    XmlDocument doc = new XmlDocument();
+                    //创建类型声明节点  
+                    XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
+                    doc.AppendChild(node);
+                    //创建根节点  
+                    XmlElement xeRoot = doc.CreateElement("cacheInfo");
+                    doc.AppendChild(xeRoot);
+                    doc.Save(ConfigFile);
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("配置文件丢失,程序无法自动升级");
-                Process process = Process.Start("UAS_MES_NEW.exe");
+                Process p = Process.Start("UAS_MES_NEW.exe");
                 CloseWhenFinished = true;
                 Close();
                 return;
             }
             try
             {
-                WebClient webClient = new WebClient();
-                webClient.DownloadFile(new Uri(GetCacheData(ConfigFile, "ServerConfigPath").ToString()), ServerConfigFile);
-                Version version = new Version(GetCacheData(ServerConfigFile, "Version").ToString());
-                Version v = new Version(GetCacheData(ConfigFile, "Version").ToString());
-                if (version > v)
+                WebClient wc = new WebClient();
+                wc.Credentials = new NetworkCredential("vsftpd", "vsftpd6ap48170cz");
+                wc.DownloadFile(new Uri(GetCacheData(ConfigFile, "ServerConfigPath").ToString()), ServerConfigFile);
+                //服务器获取的配置文件
+                Version ver1 = new Version(GetCacheData(ServerConfigFile, "Version").ToString());
+                //本地的配置文件
+                Version ver2 = new Version(GetCacheData(ConfigFile, "Version").ToString());
+                //进行版本的比较
+                if (ver1 > ver2)
                 {
-                    Process[] processesByName = Process.GetProcessesByName("UAS_MES_NEW");
-                    if (processesByName.Length == 0)
+                    Process[] pro = Process.GetProcessesByName("UAS_MES_NEW");
+                    if (pro.Length > 0)
                     {
-                        goto IL_01b0;
-                    }
-                    string a = MessageBox.Show(base.ParentForm, "检测到程序仍在运行,是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
-                    if (a == "Yes")
-                    {
-                        for (int i = 0; i < processesByName.Length; i++)
+                        string CloseProcess = MessageBox.Show(this.ParentForm, "检测到程序仍在运行,是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                        if (CloseProcess == "Yes")
+                        {
+                            for (int i = 0; i < pro.Length; i++)
+                            {
+                                Process.GetProcessById(pro[i].Id).Kill();
+                            }
+                        }
+                        else
                         {
-                            Process.GetProcessById(processesByName[i].Id).Kill();
+                            CloseWhenFinished = true;
+                            Close();
+                            return;
                         }
-                        goto IL_01b0;
                     }
-                    CloseWhenFinished = true;
-                    Close();
+                    wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
+                    wc.DownloadFileAsync(new Uri(GetCacheData(ConfigFile, "UpdatePath").ToString()), "UAS_MES.zip");
+                    SetCacheData(ConfigFile, "Version", ver1.ToString());
                 }
                 else
                 {
-                    Process process2 = Process.Start("UAS_MES_NEW.exe");
+                    Process p = Process.Start("UAS_MES_NEW.exe");
                     CloseWhenFinished = true;
                     Close();
                 }
-                goto end_IL_0095;
-            IL_01b0:
-                webClient.DownloadProgressChanged += Wc_DownloadProgressChanged;
-                webClient.DownloadFileAsync(new Uri(GetCacheData(ConfigFile, "UpdatePath").ToString()), "UAS_MES.zip");
-                SetCacheData(ConfigFile, "Version", version.ToString());
-            end_IL_0095:;
             }
-            catch (Exception ex2)
+            catch (Exception ex)
             {
-                LogManager.DoLog(ex2.Message.ToString());
-                Process process3 = Process.Start("UAS_MES_NEW.exe");
+                MessageBox.Show(ex.Message);
+                LogManager.DoLog(ex.Message.ToString());
+                Process p = Process.Start("UAS_MES_NEW.exe");
                 CloseWhenFinished = true;
                 Close();
             }