Esempio n. 1
0
    private void DownloadFinishWithMd5(DownloadTask task)
    {
        string str = Utils.BuildFileMd5(task.FileName);

        if (str.Trim() != task.MD5.Trim())
        {
            if (System.IO.File.Exists(task.FileName))
            {
                System.IO.File.Delete(task.FileName);
            }
            LoggerHelper.Error("断点MD5验证失败,从新下载:" + task.FileName + "--" + str + " vs " + task.MD5, true);
            task.bDownloadAgain = true;
            task.bFineshed      = false;
            this.CheckDownLoadList();
        }
        else
        {
            LoggerHelper.Debug("断点下载验证全部通过,下载完成:" + task.FileName, true, 0);
            if (this.FileDecompress != null)
            {
                this.FileDecompress(true);
            }
            task.bDownloadAgain = false;
            task.bFineshed      = true;
            task.Finished();
            if (this.FileDecompress != null)
            {
                this.FileDecompress(false);
            }
            LoggerHelper.Debug("断点下载完成后,再次核对下载列表", true, 0);
            this.CheckDownLoadList();
        }
    }
Esempio n. 2
0
    private void DownloadFinishWithMd5(DownloadTask task)
    {
        //验证MD5
        var md5Compute = Utils.BuildFileMd5(task.FileName);

        //md5验证失败
        if (md5Compute.Trim() != task.MD5.Trim())
        {
            //如果md5验证失败,删除原文件
            if (File.Exists(task.FileName))
            {
                File.Delete(task.FileName);
            }
            LoggerHelper.Error("断点MD5验证失败,从新下载:" + task.FileName + "--" + md5Compute + " vs " + task.MD5);
            task.bDownloadAgain = true;
            task.bFineshed      = false;
            CheckDownLoadList();
            return;
        }
        //所有通过验证就认为是下载完成
        LoggerHelper.Debug("断点下载验证全部通过,下载完成:" + task.FileName);
        if (FileDecompress != null)
        {
            FileDecompress(true);
        }
        task.bDownloadAgain = false;
        task.bFineshed      = true;
        task.Finished();
        if (FileDecompress != null)
        {
            FileDecompress(false);
        }
        LoggerHelper.Debug("断点下载完成后,再次核对下载列表");
        CheckDownLoadList();
    }
Esempio n. 3
0
    private void DownloadFinishWithMd5(DownloadTask task)
    {
        LoggerHelper.Debug("DownloadFinishWithMd51111");
        //验证MD5
#if UNITY_IPHONE
        //ios下如果封装该方法在一个函数中,调用该函数来产生文件的MD5的时候,就会抛JIT异常。
        //如果直接把这个产生MD5的方法体放在直接执行,就可以正常执行,这个原因还不清楚。
        string md5Compute = null;
        using (System.IO.FileStream fileStream = System.IO.File.OpenRead(task.FileName))
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] fileMD5Bytes = md5.ComputeHash(fileStream);
            md5Compute = System.BitConverter.ToString(fileMD5Bytes).Replace("-", "").ToLower();
        }
#else
        var md5Compute = Utils.BuildFileMd5(task.FileName);
#endif
        //md5验证失败
        if (md5Compute.Trim() != task.MD5.Trim())
        {
            //如果md5验证失败,删除原文件
            if (File.Exists(task.FileName))
            {
                File.Delete(task.FileName);
            }
            LoggerHelper.Error("断点MD5验证失败,从新下载:" + task.FileName + "--" + md5Compute + " vs " + task.MD5);
            task.bDownloadAgain = true;
            task.bFineshed      = false;
            CheckDownLoadList();
            return;
        }
        //所有通过验证就认为是下载完成
        LoggerHelper.Debug("断点下载验证全部通过,下载完成:" + task.FileName);
        if (FileDecompress != null)
        {
            FileDecompress(true);
        }
        task.bDownloadAgain = false;
        task.bFineshed      = true;
        task.Finished();
        if (FileDecompress != null)
        {
            FileDecompress(false);
        }
        LoggerHelper.Debug("断点下载完成后,再次核对下载列表");
        CheckDownLoadList();
    }
