/// <inheritdoc />
        public string GetCachedInfoFile(CacheEntry entry)
        {
            var    guid      = entry.Guid.ToString();
            string finalHash = HashingMethods.Calculate(m_GlobalHash, entry.Hash).ToString();

            return(string.Format("{0}/{1}/{2}/{2}_{3}.info", k_CachePath, guid.Substring(0, 2), guid, finalHash));
        }
        /// <inheritdoc />
        public CacheEntry GetCacheEntry(GUID asset, int version = 1)
        {
            CacheEntry entry;
            KeyValuePair <GUID, int> key = new KeyValuePair <GUID, int>(asset, version);

            if (m_GuidToHash.TryGetValue(key, out entry))
            {
                return(entry);
            }

            entry = new CacheEntry {
                Guid = asset, Version = version
            };
            string path = AssetDatabase.GUIDToAssetPath(asset.ToString());

            entry.Type = CacheEntry.EntryType.Asset;

            if (path.Equals(CommonStrings.UnityBuiltInExtraPath, StringComparison.OrdinalIgnoreCase) || path.Equals(CommonStrings.UnityDefaultResourcePath, StringComparison.OrdinalIgnoreCase))
            {
                entry.Hash = HashingMethods.Calculate(Application.unityVersion, path).ToHash128();
            }
            else
            {
                entry.Hash = AssetDatabase.GetAssetDependencyHash(path);
                if (!entry.Hash.isValid)
                {
                    entry.Hash = HashingMethods.CalculateFile(path).ToHash128();
                }
            }

            entry.Hash = HashingMethods.Calculate(entry.Hash, entry.Version).ToHash128();

            m_GuidToHash[key] = entry;
            return(entry);
        }
        /// <inheritdoc />
        public string GetCachedArtifactsDirectory(CacheEntry entry)
        {
            var    guid      = entry.Guid.ToString();
            string finalHash = HashingMethods.Calculate(m_GlobalHash, entry.Hash).ToString();

            return(string.Format("{0}/{1}/{2}", k_CachePath, guid.Substring(0, 2), finalHash));
        }
        /// <inheritdoc />
        public CacheEntry GetCacheEntry(string path, int version = 1)
        {
            CacheEntry entry;
            KeyValuePair <string, int> key = new KeyValuePair <string, int>(path, version);

            if (m_PathToHash.TryGetValue(key, out entry))
            {
                return(entry);
            }

            var guid = AssetDatabase.AssetPathToGUID(path);

            if (!string.IsNullOrEmpty(guid))
            {
                return(GetCacheEntry(new GUID(guid), version));
            }

            entry = new CacheEntry {
                File = path, Version = version
            };
            entry.Guid = HashingMethods.Calculate("FileHash", entry.File).ToGUID();
            if (File.Exists(entry.File))
            {
                entry.Hash = HashingMethods.Calculate(HashingMethods.CalculateFile(entry.File), entry.Version).ToHash128();
            }
            entry.Type = CacheEntry.EntryType.File;

            m_PathToHash[key] = entry;
            return(entry);
        }
Beispiel #5
0
        static Hash128 CalculateGlobalArtifactVersionHash()
        {
#if UNITY_2019_3_OR_NEWER
            return(HashingMethods.Calculate(Application.unityVersion, k_Version).ToHash128());
#else
            return(HashingMethods.Calculate(PlayerSettings.scriptingRuntimeVersion, Application.unityVersion, k_Version).ToHash128());
#endif
        }
 public static Hash128 GetHash128(this BuildSettings settings)
 {
     if (settings.typeDB == null)
     {
         return(HashingMethods.Calculate(settings.target, settings.group, settings.buildFlags).ToHash128());
     }
     return(HashingMethods.Calculate(settings.target, settings.group, settings.buildFlags, settings.typeDB.GetHash128()).ToHash128());
 }
