// Token: 0x0600512B RID: 20779 RVA: 0x001BB484 File Offset: 0x001B9884
    private IEnumerator UnpackAssetBundleCoroutine(AssetBundleDownload download)
    {
        this.mNumberOfConcurrentUnpacks++;
        AssetBundleDownloadManager.UnpackType unpackType = download.unpackType;
        if (unpackType != AssetBundleDownloadManager.UnpackType.Async)
        {
            if (unpackType == AssetBundleDownloadManager.UnpackType.AsyncCreateNoLoad)
            {
                yield return(base.StartCoroutine(this.CreateAsyncCoroutine(download)));
            }
        }
        else
        {
            yield return(base.StartCoroutine(this.CreateAsyncCoroutine(download)));

            if (download.currentState != AssetBundleDownload.State.Error)
            {
                yield return(base.StartCoroutine(this.LoadAsyncCoroutine(download)));
            }
        }
        if (download.currentState != AssetBundleDownload.State.Error && download.currentState != AssetBundleDownload.State.WaitingForRequestToBeSent)
        {
            download.currentState = AssetBundleDownload.State.Done;
        }
        this.mNumberOfConcurrentUnpacks--;
        if (this.CheckForCancellation(download))
        {
            yield break;
        }
        yield break;
    }
 // Token: 0x0600512D RID: 20781 RVA: 0x001BB4F8 File Offset: 0x001B98F8
 private IEnumerator DownloadAndLoadLocalPluginCoroutine(AssetBundleDownload download)
 {
     if (!string.IsNullOrEmpty(download.pluginUrl))
     {
         WWW www = new WWW(download.pluginUrl);
         www.threadPriority = UnityEngine.ThreadPriority.Normal;
         while (!www.isDone)
         {
             yield return(null);
         }
         if (string.IsNullOrEmpty(www.error))
         {
             if (this.CheckForCancellation(download))
             {
                 yield break;
             }
             try
             {
                 PluginManager.Instance.Load(download.pluginUrl, www.bytes);
             }
             catch (Exception ex)
             {
                 download.OnPluginLoadError(ex.Message);
             }
         }
         else
         {
             Debug.LogError("Error loading plugin from " + download.pluginUrl + ": " + www.error);
             download.OnDownloadError("Error loading plugin from " + download.pluginUrl + ": " + www.error, LoadErrorReason.PluginLoadFailed);
         }
     }
     yield break;
 }
示例#3
0
 // Token: 0x0600510F RID: 20751 RVA: 0x001BAACA File Offset: 0x001B8ECA
 public void CopyAssetData(AssetBundleDownload download)
 {
     this.isLzma           = download.isLzma;
     this.assetBundleBytes = download.assetBundleBytes;
     this.assetBundle      = download.assetBundle;
     this.asset            = download.asset;
 }
示例#4
0
 // Token: 0x06005BCE RID: 23502 RVA: 0x002008A5 File Offset: 0x001FECA5
 private void ReportDownloadComplete(string url, AssetBundleDownload download)
 {
     if (this.OnSceneCreated != null)
     {
         this.OnSceneCreated(download);
     }
 }
 // Token: 0x06005142 RID: 20802 RVA: 0x001BB9E4 File Offset: 0x001B9DE4
 private void UpdateManifest(AssetBundleDownload download)
 {
     if (!this.mManifest.ContainsKey(download.assetId))
     {
         this.mManifest[download.assetId] = new Dictionary <string, object>();
     }
     this.mManifest[download.assetId]["version"] = download.assetVersion;
 }
    // Token: 0x06005140 RID: 20800 RVA: 0x001BB8F8 File Offset: 0x001B9CF8
    private void SaveToDisk(AssetBundleDownload download)
    {
        FileInfo fileInfo = new FileInfo(download.assetBundleFilePath);

        fileInfo.Directory.Create();
        File.WriteAllBytes(fileInfo.FullName, download.assetBundleBytes);
        this.UpdateManifest(download);
        this.SaveManifest();
    }
    // Token: 0x0600512A RID: 20778 RVA: 0x001BB460 File Offset: 0x001B9860
    private IEnumerator DownloadAndUnpackAssetBundleCoroutine(AssetBundleDownload download)
    {
        if (this.CheckForCancellation(download))
        {
            yield break;
        }
        yield return(StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(download.assetUrl, download.assetId, download.assetVersion, download.pluginUrl, download.onProgress, download.onDownloadCompleted, download.onDownloadError, download.unpackType, download.retryCount, download.downloadId, download.forceRefreshCache)));

        yield break;
    }
