示例#1
0
        private FileSignInfo TrackFile(PathWithHash file, PathWithHash parentContainer, string collisionPriorityId)
        {
            bool isNested = parentContainer != null;

            _log.LogMessage($"Tracking file '{file.FullPath}' isNested={isNested}");

            // If there's a wixpack in ItemsToSign which corresponds to this file, pass along the path of
            // the wixpack so we can associate the wixpack with the item
            var wixPack      = _wixPacks.SingleOrDefault(w => w.Moniker.Equals(file.FileName, StringComparison.OrdinalIgnoreCase));
            var fileSignInfo = ExtractSignInfo(file, parentContainer, collisionPriorityId, wixPack.FullPath);

            if (_filesByContentKey.TryGetValue(fileSignInfo.FileContentKey, out var existingSignInfo))
            {
                // If we saw this file already we wouldn't call TrackFile unless this is a top-level file.
                Debug.Assert(!isNested);

                // Copy the signed content to the destination path.
                _filesToCopy.Add(new KeyValuePair <string, string>(existingSignInfo.FullPath, file.FullPath));
                return(fileSignInfo);
            }

            if (fileSignInfo.IsContainer())
            {
                if (fileSignInfo.IsZipContainer())
                {
                    if (TryBuildZipData(fileSignInfo, out var zipData))
                    {
                        _zipDataMap[fileSignInfo.FileContentKey] = zipData;
                    }
                }
                else if (fileSignInfo.IsWixContainer())
                {
                    _log.LogMessage($"Trying to gather data for wix container {fileSignInfo.FullPath}");
                    if (TryBuildWixData(fileSignInfo, out var msiData))
                    {
                        _zipDataMap[fileSignInfo.FileContentKey] = msiData;
                    }
                }
            }
            _log.LogMessage(MessageImportance.Low, $"Caching file {fileSignInfo.FileContentKey.FileName} {fileSignInfo.FileContentKey.StringHash}");
            _filesByContentKey.Add(fileSignInfo.FileContentKey, fileSignInfo);

            bool hasSignableParts = false;

            if (fileSignInfo.IsContainer())
            {
                // Only sign containers if the file itself is unsigned, or
                // an item in the container is unsigned.
                hasSignableParts = _zipDataMap[fileSignInfo.FileContentKey].NestedParts.Values.Any(b => b.FileSignInfo.SignInfo.ShouldSign || b.FileSignInfo.HasSignableParts);
                if (hasSignableParts)
                {
                    // If the file has contents that need to be signed, then re-evaluate the signing info
                    fileSignInfo = fileSignInfo.WithSignableParts();
                    _filesByContentKey[fileSignInfo.FileContentKey] = fileSignInfo;
                }
            }
            if (fileSignInfo.ShouldTrack)
            {
                // We never sign wixpacks
                if (!WixPackInfo.IsWixPack(fileSignInfo.FileName))
                {
                    _filesToSign.Add(fileSignInfo);
                }
            }

            return(fileSignInfo);
        }