Exemplo n.º 1
0
        public void WhenCalculatingBundleHash_HashingBeginsAtFirstObject()
        {
            ArchiveAndCompressBundles.TaskInput input = GetDefaultInput();
            WriteResult result = AddSimpleBundle(input, "mybundle", "internalName");

            // Add a serialized. Say that the first object begins 100 bytes into the file
            var osi = new ObjectSerializedInfo();
            SerializedLocation header = new SerializedLocation();

            header.SetFileName(result.resourceFiles[0].fileAlias);
            header.SetOffset(100);
            osi.SetHeader(header);
            result.SetSerializedObjects(new ObjectSerializedInfo[] { osi });
            ResourceFile rf = result.resourceFiles[0];

            rf.SetSerializedFile(true);
            result.SetResourceFiles(new ResourceFile[] { rf });
            input.InternalFilenameToWriteResults["internalName"] = result;
            string srcFile = input.InternalFilenameToWriteResults["internalName"].resourceFiles[0].fileName;

            ArchiveAndCompressBundles.Run(input, out ArchiveAndCompressBundles.TaskOutput output);
            // Change the first 100 bytes. This is before the serialized object.
            WriteRandomData(srcFile, 100, 1);
            ArchiveAndCompressBundles.Run(input, out ArchiveAndCompressBundles.TaskOutput output2);

            // Change the first 104 bytes. This should affect the hash
            WriteRandomData(srcFile, 104, 2);
            ArchiveAndCompressBundles.Run(input, out ArchiveAndCompressBundles.TaskOutput output3);

            Assert.AreEqual(output.BundleDetails["mybundle"].Hash, output2.BundleDetails["mybundle"].Hash);
            Assert.AreNotEqual(output.BundleDetails["mybundle"].Hash, output3.BundleDetails["mybundle"].Hash);
        }
    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);
        return(writeResult);
    }
    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);
    }