示例#8
0
    // Use this for initialization
    void Start()
    {
        AssetBundleDownload download = new AssetBundleDownload("test1", "http://192.168.50.26");

        download.OnFinishDownload += DownldFinish;
        download.OnError          += Error;
        download.StartDownload(this);
        // AssetBundleDownload download1 = new AssetBundleDownload("test2", "http://192.168.50.26");
        // download1.StartDownload(this);
        info = "ddd";
        //  List<FileData> list = XmlUtils.Load<List<FileData>>("test1");
    }
 // Token: 0x06005138 RID: 20792 RVA: 0x001BB658 File Offset: 0x001B9A58
 private IEnumerator WaitForAssetToLoadCoroutine(AssetBundleDownload download)
 {
     while (download.currentState != AssetBundleDownload.State.Error && download.currentState != AssetBundleDownload.State.Done)
     {
         yield return(null);
     }
     if (download.currentState != AssetBundleDownload.State.Error)
     {
         download.OnDownloadCompleted();
     }
     yield break;
 }
 // Token: 0x0600511A RID: 20762 RVA: 0x001BACC4 File Offset: 0x001B90C4
 public void CancelAssetBundleDownload(string url)
 {
     if (this.mAssetBundleDownloads.ContainsKey(url))
     {
         AssetBundleDownload assetBundleDownload = this.mAssetBundleDownloads[url];
         assetBundleDownload.isCancelled = true;
         Debug.Log("Successfully set download cancelled flag");
     }
     else
     {
         Debug.LogWarning("Cancel download failed, couldn't find bundle for url " + url);
     }
 }
 // Token: 0x0600513D RID: 20797 RVA: 0x001BB804 File Offset: 0x001B9C04
 private bool IsSavedOnDisk(AssetBundleDownload download)
 {
     this.PrintManifest();
     VRC.Core.Logger.Log(string.Concat(new object[]
     {
         "[",
         download.downloadId,
         "] Is assetId: ",
         download.assetId,
         " saved to disk?"
     }), DebugLevel.AssetBundleDownloadManager);
     return(this.mManifest.ContainsKey(download.assetId));
 }
    // Token: 0x06005132 RID: 20786 RVA: 0x001BB5AC File Offset: 0x001B99AC
    private IEnumerator AttemptLzmaDecompressionCoroutine(AssetBundleDownload download)
    {
        download.currentState = AssetBundleDownload.State.Decompressing;
        bool isLoomFinished = false;

        byte[] uncompressedData = new byte[0];
        Loom.StartSingleThread(delegate
        {
            if (download == null || download.assetBundleBytes == null)
            {
                VRC.Core.Logger.LogError("[" + download.downloadId + "] AssetBundle was NULL?!", DebugLevel.Always);
                download.isLzma            = false;
                download.assetBundleBytes  = new byte[0];
                isLoomFinished             = true;
                download.forceRefreshCache = true;
                HTTPCacheService.DeleteEntity(new Uri(download.assetUrl), true);
                return;
            }
            VRC.Core.Logger.Log("Download Asset bytes size: " + download.assetBundleBytes.Length, DebugLevel.AssetBundleDownloadManager);
            try
            {
                if (lzma.decompressBuffer(download.assetBundleBytes, ref uncompressedData, true, 0) == 0)
                {
                    VRC.Core.Logger.Log("[" + download.downloadId + "] LZMA Compressed AssetBundle Detected!", DebugLevel.AssetBundleDownloadManager);
                    download.assetBundleBytes = uncompressedData;
                    download.isLzma           = true;
                }
            }
            catch (Exception ex)
            {
                VRC.Core.Logger.LogError(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] LZMA exception: ",
                    ex.Message
                }), DebugLevel.Always);
                download.isLzma            = false;
                download.assetBundleBytes  = new byte[0];
                isLoomFinished             = true;
                download.forceRefreshCache = true;
                HTTPCacheService.DeleteEntity(new Uri(download.assetUrl), true);
            }
            isLoomFinished = true;
        }, System.Threading.ThreadPriority.Normal, true);
        while (!isLoomFinished)
        {
            yield return(null);
        }
        yield break;
    }
    // Token: 0x06005124 RID: 20772 RVA: 0x001BAFEC File Offset: 0x001B93EC
    private Coroutine RequestRemoteAssetBundle(AssetBundleDownload download, bool hasExistingDownload)
    {
        Coroutine result;

        if (hasExistingDownload)
        {
            result = base.StartCoroutine(this.WaitForRemoteAssetRequest(download));
        }
        else
        {
            result = base.StartCoroutine(this.RequestRemoteAssetBundleCoroutine(download));
        }
        return(result);
    }
 // Token: 0x06005125 RID: 20773 RVA: 0x001BB024 File Offset: 0x001B9424
 private void RetryRequestRemoteAssetBundle(AssetBundleDownload download)
 {
     download.currentState = AssetBundleDownload.State.Error;
     if (false && download.retryCount < 3)
     {
         VRC.Core.Logger.Log("[" + download.downloadId + "] RETRYING DOWNLOAD", DebugLevel.AssetBundleDownloadManager);
         this.mAssetBundleDownloads.Remove(download.assetUrl);
         download.retryCount++;
         base.StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(download));
     }
     else
     {
         VRC.Core.Logger.Log("[" + download.downloadId + "] REACHED MAX RETRY COUNT!!", DebugLevel.AssetBundleDownloadManager);
         download.OnDownloadError("[" + download.downloadId + "] Invalid assetbundle url", LoadErrorReason.InvalidURL);
     }
 }
    // Token: 0x06005126 RID: 20774 RVA: 0x001BB0D8 File Offset: 0x001B94D8
    private void OnLocalAssetBundleRequestCompleted(WWW www)
    {
        string url = www.url;

        if (!this.mAssetBundleDownloads.ContainsKey(url))
        {
            return;
        }
        AssetBundleDownload assetBundleDownload = this.mAssetBundleDownloads[url];

        if (this.CheckForCancellation(assetBundleDownload))
        {
            return;
        }
        assetBundleDownload.assetBundleBytes = www.bytes;
        AssetBundleDownloadManager.Instance.QueueAssetBundleDownload(assetBundleDownload);
    }
 // Token: 0x06005139 RID: 20793 RVA: 0x001BB674 File Offset: 0x001B9A74
 private bool CheckForCancellation(AssetBundleDownload download)
 {
     if (download == null)
     {
         return(false);
     }
     if (download.isCancelled)
     {
         download.Unload();
         this.mAssetBundleDownloads.Remove(download.assetUrl);
         if (download.currentState != AssetBundleDownload.State.Error && download.currentState != AssetBundleDownload.State.Done)
         {
             download.OnDownloadError("Download cancelled!", LoadErrorReason.Cancelled);
         }
         return(true);
     }
     return(false);
 }
 // Token: 0x06005120 RID: 20768 RVA: 0x001BAED8 File Offset: 0x001B92D8
 private void Unpack(AssetBundleDownload download)
 {
     try
     {
         base.StartCoroutine(this.UnpackAssetBundleCoroutine(download));
     }
     catch (Exception ex)
     {
         VRC.Core.Logger.LogWarning(string.Concat(new object[]
         {
             "[",
             download.downloadId,
             "] Error unpacking ab - ",
             ex.Message
         }), DebugLevel.AssetBundleDownloadManager);
         download.OnDownloadError(ex.Message, LoadErrorReason.Unknown);
     }
 }
    // Token: 0x06005130 RID: 20784 RVA: 0x001BB564 File Offset: 0x001B9964
    private IEnumerator RequestRemoteAssetBundleCoroutine(AssetBundleDownload download)
    {
        bool        error   = false;
        HTTPRequest request = null;

        try
        {
            request            = new HTTPRequest(new Uri(download.assetUrl), null);
            request.OnProgress = new OnDownloadProgressDelegate(download.OnDownloadProgress);
            request.Timeout    = TimeSpan.FromDays(10.0);
            if (download.forceRefreshCache)
            {
                HTTPCacheService.DeleteEntity(request.CurrentUri, true);
            }
            request.Send();
            if (Player.Instance != null && Player.Instance.isInternal)
            {
                Debug.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Sending request : ",
                    Json.Encode(request)
                }));
            }
            download.currentState = AssetBundleDownload.State.HttpRequestSent;
        }
        catch (Exception)
        {
            error = true;
        }
        if (error)
        {
            string message = (request == null) ? "Bad request url." : request.Exception.Message;
            download.OnDownloadError(message, LoadErrorReason.InvalidURL);
        }
        else
        {
            yield return(base.StartCoroutine(request));

            this.OnHttpAssetBundleRequestCompleted(request, request.Response);
        }
        yield break;
    }
    // Token: 0x06005133 RID: 20787 RVA: 0x001BB5C8 File Offset: 0x001B99C8
    private IEnumerator AttemptGZipDecompressionCoroutine(AssetBundleDownload download)
    {
        download.currentState = AssetBundleDownload.State.Decompressing;
        bool isGZipUncompressionComplete = false;

        Loom.StartSingleThread(delegate
        {
            if (GZip.IsValid(download.assetBundleBytes))
            {
                VRC.Core.Logger.Log("[" + download.downloadId + "] GZip Compressed AssetBundle Detected!", DebugLevel.AssetBundleDownloadManager);
                download.assetBundleBytes = GZip.Decompress(download.assetBundleBytes);
                download.isGZip           = true;
            }
            isGZipUncompressionComplete = true;
        }, System.Threading.ThreadPriority.Normal, true);
        while (!isGZipUncompressionComplete)
        {
            yield return(null);
        }
        yield break;
    }
    // Token: 0x0600512F RID: 20783 RVA: 0x001BB540 File Offset: 0x001B9940
    private IEnumerator RequestLocalAssetBundleCoroutine(AssetBundleDownload download)
    {
        WWW www = new WWW(download.assetUrl);

        www.threadPriority = UnityEngine.ThreadPriority.Normal;
        while (!www.isDone)
        {
            download.OnDownloadProgress(null, www.bytesDownloaded, www.size);
            yield return(null);
        }
        download.currentState = AssetBundleDownload.State.HttpResponseReceived;
        if (!string.IsNullOrEmpty(www.error) || !this.mAssetBundleDownloads.ContainsKey(www.url))
        {
            download.OnDownloadError(www.error, LoadErrorReason.ConnectionError);
        }
        else
        {
            this.OnLocalAssetBundleRequestCompleted(www);
        }
        yield break;
    }
    // Token: 0x06005123 RID: 20771 RVA: 0x001BAF74 File Offset: 0x001B9374
    private Coroutine RequestLocalAssetBundle(AssetBundleDownload download, bool hasExistingDownload)
    {
        Coroutine result;

        if (hasExistingDownload)
        {
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Previous request ",
                download.assetUrl,
                " detected. Waiting for it to complete."
            }), DebugLevel.AssetBundleDownloadManager);
            result = base.StartCoroutine(this.WaitForRemoteAssetRequest(download));
        }
        else
        {
            result = base.StartCoroutine(this.RequestLocalAssetBundleCoroutine(download));
        }
        return(result);
    }
    // Token: 0x06005131 RID: 20785 RVA: 0x001BB588 File Offset: 0x001B9988
    private IEnumerator WaitForRemoteAssetRequest(AssetBundleDownload download)
    {
        if (download == null)
        {
            yield break;
        }
        if (AssetBundleDownloadManager.Instance == null)
        {
            download.currentState = AssetBundleDownload.State.Error;
            yield break;
        }
        if (AssetBundleDownloadManager.Instance.mAssetBundleDownloads.ContainsKey(download.assetUrl))
        {
            download.currentState = AssetBundleDownload.State.WaitingForDuplicateToBeDone;
            yield return(new WaitWhile(() => AssetBundleDownloadManager.Instance != null && download != null && AssetBundleDownloadManager.Instance.mAssetBundleDownloads.ContainsKey(download.assetUrl) && AssetBundleDownloadManager.Instance.mAssetBundleDownloads[download.assetUrl] != null && AssetBundleDownloadManager.Instance.mAssetBundleDownloads[download.assetUrl].currentState != AssetBundleDownload.State.Done && AssetBundleDownloadManager.Instance.mAssetBundleDownloads[download.assetUrl].currentState != AssetBundleDownload.State.Error));

            if (AssetBundleDownloadManager.Instance == null || download == null || !AssetBundleDownloadManager.Instance.mAssetBundleDownloads.ContainsKey(download.assetUrl) || AssetBundleDownloadManager.Instance.mAssetBundleDownloads[download.assetUrl] == null)
            {
                if (download != null)
                {
                    download.currentState = AssetBundleDownload.State.Error;
                }
                yield break;
            }
            if (AssetBundleDownloadManager.Instance.mAssetBundleDownloads[download.assetUrl].currentState == AssetBundleDownload.State.Done)
            {
                download.asset        = this.GetLoadedAsset(download.assetUrl);
                download.currentState = AssetBundleDownload.State.Done;
                VRC.Core.Logger.Log("[" + download.downloadId + "] Duplicate finished!", DebugLevel.AssetBundleDownloadManager);
            }
            else
            {
                VRC.Core.Logger.Log("[" + download.downloadId + "] Duplicate failed to load because original failed!", DebugLevel.AssetBundleDownloadManager);
                download.OnDownloadError("Duplicate failed to load because original failed!", LoadErrorReason.DuplicateLoadFailed);
            }
        }
        yield break;
    }
    // Token: 0x06005135 RID: 20789 RVA: 0x001BB608 File Offset: 0x001B9A08
    private IEnumerator CreateAsyncCoroutine(AssetBundleDownload download)
    {
        yield return(base.StartCoroutine(this.AttemptLzmaDecompressionCoroutine(download)));

        AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(download.assetBundleBytes);

        yield return(assetBundleCreateRequest);

        download.assetBundle = assetBundleCreateRequest.assetBundle;
        if (this.CheckForCancellation(download))
        {
            yield break;
        }
        if (download.assetBundle == null)
        {
            if (!download.forceRefreshCache && !download.assetUrl.StartsWith("file"))
            {
                Debug.LogError(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] cached asset bundle was corrupt, redownloading.. - ",
                    download.assetUrl
                }));
                download.forceRefreshCache = true;
                download.currentState      = AssetBundleDownload.State.WaitingForRequestToBeSent;
                this.mAssetBundleDownloads.Remove(download.assetUrl);
                base.StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(download));
            }
            else
            {
                download.OnDownloadError("AssetBundle.LoadFromMemoryAsync failed!", LoadErrorReason.AssetBundleCorrupt);
            }
        }
        yield break;
    }
    // Token: 0x06005134 RID: 20788 RVA: 0x001BB5E4 File Offset: 0x001B99E4
    private IEnumerator CreateAsyncCoroutineWithDiskSaving(AssetBundleDownload download)
    {
        if (!download.isSavedOnDisk)
        {
            yield return(base.StartCoroutine(this.AttemptLzmaDecompressionCoroutine(download)));

            yield return(base.StartCoroutine(this.AttemptGZipDecompressionCoroutine(download)));

            if (!download.isLzma && !download.isGZip)
            {
                VRC.Core.Logger.Log("[" + download.downloadId + "] Unity Compressed AssetBundle Detected!", DebugLevel.AssetBundleDownloadManager);
            }
            bool doneSavingFile = false;
            Loom.StartSingleThread(delegate
            {
                this.SaveToDisk(download);
                if (download.isLzma || download.isGZip)
                {
                    Loom.DispatchToMainThread(delegate
                    {
                        download.assetBundle = this.LoadFromDisk(download);
                        doneSavingFile       = true;
                    }, false, true);
                }
                else
                {
                    doneSavingFile = true;
                }
            }, System.Threading.ThreadPriority.Normal, true);
            while (!doneSavingFile)
            {
                yield return(null);
            }
            if (!download.isLzma && !download.isGZip)
            {
                AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(download.assetBundleBytes);
                yield return(assetBundleCreateRequest);

                download.assetBundle = assetBundleCreateRequest.assetBundle;
            }
        }
        else
        {
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Attempting to create uncompressed ab from disk - ",
                download.assetUrl
            }), DebugLevel.AssetBundleDownloadManager);
            download.assetBundle = this.LoadFromDisk(download);
            if (download.assetBundle == null)
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Creating unity compressed AB from disk - ",
                    download.assetUrl
                }), DebugLevel.AssetBundleDownloadManager);
                Loom.StartSingleThread(delegate
                {
                    download.assetBundleBytes = File.ReadAllBytes(download.assetBundleFilePath);
                }, System.Threading.ThreadPriority.Normal, true);
                while (download.assetBundleBytes == null)
                {
                    yield return(null);
                }
                AssetBundleCreateRequest assetBundleCreateRequest2 = AssetBundle.LoadFromMemoryAsync(download.assetBundleBytes);
                yield return(assetBundleCreateRequest2);

                download.assetBundle = assetBundleCreateRequest2.assetBundle;
            }
        }
        yield break;
    }
    // Token: 0x06005127 RID: 20775 RVA: 0x001BB130 File Offset: 0x001B9530
    private void OnHttpAssetBundleRequestCompleted(HTTPRequest request, HTTPResponse response)
    {
        string originalString = request.Uri.OriginalString;

        if (!this.mAssetBundleDownloads.ContainsKey(originalString))
        {
            return;
        }
        AssetBundleDownload assetBundleDownload = this.mAssetBundleDownloads[originalString];

        if (this.CheckForCancellation(assetBundleDownload))
        {
            return;
        }
        assetBundleDownload.currentState = AssetBundleDownload.State.Error;
        switch (request.State)
        {
        case HTTPRequestStates.Queued:
            VRC.Core.Logger.Log("[" + assetBundleDownload.downloadId + "] Queued request.", DebugLevel.AssetBundleDownloadManager);
            request.Callback = new OnRequestFinishedDelegate(this.OnHttpAssetBundleRequestCompleted);
            return;

        case HTTPRequestStates.Finished:
            if (request.Response.IsSuccess)
            {
                if (Player.Instance != null && Player.Instance.isInternal)
                {
                    Debug.Log(string.Format(string.Concat(new object[]
                    {
                        "[",
                        assetBundleDownload.downloadId,
                        "] AssetBundle [",
                        assetBundleDownload.assetUrl,
                        "] downloaded! Loaded from local cache: {0}, with size: {1}"
                    }), request.Response.IsFromCache.ToString(), response.Data.Length));
                }
                assetBundleDownload.assetBundleBytes = response.Data;
                AssetBundleDownloadManager.Instance.QueueAssetBundleDownload(assetBundleDownload);
                assetBundleDownload.currentState = AssetBundleDownload.State.HttpResponseReceived;
            }
            else
            {
                string message = string.Format(string.Concat(new object[]
                {
                    "[",
                    assetBundleDownload.downloadId,
                    "] Request [",
                    originalString,
                    "] finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}"
                }), request.Response.StatusCode, request.Response.Message, request.Response.DataAsText);
                VRC.Core.Logger.LogError(message, DebugLevel.AssetBundleDownloadManager);
                assetBundleDownload.OnDownloadError(message, LoadErrorReason.ServerReturnedError);
            }
            return;

        case HTTPRequestStates.Error:
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                assetBundleDownload.downloadId,
                "] Request completed with state: ",
                request.State,
                " and message: ",
                request.Exception.Message
            }), DebugLevel.AssetBundleDownloadManager);
            this.RetryRequestRemoteAssetBundle(assetBundleDownload);
            return;

        case HTTPRequestStates.Aborted:
            assetBundleDownload.OnDownloadError("[" + assetBundleDownload.downloadId + "] Download aborted. Server closed the connection.", LoadErrorReason.ConnectionError);
            return;
        }
        assetBundleDownload.OnDownloadError(string.Concat(new object[]
        {
            "[",
            assetBundleDownload.assetUrl,
            "] Error Downloading AssetBundle: ",
            request.State
        }), LoadErrorReason.ConnectionError);
    }
 // Token: 0x06005137 RID: 20791 RVA: 0x001BB647 File Offset: 0x001B9A47
 private Coroutine WaitForAssetToLoad(AssetBundleDownload download)
 {
     return(base.StartCoroutine(this.WaitForAssetToLoadCoroutine(download)));
 }
