void PushDownFile(List <DownResInfo> downList, string url) { DownResInfo node = new DownResInfo(); node.url = url; CHttpDown.GetDownFileSize(url, out node.nFileSize); downList.Add(node); }
void DownFile(CHttp http, string url, int nFileSize, int nLastDownSize) { // 如果文件比较小的话,可以不分片下载,真正下载整个文件 if (nFileSize == 0) { CHttpDown.GetDownFileSize(url, out nFileSize); } DownResFile resInfo = new DownResFile(); resInfo.url = url; resInfo.nFileSize = 0; if (0 == nFileSize) { // 无法获取文件大小信息,整个下载吧 bool bSuc = DownPart(http, url, 0, 0, nFileSize, resInfo); NotifyDownEvent(url, bSuc, resInfo); return; } int nPageSize = 1024 * 300; // 分片的大小,应小于你的最大限制下载速度, 这里默认选用300K,读者自己根据项目修改 int nFileOffset = nLastDownSize; // 从上一次下载的位置接着下载 int nDownSize = 0; for (; nFileOffset < nFileSize; nFileOffset += nPageSize) { // 先限速 LimitSpeed(); // 开始分片下载 nDownSize = nFileOffset + nPageSize < nFileSize ? nPageSize : (nFileSize - nFileOffset); if (!DownPart(http, url, nFileOffset, nDownSize, nFileSize, resInfo)) { NotifyDownEvent(url, false, resInfo); return; } } NotifyDownEvent(url, true, resInfo); }