private void Form1_Load(object sender, EventArgs e)
        {
            if (copylist.Count <= 0)
            {
                this.Close();
                return;
            }
            letdo = async_status;

            letdo.BeginInvoke("正在分析需要备份的文件***", null, null);
            for (int i = 0; i < copylist.Count; i++)
            {
                Update_File uf  = copylist[i] as Update_File;
                string      url = servicespath + uf.Fileurl;
                FileInfo    fi  = null;
                fi = new FileInfo(url);
                if (fi.Exists)
                {
                    TotalSize += (int)fi.Length;
                    letdo.BeginInvoke("INFO:文件正常!将被覆盖。" + url, null, null);
                    baklist.Add(url);
                }
                else
                {
                    letdo.BeginInvoke("WARNING:文件不存在!将以更新包内文件插入。" + url, null, null);
                }
            }
            letdo.BeginInvoke("INFO:检查完毕,总共需要备份" + baklist.Count + "个文件,总共大小" + TotalSize, null, null);
            letdo.BeginInvoke("INFO:开始备份", null, null);
            this.progressBar1.Minimum = 0;
            this.progressBar1.Maximum = TotalSize;
            copyCircle();
        }
        private void copyCircle()
        {
            if (curCopyNo >= copylist.Count)
            {
                letdo.BeginInvoke("INFO: 打包完成!", null, null);
                AutoClose ac = AutoColseFunc;
                this.BeginInvoke(ac, null);
                return;
            }
            string bakto = AutoCreateFolder(System.Environment.CurrentDirectory + @"\" + GobalParameters.UpdateFolder + copylist[curCopyNo]);

            //FileInfo fi = new FileInfo(bakto);
            try {
                if (File.Exists(bakto))
                {
                    File.Delete(bakto);
                }
            } catch (Exception e1) {
                MessageBox.Show(e1.ToString());
            }

            letdo.BeginInvoke("INFO: 正在复制文件:" + frompath + copylist[curCopyNo], null, null);
            //开始备份
            try
            {
                FileStream fs = new FileStream(frompath + (string)copylist[curCopyNo], FileMode.Open, FileAccess.Read);
                Size     = (int)fs.Length;
                position = 0;
                stream   = fs;
                //这里是设置缓存的大小,可以根据需要修改逻辑
                if (Size < BUFFER_SIZE)
                {
                    buffer = new byte[Size];
                    stream.BeginRead(buffer, 0, Size, new AsyncCallback(AsyncCopyFile), bakto);
                }
                else
                {
                    buffer = new byte[BUFFER_SIZE];
                    stream.BeginRead(buffer, 0, BUFFER_SIZE, new AsyncCallback(AsyncCopyFile), bakto);
                }
            }
            catch (Exception Ex)
            {
                curCopyNo++;
                TotalPostion += Size;
                copyCircle();

                MessageBox.Show("ERROR:复制文件:" + frompath + copylist[curCopyNo] + "出错(" + Ex.ToString());
                letdo.BeginInvoke("ERROR:复制文件文件:" + frompath + copylist[curCopyNo] + "出错(" + Ex.ToString() + ")", null, null);
            }
        }
        /// <summary>
        /// 更新正式开始
        /// </summary>
        private void UpdateFiles()
        {
            //提示倒数3秒
            Thread.Sleep(1000);
            letdo.BeginInvoke("INFO: 开始更新***倒数 3", null, null);
            Thread.Sleep(1000);
            letdo.BeginInvoke("INFO: 开始更新***倒数 2", null, null);
            Thread.Sleep(1000);
            letdo.BeginInvoke("INFO: 开始更新***倒数 1", null, null);

            //清空原来用作备份的数组,初始化各参数
            this.baklist.Clear();
            this.TotalSize    = 0;
            this.TotalPostion = 0;
            this.position     = 0;
            this.curCopyNo    = 0;

            //从更新包里预读文件,以便确定更新和统计更新大小
            foreach (Update_File element in copylist)
            {
                if (File.Exists(GobalParameters.UpdateFolder + element.Fileurl))
                {
                    FileInfo fi = new FileInfo(GobalParameters.UpdateFolder + element.Fileurl);
                    TotalSize += (int)fi.Length;
                    baklist.Add(element.Fileurl);
                }
                else
                {
                    letdo.BeginInvoke("ERROR: 需要更新的文件:" + element.Fileurl + "不在更新包中。", null, null);
                }
            }
            letdo.BeginInvoke("INFO: 需要更新文件" + baklist.Count + "共" + TotalSize, null, null);

            copyCircle();
        }
 private void Form1_Load(object sender, EventArgs e)
 {
     if (copylist.Count <= 0)
     {
         this.Close();
         return;
     }
     letdo = async_status;
     letdo.BeginInvoke("正在检查需要打包的文件***", null, null);
     for (int i = 0; i < copylist.Count; i++)
     {
         FileInfo fi = null;
         fi = new FileInfo(this.frompath + copylist[i] as string);
         if (fi.Exists)
         {
             TotalSize += (int)fi.Length;
         }
         //有可能是一个空文件夹
         else if (Directory.Exists(this.frompath + copylist[i] as string))
         {
             NullFileFolderlist.Add(copylist[i] as string);
             copylist.RemoveAt(i);
         }
         else
         {
             copylist.RemoveAt(i);
             letdo.BeginInvoke("ERROR:文件" + copylist[i] as string + "不存在", null, null);
         }
     }
     letdo.BeginInvoke("INFO:检查完毕,总共需要打包" + copylist.Count + "个文件,总共大小" + TotalSize, null, null);
     letdo.BeginInvoke("INFO:开始打包", null, null);
     this.progressBar1.Minimum = 0;
     this.progressBar1.Maximum = TotalSize;
     //为空文件夹创建文件夹,及复制
     for (int i = 0; i < NullFileFolderlist.Count; i++)
     {
         AutoCreateFolder(System.Environment.CurrentDirectory + @"\" + GobalParameters.UpdateFolder + NullFileFolderlist[i]);
     }
     copyCircle();
 }