Esempio n. 1
0
 //生成记录所有AssetBundle包的Md5文件
 private static void CreateMd5File4AssetBundleFiles()
 {
     try
     {
         List <string> list = new List <string>();
         Util.Recursive(ABPathConfig.AssetBundleBuildTargetPath, ref list);
         string outPath = Util.DeviceResPath() + AppConfig.Md5FilePath;
         if (File.Exists(outPath))
         {
             File.Delete(outPath);
         }
         FileStream   fs = new FileStream(outPath, FileMode.CreateNew);
         StreamWriter sw = new StreamWriter(fs);
         for (int i = 0; i < list.Count; i++)
         {
             string file = list[i];
             if (file.EndsWith(".manifest"))
             {
                 continue;
             }
             string md5 = Md5Helper.Md5File(file);
             file = file.Replace("\\", "/");
             file = file.Replace(Application.streamingAssetsPath + "/", "");
             sw.WriteLine(file + "|" + md5);
         }
         fs.Flush();
         sw.Close();
         fs.Close();
     }
     catch (System.Exception e)
     {
         Debug.LogError("CreateMd5File4AssetBundleFiles error: " + e.Message);
     }
 }
Esempio n. 2
0
 private void OnComplete(int code)
 {
     if (code == 206)
     {
         DownloadSuccess();
     }
     else if (code == 416)
     {
         ///在使用暂停下载的时候有几率会出现此问题
         ///因为是线程下载,在下载完成的瞬间暂停后 会把当前文件重新加入下载队列导致重复下载, 实际上暂停之后的同时或者下一帧这个文件已经下载完毕
         /// 所以临时文件 aaa.mp4.tmp 和 远程 aaa.mp4 的大小一样 只不过没有被移动 在续传的时候会返回一次416
         /// 所以这里判断如果临时文件的md5和远程md5相等 直接判定下载成功 不走下面下载失败流程 否则会删除重新下载
         /// 这里跳过了manifest文件 因为这个文件没有对应的md5字符串,也没有必要做对比,一般都是1k大小 重新下载没毛病
         if (m_currentConfig.fileName.EndsWith(".manifest") == false)
         {
             string fileMd5   = Md5Helper.Md5File(m_currentConfig.localUrl + ".tmp");
             string remoteMd5 = m_md5File.GetRemoteMd5(m_currentConfig.fileName);
             if (fileMd5.Trim() == remoteMd5.Trim())
             {
                 Debug.LogWarning(m_currentConfig.fileName + " 返回了416 但是文件已经下载完毕 不需要重新下载" + fileMd5 + "==" + remoteMd5);
                 DownloadSuccess();
             }
             else
             {
                 Debug.LogWarning(m_currentConfig.fileName + " 返回了416 文件不一样 重新下载" + fileMd5 + "!=" + remoteMd5);
                 DownloadFail(code);
             }
         }
     }
     else
     {
         DownloadFail(code);
     }
     m_currentConfig = new SGameUpdaterDownloadConfig();
     DownloadNext();
 }