/// <summary>
 /// Zip解压并更新目标文件
 /// </summary>
 /// <param name="ZipFile">Zip压缩包路径</param>
 /// <param name="UnZipDir">解压目标路径</param>
 /// <returns></returns>
 public static bool UnZip2(String ZipFile, String UnZipDir, UZipProgressDelegate uZipProgress)
 {
     try
     {
         UnZipDir = UnZipDir.EndsWith(@"\") ? UnZipDir : UnZipDir + @"\";
         using (var zipfile = ZipHelper.OpenOnFile(ZipFile))
         {
             int total = zipfile.Files.Count();
             int index = 0;
             foreach (var file in zipfile.Files)
             {
                 if (!file.Name.EndsWith("/"))
                 {
                     string FilePath    = UnZipDir + file.Name.Replace("/", @"\"); //设置解压路径
                     string GreatFolder = FilePath.Substring(0, FilePath.LastIndexOf(@"\"));
                     if (!Directory.Exists(GreatFolder))
                     {
                         Directory.CreateDirectory(GreatFolder);
                     }
                     byte[] content = new byte[file.GetStream().Length];
                     file.GetStream().Read(content, 0, content.Length);
                     index++;
                     if (File.Exists(FilePath))                      //跳过相同的文件,否则覆盖更新
                     {
                         if (content.Length == new FileInfo(FilePath).Length)
                         {
                             continue;
                         }
                     }
                     else
                     {
                         File.WriteAllBytes(FilePath, content);
                     }
                     uZipProgress?.Invoke(total, index);
                 }
             }
             uZipProgress?.Invoke(total, index);
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
        /// <summary>
        /// 下载文件(同步)  支持断点续传
        /// </summary>
        /// <param name="url">文件url</param>
        /// <param name="savepath">本地保存路径</param>
        /// <param name="progress">下载进度(百分比)</param>
        /// <param name="size">下载文件大小</param>
        public static void DowLoadFile(string url, string savepath, UZipProgressDelegate uZipProgress, long size = 0)
        {
            //打开上次下载的文件
            long       lStartPos = 0;
            FileStream fs;

            if (File.Exists(savepath))
            {
                //fs = File.OpenWrite(savepath);
                //lStartPos = fs.Length;
                //fs.Seek(lStartPos, SeekOrigin.Current);//移动文件流中的当前指针
                File.Delete(savepath);
            }

            string direName = Path.GetDirectoryName(savepath);

            if (!Directory.Exists(direName))//如果不存在保存文件夹路径,新建文件夹
            {
                Directory.CreateDirectory(direName);
            }
            fs        = new FileStream(savepath, FileMode.Create);
            lStartPos = 0;

            HttpWebRequest request = null;

            try
            {
                if (size == 0)
                {
                    size = GetFileContentLength(url);
                    if (size < 0)
                    {
                        return;
                    }
                }
                if (size != 0 && size == lStartPos)
                {
                    //下载完成
                    fs.Close();
                    return;
                }

                request = (HttpWebRequest)WebRequest.Create(url);
                request.ReadWriteTimeout = ReadWriteTimeOut;
                request.Timeout          = TimeOutWait;
                request.Headers.Add(HttpControl.azHeader, HttpControl.GetFileAutohrization);
                if (lStartPos > 0)
                {
                    request.AddRange((int)lStartPos);//设置Range值,断点续传
                }
                //向服务器请求,获得服务器回应数据流
                WebResponse respone   = request.GetResponse();
                long        totalSize = respone.ContentLength + lStartPos;
                long        curSize   = lStartPos;

                Stream ns = respone.GetResponseStream();

                byte[] nbytes    = new byte[bytebuff];
                int    nReadSize = 0;
                while (nReadSize < respone.ContentLength)
                {
                    nReadSize = ns.Read(nbytes, 0, bytebuff);
                    fs.Write(nbytes, 0, nReadSize);

                    curSize += nReadSize;
                    //下载进度计算
                    uZipProgress?.Invoke(curSize, totalSize);
                }
                fs.Flush();
                ns.Close();
                fs.Close();
                if (curSize != totalSize)//文件长度不等于下载长度,下载出错
                {
                    throw new Exception();
                }
                if (request != null)
                {
                    request.Abort();
                }
                TryNumDic.Remove(url);
            }
            catch (Exception ex)
            {
                if (request != null)
                {
                    request.Abort();
                }

                fs.Close();
                if (TryNumDic.ContainsKey(url))
                {
                    if (TryNumDic[url] > MaxTryTime)
                    {
                        TryNumDic.Remove(url);
                        throw new Exception();
                    }
                    else
                    {
                        TryNumDic[url]++;
                    }
                }
                else
                {
                    TryNumDic.Add(url, 1);
                }
                //DowLoadFile(url, savepath, uZipProgress,size);
            }
        }