Esempio n. 4
0
 private void TaskFinish(DownloadTask task, Exception e = null)
 {
     if (task == null)
     {
         return;
     }
     if (e != null)
     {
         Debug.Log("下载出错" + e.Message);
         Debug.LogException(e);
         task.OnError(e);
         task.Finished(false);
     }
     else
     {
         DownloadFinishWithMd5(task);
     }
 }
Esempio n. 5
0
    void webClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    {
        String       keyurl = e.UserState.ToString();
        DownloadTask task   = GetTask(keyurl);

        if (task != null)
        {
            //先校验网络是否异常
            if (e.Error != null)
            {
                HandleNetworkError(e.Error,
                                   () =>
                {
                    //跳过当前这个下载下一个
                    task.bDownloadAgain = false;
                    task.bFineshed      = true;
                    CheckDownLoadList();
                },
                                   () =>
                {
                    //从新下载这个
                    task.bDownloadAgain = true;
                    task.bFineshed      = false;
                    CheckDownLoadList();
                });
            }
            else
            {
                //验证MD5
#if UNITY_IPHONE
                //ios下如果封装该方法在一个函数中,调用该函数来产生文件的MD5的时候,就会抛JIT异常。
                //如果直接把这个产生MD5的方法体放在直接执行,就可以正常执行,这个原因还不清楚。
                string md5Compute = null;
                using (System.IO.FileStream fileStream = System.IO.File.OpenRead(task.FileName))
                {
                    System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                    byte[] fileMD5Bytes = md5.ComputeHash(fileStream);
                    md5Compute = System.BitConverter.ToString(fileMD5Bytes).Replace("-", "").ToLower();
                }
#else
                String md5Compute = Utils.BuildFileMd5(task.FileName);
#endif
                //md5验证失败
                if (md5Compute.Trim() != task.MD5.Trim())
                {
                    //如果md5验证失败,删除原文件
                    if (File.Exists(task.FileName))
                    {
                        File.Delete(task.FileName);
                    }
                    LoggerHelper.Error("MD5验证失败,从新下载:" + task.FileName + "--" + md5Compute + " vs " + task.MD5);
                    task.bDownloadAgain = true;
                    task.bFineshed      = false;
                    CheckDownLoadList();
                    return;
                }
                //所有通过验证就认为是下载完成
                LoggerHelper.Debug("下载验证全部通过,下载完成:" + task.FileName);
                if (FileDecompress != null)
                {
                    FileDecompress(true);
                }
                task.bDownloadAgain = false;
                task.bFineshed      = true;
                task.Finished();
                if (FileDecompress != null)
                {
                    FileDecompress(false);
                }
                LoggerHelper.Debug("下载完成后,再次核对下载列表");
                CheckDownLoadList();
            }
        }
    }
Esempio n. 6
0
    private void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        Action       mycontinue = null;
        Action       again      = null;
        string       url        = e.UserState.ToString();
        DownloadTask task       = this.GetTask(url);

        if (task != null)
        {
            if (e.Error != null)
            {
                if (mycontinue == null)
                {
                    mycontinue = delegate {
                        task.bDownloadAgain = false;
                        task.bFineshed      = true;
                        this.CheckDownLoadList();
                    };
                }
                if (again == null)
                {
                    again = delegate {
                        task.bDownloadAgain = true;
                        task.bFineshed      = false;
                        this.CheckDownLoadList();
                    };
                }
                HandleNetworkError(e.Error, mycontinue, again, null);
            }
            else
            {
                string str2 = Utils.BuildFileMd5(task.FileName);
                if (str2.Trim() != task.MD5.Trim())
                {
                    if (System.IO.File.Exists(task.FileName))
                    {
                        System.IO.File.Delete(task.FileName);
                    }
                    LoggerHelper.Error("MD5验证失败,从新下载:" + task.FileName + "--" + str2 + " vs " + task.MD5, true);
                    task.bDownloadAgain = true;
                    task.bFineshed      = false;
                    this.CheckDownLoadList();
                }
                else
                {
                    LoggerHelper.Debug("下载验证全部通过,下载完成:" + task.FileName, true, 0);
                    if (this.FileDecompress != null)
                    {
                        this.FileDecompress(true);
                    }
                    task.bDownloadAgain = false;
                    task.bFineshed      = true;
                    task.Finished();
                    if (this.FileDecompress != null)
                    {
                        this.FileDecompress(false);
                    }
                    LoggerHelper.Debug("下载完成后,再次核对下载列表", true, 0);
                    this.CheckDownLoadList();
                }
            }
        }
    }
