Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tempXmlName"></param>
        /// <param name="serverXmlUrl"></param>
        /// <returns></returns>
        private UpdateXmlFile GetServerXmlFile(string tempXmlName, string serverXmlUrl)
        {
            if (File.Exists(tempXmlName))
            {
                File.Delete(tempXmlName);
            }
            WebFile.DownLoadFile(tempXmlName, serverXmlUrl);
            UpdateXmlFile serverXmlFile = new UpdateXmlFile(tempXmlName);

            return(serverXmlFile);
        }
Exemplo n.º 2
0
        protected override void OnShown(EventArgs e)
        {
            Updater updater = new Updater();

            PreDownLoad(updater.EntryPoint);
            IEnumerable <UpdateFileInfo> updateFiles = updater.CheckUpdateFile();
            int    count    = updateFiles.Count();
            int    index    = 1;
            Thread downTask = new Thread(() =>
            {
                foreach (var item in updateFiles)
                {
                    string tempFileName  = Path.Combine(updater.TempDirectory, item.FileName);//升级下载的临时文件名(fullName)
                    string serverFileUrl = updater.ServerUrl.TrimEnd('/') + "/" + item.FileName.Replace('\\', '/');
                    this.BeginInvoke(new Action(() =>
                    {
                        lblFile.Text      = Path.GetFileName(tempFileName);
                        lblFileCount.Text = index + "/" + count;
                    }));
                    Thread.Sleep(128);/*让下载慢点点,也就慢点点^_^*/
                    try
                    {
                        if (File.Exists(tempFileName))
                        {
                            File.Delete(tempFileName);
                        }
                    }
                    catch {}
                    try
                    {
                        WebFile.DownLoadFile(tempFileName, serverFileUrl, PreDown, DownAction);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(serverFileUrl + "\r\n详细信息:" + ex.Message);
                    }
                    index++;
                }
                this.Invoke(new Action(() => CopyUpdateFile(updater, updateFiles)));//完成下载,拷贝文件
            });

            downTask.IsBackground = true;
            downTask.Start();
            base.OnShown(e);
        }