internal static Hash128 CalculateHashVersion(ArchiveWorkItem item, string[] dependencies) { List <Hash128> hashes = new List <Hash128>(); hashes.AddRange(item.SeriliazedFileMetaDatas.Select(x => x.ContentHash)); return(HashingMethods.Calculate(hashes, dependencies).ToHash128()); }
static ArchiveWorkItem GetOrCreateWorkItem(TaskInput input, string bundleName, Dictionary <string, ArchiveWorkItem> bundleToWorkItem) { if (!bundleToWorkItem.TryGetValue(bundleName, out ArchiveWorkItem item)) { item = new ArchiveWorkItem(); item.BundleName = bundleName; item.Compression = input.GetCompressionForIdentifier(bundleName); item.OutputFilePath = input.GetOutputFilePathForIdentifier(bundleName); item.ResourceFiles = new List <ResourceFile>(); bundleToWorkItem[bundleName] = item; } return(item); }
static private void ArchiveSingleItem(ArchiveWorkItem item, Dictionary <string, ulong> fileOffsets, string tempOutputFolder) { item.ResultDetails = new BundleDetails(); string writePath = string.Format("{0}/{1}", tempOutputFolder, item.BundleName); if (!string.IsNullOrEmpty(item.CachedArtifactPath)) { writePath = item.CachedArtifactPath; } Directory.CreateDirectory(Path.GetDirectoryName(writePath)); item.ResultDetails.FileName = item.OutputFilePath; item.ResultDetails.Crc = ContentBuildInterface.ArchiveAndCompress(item.ResourceFiles, writePath, item.Compression); item.ResultHash = CalculateHashVersion(fileOffsets, item.ResourceFiles, item.ResultDetails.Dependencies); CopyToOutputLocation(writePath, item.ResultDetails.FileName); }
static private void ArchiveSingleItem(ArchiveWorkItem item, Dictionary <string, ulong> fileOffsets, string tempOutputFolder, IBuildLogger log) { using (log.ScopedStep(LogLevel.Info, $"Archive {item.BundleName}")) { item.ResultDetails = new BundleDetails(); string writePath = string.Format("{0}/{1}", tempOutputFolder, item.BundleName); if (!string.IsNullOrEmpty(item.CachedArtifactPath)) { writePath = item.CachedArtifactPath; } Directory.CreateDirectory(Path.GetDirectoryName(writePath)); item.ResultDetails.FileName = item.OutputFilePath; item.ResultDetails.Crc = ContentBuildInterface.ArchiveAndCompress(item.ResourceFiles, writePath, item.Compression); item.ResultHash = CalculateHashVersion(fileOffsets, item.ResourceFiles, item.ResultDetails.Dependencies); CopyFileWithTimestampIfDifferent(writePath, item.ResultDetails.FileName, log); } }
static private void ArchiveSingleItem(ArchiveWorkItem item, string tempOutputFolder, IBuildLogger log) { using (log.ScopedStep(LogLevel.Info, "ArchiveSingleItem", item.BundleName)) { item.ResultDetails = new BundleDetails(); string writePath = string.Format("{0}/{1}", tempOutputFolder, item.BundleName); if (!string.IsNullOrEmpty(item.CachedArtifactPath)) { writePath = item.CachedArtifactPath; } Directory.CreateDirectory(Path.GetDirectoryName(writePath)); item.ResultDetails.FileName = item.OutputFilePath; item.ResultDetails.Crc = ContentBuildInterface.ArchiveAndCompress(item.ResourceFiles.ToArray(), writePath, item.Compression); CopyFileWithTimestampIfDifferent(writePath, item.ResultDetails.FileName, log); } }
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); } }