private void timer1_Tick(object sender, EventArgs e)
        {
            if (_HosterParent.ProcessState.CurrentProcessContent != null)
            {
                VersionUpdateFileInfo dataInfo = _HosterParent.ProcessState.CurrentProcessContent as VersionUpdateFileInfo;
                ListViewItem          lstItem  = getListViewByData(dataInfo);
                lstItem.EnsureVisible();
                if (dataInfo.Completed)
                {
                    lstItem.ForeColor = Color.Black;
                }

                // lstItem.SubItems[3].Text = System.Convert.ToInt32(dataInfo.HasDownLoad * 100 / dataInfo.FileLength).ToString() + "%";
                lstItem.SubItems[3].Text = VersionDownloadHelper.DividendToInt32(dataInfo.HasDownLoad * 100, dataInfo.FileLength).ToString() + "%";
                //if (lstItem.Index > 0) {
                //    lsvDownFiles.Items[lstItem.Index - 1].ForeColor = Color.Black;
                //    lsvDownFiles.Items[lstItem.Index - 1].SubItems[3].Text = "100%";
                //}
            }


            if (_HosterParent.ProcessState.Processed)
            {
                this.Close();
            }
        }
        // 检查并下载新版本。
        private bool checkDownloadVersionFiles()
        {
            VersionDownloadHelper download = new VersionDownloadHelper();
            double newNumber = 0;
            bool   exists    = download.CheckExistsNewVersion(out newNumber);

            if (exists)
            {
                bool b = download.DownloadVersionFileDialog();

                if (b)
                {
#if (!DEBUG)
                    //startNewApplication(_ApplicationName, string.Empty);
                    //如果成功下载,需要启动Copy 新版本的功能
                    string lastVersionLog = string.Format(DOWNLOAD_LOG, newNumber);
                    string val            = MB.Util.IniFile.ReadString("VersionUpdate", "DownLoad", string.Empty, lastVersionLog);
                    //判断版本是否已经下载
                    if (string.Compare(val, "True", true) == 0)
                    {
                        completedNewVersionUpdate(newNumber);
                    }
#else
                    MB.Util.IniFile.WriteString("VersionInformation", VERSION_NUMBER_CFG_KEY, newNumber.ToString(), APPLICATION_INFO);
#endif
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 判断是否存在已经下载完成但未更新的版本,如果存在就更新它。
        /// </summary>
        /// <returns></returns>
        public bool CheckAndUpdateNewVersion()
        {
            try {
                // MB.Util.TraceEx.Write("52");
                if (!System.IO.Directory.Exists(AUTO_UPDATE_PATH))
                {
                    return(checkDownloadVersionFiles());
                }

                string[] versions = System.IO.Directory.GetDirectories(AUTO_UPDATE_PATH);
                if (versions == null || versions.Length == 0)
                {
                    return(checkDownloadVersionFiles());
                }
                // MB.Util.TraceEx.Write("60");
                double        clientVersion = GetClientVersionNumber();
                List <string> lst           = new List <string>(versions);
                lst.Sort();
                string active = lst.Last();

                string pathName = System.IO.Path.GetFileName(active);

                string[] v = pathName.Split(' ');

                double lastVersion = System.Convert.ToDouble(v[1]);
                //如果当前应用程序的版本号大于或者等于已下载或者已完成下载的版本,那么就判断并下载是否存在的新版本
                VersionDownloadHelper download = new VersionDownloadHelper();
                double serverNewNumber         = 0;
                bool   exists = download.CheckExistsNewVersion(out serverNewNumber);

                if (clientVersion >= lastVersion || lastVersion < serverNewNumber)
                {
                    return(checkDownloadVersionFiles());
                }
                // MB.Util.TraceEx.Write("76");
                string lastVersionLog = string.Format(DOWNLOAD_LOG, lastVersion);
                string val            = MB.Util.IniFile.ReadString("VersionUpdate", "DownLoad", string.Empty, lastVersionLog);
                //判断版本是否已经下载
                if (string.Compare(val, "True", true) == 0)
                {
                    //  MB.Util.TraceEx.Write("81");
                    completedNewVersionUpdate(lastVersion);
                }
                else
                {
                    //  MB.Util.TraceEx.Write("85");
                    //存在未完成的版本。
                    return(checkDownloadVersionFiles());
                }
            }
            catch (Exception ex) {
                throw MB.Util.APPExceptionHandlerHelper.PromoteException(ex, string.Empty);
            }
            //最后表示不存在新版本
            return(false);
        }
        /// <summary>
        ///  版本下载更新等待处理窗口。
        /// </summary>
        /// <param name="autoUpdate"></param>
        /// <param name="forDownloadFiles"></param>
        public FileDownloadWaitDialog(VersionDownloadHelper hosterParent, IVersionDownload autoUpdate, List <VersionUpdateFileInfo> forDownloadFiles)
        {
            InitializeComponent();

            lsvDownFiles.Dock = DockStyle.Fill;

            _UpdateHelper     = hosterParent;
            _HosterParent     = hosterParent;
            _AutoUpdate       = autoUpdate;
            _ForDownloadFiles = forDownloadFiles;

            this.Load += new EventHandler(VersionUpdateDialog_Load);
        }
        //根据Info 创建listview 的item
        private System.Windows.Forms.ListViewItem createItemByInfo(VersionUpdateFileInfo dataInfo)
        {
            ListViewItem item = new ListViewItem(dataInfo.FileName);

            item.ForeColor = dataInfo.Completed ? Color.Black : Color.Blue;

            item.SubItems.Add(dataInfo.ChildDirectoryName);
            if (dataInfo.FileLength < 1000)
            {
                item.SubItems.Add("1 KB");
            }
            else
            {
                item.SubItems.Add((dataInfo.FileLength / 1000).ToString() + " KB");
            }

            item.SubItems.Add(VersionDownloadHelper.DividendToInt32(dataInfo.HasDownLoad * 100, dataInfo.FileLength).ToString() + "%");
            item.SubItems.Add(dataInfo.Remark);
            item.Tag = dataInfo;

            return(item);
        }