Beispiel #1
0
        private void AutoUpdate_Load(object sender, EventArgs e)
        {
            try
            {
                lblProcess.Text = "";
                lblFile.Text = "";
                lblDownloadSize.Text = "";
                progressBarDownload.Value = 0;
                _updateOm = XmlUtility.GetUpdateInfo(_updatexml);
                //if (_updatexml != null)
                //    LogHelper.Write("FrmAutoUpdate.AutoUpdate_Load", _updatexml, LogSeverity.Info);
                //else
                //    LogHelper.Write("FrmAutoUpdate.AutoUpdate_Load", "_updatexml is null", LogSeverity.Info);
                if (_updateOm == null)
                {
                    MessageBox.Show("无法取得更新信息!", Program.MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Quit();
                    return;
                }

                lblVersion.Text = "最新版本:" + _updateOm.Version;
                lblUpdateDate.Text = "更新日期:" + _updateOm.UpdateTime;
                backgroundWorker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Program.MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //LogHelper.Write("FrmAutoUpdate.AutoUpdate_Load", ex, LogSeverity.Error);
                Quit();
            }
        }
Beispiel #2
0
        public static UpdateInfo GetUpdateInfo(string strxml)
        {
            try
            {
                if (String.IsNullOrEmpty(strxml))
                {
                    //return null;
                    using (StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Johnny.Kaixin.AutoUpdate.update.xml")))
                    {
                        strxml = streamReader.ReadToEnd();
                    }
                }

                XmlDocument objXmlDoc = new XmlDocument();
                objXmlDoc.LoadXml(strxml);

                if (objXmlDoc == null)
                {
                    return(null);
                }

                //root node
                XmlNode objRootNode = objXmlDoc.SelectSingleNode("AutoUpdater");
                if (objRootNode == null)
                {
                    return(null);
                }

                UpdateInfo updateOM = new UpdateInfo();

                XmlNode objNode;
                objNode             = objRootNode.SelectSingleNode("URLAddress");
                updateOM.UrlAddress = objNode.Attributes["URL"].Value;

                objNode             = objRootNode.SelectSingleNode("ReleaseInfo/UpdateTime");
                updateOM.UpdateTime = objNode.Attributes["Date"].Value;

                objNode          = objRootNode.SelectSingleNode("ReleaseInfo/Version");
                updateOM.Version = objNode.Attributes["Num"].Value;

                DataView dv = GetData(objXmlDoc, "AutoUpdater/UpdateFileList");

                string[] files = new string[dv.Table.Rows.Count];

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    files[ix] = dv.Table.Rows[ix][0].ToString();
                }
                updateOM.UpdateFileList = files;

                //deletion directory
                dv = GetData(objXmlDoc, "AutoUpdater/DeletionDirectoryList");

                string[] delFolders = new string[dv.Table.Rows.Count];

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    delFolders[ix] = dv.Table.Rows[ix][0].ToString();
                }
                updateOM.DeletionDirectoryList = delFolders;

                //deletion file
                dv = GetData(objXmlDoc, "AutoUpdater/DeletionFileList");

                string[] delFiles = new string[dv.Table.Rows.Count];

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    delFiles[ix] = dv.Table.Rows[ix][0].ToString();
                }
                updateOM.DeletionFileList = delFiles;

                objNode          = objRootNode.SelectSingleNode("RestartApp/ReStart");
                updateOM.ReStart = Convert.ToBoolean(objNode.Attributes["Allow"].Value);

                objNode          = objRootNode.SelectSingleNode("RestartApp/AppName");
                updateOM.AppName = objNode.Attributes["Name"].Value;

                return(updateOM);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }