コード例 #1
0
ファイル: PatchSequencer.cs プロジェクト: skyhoshi/psmsi
 private void AddTargetProductCodesFromPatch(string path)
 {
     using (var patch = new PatchPackage(path))
     {
         foreach (var productCode in patch.GetTargetProductCodes())
         {
             this.TargetProductCodes.Add(productCode);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Writes a <see cref="SummaryInfo"/> object for each supported file type to the pipeline.
        /// </summary>
        /// <param name="item">A <see cref="PSObject"/> representing the file system object to process.</param>
        protected override void ProcessItem(PSObject item)
        {
            var path         = item.GetPropertyValue <string>("PSPath");
            var providerPath = this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path);

            // Make sure the file exists and is a patch.
            var type = FileInfo.GetFileTypeInternal(providerPath);

            if (FileType.Package == type || FileType.Patch == type || FileType.Transform == type)
            {
                using (var info = new Deployment.WindowsInstaller.SummaryInfo(providerPath, false))
                {
                    var copy = new SummaryInfo(info);
                    var obj  = PSObject.AsPSObject(copy);

                    // Add the class type as the first type name.
                    var name = typeof(SummaryInfo).FullName + "#" + type;
                    obj.TypeNames.Insert(0, name);

                    // Attach the original PSPath and write to the pipeline.
                    obj.SetPropertyValue("PSPath", path);
                    this.WriteObject(obj);
                }
            }

            // Enumerate transforms in the patch.
            if (FileType.Patch == type && this.IncludeTransforms)
            {
                using (var patch = new PatchPackage(providerPath))
                {
                    foreach (var transform in patch.GetTransformsInfo(true))
                    {
                        var obj = PSObject.AsPSObject(transform);

                        // Attach the original patch path and write to the pipeline.
                        obj.SetPropertyValue("Patch", providerPath);
                        this.WriteObject(obj);
                    }
                }
            }
        }
コード例 #3
0
ファイル: PatchApplicator.cs プロジェクト: skyhoshi/psmsi
        /// <summary>
        /// Applies applicable transforms in order of sequenced patches.
        /// </summary>
        /// <param name="throwOnError">Whether to throw an exception if an error occurs.</param>
        internal void Apply(bool throwOnError = false)
        {
            // Need to make a copy of the database since exclusivity is required.
            IEnumerable <string> applicable = null;

            using (var copy = Copy(this.db))
            {
                // Copy the items to a list so they are enumerated immediately and the temporary database can be closed.
                applicable = this.sequencer.GetApplicablePatches(copy.FilePath).Select(patch => patch.Patch).ToList();
            }

            foreach (var path in applicable)
            {
                using (var patch = new PatchPackage(path))
                {
                    var transforms = patch.GetValidTransforms(this.db);
                    foreach (var transform in transforms)
                    {
                        // GetValidTransforms does not return the patch transform so assume it too is valid.
                        foreach (var prefix in PatchApplicator.TransformPrefixes)
                        {
                            var temp = Path.ChangeExtension(Path.GetTempFileName(), ".mst");
                            patch.ExtractTransform(prefix + transform, temp);

                            // Apply and commit the authored transform so further transforms may apply.
                            this.db.ApplyTransform(temp, PatchApplicator.IgnoreErrors);
                            this.db.ApplyTransform(temp, PatchApplicator.IgnoreErrors | TransformErrors.ViewTransform);
                            this.db.Commit();

                            // Attempt to delete the temporary transform.
                            TryDelete(temp);
                        }
                    }
                }
            }
        }