Пример #1
0
    public static 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);
    }
Пример #2
0
        private SerializedFileMetaData CalculateFileMetadata(ref WriteResult result)
        {
            List <object> contentHashObjects = new List <object>();
            List <object> fullHashObjects    = new List <object>();

            foreach (ResourceFile file in result.resourceFiles)
            {
                RawHash fileHash    = HashingMethods.CalculateFile(file.fileName);
                RawHash contentHash = fileHash;
                fullHashObjects.Add(fileHash);
                if (file.serializedFile && result.serializedObjects.Count > 0)
                {
                    using (var stream = new FileStream(file.fileName, FileMode.Open, FileAccess.Read))
                    {
                        stream.Position = (long)result.serializedObjects[0].header.offset;
                        contentHash     = HashingMethods.CalculateStream(stream);
                    }
                }
                contentHashObjects.Add(contentHash);
            }
            SerializedFileMetaData data = new SerializedFileMetaData();

            data.RawFileHash = HashingMethods.Calculate(fullHashObjects).ToHash128();
            data.ContentHash = HashingMethods.Calculate(contentHashObjects).ToHash128();
            return(data);
        }
        /// <inheritdoc />
        public Hash128 GetHash128()
        {
#if UNITY_2019_3_OR_NEWER
            return(HashingMethods.Calculate(Command, UsageSet.GetHash128(), ReferenceMap.GetHash128(), Scene, PreloadInfo).ToHash128());
#else
            var processedSceneHash = HashingMethods.CalculateFile(ProcessedScene).ToHash128();
            return(HashingMethods.Calculate(Command, UsageSet.GetHash128(), ReferenceMap.GetHash128(), Scene, processedSceneHash, PreloadInfo).ToHash128());
#endif
        }
Пример #4
0
        CacheEntry GetCacheEntry(string path, BuildUsageTagGlobal additionalGlobalUsage)
        {
            var entry = new CacheEntry();

            entry.Type    = CacheEntry.EntryType.Data;
            entry.Guid    = HashingMethods.Calculate("CalculateCustomDependencyData", path).ToGUID();
            entry.Hash    = HashingMethods.Calculate(HashingMethods.CalculateFile(path), additionalGlobalUsage).ToHash128();
            entry.Version = Version;
            return(entry);
        }
Пример #5
0
        /// <inheritdoc />
        public Hash128 GetHash128()
        {
#if UNITY_2019_3_OR_NEWER
            var prefabHashes = AssetDatabase.GetDependencies(Scene).Where(path => path.EndsWith(".prefab")).Select(AssetDatabase.GetAssetDependencyHash);
            return(HashingMethods.Calculate(Command, UsageSet.GetHash128(), ReferenceMap.GetHash128(), Scene, PreloadInfo, Info, prefabHashes).ToHash128());
#else
            var processedSceneHash = HashingMethods.CalculateFile(ProcessedScene).ToHash128();
            var prefabHashes       = AssetDatabase.GetDependencies(Scene).Where(path => path.EndsWith(".prefab")).Select(AssetDatabase.GetAssetDependencyHash);
            return(HashingMethods.Calculate(Command, UsageSet.GetHash128(), ReferenceMap.GetHash128(), Scene, processedSceneHash, PreloadInfo, Info, prefabHashes).ToHash128());
#endif
        }
    internal WriteResult AddSimpleBundle(ArchiveAndCompressBundles.TaskInput input, string bundleName, string internalName, string filePath)
    {
        WriteResult  writeResult = new WriteResult();
        ResourceFile file        = new ResourceFile();

        file.SetFileName(filePath);
        file.SetFileAlias(internalName);
        file.SetSerializedFile(false);
        writeResult.SetResourceFiles(new ResourceFile[] { file });
        input.InternalFilenameToWriteResults.Add(internalName, writeResult);
        input.InternalFilenameToBundleName.Add(internalName, bundleName);
        SerializedFileMetaData md = new SerializedFileMetaData();

        md.RawFileHash = HashingMethods.CalculateFile(filePath).ToHash128();
        md.ContentHash = HashingMethods.CalculateFile(filePath).ToHash128();
        input.InternalFilenameToWriteMetaData.Add(internalName, md);
        return(writeResult);
    }
    public static 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 && File.Exists(path))
            {
                entry.Hash = HashingMethods.CalculateFile(path).ToHash128();
            }
            if (path.EndsWith(".unity", StringComparison.OrdinalIgnoreCase))
            {
                entry.Hash = HashingMethods.Calculate(entry.Hash, BuildInterfacesWrapper.SceneCallbackVersionHash).ToHash128();
            }
        }

        if (entry.Hash.isValid)
        {
            entry.Hash = HashingMethods.Calculate(entry.Hash, entry.Version).ToHash128();
        }

        m_GuidToHash[key] = entry;
        return(entry);
    }
        static Hash128 CalculateHashVersion(Dictionary <string, ulong> fileOffsets, ResourceFile[] resourceFiles)
        {
            List <RawHash> hashes = new List <RawHash>();

            foreach (ResourceFile file in resourceFiles)
            {
                if (file.serializedFile)
                {
                    // For serialized files, we ignore the header for the hash value.
                    // This leaves us with a hash value of just the written object data.
                    using (var stream = new FileStream(file.fileName, FileMode.Open, FileAccess.Read))
                    {
                        stream.Position = (long)fileOffsets[file.fileName];
                        hashes.Add(HashingMethods.CalculateStream(stream));
                    }
                }
                else
                {
                    hashes.Add(HashingMethods.CalculateFile(file.fileName));
                }
            }
            return(HashingMethods.Calculate(hashes).ToHash128());
        }
 static RawHash HashResourceFiles(List <ResourceFile> files)
 {
     return(HashingMethods.Calculate(files.Select((x) => HashingMethods.CalculateFile(x.fileName))));
 }
Пример #10
0
        /// <inheritdoc />
        public Hash128 GetHash128()
        {
            Hash128 processedSceneHash = HashingMethods.CalculateFile(ProcessedScene).ToHash128();

            return(HashingMethods.Calculate(Command, UsageSet.GetHash128(), ReferenceMap.GetHash128(), Scene, processedSceneHash, PreloadInfo).ToHash128());
        }