Пример #1
0
    private void DownloadFinishWithMd5(DownloadTask task)
    {
#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 = MD5Utils.BuildFileMd5(task.FileName);
#endif

        if (task.hasMD5 && md5Compute.Trim() != task.MD5.Trim())
        {
            task.tryTimes++;
            if (task.tryTimes > MaxTryTime)
            {
                Debug.unityLogger.Log("重试" + MaxTryTime + "无效, 停止重试");
                task.bDownloadAgain = false;
                task.bFineshed      = true;
                task.OnError(new Exception("md5验证失败,下载失败"));
                task.OnFinished(false);
            }
            else
            {
                if (File.Exists(task.FileName))
                {
                    File.Delete(task.FileName);
                }

                Debug.Log("断点MD5验证失败,第" + task.tryTimes + "次重试,从新下载:" + task.FileName + "--" + md5Compute + " vs " + task.MD5);

                task.bDownloadAgain = true;
                task.bFineshed      = false;
            }
        }
        else
        {
            task.bDownloadAgain = false;
            task.bFineshed      = true;
            task.OnFinished(true);
        }

        CheckDownLoadList(finishedAct, progressAct);
    }
Пример #2
0
        private static void CompressPackage()
        {
            bundlePathList = new List <string>();
            string mainBundlePath = PathConfig.AssetRootBundleFilePath;

            bundlePathList.Add(mainBundlePath);
            bundlePathList.Add(mainBundlePath + AssetBundleConst.ManifestEx);
            foreach (string path in pathList)
            {
                string fileName = FileEx.GetFileName(path);
                string resPath  = ResourcesLoaderHelper.GetResourcesBundlePathByObjectName(fileName);
                bundlePathList.Add(resPath);
                resPath = ResourcesLoaderHelper.GetResourcesBundleManifestPathByObjectName(fileName);
                bundlePathList.Add(resPath);
            }
            foreach (string path in bundlePathList)
            {
                Debug.logger.Log("压缩", path + "压缩");
            }
            CompressHelper.CompressFiles(PathConfig.bundleRootPath, bundlePathList.ToArray(), PathConfig.GetPkgExportPath(resVersion));
            string MD5 = MD5Utils.BuildFileMd5(PathConfig.GetPkgExportPath(resVersion));

            GenVersionInfo(MD5);
        }