Esempio n. 7
0
    private void DownloadFinishWithMd5(DownloadTask task)
    {
        LoggerHelper.Debug("DownloadFinishWithMd51111");
        //验证MD5
#if UNITY_IPHONE
    //ios下如果封装该方法在一个函数中,调用该函数来产生文件的MD5的时候,就会抛JIT异常。
    //如果直接把这个产生MD5的方法体放在直接执行,就可以正常执行,这个原因还不清楚。
                string md5Compute = null;
				using(System.IO.FileStream fileStream = System.IO.File.OpenRead(task.FileName))
				{
					System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
					byte[] fileMD5Bytes = md5.ComputeHash(fileStream);
                    md5Compute = System.BitConverter.ToString(fileMD5Bytes).Replace("-", "").ToLower();
				}
#else
        var md5Compute = Utils.BuildFileMd5(task.FileName);
#endif
        //md5验证失败
        if (md5Compute.Trim() != task.MD5.Trim())
        {
            //如果md5验证失败,删除原文件
            if (File.Exists(task.FileName))
                File.Delete(task.FileName);
            LoggerHelper.Error("断点MD5验证失败,从新下载:" + task.FileName + "--" + md5Compute + " vs " + task.MD5);
            task.bDownloadAgain = true;
            task.bFineshed = false;
            CheckDownLoadList();
            return;
        }
        //所有通过验证就认为是下载完成
        LoggerHelper.Debug("断点下载验证全部通过,下载完成:" + task.FileName);
        if (FileDecompress != null)
            FileDecompress(true);
        task.bDownloadAgain = false;
        task.bFineshed = true;
        task.Finished();
        if (FileDecompress != null)
            FileDecompress(false);
        LoggerHelper.Debug("断点下载完成后,再次核对下载列表");
        CheckDownLoadList();
    }
Esempio n. 8
0
    void webClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    {
        String       keyurl = e.UserState.ToString();
        DownloadTask task   = GetTask(keyurl);

        if (task != null)
        {
            //先校验网络是否异常
            if (e.Error != null)
            {
                HandleNetworkError(e.Error,
                                   () =>
                {
                    //跳过当前这个下载下一个
                    task.bDownloadAgain = false;
                    task.bFineshed      = true;
                    CheckDownLoadList();
                },
                                   () =>
                {
                    //从新下载这个
                    task.bDownloadAgain = true;
                    task.bFineshed      = false;
                    CheckDownLoadList();
                });
            }
            else
            {
                String md5Compute = Utils.BuildFileMd5(task.FileName);
                //md5验证失败
                if (md5Compute.Trim() != task.MD5.Trim())
                {
                    //如果md5验证失败,删除原文件
                    if (File.Exists(task.FileName))
                    {
                        File.Delete(task.FileName);
                    }
                    LoggerHelper.Error("MD5验证失败,从新下载:" + task.FileName + "--" + md5Compute + " vs " + task.MD5);
                    task.bDownloadAgain = true;
                    task.bFineshed      = false;
                    CheckDownLoadList();
                    return;
                }
                //所有通过验证就认为是下载完成
                LoggerHelper.Debug("下载验证全部通过,下载完成:" + task.FileName);
                if (FileDecompress != null)
                {
                    FileDecompress(true);
                }
                task.bDownloadAgain = false;
                task.bFineshed      = true;
                task.Finished();
                if (FileDecompress != null)
                {
                    FileDecompress(false);
                }
                LoggerHelper.Debug("下载完成后,再次核对下载列表");
                CheckDownLoadList();
            }
        }
    }