示例#27
0
 // Use this for initialization
 void Start()
 {
     AssetBundleDownload download = new AssetBundleDownload("test1", "http://192.168.50.26");
     download.OnFinishDownload += DownldFinish;
     download.OnError += Error;
     download.StartDownload(this);
     // AssetBundleDownload download1 = new AssetBundleDownload("test2", "http://192.168.50.26");
     // download1.StartDownload(this);
     info = "ddd";
     //  List<FileData> list = XmlUtils.Load<List<FileData>>("test1");
 }
    // Token: 0x06005136 RID: 20790 RVA: 0x001BB62C File Offset: 0x001B9A2C
    private IEnumerator LoadAsyncCoroutine(AssetBundleDownload download)
    {
        if (download.currentState == AssetBundleDownload.State.Error)
        {
            yield break;
        }
        download.currentState = AssetBundleDownload.State.LoadingAssetFromAssetBundle;
        if (download.assetBundle != null)
        {
            string             mainAssetName = AssetBundleDownloadManager.GetMainAssetName(download.assetBundle);
            AssetBundleRequest asyncRequest  = null;
            UnityEngine.Object asset         = null;
            if (string.IsNullOrEmpty(mainAssetName))
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Loading asset ",
                    download.assetUrl,
                    " synchronously."
                }), DebugLevel.AssetBundleDownloadManager);
                asset = download.assetBundle.mainAsset;
            }
            else
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Loading asset ",
                    download.assetUrl,
                    " aynchronously."
                }), DebugLevel.AssetBundleDownloadManager);
                asyncRequest = download.assetBundle.LoadAssetWithSubAssetsAsync(mainAssetName);
                yield return(asyncRequest);

                asset = asyncRequest.asset;
            }
            if (asset != null)
            {
                AssetBundleDownloadManager.Instance.mLoadedAssets[download.assetUrl] = asset;
                download.asset        = asset;
                download.currentState = AssetBundleDownload.State.Done;
            }
            else
            {
                VRC.Core.Logger.Log("[" + download.downloadId + "] Error unpacking asset from asset bundle.", DebugLevel.AssetBundleDownloadManager);
                download.OnDownloadError("Error unpacking asset from asset bundle.", LoadErrorReason.AssetBundleInvalidOrNull);
            }
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] UNLOADING ASSET BUNDLE ",
                download.assetUrl
            }), DebugLevel.AssetBundleDownloadManager);
            download.assetBundle.Unload(false);
        }
        else
        {
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Asset bundle for url ",
                download.assetUrl,
                " is invalid (and null)"
            }), DebugLevel.AssetBundleDownloadManager);
            download.OnDownloadError("LoadAsyncCoroutine: Asset bundle is null.", LoadErrorReason.AssetBundleInvalidOrNull);
        }
        yield break;
    }
    // Token: 0x0600512E RID: 20782 RVA: 0x001BB51C File Offset: 0x001B991C
    private IEnumerator DownloadAndLoadRemotePluginCoroutine(AssetBundleDownload download)
    {
        if (Player.Instance != null && Player.Instance.isInternal)
        {
            Debug.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Requires plugin. About to download ",
                download.pluginUrl
            }));
        }
        if (!PluginManager.IsAllowedUrl(download.pluginUrl))
        {
            yield break;
        }
        HTTPRequest pluginReq = null;

        try
        {
            pluginReq = new HTTPRequest(new Uri(download.pluginUrl), null);
        }
        catch (Exception ex)
        {
            download.OnDownloadError("Bad plugin url: " + ex.Message, LoadErrorReason.InvalidURL);
            yield break;
        }
        if (download.forceRefreshCache)
        {
            HTTPCacheService.DeleteEntity(pluginReq.CurrentUri, true);
        }
        pluginReq.OnProgress = new OnDownloadProgressDelegate(download.OnDownloadProgress);
        pluginReq.Send();
        yield return(base.StartCoroutine(pluginReq));

        VRC.Network.ValidateCompletedHTTPRequest(pluginReq, delegate(HTTPResponse response)
        {
            if (!this.CheckForCancellation(download))
            {
                VRC.Core.Logger.Log("[" + download.downloadId + "] Downloaded and loading plugin...", DebugLevel.AssetBundleDownloadManager);
                try
                {
                    PluginManager.Instance.Load(download.pluginUrl, pluginReq.Response.Data);
                }
                catch (Exception ex2)
                {
                    download.OnPluginLoadError(ex2.Message);
                }
            }
        }, delegate(string errorStr)
        {
            string text = "Failed to download plugin from " + download.pluginUrl + " - " + errorStr;
            VRC.Core.Logger.LogError(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] ",
                text
            }), DebugLevel.AssetBundleDownloadManager);
            download.OnDownloadError(text, LoadErrorReason.ConnectionError);
        });
        yield break;
    }
    // Token: 0x06005129 RID: 20777 RVA: 0x001BB3F0 File Offset: 0x001B97F0
    private IEnumerator DownloadAndUnpackAssetBundleCoroutine(string url, string assetId, int assetVersion, string pluginUrl, OnDownloadProgressDelegate onProgress, AssetBundleDownloadManager.OnDownloadCompleted onSuccess, AssetBundleDownloadManager.OnDownloadError onError, AssetBundleDownloadManager.UnpackType unpackType, int retryCount = 0, int downloadId = 0, bool forceRefreshCache = false)
    {
        AssetBundleDownload download = new AssetBundleDownload(url, unpackType);

        download.onDownloadCompleted = onSuccess;
        download.onDownloadError     = onError;
        download.onProgress          = onProgress;
        download.retryCount          = retryCount;
        download.forceRefreshCache   = forceRefreshCache;
        download.assetId             = assetId;
        download.assetVersion        = assetVersion;
        download.pluginUrl           = pluginUrl;
        download.onPluginLoadError   = delegate(string message)
        {
            Debug.LogError("Plugin failed to load: " + message);
            if (!download.forceRefreshCache)
            {
                download.forceRefreshCache = true;
                this.StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(download));
            }
            else
            {
                download.OnDownloadError("Plugin failed to load: " + message, LoadErrorReason.PluginLoadFailed);
            }
        };
        if (Player.Instance != null && Player.Instance.isInternal)
        {
            Debug.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Downloading asset: '",
                download.assetUrl,
                "'"
            }));
        }
        if (string.IsNullOrEmpty(download.assetUrl))
        {
            download.OnDownloadError("URL is empty", LoadErrorReason.InvalidURL);
            yield break;
        }
        if (downloadId > 0)
        {
            download.downloadId = downloadId;
        }
        bool hasExistingDownload = this.mAssetBundleDownloads.ContainsKey(download.assetUrl);

        if (!hasExistingDownload)
        {
            this.mAssetBundleDownloads[download.assetUrl] = download;
        }
        if (download.assetUrl.StartsWith("file"))
        {
            if (!string.IsNullOrEmpty(download.pluginUrl))
            {
                yield return(this.DownloadAndLoadLocalPlugin(download));
            }
            if (download.currentState == AssetBundleDownload.State.Error)
            {
                yield break;
            }
            if (this.CheckForCancellation(download))
            {
                yield break;
            }
            if (!string.IsNullOrEmpty(download.assetUrl))
            {
                yield return(this.RequestLocalAssetBundle(download, hasExistingDownload));
            }
            yield return(this.WaitForAssetToLoad(download));
        }
        else
        {
            UnityEngine.Object asset = AssetBundleDownloadManager.Instance.GetLoadedAsset(download.assetUrl);
            if (asset == null)
            {
                download.currentState = AssetBundleDownload.State.WaitingForRequestToBeSent;
                if (!string.IsNullOrEmpty(download.pluginUrl) && PluginManager.IsAllowedUrl(download.pluginUrl))
                {
                    yield return(this.DownloadAndLoadRemotePlugin(download));
                }
                else
                {
                    download.pluginUrl = null;
                }
                if (download.currentState == AssetBundleDownload.State.Error)
                {
                    yield break;
                }
                if (this.CheckForCancellation(download))
                {
                    yield break;
                }
                if (!string.IsNullOrEmpty(download.assetUrl))
                {
                    yield return(this.RequestRemoteAssetBundle(download, hasExistingDownload));
                }
                yield return(this.WaitForAssetToLoad(download));
            }
            else
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Asset: ",
                    download.assetUrl,
                    " already loaded."
                }), DebugLevel.AssetBundleDownloadManager);
                download.asset = asset;
                download.OnDownloadCompleted();
            }
        }
        yield break;
    }
 // Token: 0x06005122 RID: 20770 RVA: 0x001BAF63 File Offset: 0x001B9363
 private Coroutine DownloadAndLoadRemotePlugin(AssetBundleDownload download)
 {
     return(base.StartCoroutine(this.DownloadAndLoadRemotePluginCoroutine(download)));
 }