Beispiel #7
0
        // We return from this function before all uploads are complete. So we must wait to dispose until all uploads are finished.
        public void QueueUpload(CacheEntry entry, string artifactsPath, MemoryStream stream)
        {
            var    item      = new WorkItem();
            string finalHash = HashingMethods.Calculate(entry.Hash, m_GlobalHash).ToString();

            item.fileId        = FileId.From(entry.Guid.ToString(), finalHash);
            item.artifactsPath = artifactsPath;
            item.stream        = stream;
            ThreadingManager.QueueTask(ThreadingManager.ThreadQueues.UploadQueue, UploadItem, item);
        }
        // We return from this function before all uploads are complete. So we must wait to dispose until all uploads are finished.
        public void QueueUpload(CacheEntry entry, string artifactsPath, MemoryStream stream)
        {
            var    item      = new WorkItem();
            string finalHash = HashingMethods.Calculate(entry.Hash, m_GlobalHash).ToString();

            item.fileId        = FileId.From(entry.Guid.ToString(), finalHash);
            item.artifactsPath = artifactsPath;
            item.stream        = stream;

            lock (m_WorkItems)
                m_WorkItems.Enqueue(item);
            m_Semaphore.Release();
        }
Beispiel #9
0
        /// <inheritdoc />
        public CacheEntry GetCacheEntry(string path)
        {
            CacheEntry entry;

            if (m_PathToHash.TryGetValue(path, out entry))
            {
                return(entry);
            }

            entry = new CacheEntry {
                File = path
            };
            entry.Guid = HashingMethods.Calculate("FileHash", entry.File).ToGUID();
            entry.Hash = HashingMethods.CalculateFile(entry.File).ToHash128();
            entry.Type = CacheEntry.EntryType.File;

            m_PathToHash[entry.File] = entry;
            return(entry);
        }
        /// <inheritdoc />
        public CacheEntry GetCacheEntry(string path, int version = 1)
        {
            CacheEntry entry;
            KeyValuePair <string, int> key = new KeyValuePair <string, int>(path, version);

            if (m_PathToHash.TryGetValue(key, out entry))
            {
                return(entry);
            }

            entry = new CacheEntry {
                File = path, Version = version
            };
            entry.Guid = HashingMethods.Calculate("FileHash", entry.File).ToGUID();
            entry.Hash = HashingMethods.Calculate(HashingMethods.CalculateFile(entry.File), entry.Version).ToHash128();
            entry.Type = CacheEntry.EntryType.File;

            m_PathToHash[key] = entry;
            return(entry);
        }
        internal void GatherCallbackVersions()
        {
            var            versionedType  = typeof(VersionedCallbackAttribute);
            var            typeCollection = TypeCache.GetTypesWithAttribute(versionedType);
            List <Hash128> sceneInputs    = new List <Hash128>();
            List <Hash128> shaderInputs   = new List <Hash128>();

            foreach (var type in typeCollection)
            {
                var attribute = (VersionedCallbackAttribute)Attribute.GetCustomAttribute(type, versionedType);
#if UNITY_2020_2_OR_NEWER
                if (typeof(IPreprocessShaders).IsAssignableFrom(type) || typeof(IPreprocessComputeShaders).IsAssignableFrom(type))
#else
                if (typeof(IPreprocessShaders).IsAssignableFrom(type))
#endif
                {
                    shaderInputs.Add(HashingMethods.Calculate(type.AssemblyQualifiedName, attribute.version).ToHash128());
                }
#pragma warning disable CS0618 // Type or member is obsolete
                else if (typeof(IProcessScene).IsAssignableFrom(type) || typeof(IProcessSceneWithReport).IsAssignableFrom(type))
#pragma warning restore CS0618 // Type or member is obsolete
                {
                    sceneInputs.Add(HashingMethods.Calculate(type.AssemblyQualifiedName, attribute.version).ToHash128());
                }
            }

            SceneCallbackVersionHash = new Hash128();
            if (sceneInputs.Count > 0)
            {
                sceneInputs.Sort();
                SceneCallbackVersionHash = HashingMethods.Calculate(sceneInputs).ToHash128();
            }

            ShaderCallbackVersionHash = new Hash128();
            if (shaderInputs.Count > 0)
            {
                shaderInputs.Sort();
                ShaderCallbackVersionHash = HashingMethods.Calculate(shaderInputs).ToHash128();
            }
        }
 static Hash128 CalculateGlobalArtifactVersionHash()
 {
     return(HashingMethods.Calculate(PlayerSettings.scriptingRuntimeVersion, Application.unityVersion).ToHash128());
 }
