Esempio n. 1
0
        /// <summary>
        /// Assess and remove any duplicates found in <paramref name="assets"/>.
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="useVersioning"></param>
        /// <returns></returns>
        protected virtual IEnumerable <Asset> EliminateDuplicates(IEnumerable <Asset> assets, bool useVersioning)
        {
            var finalAssetList  = new List <Asset>();
            var pathMap         = new HashSet <string>();
            var bundledContents = new HashSet <string>();

            foreach (Asset asset in assets)
            {
                if (asset.IsStatic)
                {
                    finalAssetList.Add(asset);
                    continue;
                }

                if (!pathMap.Contains(asset.Value))
                {
                    // open bundles file list to look at its contents
                    if (asset.IsBundle && asset.Bundle != null)
                    {
                        // add the bundled contents to list to check so those scripts are not duplicated in the resulting list
                        foreach (string filePath in asset.Bundle.Files)
                        {
                            bundledContents.Add(PathFormatter.GetFullPath(filePath, useVersioning));
                        }
                    }

                    finalAssetList.Add(asset);
                    pathMap.Add(asset.Value);
                }
            }

            return(finalAssetList.Where(asset => asset.IsStatic || !bundledContents.Contains(asset.Value)));
        }
Esempio n. 2
0
 /// <summary>
 /// Recursively build list of assets based on list of string / path reference alues.
 /// </summary>
 /// <param name="assets">List of assets being built recursively.</param>
 /// <param name="references">List of paths or bundles to be resolved.</param>
 /// <param name="useBundledOutput">Use bundled output over list of files in bundle.</param>
 /// <param name="useVersioning">Apply versioning to asset output.</param>
 protected virtual void BuildAssets(List <Asset> assets, IEnumerable <string> references, bool useBundledOutput, bool useVersioning)
 {
     foreach (string contentReference in references)
     {
         if (BundleLookup.TryGetBundle(contentReference, out Bundle? bundle) && bundle != null)
         {
             if (useBundledOutput)
             {
                 assets.Add(new Asset(PathFormatter.GetFullPath(bundle.OutputPath, useVersioning), bundle: bundle));
             }
             else
             {
                 BuildAssets(assets, bundle.Files, useBundledOutput, useVersioning);
             }
         }
         else
         {
             assets.Add(new Asset(PathFormatter.GetFullPath(contentReference, useVersioning)));
         }
     }
 }