< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AssetBundleDepMapLoadHelper()0%110100%
GetDependenciesAsync()0%660100%
WaitUntilExternalDepMapIsResolved(...)0%2100%
LoadExternalDepMap()0%10.378066.67%
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 Cysharp.Threading.Tasks;
 2using DCL;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Threading;
 7using UnityEngine;
 8
 9public static class AssetBundleDepMapLoadHelper
 10{
 111    static bool VERBOSE = false;
 12    private const string MAIN_SHADER_FILENAME = "mainshader";
 13
 114    public static Dictionary<string, List<string>> dependenciesMap = new ();
 15
 116    static HashSet<string> failedRequests = new ();
 117    static HashSet<string> downloadingDepmap = new ();
 18
 19    public static async UniTask<IReadOnlyList<string>> GetDependenciesAsync(this AssetBundle assetBundle, string baseUrl
 20    {
 21        // Check internal metadata file (dependencies, version, timestamp) and if it doesn't exist, fetch the external d
 2222        TextAsset metadata = Asset_AB.GetMetadata(assetBundle);
 23
 2224        if (metadata != null)
 525            LoadDepMapFromJSON(metadata.text, hash);
 26        else
 27        {
 1728            if (!dependenciesMap.ContainsKey(hash))
 1029                await LoadExternalDepMap(baseUrl, hash, cancellationToken);
 30        }
 31
 2232        if (!dependenciesMap.TryGetValue(hash, out List<string> dependencies))
 233            dependencies = new List<string>();
 34
 2235        return dependencies;
 2236    }
 37
 38    public static UniTask WaitUntilExternalDepMapIsResolved(string hash)
 39    {
 040        return UniTask.WaitUntil(() => !downloadingDepmap.Contains(hash) && (dependenciesMap.ContainsKey(hash) || failed
 41    }
 42
 43    public static async UniTask LoadExternalDepMap(string baseUrl, string hash, CancellationToken cancellationToken)
 44    {
 445        if (dependenciesMap.ContainsKey(hash))
 046            return;
 47
 448        if (failedRequests.Contains(hash))
 149            return;
 50
 351        if (downloadingDepmap.Contains(hash))
 52        {
 053            await WaitUntilExternalDepMapIsResolved(hash);
 054            return;
 55        }
 56
 357        string url = baseUrl + hash + ".depmap";
 58
 359        downloadingDepmap.Add(hash);
 60
 961        await DCL.Environment.i.platform.webRequest.Get(
 62            url: url,
 63            OnSuccess: (depmapRequest) =>
 64            {
 265                LoadDepMapFromJSON(depmapRequest.webRequest.downloadHandler.text, hash);
 66
 267                downloadingDepmap.Remove(hash);
 268            },
 69            OnFail: _ =>
 70            {
 171                failedRequests.Add(hash);
 172                downloadingDepmap.Remove(hash);
 173            }).WithCancellation(cancellationToken);
 474    }
 75
 76    public static void LoadDepMapFromJSON(string metadataJSON, string hash)
 77    {
 778        AssetBundleMetadata metadata = JsonUtility.FromJson<AssetBundleMetadata>(metadataJSON);
 79
 780        if (VERBOSE)
 81        {
 082            Debug.Log($"DependencyMapLoadHelper: {hash} asset bundle version: " + metadata.version);
 083            Debug.Log($"DependencyMapLoadHelper: {hash} asset bundle timestamp: " + (metadata.timestamp > 0 ? new DateTi
 84        }
 85
 886        metadata.dependencies = metadata.dependencies.Where(x => !x.Contains(MAIN_SHADER_FILENAME)).ToArray();
 87
 788        dependenciesMap[hash] = new List<string>(metadata.dependencies);
 789    }
 90}