Beispiel #13
0
        // We don't return from this function until all downloads are processed. So it is safe to dispose immediately after.
        public void DownloadMissing(IList <CacheEntry> entries, IList <CachedInfo> cachedInfos)
        {
            Assert.AreEqual(entries.Count, cachedInfos.Count);
            Directory.CreateDirectory(k_CachePath);

            m_Semaphore = new Semaphore(0, entries.Count);
            m_Client.DownloadFinished += ThreadedDownloadFinished;

            // Queue up downloads for the missing or invalid local data
            for (var index = 0; index < entries.Count; index++)
            {
                // Only download data for cachedInfos that are invalid
                if (cachedInfos[index] != null)
                {
                    continue;
                }

                var entry = entries[index];

                string finalHash = HashingMethods.Calculate(entry.Hash, m_GlobalHash).ToHash128().ToString();
                var    fileId    = FileId.From(entry.Guid.ToString(), finalHash);

                // Download artifacts before info to ensure both are available when download for info returns
                var downloadArtifact = new FileDownloadItem(fileId, FileType.Resource, GetCachedArtifactsFile(entry));
                m_Client.QueueDownload(downloadArtifact);

                var downloadInfo = new FileDownloadItem(fileId, FileType.Info, GetCachedInfoFile(entry));
                m_Client.QueueDownload(downloadInfo);
            }

            // Check downloads to see if it is usable data
            var formatter = new BinaryFormatter();

            for (var index = 0; index < entries.Count; index++)
            {
                // find the next invalid cachedInfo
                while (index < entries.Count && cachedInfos[index] != null)
                {
                    index++;
                }
                // make sure we didn't go out of bounds looking for invalid entries
                if (index >= entries.Count)
                {
                    break;
                }

                // Wait for info download
                m_Semaphore.WaitOne();

                string tempInfoFile = GetCachedInfoFile(entries[index]);
                if (!File.Exists(tempInfoFile))
                {
                    continue;
                }

                try
                {
                    CachedInfo info;
                    using (var fileStream = new FileStream(tempInfoFile, FileMode.Open, FileAccess.Read))
                        info = formatter.Deserialize(fileStream) as CachedInfo;

                    if (m_Cache.HasAssetOrDependencyChanged(info))
                    {
                        continue;
                    }

                    // Not every info file will have artifacts. So just check to see if we downloaded something.
                    // TODO: May want to extend CachedInfo with Artifact knowledge if there is a performance benefit?
                    string tempArtifactFile = GetCachedArtifactsFile(entries[index]);
                    string tempArtifactDir  = Path.ChangeExtension(tempArtifactFile, "");
                    if (File.Exists(tempArtifactFile) && !FileCompressor.Decompress(tempArtifactFile, tempArtifactDir))
                    {
                        continue;
                    }

                    // All valid, move downloaded data into place
                    cachedInfos[index] = info;

                    string targetInfoFile = m_Cache.GetCachedInfoFile(info.Asset);
                    if (File.Exists(targetInfoFile))
                    {
                        File.Delete(targetInfoFile);
                    }
                    else
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(targetInfoFile));
                    }
                    File.Move(tempInfoFile, targetInfoFile);

                    if (Directory.Exists(tempArtifactDir))
                    {
                        string targetArtifactDir = m_Cache.GetCachedArtifactsDirectory(info.Asset);
                        if (Directory.Exists(targetArtifactDir))
                        {
                            Directory.Delete(targetArtifactDir, true);
                        }
                        Directory.Move(tempArtifactDir, targetArtifactDir);
                    }
                }
                catch (Exception e)
                {
                    BuildLogger.LogException(e);
                }
            }

            m_Client.ResetDownloadFinishedEventHandler();

            ((IDisposable)m_Semaphore).Dispose();
            m_Semaphore = null;

            Directory.Delete(k_CachePath, true);
        }
Beispiel #14
0
        string GetCachedArtifactsFile(CacheEntry entry)
        {
            string finalHash = HashingMethods.Calculate(entry.Hash, m_GlobalHash).ToString();

            return(string.Format("{0}/{1}_{2}.sbpGz", k_CachePath, entry.Guid.ToString(), finalHash));
        }