Exemplo n.º 1
0
        public void Execute()
        {
            var payloadCount = this.Payloads.Count(); // The number of embedded payloads

            if (!String.IsNullOrEmpty(this.ManifestFile))
            {
                ++payloadCount;
            }

            var cabinetPath = Path.GetFullPath(this.OutputPath);

            var files = new List <CabinetCompressFile>();

            // If a manifest was provided always add it as "payload 0" to the container.
            if (!String.IsNullOrEmpty(this.ManifestFile))
            {
                files.Add(new CabinetCompressFile(this.ManifestFile, "0"));
            }

            files.AddRange(this.Payloads.Select(p => new CabinetCompressFile(p.SourceFile.Path, p.EmbeddedId)));

            var cab = new Cabinet(cabinetPath);

            cab.Compress(files, this.CompressionLevel ?? Data.CompressionLevel.Mszip);

            // Now that the container is created, set the outputs of the command.
            var fileInfo = new FileInfo(cabinetPath);

            this.Hash = BundleHashAlgorithm.Hash(fileInfo);

            this.Size = fileInfo.Length;
        }
        private WixBundlePayloadSymbol CreateBundleExtensionManifestPayloadRow(string bextManifestPath)
        {
            var generatedId = Common.GenerateIdentifier("ux", BurnCommon.BundleExtensionDataFileName);

            var symbol = this.Section.AddSymbol(new WixBundlePayloadSymbol(this.BundleSymbol.SourceLineNumbers, new Identifier(AccessModifier.Private, generatedId))
            {
                Name       = BurnCommon.BundleExtensionDataFileName,
                SourceFile = new IntermediateFieldPathValue {
                    Path = bextManifestPath
                },
                Compressed           = true,
                UnresolvedSourceFile = bextManifestPath,
                ContainerRef         = BurnConstants.BurnUXContainerName,
                EmbeddedId           = String.Format(CultureInfo.InvariantCulture, BurnCommon.BurnUXContainerEmbeddedIdFormat, this.LastUXPayloadIndex),
                Packaging            = PackagingType.Embedded,
            });

            var fileInfo = new FileInfo(bextManifestPath);

            symbol.FileSize = (int)fileInfo.Length;

            symbol.Hash = BundleHashAlgorithm.Hash(fileInfo);

            return(symbol);
        }
Exemplo n.º 3
0
        private void UpdatePayloadFileInformation(WixBundlePayloadSymbol payload, IntermediateFieldPathValue sourceFile)
        {
            var fileInfo = new FileInfo(sourceFile.Path);

            if (null != fileInfo)
            {
                payload.FileSize = fileInfo.Length;

                payload.Hash = BundleHashAlgorithm.Hash(fileInfo);
            }
            else
            {
                payload.FileSize = 0;
            }
        }
Exemplo n.º 4
0
        private void UpdatePayloadFileInformation(WixBundlePayloadSymbol payload, IntermediateFieldPathValue sourceFile)
        {
            var fileInfo = new FileInfo(sourceFile.Path);

            if (null != fileInfo)
            {
                payload.FileSize = (int)fileInfo.Length;

                payload.Hash = BundleHashAlgorithm.Hash(fileInfo);

                // Try to get the certificate if the payload is a signed file and we're not suppressing signature validation.
                if (payload.EnableSignatureValidation)
                {
                    X509Certificate2 certificate = null;
                    try
                    {
                        certificate = new X509Certificate2(fileInfo.FullName);
                    }
                    catch (CryptographicException) // we don't care about non-signed files.
                    {
                    }

                    // If there is a certificate, remember its hashed public key identifier and thumbprint.
                    if (null != certificate)
                    {
                        byte[] publicKeyIdentifierHash     = new byte[128];
                        uint   publicKeyIdentifierHashSize = (uint)publicKeyIdentifierHash.Length;

                        Native.NativeMethods.HashPublicKeyInfo(certificate.Handle, publicKeyIdentifierHash, ref publicKeyIdentifierHashSize);

                        var sb = new StringBuilder(((int)publicKeyIdentifierHashSize + 1) * 2);
                        for (var i = 0; i < publicKeyIdentifierHashSize; ++i)
                        {
                            sb.AppendFormat("{0:X2}", publicKeyIdentifierHash[i]);
                        }

                        payload.PublicKey  = sb.ToString();
                        payload.Thumbprint = certificate.Thumbprint;
                    }
                }
            }
            else
            {
                payload.FileSize = 0;
            }
        }