Explorar o código

如无法启动则直接开启程序

章政 %!s(int64=7) %!d(string=hai) anos
pai
achega
2dbd050894
Modificáronse 1 ficheiros con 33 adicións e 24 borrados
  1. 33 24
      UAS_AutoUpdate/CheckUpdateWindow.cs

+ 33 - 24
UAS_AutoUpdate/CheckUpdateWindow.cs

@@ -40,38 +40,47 @@ namespace UAS_AutoUpdate
                 doc.AppendChild(xeRoot);
                 doc.Save(ConfigFile);
             }
-            WebClient wc = new WebClient();
-            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)
+            try
             {
-                Process[] pro = Process.GetProcessesByName("UAS_MES_NEW");
-                if (pro.Length > 0)
+                WebClient wc = new WebClient();
+                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)
                 {
-                    string CloseProcess = MessageBox.Show(this.ParentForm, "检测到程序仍在运行,是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
-                    if (CloseProcess == "Yes")
+                    Process[] pro = Process.GetProcessesByName("UAS_MES_NEW");
+                    if (pro.Length > 0)
                     {
-                        for (int i = 0; i < pro.Length; i++)
+                        string CloseProcess = MessageBox.Show(this.ParentForm, "检测到程序仍在运行,是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                        if (CloseProcess == "Yes")
                         {
-                            Process.GetProcessById(pro[i].Id).Kill();
+                            for (int i = 0; i < pro.Length; i++)
+                            {
+                                Process.GetProcessById(pro[i].Id).Kill();
+                            }
+                        }
+                        else
+                        {
+                            CloseWhenFinished = true;
+                            Close();
+                            return;
                         }
                     }
-                    else
-                    {
-                        CloseWhenFinished = true;
-                        Close();
-                        return;
-                    }
+                    wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
+                    wc.DownloadFileAsync(new Uri(GetCacheData(ConfigFile, "UpdatePath").ToString()), "UAS_MES.zip");
+                    SetCacheData(ConfigFile, "Version", ver1.ToString());
+                }
+                else
+                {
+                    Process p = Process.Start("UAS_MES_NEW.exe");
+                    CloseWhenFinished = true;
+                    Close();
                 }
-                wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
-                wc.DownloadFileAsync(new Uri(GetCacheData(ConfigFile, "UpdatePath").ToString()), "UAS_MES.zip");
-                SetCacheData(ConfigFile, "Version", ver1.ToString());
             }
-            else
+            catch (Exception)
             {
                 Process p = Process.Start("UAS_MES_NEW.exe");
                 CloseWhenFinished = true;