/// <summary>
        /// Constructor for auto media assigner.
        /// </summary>
        /// <param name="output">Output</param>
        /// <param name="core">Binder core.</param>
        /// <param name="filesCompressed">True if files are compressed by default. </param>
        public AutoMediaAssigner(Output output, BinderCore core, bool filesCompressed)
        {
            this.output              = output;
            this.core                = core;
            this.filesCompressed     = filesCompressed;
            this.cabinetNameTemplate = "Cab{0}.cab";

            uncompressedFileRows = new FileRowCollection();
            mediaRows            = new MediaRowCollection();
            cabinets             = new Hashtable();
        }
예제 #2
0
        /// <summary>
        /// Binds an output.
        /// </summary>
        /// <param name="output">The output to bind.</param>
        /// <param name="file">The Windows Installer file to create.</param>
        /// <remarks>The Binder.DeleteTempFiles method should be called after calling this method.</remarks>
        /// <returns>true if binding completed successfully; false otherwise</returns>
        public bool Bind(Output output, string file)
        {
            // Ensure the cabinet cache path exists if we are going to use it.
            if (!String.IsNullOrEmpty(this.CabCachePath))
            {
                Directory.CreateDirectory(this.CabCachePath);
            }

            this.fileManagerCore = new BinderFileManagerCore();
            this.fileManagerCore.CabCachePath      = this.CabCachePath;
            this.fileManagerCore.Output            = output;
            this.fileManagerCore.TempFilesLocation = this.TempFilesLocation;
            this.fileManagerCore.AddBindPaths(this.BindPaths, BindStage.Normal);
            this.fileManagerCore.AddBindPaths(this.TargetBindPaths, BindStage.Target);
            this.fileManagerCore.AddBindPaths(this.UpdatedBindPaths, BindStage.Updated);
            foreach (IBinderFileManager fileManager in this.fileManagers)
            {
                fileManager.Core = this.fileManagerCore;
            }

            this.core = new BinderCore();
            this.core.FileManagerCore = this.fileManagerCore;

            this.WriteBuildInfoTable(output, file);

            // Initialize extensions.
            foreach (IBinderExtension extension in this.extensions)
            {
                extension.Core = this.core;

                extension.Initialize(output);
            }

            // Gather all the wix variables.
            Table wixVariableTable = output.Tables["WixVariable"];

            if (null != wixVariableTable)
            {
                foreach (WixVariableRow wixVariableRow in wixVariableTable.Rows)
                {
                    this.WixVariableResolver.AddVariable(wixVariableRow);
                }
            }

            IEnumerable <FileTransfer> fileTransfers = null;
            IEnumerable <string>       contentPaths  = null;

            switch (output.Type)
            {
            case OutputType.Bundle:
                this.BindBundle(output, file, out fileTransfers, out contentPaths);
                break;

            case OutputType.Transform:
                this.BindTransform(output, file);
                break;

            default:
                this.BindDatabase(output, file, out fileTransfers, out contentPaths);
                break;
            }


            // Layout media
            try
            {
                this.LayoutMedia(fileTransfers);
            }
            finally
            {
                if (!String.IsNullOrEmpty(this.ContentsFile) && contentPaths != null)
                {
                    this.CreateContentsFile(this.ContentsFile, contentPaths);
                }

                if (!String.IsNullOrEmpty(this.OutputsFile) && fileTransfers != null)
                {
                    this.CreateOutputsFile(this.OutputsFile, fileTransfers, this.PdbFile);
                }

                if (!String.IsNullOrEmpty(this.BuiltOutputsFile) && fileTransfers != null)
                {
                    this.CreateBuiltOutputsFile(this.BuiltOutputsFile, fileTransfers, this.PdbFile);
                }
            }

            this.core = null;

            return(Messaging.Instance.EncounteredError);
        }