Example #1
0
        /// <summary>
        /// 检查更新,运行softupdate.exe
        /// </summary>
        protected void checkUpdate()
        {
            if (CheckForUpdate() > 0)
            {
                btn_Login.Enabled = true;
                btn_Login.Text    = "是否升级?";
                btn_Login.Enabled = false;

                EchoHelper.Echo("发现新内容,马上更新吗?", "软件更新", EchoHelper.EchoType.任务信息);
                string xmlFile = Application.StartupPath + @"\Temp\UpdateList.xml";
                string upStr   = new XmlFiles(xmlFile).GetNodeValue("//description");
                if (upStr.Contains("\n"))
                {
                    upStr = upStr.Split('\n')[2].ToString();
                    upStr = upStr.Trim();
                }
                DialogResult dre = MessageBox.Show("发现新内容,马上更新吗?\n" + upStr, "更新程序", MessageBoxButtons.OKCancel);
                if (dre == DialogResult.OK)
                {
                    string exe_path = Application.StartupPath;
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.FileName         = "X_Update.exe";
                    process.StartInfo.WorkingDirectory = exe_path;
                    process.StartInfo.CreateNoWindow   = true;
                    process.Start();
                    Application.Exit();
                }
            }
            else
            {
                EchoHelper.Echo("恭喜您,您的版本已经是最新!", "软件更新", EchoHelper.EchoType.任务信息);
            }
            btn_Login.Text    = "登陆";
            btn_Login.Enabled = true;
        }
Example #2
0
        /// <summary>
        /// 检查更新文件,返回需要更新的个数。
        /// </summary>
        /// <param name="serverXmlFile"></param>
        /// <param name="localXmlFile"></param>
        /// <param name="updateFileList"></param>
        /// <returns></returns>
        public int CheckForUpdate()
        {
#if !DEBUG
            wait.ShowMsg("2/10 检查是否存在更新补丁,请稍后...");
            string localXmlFile = Application.StartupPath + "\\UpdateList.xml";
            if (!File.Exists(localXmlFile))
            {
                return(-1);
            }
            XmlFiles updaterXmlFiles = new XmlFiles(localXmlFile);

            string tempUpdatePath = Application.StartupPath + "\\Temp\\";
            this.UpdaterUrl = updaterXmlFiles.GetNodeValue("//Url") + "UpdateList.xml";
            this.DownAutoUpdateFile(tempUpdatePath);

            string serverXmlFile = tempUpdatePath + "UpdateList.xml";

            if (!File.Exists(serverXmlFile))
            {
                return(-1);
            }

            XmlFiles serverXmlFiles = new XmlFiles(serverXmlFile);
            XmlFiles localXmlFiles  = new XmlFiles(localXmlFile);

            XmlNodeList newNodeList = serverXmlFiles.GetNodeList("AutoUpdater/Files");
            XmlNodeList oldNodeList = localXmlFiles.GetNodeList("AutoUpdater/Files");

            int k = 0;
            for (int i = 0; i < newNodeList.Count; i++)
            {
                string[] fileList = new string[3];

                string newFileName = newNodeList.Item(i).Attributes["Name"].Value.Trim();
                string newVer      = newNodeList.Item(i).Attributes["Ver"].Value.Trim();

                ArrayList oldFileAl = new ArrayList();
                for (int j = 0; j < oldNodeList.Count; j++)
                {
                    string oldFileName = oldNodeList.Item(j).Attributes["Name"].Value.Trim();
                    string oldVer      = oldNodeList.Item(j).Attributes["Ver"].Value.Trim();

                    oldFileAl.Add(oldFileName);
                    oldFileAl.Add(oldVer);
                }
                int pos = oldFileAl.IndexOf(newFileName);
                if (pos == -1)
                {
                    fileList[0] = newFileName;
                    fileList[1] = newVer;
                    k++;
                }
                else if (pos > -1 && newVer.CompareTo(oldFileAl[pos + 1].ToString()) > 0)
                {
                    fileList[0] = newFileName;
                    fileList[1] = newVer;
                    k++;
                }
            }
            wait.CloseMsg();
            return(k);
#else
            return(0);
#endif
        }