void ExtractUpk()
 {
     ResetProgress(Status.Extract);
     StartThread(delegate {
         if (File.Exists(_upkPath))
         {
             FingerPrint.StartWriting(_bundleFolder);
             if (UPKExtra.ExtraUPK(_upkPath, _bundleFolder, _progress, true, delegate(string path, byte[] bytes) {
                 FingerPrint.AddItem(path, MiscUtils.GetMd5HashFromBytes(bytes), _bundleFolder);
             }))
             {
                 FingerPrint.Flush();
                 ChangeStatus(Status.Done);
                 File.Delete(_upkPath);
             }
             else
             {
                 Fail();
             }
         }
         else
         {
             ChangeStatus(Status.Request);
         }
     });
 }
Beispiel #2
0
    public IEnumerator DownloadBundleFile(BundleInfo info)
    {
        WWW www = new WWW(info._url);

        m_CurrentWWW = www;
        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            if (www.responseHeaders.ContainsKey("X-CACHE"))
            {
                LogManager.Log(info._path + ": " + www.responseHeaders["X-CACHE"]);
            }
            try {
                string filePath = m_AssetBundlePath + info._path;
                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                }
                File.WriteAllBytes(filePath, www.bytes);
                FingerPrint.AddItem(filePath, MiscUtils.GetMd5HashFromBytes(www.bytes), m_AssetBundlePath);
                m_DownloadedNum++;
                m_FinishedBytes += www.bytes.Length;

                www.Dispose();
            } catch (Exception e) {
                LogManager.Log("下载失败:url: " + info._url + ", error: " + e.Message);
                m_FailedBundles.Add(info);
            }
        }
        else
        {
            LogManager.Log("下载失败:url: " + info._url + ", error: " + www.error);
            m_FailedBundles.Add(info);
        }

        m_DownloadIndex++;
        if (m_DownloadIndex == m_WaitForDownloadBundles.Count)
        {
            if (m_FailedBundles.Count > 0)
            {
                LogManager.Log(m_FailedBundles.Count + " files failed! ");
                m_WaitForDownloadBundles.Clear();
                for (int i = 0; i < m_FailedBundles.Count; ++i)
                {
                    m_WaitForDownloadBundles.Add(new BundleInfo()
                    {
                        _url  = m_FailedBundles[i]._url,
                        _path = m_FailedBundles[i]._path
                    });
                }
                m_FailedBundles.Clear();
                m_DownloadIndex = 0;
                StartDownloadAtIndex();
            }
            else
            {
                LogManager.Log("all files completed!!");
                Ready();
                FingerPrint.Flush();
            }
        }
        else
        {
            StartDownloadAtIndex();
        }
        Resources.UnloadUnusedAssets();
    }