コード例 #1
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);
        }
コード例 #2
0
        public void HashingMethods_ProducesValidHashFor_UnicodeStrings(IHasher hashFunc)
        {
            // It might not look it at first glance, but the below 2 strings are indeed different!
            // The ASCII byte representation of both of these strings is identical, which was causing
            // hashing methods to return identical hashes as we had used ASCII for everything.
            string  str1  = "[기본]양손무기";
            string  str2  = "[기본]한손무기";
            RawHash hash1 = hashFunc.Calculate(str1);
            RawHash hash2 = hashFunc.Calculate(str2);

            Assert.AreNotEqual(str1, str2);
            Assert.AreNotEqual(hash1, hash2);
            Assert.AreEqual(TestResults[hashFunc.HashType()][(int)TestIndex.Unicode], hash1.ToString());
        }
コード例 #3
0
        public void CalculateStreamCanUseOffsets()
        {
            byte[] bytes = { 0xe1, 0x43, 0x2f, 0x83, 0xdf, 0xeb, 0xa8, 0x86, 0xfb, 0xfe, 0xc9, 0x97, 0x20, 0xfb, 0x53, 0x45,
                             0x24, 0x5d, 0x92, 0x8b, 0xa2, 0xc4, 0xe1, 0xe2, 0x48, 0x4a, 0xbb, 0x66, 0x43, 0x9a, 0xbc, 0x84 };

            using (var stream = new MemoryStream(bytes))
            {
                stream.Position = 16;
                RawHash hash1 = HashingMethods.CalculateStream(stream);

                stream.Position = 0;
                RawHash hash2 = HashingMethods.CalculateStream(stream);

                Assert.AreNotEqual(hash1.ToString(), hash2.ToString());
            }
        }
コード例 #4
0
        public void HashingMethods_ProducesValidHashFor_OffsetStreams(IHasher hashFunc)
        {
            byte[] bytes = { 0xe1, 0x43, 0x2f, 0x83, 0xdf, 0xeb, 0xa8, 0x86, 0xfb, 0xfe, 0xc9, 0x97, 0x20, 0xfb, 0x53, 0x45,
                             0x24, 0x5d, 0x92, 0x8b, 0xa2, 0xc4, 0xe1, 0xe2, 0x48, 0x4a, 0xbb, 0x66, 0x43, 0x9a, 0xbc, 0x84 };

            using (var stream = new MemoryStream(bytes))
            {
                stream.Position = 16;
                RawHash hash1 = hashFunc.CalculateStream(stream);

                stream.Position = 0;
                RawHash hash2 = hashFunc.CalculateStream(stream);

                Assert.AreNotEqual(hash1.ToString(), hash2.ToString());
                Assert.AreEqual(TestResults[hashFunc.HashType()][(int)TestIndex.Offset], hash1.ToString());
            }
        }
コード例 #5
0
        static List <ArchiveWorkItem> CreateWorkItems(TaskInput input)
        {
            using (input.Log.ScopedStep(LogLevel.Info, "CreateWorkItems"))
            {
                Dictionary <string, ArchiveWorkItem> bundleNameToWorkItem = new Dictionary <string, ArchiveWorkItem>();

                foreach (var pair in input.InternalFilenameToWriteResults)
                {
                    string          internalName = pair.Key;
                    string          bundleName   = input.InternalFilenameToBundleName[internalName];
                    ArchiveWorkItem item         = GetOrCreateWorkItem(input, bundleName, bundleNameToWorkItem);

                    if (input.InternalFilenameToWriteMetaData.TryGetValue(pair.Key, out SerializedFileMetaData md))
                    {
                        item.SeriliazedFileMetaDatas.Add(md);
                    }
                    else
                    {
                        throw new Exception($"Archive {bundleName} with internal name {internalName} does not have associated SerializedFileMetaData");
                    }

                    item.ResourceFiles.AddRange(pair.Value.resourceFiles);

#if UNITY_2019_3_OR_NEWER
                    if (input.BundleNameToAdditionalFiles.TryGetValue(bundleName, out List <ResourceFile> additionalFiles))
                    {
                        RawHash hash = HashResourceFiles(additionalFiles);
                        item.SeriliazedFileMetaDatas.Add(new SerializedFileMetaData()
                        {
                            ContentHash = hash.ToHash128(), RawFileHash = hash.ToHash128()
                        });
                        item.ResourceFiles.AddRange(additionalFiles);
                    }
#endif
                }

                List <ArchiveWorkItem> allItems = bundleNameToWorkItem.Select((x, index) => { x.Value.Index = index; return(x.Value); }).ToList();
                return(allItems);
            }
        }
コード例 #6
0
    public void AddHashToBundleNameTask_DoesNotChangeHash_WhenAssetsChangeOrder()
    {
        //Setup
        string path1 = $"{TempPath}/test1.prefab";
        string path2 = $"{TempPath}/test2.prefab";
        string path3 = $"{TempPath}/test3.prefab";

        GUID guid1 = new GUID(CreateAsset(path1, "1"));
        GUID guid2 = new GUID(CreateAsset(path2, "2"));
        GUID guid3 = new GUID(CreateAsset(path3, "3"));

        List <GUID> list1 = new List <GUID>()
        {
            guid1,
            guid2,
            guid3
        };

        List <GUID> list2 = new List <GUID>()
        {
            guid2,
            guid1,
            guid3
        };

        AddressableAssetGroup group = m_Settings.CreateGroup("AddHashTestGroup", false, false, false,
                                                             new List <AddressableAssetGroupSchema>());

        m_Settings.CreateOrMoveEntry(guid1.ToString(), group);
        m_Settings.CreateOrMoveEntry(guid2.ToString(), group);
        m_Settings.CreateOrMoveEntry(guid3.ToString(), group);

        IDependencyData dependencyData = new BuildDependencyData()
        {
            AssetInfo =
            {
                { guid1, new AssetLoadInfo()
                    {
                        referencedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(guid1, EditorUserBuildSettings.activeBuildTarget).ToList()
                    } },
                { guid2, new AssetLoadInfo()
                    {
                        referencedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(guid2, EditorUserBuildSettings.activeBuildTarget).ToList()
                    } },
                { guid3, new AssetLoadInfo()
                    {
                        referencedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(guid3, EditorUserBuildSettings.activeBuildTarget).ToList()
                    } }
            }
        };

        AddressableAssetsBuildContext context = new AddressableAssetsBuildContext()
        {
            Settings = m_Settings
        };

        AddHashToBundleNameTask addHashTask = new AddHashToBundleNameTask();
        var field = typeof(AddHashToBundleNameTask).GetField("m_DependencyData", BindingFlags.Instance | BindingFlags.NonPublic);

        field.SetValue(addHashTask, dependencyData);

        //Test
        RawHash hash1 = addHashTask.GetAssetsHash(list1, context);
        RawHash hash2 = addHashTask.GetAssetsHash(list2, context);

        //Assert
        Assert.AreEqual(hash1, hash2);

        //Cleanup
        m_Settings.RemoveGroup(group);
    }