< Summary

Class:AssetBundleDepMapLoadHelper
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AssetBundleDepMapLoadHelper.cs
Covered lines:28
Uncovered lines:6
Coverable lines:34
Total lines:77
Line coverage:82.3% (28 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AssetBundleDepMapLoadHelper()0%110100%
WaitUntilExternalDepMapIsResolved()0%550100%
LoadExternalDepMap()0%9.367063.64%
LoadDepMapFromJSON(...)0%4.374071.43%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AssetBundleDepMapLoadHelper.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6
 7public static class AssetBundleDepMapLoadHelper
 8{
 19    static bool VERBOSE = false;
 10    private const string MAIN_SHADER_FILENAME = "mainshader";
 11
 112    public static Dictionary<string, List<string>> dependenciesMap = new Dictionary<string, List<string>>();
 13
 114    static HashSet<string> failedRequests = new HashSet<string>();
 115    static HashSet<string> downloadingDepmap = new HashSet<string>();
 16
 17    public static IEnumerator WaitUntilExternalDepMapIsResolved(string hash)
 18    {
 319        while (true)
 20        {
 2321            bool depmapBeingDownloaded = downloadingDepmap.Contains(hash);
 2322            bool depmapRequestIsDone = dependenciesMap.ContainsKey(hash) || failedRequests.Contains(hash);
 23
 2324            if (!depmapBeingDownloaded && depmapRequestIsDone)
 25                break;
 26
 327            yield return null;
 28        }
 2029    }
 30
 31    public static IEnumerator LoadExternalDepMap(string baseUrl, string hash)
 32    {
 333        if (dependenciesMap.ContainsKey(hash))
 034            yield break;
 35
 336        if (failedRequests.Contains(hash))
 037            yield break;
 38
 339        if (downloadingDepmap.Contains(hash))
 40        {
 041            yield return WaitUntilExternalDepMapIsResolved(hash);
 042            yield break;
 43        }
 44
 345        string url = baseUrl + hash + ".depmap";
 46
 347        downloadingDepmap.Add(hash);
 348        yield return DCL.Environment.i.platform.webRequest.Get(
 49            url: url,
 50            OnSuccess: (depmapRequest) =>
 51            {
 252                LoadDepMapFromJSON(depmapRequest.webRequest.downloadHandler.text, hash);
 53
 254                downloadingDepmap.Remove(hash);
 255            },
 56            OnFail: (depmapRequest) =>
 57            {
 158                failedRequests.Add(hash);
 159                downloadingDepmap.Remove(hash);
 160            });
 361    }
 62
 63    public static void LoadDepMapFromJSON(string metadataJSON, string hash)
 64    {
 265        AssetBundleMetadata metadata = JsonUtility.FromJson<AssetBundleMetadata>(metadataJSON);
 66
 267        if (VERBOSE)
 68        {
 069            Debug.Log($"DependencyMapLoadHelper: {hash} asset bundle version: " + metadata.version);
 070            Debug.Log($"DependencyMapLoadHelper: {hash} asset bundle timestamp: " + (metadata.timestamp > 0 ? new DateTi
 71        }
 72
 373        metadata.dependencies = metadata.dependencies.Where(x => !x.Contains(MAIN_SHADER_FILENAME)).ToArray();
 74
 275        dependenciesMap.Add(hash, new List<string>(metadata.dependencies));
 276    }
 77}