Beispiel #1
0
 /// <summary>
 /// Gets all sections. 
 /// </summary>
 /// <returns>SectionCollection</returns>
 public static SectionCollection GetAllSections()
 {
     var q = new QueryFactory().Section.OrderBy(SectionFields.OrderNo.Ascending(), SectionFields.SectionName.Ascending());
     SectionCollection sections = new SectionCollection();
     sections.GetMulti(q);
     return sections;
 }
        public override IHierarchicalEnumerable Select()
        {
            HttpRequest currentRequest = HttpContext.Current.Request;

            //if (!currentRequest.IsAuthenticated)
            //    throw new NotSupportedException("The SectionDataSourceView only presents data in an authenticated context.");

            SectionCollection sections = new SectionCollection();

            if (this.viewPath == Section.Root)
            {
                Section root = new Section(Guid.Empty);

                foreach (Section c in root.Childs)
                    sections.Add(new SectionHierarchyData(c));

                return sections;
            }

            ISection section = ContentManagementService.GetSection(this.viewPath);

            if (section != null)
            {
                foreach (ISection child in section.Childs)
                {
                    sections.Add(new SectionHierarchyData(child));
                }
            }

            return sections;
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Solution" /> class.
 /// </summary>
 /// <param name="fullpath">The fullpath.</param>
 /// <param name="headers">The headers.</param>
 /// <param name="projects">The projects.</param>
 /// <param name="globalSections">The global sections.</param>
 /// <param name="properties">The properties.</param>
 public Solution(string fullpath, IEnumerable<string> headers, IEnumerable<Project> projects, IEnumerable<Section> globalSections, IEnumerable<PropertyItem> properties)
 {
     FullPath = fullpath;
     this.headers = new List<string>(headers);
     this.projects = new ProjectCollection(this, projects);
     this.globalSections = new SectionCollection(globalSections);
     this.Properties = new PropertyItemCollection(properties);
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Solution"/> class.
 /// </summary>
 public Solution()
 {
     FullPath = null;
     headers = new List<string>();
     projects = new ProjectCollection(this);
     globalSections = new SectionCollection();
     Properties = new PropertyItemCollection();
 }
Beispiel #5
0
        public SeatOptions(DataTable seatsTable, DataTable sectionsTable, DataTable seatTypesTable,
				DataTable allocTable)
        {
            Seats = new SeatCollection(seatsTable);
            Sections = new SectionCollection(sectionsTable);
            SeatTypes = new SeatTypeCollection(seatTypesTable);
            Allocations = new AllocationCollection(allocTable);
        }
        public IHierarchicalEnumerable GetChildren()
        {
            SectionCollection children = new SectionCollection();

            foreach (ISection child in item.Childs)
                children.Add(new SectionHierarchyData(child));

            return children;
        }
Beispiel #7
0
        public LytroFile(string file)
        {
            this.RawImageSections = new SectionCollection<RawImageSection>();
            this.TextSections = new SectionCollection<TextSection>();
            this.JpegSections = new SectionCollection<JpegSection>();

            this.File = file;
            this.Filename = Path.GetFileNameWithoutExtension(this.File);
        }
Beispiel #8
0
        /// <summary>
        /// Removes the given section from the database. Returns true if succeeded.
        /// </summary>
        /// <param name="ID">ID of section to delete</param>
        /// <returns>True if succeeded, false otherwise</returns>
        public static bool DeleteSection(int ID)
        {
            // trying to delete the entity directly from the database without first loading it.
            // for that we use an entity collection and use the DeleteMulti method with a filter on the PK.
            SectionCollection sections = new SectionCollection();
            // try to delete the entity
            int deletedRows = sections.DeleteMulti(SectionFields.SectionID == ID);

            // there should only be one deleted row, since we are filtering by the PK.
            // return true if there's 1, otherwise false.
            return (deletedRows == 1);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectFile"/> class with the specified name.
        /// </summary>
        /// <param name="format">The format of the object file.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="name">The name of the object file; or <see langword="null"/> to specify no name.</param>
        public ObjectFile(IObjectFileFormat format, IArchitecture architecture, string name)
        {
            #region Contract
            Contract.Requires<ArgumentNullException>(format != null);
            Contract.Requires<ArgumentNullException>(architecture != null);
            Contract.Requires<ArgumentException>(format.IsSupportedArchitecture(architecture));
            #endregion

            this.format = format;
            this.architecture = architecture;
            this.sections = new SectionCollection(this);
            this.AssociatedSymbol = new Symbol(SymbolType.None, name);
        }
Beispiel #10
0
 public LogIniFile(string iniPath)
     : base(iniPath)
 {
     Sections = new SectionCollection<LogIniSection>();
     try
     {
         foreach (string sectionName in SectionNames)
             Sections.AddSection(new LogIniSection(this, sectionName));
     }
     catch (IniFiles.Exceptions.IniFileSectionsReadException e)
     {
         throw new Common.Exceptions.LogIniSectionReadException("", e);
     }
 }
Beispiel #11
0
		public override void VisitSectionCollection (SectionCollection sections)
		{
			Section old = null;
			foreach (Section s in m_originalImage.Sections)
				if (s.Name == Section.Resources)
					old = s;

			if (old == null)
				return;

			Section rsrc = new Section ();
			rsrc.Characteristics = old.Characteristics;
			rsrc.Name = old.Name;

			sections.Add (rsrc);
		}
Beispiel #12
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            try
            {
                Librarian         librarian = null;
                SectionCollection sections  = new SectionCollection();

                // parse the command line
                this.ParseCommandLine(args);

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                if (0 == this.inputFiles.Count)
                {
                    this.showHelp = true;
                }
                else if (null == this.outputFile)
                {
                    if (1 < this.inputFiles.Count)
                    {
                        throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput());
                    }

                    this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wixlib");
                }

                if (this.showLogo)
                {
                    AppCommon.DisplayToolHeader();
                }

                if (this.showHelp)
                {
                    Console.WriteLine(LitStrings.HelpMessage);
                    AppCommon.DisplayToolFooter();
                    return(this.messageHandler.LastErrorNumber);
                }

                foreach (string parameter in this.invalidArgs)
                {
                    this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter));
                }
                this.invalidArgs = null;

                // create the librarian
                librarian          = new Librarian();
                librarian.Message += new MessageEventHandler(this.messageHandler.Display);
                librarian.ShowPedanticMessages = this.showPedanticMessages;

                if (null != this.bindPaths)
                {
                    foreach (string bindPath in this.bindPaths)
                    {
                        if (-1 == bindPath.IndexOf('='))
                        {
                            this.sourcePaths.Add(bindPath);
                        }
                    }
                }

                // load any extensions
                foreach (string extension in this.extensionList)
                {
                    WixExtension wixExtension = WixExtension.Load(extension);

                    librarian.AddExtension(wixExtension);

                    // load the binder file manager regardless of whether it will be used in case there is a collision
                    if (null != wixExtension.BinderFileManager)
                    {
                        if (null != this.binderFileManager)
                        {
                            throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, LitStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), this.binderFileManager.GetType().ToString()), "ext");
                        }

                        this.binderFileManager = wixExtension.BinderFileManager;
                    }
                }

                // add the sections to the librarian
                foreach (string inputFile in this.inputFiles)
                {
                    string inputFileFullPath = Path.GetFullPath(inputFile);
                    string dirName           = Path.GetDirectoryName(inputFileFullPath);

                    if (!this.sourcePaths.Contains(dirName))
                    {
                        this.sourcePaths.Add(dirName);
                    }

                    // try loading as an object file
                    try
                    {
                        Intermediate intermediate = Intermediate.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        sections.AddRange(intermediate.Sections);
                        continue; // next file
                    }
                    catch (WixNotIntermediateException)
                    {
                        // try another format
                    }

                    // try loading as a library file
                    Library loadedLibrary = Library.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                    sections.AddRange(loadedLibrary.Sections);
                }

                // and now for the fun part
                Library library = librarian.Combine(sections);

                // save the library output if an error did not occur
                if (null != library)
                {
                    if (this.bindFiles)
                    {
                        // if the binder file manager has not been loaded yet use the built-in binder extension
                        if (null == this.binderFileManager)
                        {
                            this.binderFileManager = new BinderFileManager();
                        }


                        if (null != this.bindPaths)
                        {
                            foreach (string bindPath in this.bindPaths)
                            {
                                if (-1 == bindPath.IndexOf('='))
                                {
                                    this.binderFileManager.BindPaths.Add(bindPath);
                                }
                                else
                                {
                                    string[] namedPair = bindPath.Split('=');

                                    //It is ok to have duplicate key.
                                    this.binderFileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]);
                                }
                            }
                        }

                        foreach (string sourcePath in this.sourcePaths)
                        {
                            this.binderFileManager.SourcePaths.Add(sourcePath);
                        }
                    }
                    else
                    {
                        this.binderFileManager = null;
                    }

                    foreach (string localizationFile in this.localizationFiles)
                    {
                        Localization localization = Localization.Load(localizationFile, librarian.TableDefinitions, this.suppressSchema);

                        library.AddLocalization(localization);
                    }

                    WixVariableResolver wixVariableResolver = new WixVariableResolver();

                    wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display);

                    library.Save(this.outputFile, this.binderFileManager, wixVariableResolver);
                }
            }
            catch (WixException we)
            {
                this.messageHandler.Display(this, we.Error);
            }
            catch (Exception e)
            {
                this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }

            return(this.messageHandler.LastErrorNumber);
        }
Beispiel #13
0
 private static void InvalidateExternalSectionsCollections(object sender, EventArgs e)
 {
     _Children = null;
 }
Beispiel #14
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]);

            _thread = ThreadGuiHelper.GetThread(threadID);
            if (_thread == null)
            {
                // not found, return to default page
                Response.Redirect("default.aspx", true);
            }

            // Check credentials
            bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum);

            if (!userHasAccess)
            {
                // doesn't have access to this forum. redirect
                Response.Redirect("default.aspx");
            }

            bool userMayMoveThread = SessionAdapter.HasSystemActionRight(ActionRights.SystemWideThreadManagement);

            if (!userMayMoveThread)
            {
                // doesn't have access to this forum. redirect
                Response.Redirect("Messages.aspx?ThreadID=" + threadID, true);
            }

            // check if the user can view this thread. If not, don't continue.
            if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) &&
                !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) &&
                !_thread.IsSticky)
            {
                // can't view this thread, it isn't visible to the user
                Response.Redirect("default.aspx", true);
            }

            if (!Page.IsPostBack)
            {
                // fill the page's content. Bind the known sections
                SectionCollection sections = CacheManager.GetAllSections();
                cbxSections.DataSource = sections;
                cbxSections.DataBind();

                lblThreadSubject.Text = HttpUtility.HtmlEncode(_thread.Subject);
                ForumEntity forum = CacheManager.GetForum(_thread.ForumID);
                if (forum == null)
                {
                    // Orphaned thread
                    Response.Redirect("default.aspx", true);
                }

                // pre-select the section the forum is currently in. Do that with an in-memory search through the known sections.
                SectionEntity toFind = new SectionEntity();
                toFind.Fields[(int)SectionFieldIndex.SectionID].ForcedCurrentValueWrite(forum.SectionID);
                toFind.IsNew = false;
                int index = sections.IndexOf(toFind);
                if (index >= 0)
                {
                    cbxSections.SelectedIndex = index;
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// Retrieves for all available sections all forums with all relevant statistical information. This information is stored per forum in a
        /// DataView which is stored in the returned Dictionary, with the SectionID where the forum is located in as Key.
        /// </summary>
        /// <param name="availableSections">SectionCollection with all available sections</param>
        /// <param name="accessableForums">List of accessable forums IDs.</param>
        /// <param name="forumsWithOnlyOwnThreads">The forums for which the calling user can view other users' threads. Can be null</param>
        /// <param name="userID">The userid of the calling user.</param>
        /// <returns>
        /// Dictionary with per key (sectionID) a dataview with forum information of all the forums in that section.
        /// </returns>
        /// <remarks>Uses dataviews because a dynamic list is executed to retrieve the information for the forums, which include aggregate info about
        /// # of posts.</remarks>
        public static Dictionary<int, DataView> GetAllAvailableForumsDataViews(SectionCollection availableSections, List<int> accessableForums,
            List<int> forumsWithThreadsFromOthers, int userID)
        {
            Dictionary<int, DataView> toReturn = new Dictionary<int, DataView>();

            // return an empty list, if the user does not have a valid list of forums to access
            if (accessableForums == null || accessableForums.Count <= 0)
            {
                return toReturn;
            }

            // fetch all forums with statistics in a dynamic list, while filtering on the list of accessable forums for this user.
            // Create the filter separate of the query itself, as it's re-used multiple times.
            IPredicateExpression threadFilter = ThreadGuiHelper.CreateThreadFilter(forumsWithThreadsFromOthers, userID);

            var qf = new QueryFactory();
            var q = qf.Create()
                        .Select(ForumFields.ForumID,
                                ForumFields.ForumName,
                                ForumFields.ForumDescription,
                                ForumFields.ForumLastPostingDate,
                                // add a scalar query which retrieves the # of threads in the specific forum.
                                // this will result in the query:
                                // (
                                //		SELECT COUNT(ThreadID) FROM Thread
                                //		WHERE ForumID = Forum.ForumID AND threadfilter.
                                // ) As AmountThreads
                                qf.Create()
                                        .Select(ThreadFields.ThreadID.Count())
                                        .CorrelatedOver(ThreadFields.ForumID == ForumFields.ForumID)
                                        .Where(threadFilter)
                                        .ToScalar().As("AmountThreads"),
                                // add a scalar query which retrieves the # of messages in the threads of this forum.
                                // this will result in the query:
                                // (
                                //		SELECT COUNT(MessageID) FROM Message
                                //		WHERE ThreadID IN
                                //		(
                                //			SELECT ThreadID FROM Thread WHERE ForumID = Forum.ForumID AND threadfilter
                                //		)
                                // ) AS AmountMessages
                                qf.Create()
                                        .Select(MessageFields.MessageID.Count())
                                        .Where(MessageFields.ThreadID.In(
                                                qf.Create()
                                                    .Select(ThreadFields.ThreadID)
                                                    .CorrelatedOver(ThreadFields.ForumID == ForumFields.ForumID)
                                                    .Where(threadFilter)))
                                        .ToScalar().As("AmountMessages"),
                                ForumFields.HasRSSFeed,
                                ForumFields.SectionID)
                        .Where(ForumFields.ForumID == accessableForums)
                        .OrderBy(ForumFields.OrderNo.Ascending(), ForumFields.ForumName.Ascending());

            var results = new TypedListDAO().FetchAsDataTable(q);

            // Now per section create a new DataView in memory using in-memory filtering on the DataTable.
            foreach(SectionEntity section in availableSections)
            {
                // Create view for current section and filter out rows we don't want. Do this with in-memory filtering of the dataview, so we don't
                // have to execute multiple queries.
                DataView forumsInSection = new DataView(results, "SectionID=" + section.SectionID, string.Empty, DataViewRowState.CurrentRows);
                // add to sorted list with SectionID as key
                toReturn.Add(section.SectionID, forumsInSection);
            }

            // return the dictionary
            return toReturn;
        }
        /// <summary>
        /// Gets extended fields from controls (checks in related DataFields).
        /// </summary>
        /// <param name="declareExtendedFields">Supported extended fields.</param>
        /// <param name="sections">Report's control sections.</param>
        /// <param name="extendedFields">Founded extended fields in controls.</param>
        private void _GetExtendedFieldsFromControl(ICollection<string> declareExtendedFields,
                                                   SectionCollection sections,
                                                   ref List<string> extendedFields)
        {
            Debug.Assert(null != declareExtendedFields);
            Debug.Assert(null != sections);
            Debug.Assert(null != extendedFields);

            // check in control's "DataField"
            for (int sectionIndex = 0; sectionIndex < sections.Count; ++sectionIndex)
            {
                Section section = sections[sectionIndex];
                for (int controlIndex = 0; controlIndex < section.Controls.Count; ++controlIndex)
                {
                    string dataField = section.Controls[controlIndex].DataField;
                    if (string.IsNullOrEmpty(dataField))
                        continue; // skip this

                    foreach (string field in declareExtendedFields)
                    {
                        if (dataField.Equals(field, StringComparison.OrdinalIgnoreCase) &&
                            !extendedFields.Contains(field))
                            extendedFields.Add(field);
                    }
                }
            }
        }
Beispiel #17
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // If the user doesn't have any access rights to management stuff, the user should
            // be redirected to the default of the global system.
            if (!SessionAdapter.HasSystemActionRights())
            {
                // doesn't have system rights. redirect.
                Response.Redirect("../Default.aspx", true);
            }

            // Check if the user has the right systemright
            if (!SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement))
            {
                // no, redirect to admin default page, since the user HAS access to the admin menu.
                Response.Redirect("Default.aspx", true);
            }

            _forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]);

            if (!Page.IsPostBack)
            {
                // read sections for the drop down list.
                SectionCollection sections = SectionGuiHelper.GetAllSections();
                cbxSections.DataSource = sections;
                cbxSections.DataBind();

                SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues();
                cbxSupportQueues.DataSource = supportQueues;
                cbxSupportQueues.DataBind();

                // Load the forum.
                ForumEntity forum = ForumGuiHelper.GetForum(_forumID);
                if (forum != null)
                {
                    // forum found
                    tbxForumDescription.Text = forum.ForumDescription;
                    tbxForumName.Value       = forum.ForumName;
                    tbxOrderNo.Text          = forum.OrderNo.ToString();

                    cbxSections.SelectedValue = forum.SectionID.ToString();

                    if (forum.DefaultSupportQueueID.HasValue)
                    {
                        cbxSupportQueues.SelectedValue = forum.DefaultSupportQueueID.Value.ToString();
                    }
                    chkHasRSSFeed.Checked = forum.HasRSSFeed;
                    cbxThreadListInterval.SelectedValue  = forum.DefaultThreadListInterval.ToString();
                    tbxMaxAttachmentSize.Text            = forum.MaxAttachmentSize.ToString();
                    tbxMaxNoOfAttachmentsPerMessage.Text = forum.MaxNoOfAttachmentsPerMessage.ToString();

                    if (forum.NewThreadWelcomeText != null)
                    {
                        tbxNewThreadWelcomeText.Text = forum.NewThreadWelcomeText;
                    }
                }
                else
                {
                    // not found
                    Response.Redirect("Default.aspx", true);
                }
            }
        }
Beispiel #18
0
 public ListViewFragment(ListViewStyle style)
 {
     Sections = new SectionCollection();
     Style    = style;
 }
        /// <summary>
        /// Generates the appropriate MSI file for the package.
        /// </summary>
        /// <param name="sourceDoc">WiX document to create MSI from.</param>
        /// <param name="outputFile">File path for the MSI file.</param>
        /// <returns>True if generation works, false if anything goes wrong.</returns>
        private bool GenerateMsi(XmlDocument sourceDoc, string outputFile)
        {
            // Create the Compiler.
            Compiler compiler = new Compiler();

            compiler.Message += this.core.MessageEventHandler;

            // Compile the source document.
            Intermediate intermediate = compiler.Compile(sourceDoc);

            if (intermediate == null)
            {
                return(false);
            }

            // Create the variable resolver that will be used in the Linker and Binder.
            WixVariableResolver wixVariableResolver = new WixVariableResolver();

            wixVariableResolver.Message += this.core.MessageEventHandler;

            // Create the Linker.
            Linker linker = new Linker();

            linker.Message            += this.core.MessageEventHandler;
            linker.WixVariableResolver = wixVariableResolver;

            // Load the isolatedapp.wixlib.
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            Library appLib = LoadLibraryHelper(assembly, "WixToolset.Extensions.OfficeAddin.Data.OfficeAddin.wixlib", linker.TableDefinitions);

            // Link the compiled source document and the isolatedapp.wixlib together.
            SectionCollection sections = new SectionCollection();

            sections.AddRange(intermediate.Sections);
            sections.AddRange(appLib.Sections);

            Output output = linker.Link(sections);

            if (output == null)
            {
                return(false);
            }

            // Tweak the compiled output to add a few GUIDs for Components from the oaddin.wixlib.
            Table components = output.Tables["Component"];

            foreach (Row row in components.Rows)
            {
                switch ((string)row[0])
                {
                case "ThisApplicationVersionRegistryKeyComponent":
                    row[1] = Guid.NewGuid().ToString("B");
                    break;

                case "ThisApplicationCacheFolderComponent":
                    row[1] = Guid.NewGuid().ToString("B");
                    break;

                case "ThisApplicationShortcutComponent":
                    row[1] = Guid.NewGuid().ToString("B");
                    break;
                }
            }

            // Bind the final output.
            Binder binder = new Binder();

            binder.FileManager = new BinderFileManager();
            binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(outputFile));
            binder.FileManager.SourcePaths.Add(this.source);
            binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(assembly.Location));
            binder.Message            += this.core.MessageEventHandler;
            binder.WixVariableResolver = wixVariableResolver;
            return(binder.Bind(output, outputFile));
        }
Beispiel #20
0
        /// <summary>
        /// Generates the appropriate MSI file for the package.
        /// </summary>
        /// <param name="sourceDoc">WiX document to create MSI from.</param>
        /// <param name="filePath">File path for the RSS feed.</param>
        private void GenerateMsi(XmlDocument sourceDoc, string filePath)
        {
            // Compile
            Compiler compiler = new Compiler();
            compiler.Message += new MessageEventHandler(this.MessageHandler);

            Intermediate intermediate = compiler.Compile(sourceDoc);
            if (intermediate == null)
            {
                return;
            }

            // locate the applib.wixlib
            string assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string applibPath = Path.Combine(assemblyPath, "applib.wixlib");

            if (!File.Exists(applibPath))
            {
                this.OnMessage(ClickThroughErrors.CannotLoadApplib(applibPath));
                return;
            }

            WixVariableResolver wixVariableResolver = new WixVariableResolver();
            wixVariableResolver.Message += new MessageEventHandler(this.MessageHandler);

            // create the linker
            Linker linker = new Linker();
            linker.Message += new MessageEventHandler(this.MessageHandler);
            linker.WixVariableResolver = wixVariableResolver;

            // load applib.wixlib
            Library lowImpactAppLib = Library.Load(applibPath, linker.TableDefinitions, false, false);
            SectionCollection sections = new SectionCollection();
            sections.AddRange(intermediate.Sections);
            sections.AddRange(lowImpactAppLib.Sections);

            // Link
            Output output = linker.Link(sections);
            if (output == null)
            {
                return;
            }

            Table components = output.Tables["Component"];
            foreach (Row row in components.Rows)
            {
                switch ((string)row[0])
                {
                    case "ThisApplicationVersionRegistryKeyComponent":
                        row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}");
                        break;
                    case "ThisApplicationCacheFolderComponent":
                        row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}");
                        break;
                    case "ThisApplicationShortcutComponent":
                        row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}");
                        break;
                }
            }

            // Bind
            Binder binder = new Binder();
            binder.Extension = new BinderExtension();
            binder.Extension.SourcePaths.Add(Path.GetDirectoryName(filePath));
            binder.Extension.SourcePaths.Add(assemblyPath);
            binder.WixVariableResolver = wixVariableResolver;
            binder.Message += new MessageEventHandler(this.MessageHandler);
            binder.Bind(output, filePath);

            return;
        }
Beispiel #21
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            Linker linker = null;
            Localizer localizer = null;
            SectionCollection sections = new SectionCollection();
            ArrayList transforms = new ArrayList();

            try
            {
                // parse the command line
                this.ParseCommandLine(args);

                // load any extensions
                List<WixExtension> loadedExtensionList = new List<WixExtension>();
                foreach (string extension in this.extensionList)
                {
                    WixExtension wixExtension = WixExtension.Load(extension);
                    loadedExtensionList.Add(wixExtension);

                    // If the extension provides a binder, use that now if it
                    // matches the class from the command line.
                    if (null != wixExtension.CustomBinder && null != this.binderClass && wixExtension.CustomBinder.GetType().Name.Equals(this.binderClass, StringComparison.Ordinal))
                    {
                        this.binder = wixExtension.CustomBinder;
                    }
                }

                // If a binder was specified, but not found then show an error.
                if (!String.IsNullOrEmpty(this.binderClass) && null == this.binder)
                {
                    throw new WixException(WixErrors.SpecifiedBinderNotFound(this.binderClass));
                }

                // create the linker, binder, and validator
                linker = new Linker();
                if (null == this.binder)
                {
                    this.binder = new Microsoft.Tools.WindowsInstallerXml.Binder();
                }

                // have the binder parse the command line arguments light did not recognize
                string[] unparsedArgsArray = new string[this.unparsedArgs.Count];
                this.unparsedArgs.CopyTo(unparsedArgsArray, 0);
                StringCollection remainingArgs = this.binder.ParseCommandLine(unparsedArgsArray, this.messageHandler);

                // Loop through the extensions to give them a shot at processing the remaining command-line args.
                foreach (WixExtension wixExtension in loadedExtensionList)
                {
                    if (0 == remainingArgs.Count)
                    {
                        break;
                    }

                    remainingArgs = wixExtension.ParseCommandLine(remainingArgs, this.messageHandler);
                }

                this.ParseCommandLinePassTwo(remainingArgs);

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return this.messageHandler.LastErrorNumber;
                }

                foreach (string parameter in this.invalidArgs)
                {
                    this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter));
                }

                this.invalidArgs = null;

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return this.messageHandler.LastErrorNumber;
                }

                if (0 == this.inputFiles.Count)
                {
                    this.showHelp = true;
                }
                else if (null == this.outputFile)
                {
                    if (1 < this.inputFiles.Count)
                    {
                        throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput());
                    }

                    this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wix"); // we'll let the linker change the extension later
                }

                this.binder.OutputFile = this.outputFile;
                this.binder.PostParseCommandLine();

                if (this.showLogo)
                {
                    AppCommon.DisplayToolHeader();
                }

                if (this.showHelp)
                {
                    this.PrintHelp();
                    AppCommon.DisplayToolFooter();
                    return this.messageHandler.LastErrorNumber;
                }

                linker.AllowIdenticalRows = this.allowIdenticalRows;
                linker.AllowUnresolvedReferences = this.allowUnresolvedReferences;
                linker.Cultures = this.cultures;
                linker.UnreferencedSymbolsFile = this.unreferencedSymbolsFile;
                linker.ShowPedanticMessages = this.showPedanticMessages;
                linker.DropUnrealTables = this.dropUnrealTables;
                linker.SuppressLocalization = this.suppressLocalization;
                linker.SuppressMsiAssemblyTable = this.suppressMsiAssemblyTable;
                linker.WixVariableResolver = this.wixVariableResolver;

                // set the sequence suppression options
                linker.SuppressAdminSequence = this.suppressAdminSequence;
                linker.SuppressAdvertiseSequence = this.suppressAdvertiseSequence;
                linker.SuppressUISequence = this.suppressUISequence;

                linker.SectionIdOnRows = this.sectionIdOnRows;

                this.binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP");
                this.binder.WixVariableResolver = this.wixVariableResolver;

                if (null != this.bindPaths)
                {
                    foreach (string bindPath in this.bindPaths)
                    {
                        if (-1 == bindPath.IndexOf('='))
                        {
                            this.sourcePaths.Add(bindPath);
                        }
                    }
                }

                // instantiate the localizer and load any localization files
                if (!this.suppressLocalization || 0 < this.localizationFiles.Count || null != this.cultures || !this.outputXml)
                {
                    List<Localization> localizations = new List<Localization>();
                    localizer = new Localizer();

                    localizer.Message += new MessageEventHandler(this.messageHandler.Display);

                    // load each localization file
                    foreach (string localizationFile in this.localizationFiles)
                    {
                        Localization localization = Localization.Load(localizationFile, linker.TableDefinitions, this.suppressSchema);
                        localizations.Add(localization);
                    }

                    if (null != this.cultures)
                    {
                        // add localizations in order specified in cultures
                        foreach (string culture in this.cultures)
                        {
                            foreach (Localization localization in localizations)
                            {
                                if (culture.Equals(localization.Culture, StringComparison.OrdinalIgnoreCase))
                                {
                                    localizer.AddLocalization(localization);
                                }
                            }
                        }
                    }
                    else 
                    {
                        bool neutralFound = false;
                        foreach (Localization localization in localizations)
                        {
                            if (0 == localization.Culture.Length)
                            {
                                // if a neutral wxl was provided use it
                                localizer.AddLocalization(localization);
                                neutralFound = true;
                            }
                        }

                        if (!neutralFound)
                        {
                            // cultures wasn't specified and no neutral wxl are available, include all of the files
                            foreach (Localization localization in localizations)
                            {
                                localizer.AddLocalization(localization);
                            }
                        }
                    }

                    // immediately stop processing if any errors were found
                    if (this.messageHandler.EncounteredError)
                    {
                        return this.messageHandler.LastErrorNumber;
                    }

                    // tell all of the objects about the localizer
                    linker.Localizer = localizer;
                    this.binder.Localizer = localizer;
                    this.wixVariableResolver.Localizer = localizer;
                }

                // process loaded extensions
                foreach (WixExtension wixExtension in loadedExtensionList)
                {
                    linker.AddExtension(wixExtension);
                    this.binder.AddExtension(wixExtension);

                    // load the extension's localizations
                    Library library = wixExtension.GetLibrary(linker.TableDefinitions);
                    if (null != library)
                    {
                        // load the extension's default culture if it provides one and we don't specify any cultures
                        string[] extensionCultures = this.cultures;
                        if (null == extensionCultures && null != wixExtension.DefaultCulture)
                        {
                            extensionCultures = new string[] { wixExtension.DefaultCulture };
                        }

                        library.GetLocalizations(extensionCultures, localizer);
                    }
                }

                this.binder.ProcessExtensions(loadedExtensionList.ToArray());

                // set the message handlers
                linker.Message += new MessageEventHandler(this.messageHandler.Display);
                this.binder.AddMessageEventHandler(new MessageEventHandler(this.messageHandler.Display));

                Output output = null;

                // loop through all the believed object files
                foreach (string inputFile in this.inputFiles)
                {
                    string dirName = Path.GetDirectoryName(inputFile);
                    string inputFileFullPath = Path.GetFullPath(inputFile);

                    if (!this.sourcePaths.Contains(dirName))
                    {
                        this.sourcePaths.Add(dirName);
                    }

                    // try loading as an object file
                    try
                    {
                        Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        sections.AddRange(intermediate.Sections);
                        continue; // next file
                    }
                    catch (WixNotIntermediateException)
                    {
                        // try another format
                    }

                    // try loading as a library file
                    try
                    {
                        Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        library.GetLocalizations(this.cultures, localizer);
                        sections.AddRange(library.Sections);
                        continue; // next file
                    }
                    catch (WixNotLibraryException)
                    {
                        // try another format
                    }

                    // try loading as an output file
                    output = Output.Load(inputFileFullPath, this.suppressVersionCheck, this.suppressSchema);
                }

                // immediately stop processing if any errors were found
                if (this.messageHandler.EncounteredError)
                {
                    return this.messageHandler.LastErrorNumber;
                }

                // set the binder file manager information
                foreach (string bindPath in this.bindPaths)
                {
                    //Checking as IndexOf will return 0 if the string value is String.Empty.
                    if (String.IsNullOrEmpty(bindPath))
                    {
                        continue;
                    }

                    if (-1 == bindPath.IndexOf('='))
                    {
                        this.binder.FileManager.BindPaths.Add(bindPath);
                    }
                    else
                    {
                        string[] namedPair = bindPath.Split('=');

                        //It is ok to have duplicate key.
                        this.binder.FileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]);
                    }
                }

                foreach (string sourcePath in this.sourcePaths)
                {
                    this.binder.FileManager.SourcePaths.Add(sourcePath);
                }

                // and now for the fun part
                if (null == output)
                {
                    OutputType expectedOutputType = OutputType.Unknown;
                    if (this.outputFile != null)
                    {
                        expectedOutputType = Output.GetOutputType(Path.GetExtension(this.outputFile));
                    }

                    output = linker.Link(sections, transforms, expectedOutputType);

                    // if an error occurred during linking, stop processing
                    if (null == output)
                    {
                        return this.messageHandler.LastErrorNumber;
                    }
                }
                else if (0 != sections.Count)
                {
                    throw new InvalidOperationException(LightStrings.EXP_CannotLinkObjFilesWithOutpuFile);
                }

                // Now that the output object is either linked or loaded, tell the binder file manager about it.
                this.binder.FileManager.Output = output;

                // only output the xml if its a patch build or user specfied to only output wixout
                if (this.outputXml || OutputType.Patch == output.Type)
                {
                    string outputExtension = Path.GetExtension(this.outputFile);
                    if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension)
                    {
                        if (OutputType.Patch == output.Type)
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".wixmsp");
                        }
                        else
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".wixout");
                        }
                    }

                    output.Save(this.outputFile, (this.bindFiles ? this.binder.FileManager : null), this.wixVariableResolver, this.binder.TempFilesLocation);
                }
                else // finish creating the MSI/MSM
                {
                    string outputExtension = Path.GetExtension(this.outputFile);
                    if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension)
                    {
                        outputExtension = Output.GetExtension(output.Type);
                        this.outputFile = Path.ChangeExtension(this.outputFile, outputExtension);
                    }

                    this.binder.Bind(output, this.outputFile);
                }
            }
            catch (WixException we)
            {
                if (we is WixInvalidIdtException)
                {
                    // make sure the IDT files stay around
                    this.tidy = false;
                }

                this.messageHandler.Display(this, we.Error);
            }
            catch (Exception e)
            {
                // make sure the files stay around for debugging
                this.tidy = false;

                this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }
            finally
            {
                if (null != binder)
                {
                    this.binder.Cleanup(this.tidy);
                }
            }

            return this.messageHandler.LastErrorNumber;
        }
Beispiel #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        /// <param name="solution">The solution.</param>
        /// <param name="guid">The unique identifier.</param>
        /// <param name="typeGuid">The type unique identifier.</param>
        /// <param name="name">The name.</param>
        /// <param name="relativePath">The relative path.</param>
        /// <param name="parentGuid">The parent unique identifier.</param>
        /// <param name="projectSections">The project sections.</param>
        /// <param name="versionControlLines">The version control lines.</param>
        /// <param name="projectConfigurationPlatformsLines">The project configuration platforms lines.</param>
        /// <exception cref="System.ArgumentNullException">
        /// solution
        /// or
        /// guid
        /// or
        /// typeGuid
        /// or
        /// name
        /// </exception>
        public Project(
            Solution solution,
            Guid guid,
            Guid typeGuid,
            string name,
            string relativePath,
            Guid parentGuid,
            IEnumerable<Section> projectSections,
            IEnumerable<PropertyItem> versionControlLines,
            IEnumerable<PropertyItem> projectConfigurationPlatformsLines)
        {
            if (solution == null) throw new ArgumentNullException("solution");
            if (guid == null) throw new ArgumentNullException("guid");
            if (typeGuid == null) throw new ArgumentNullException("typeGuid");
            if (name == null) throw new ArgumentNullException("name");

            this.solution = solution;
            this.guid = guid;
            this.TypeGuid = typeGuid;
            this.Name = name;
            this.RelativePath = relativePath;
            this.ParentGuid = parentGuid;
            sections = new SectionCollection(projectSections);
            versionControlProperties = new PropertyItemCollection(versionControlLines);
            platformProperties = new PropertyItemCollection(projectConfigurationPlatformsLines);
        }
Beispiel #23
0
        private void Run()
        {
            // Initialize the variable resolver from the command line.
            WixVariableResolver wixVariableResolver = new WixVariableResolver();

            foreach (var wixVar in this.commandLine.Variables)
            {
                wixVariableResolver.AddVariable(wixVar.Key, wixVar.Value);
            }

            // Initialize the linker from the command line.
            Linker linker = new Linker();

            linker.UnreferencedSymbolsFile = this.commandLine.UnreferencedSymbolsFile;
            linker.ShowPedanticMessages    = this.commandLine.ShowPedanticMessages;
            linker.WixVariableResolver     = wixVariableResolver;

            foreach (IExtensionData data in this.extensionData)
            {
                linker.AddExtensionData(data);
            }

            // Initialize the binder from the command line.
            WixToolset.Binder binder = new WixToolset.Binder();
            binder.CabCachePath     = this.commandLine.CabCachePath;
            binder.ReuseCabinets    = this.commandLine.ReuseCabinets;
            binder.ContentsFile     = this.commandLine.ContentsFile;
            binder.BuiltOutputsFile = this.commandLine.BuiltOutputsFile;
            binder.OutputsFile      = this.commandLine.OutputsFile;
            binder.WixprojectFile   = this.commandLine.WixprojectFile;
            binder.BindPaths.AddRange(this.commandLine.BindPaths);
            binder.CabbingThreadCount      = this.commandLine.CabbingThreadCount;
            binder.DefaultCompressionLevel = this.commandLine.DefaultCompressionLevel;
            binder.ExactAssemblyVersions   = this.commandLine.ExactAssemblyVersions;
            binder.Ices.AddRange(this.commandLine.Ices);
            binder.SuppressIces.AddRange(this.commandLine.SuppressIces);
            binder.SetMsiAssemblyNameFileVersion = this.commandLine.SetMsiAssemblyNameFileVersion;
            binder.SuppressAclReset    = this.commandLine.SuppressAclReset;
            binder.SuppressLayout      = this.commandLine.SuppressLayout;
            binder.SuppressValidation  = this.commandLine.SuppressValidation;
            binder.PdbFile             = this.commandLine.SuppressWixPdb ? null : this.commandLine.PdbFile;
            binder.TempFilesLocation   = Environment.GetEnvironmentVariable("WIX_TEMP") ?? Path.GetTempPath();
            binder.WixVariableResolver = wixVariableResolver;

            foreach (IBinderExtension extension in this.binderExtensions)
            {
                binder.AddExtension(extension);
            }

            foreach (IBinderFileManager fm in this.fileManagers)
            {
                binder.AddExtension(fm);
            }

            // Initialize the localizer.
            Localizer localizer = this.InitializeLocalization(linker.TableDefinitions);

            if (Messaging.Instance.EncounteredError)
            {
                return;
            }

            wixVariableResolver.Localizer = localizer;
            linker.Localizer = localizer;
            binder.Localizer = localizer;

            // Loop through all the believed object files.
            SectionCollection sections = new SectionCollection();
            Output            output   = null;

            foreach (string inputFile in this.commandLine.Files)
            {
                string inputFileFullPath = Path.GetFullPath(inputFile);

                // try loading as an object file
                try
                {
                    Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck, true);
                    sections.AddRange(intermediate.Sections);
                    continue; // next file
                }
                catch (WixNotIntermediateException)
                {
                    // try another format
                }

                // try loading as a library file
                try
                {
                    Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck, true);
                    library.GetLocalizations(this.commandLine.Cultures, localizer);
                    sections.AddRange(library.Sections);
                    continue; // next file
                }
                catch (WixNotLibraryException)
                {
                    // try another format
                }

                // try loading as an output file
                output = Output.Load(inputFileFullPath, this.commandLine.SuppressVersionCheck, true);
            }

            // Stop processing if any errors were found loading object files.
            if (Messaging.Instance.EncounteredError)
            {
                return;
            }

            // and now for the fun part
            if (null == output)
            {
                OutputType expectedOutputType = OutputType.Unknown;
                if (!String.IsNullOrEmpty(this.commandLine.OutputFile))
                {
                    expectedOutputType = Output.GetOutputType(Path.GetExtension(this.commandLine.OutputFile));
                }

                ArrayList transforms = new ArrayList();
                output = linker.Link(sections, transforms, expectedOutputType);

                // If an error occurred during linking, stop processing.
                if (null == output)
                {
                    return;
                }
            }
            else if (0 != sections.Count)
            {
                throw new InvalidOperationException(LightStrings.EXP_CannotLinkObjFilesWithOutpuFile);
            }

            bool tidy = true; // clean up after ourselves by default.

            try
            {
                // only output the xml if its a patch build or user specfied to only output wixout
                string outputFile      = this.commandLine.OutputFile;
                string outputExtension = Path.GetExtension(outputFile);
                if (this.commandLine.OutputXml || OutputType.Patch == output.Type)
                {
                    if (String.IsNullOrEmpty(outputExtension) || outputExtension.Equals(".wix", StringComparison.Ordinal))
                    {
                        outputExtension = (OutputType.Patch == output.Type) ? ".wixmsp" : ".wixout";
                        outputFile      = Path.ChangeExtension(outputFile, outputExtension);
                    }

                    output.Save(outputFile, null, wixVariableResolver, binder.TempFilesLocation);
                }
                else // finish creating the MSI/MSM
                {
                    if (String.IsNullOrEmpty(outputExtension) || outputExtension.Equals(".wix", StringComparison.Ordinal))
                    {
                        outputExtension = Output.GetExtension(output.Type);
                        outputFile      = Path.ChangeExtension(outputFile, outputExtension);
                    }

                    binder.Bind(output, outputFile);
                }
            }
            catch (WixException we) // keep files around for debugging IDT issues.
            {
                if (we is WixInvalidIdtException)
                {
                    tidy = false;
                }

                throw;
            }
            catch (Exception) // keep files around for debugging unexpected exceptions.
            {
                tidy = false;
                throw;
            }
            finally
            {
                if (null != binder)
                {
                    binder.Cleanup(tidy);
                }
            }

            return;
        }
Beispiel #24
0
        /// <summary>
        /// Generates the appropriate MSI file for the package.
        /// </summary>
        /// <param name="sourceDoc">WiX document to create MSI from.</param>
        /// <param name="filePath">File path for the RSS feed.</param>
        private void GenerateMsi(XmlDocument sourceDoc, string filePath)
        {
            // Compile
            Compiler compiler = new Compiler();

            compiler.Message += new MessageEventHandler(this.MessageHandler);

            Intermediate intermediate = compiler.Compile(sourceDoc);

            if (intermediate == null)
            {
                return;
            }

            // locate the applib.wixlib
            string assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string applibPath   = Path.Combine(assemblyPath, "applib.wixlib");

            if (!File.Exists(applibPath))
            {
                this.OnMessage(ClickThroughErrors.CannotLoadApplib(applibPath));
                return;
            }

            WixVariableResolver wixVariableResolver = new WixVariableResolver();

            wixVariableResolver.Message += new MessageEventHandler(this.MessageHandler);

            // create the linker
            Linker linker = new Linker();

            linker.Message            += new MessageEventHandler(this.MessageHandler);
            linker.WixVariableResolver = wixVariableResolver;

            // load applib.wixlib
            Library           lowImpactAppLib = Library.Load(applibPath, linker.TableDefinitions, false, false);
            SectionCollection sections        = new SectionCollection();

            sections.AddRange(intermediate.Sections);
            sections.AddRange(lowImpactAppLib.Sections);

            // Link
            Output output = linker.Link(sections);

            if (output == null)
            {
                return;
            }

            Table components = output.Tables["Component"];

            foreach (Row row in components.Rows)
            {
                switch ((string)row[0])
                {
                case "ThisApplicationVersionRegistryKeyComponent":
                    row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}");
                    break;

                case "ThisApplicationCacheFolderComponent":
                    row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}");
                    break;

                case "ThisApplicationShortcutComponent":
                    row[1] = String.Concat("{", Guid.NewGuid().ToString().ToUpper(), "}");
                    break;
                }
            }

            // Bind
            Binder binder = new Binder();

            binder.Extension = new BinderExtension();
            binder.Extension.SourcePaths.Add(Path.GetDirectoryName(filePath));
            binder.Extension.SourcePaths.Add(assemblyPath);
            binder.WixVariableResolver = wixVariableResolver;
            binder.Message            += new MessageEventHandler(this.MessageHandler);
            binder.Bind(output, filePath);

            return;
        }
Beispiel #25
0
        /// <summary>
        /// Generates the appropriate MSI file for the package.
        /// </summary>
        /// <param name="sourceDoc">WiX document to create MSI from.</param>
        /// <param name="outputFile">File path for the MSI file.</param>
        /// <returns>True if generation works, false if anything goes wrong.</returns>
        private bool GenerateMsi(XmlDocument sourceDoc, string outputFile)
        {
            // Create the Compiler.
            Compiler compiler = new Compiler();
            compiler.Message += this.core.MessageEventHandler;

            // Compile the source document.
            Intermediate intermediate = compiler.Compile(sourceDoc);
            if (intermediate == null)
            {
                return false;
            }

            // Create the variable resolver that will be used in the Linker and Binder.
            WixVariableResolver wixVariableResolver = new WixVariableResolver();
            wixVariableResolver.Message += this.core.MessageEventHandler;

            // Create the Linker.
            Linker linker = new Linker();
            linker.Message += this.core.MessageEventHandler;
            linker.WixVariableResolver = wixVariableResolver;

            // Load the isolatedapp.wixlib.
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            Library appLib = LoadLibraryHelper(assembly, "Microsoft.Tools.WindowsInstallerXml.Extensions.OfficeAddin.Data.OfficeAddin.wixlib", linker.TableDefinitions);

            // Link the compiled source document and the isolatedapp.wixlib together.
            SectionCollection sections = new SectionCollection();
            sections.AddRange(intermediate.Sections);
            sections.AddRange(appLib.Sections);

            Output output = linker.Link(sections);
            if (output == null)
            {
                return false;
            }

            // Tweak the compiled output to add a few GUIDs for Components from the oaddin.wixlib.
            Table components = output.Tables["Component"];
            foreach (Row row in components.Rows)
            {
                switch ((string)row[0])
                {
                    case "ThisApplicationVersionRegistryKeyComponent":
                        row[1] = Guid.NewGuid().ToString("B");
                        break;
                    case "ThisApplicationCacheFolderComponent":
                        row[1] = Guid.NewGuid().ToString("B");
                        break;
                    case "ThisApplicationShortcutComponent":
                        row[1] = Guid.NewGuid().ToString("B");
                        break;
                }
            }

            // Bind the final output.
            Binder binder = new Binder();
            binder.FileManager = new BinderFileManager();
            binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(outputFile));
            binder.FileManager.SourcePaths.Add(this.source);
            binder.FileManager.SourcePaths.Add(Path.GetDirectoryName(assembly.Location));
            binder.Message += this.core.MessageEventHandler;
            binder.WixVariableResolver = wixVariableResolver;
            return binder.Bind(output, outputFile);
        }
Beispiel #26
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            Linker            linker     = null;
            Localizer         localizer  = null;
            SectionCollection sections   = new SectionCollection();
            ArrayList         transforms = new ArrayList();

            try
            {
                // parse the command line
                this.ParseCommandLine(args);

                // load any extensions
                List <WixExtension> loadedExtensionList = new List <WixExtension>();
                foreach (string extension in this.extensionList)
                {
                    WixExtension wixExtension = WixExtension.Load(extension);
                    loadedExtensionList.Add(wixExtension);

                    // If the extension provides a binder, use that now if it
                    // matches the class from the command line.
                    if (null != wixExtension.CustomBinder && null != this.binderClass && wixExtension.CustomBinder.GetType().Name.Equals(this.binderClass, StringComparison.Ordinal))
                    {
                        this.binder = wixExtension.CustomBinder;
                    }
                }

                // If a binder was specified, but not found then show an error.
                if (!String.IsNullOrEmpty(this.binderClass) && null == this.binder)
                {
                    throw new WixException(WixErrors.SpecifiedBinderNotFound(this.binderClass));
                }

                // create the linker, binder, and validator
                linker = new Linker();
                if (null == this.binder)
                {
                    this.binder = new Microsoft.Tools.WindowsInstallerXml.Binder();
                }

                // have the binder parse the command line arguments light did not recognize
                string[] unparsedArgsArray = new string[this.unparsedArgs.Count];
                this.unparsedArgs.CopyTo(unparsedArgsArray, 0);
                StringCollection remainingArgs = this.binder.ParseCommandLine(unparsedArgsArray, this.messageHandler);

                // Loop through the extensions to give them a shot at processing the remaining command-line args.
                foreach (WixExtension wixExtension in loadedExtensionList)
                {
                    if (0 == remainingArgs.Count)
                    {
                        break;
                    }

                    remainingArgs = wixExtension.ParseCommandLine(remainingArgs, this.messageHandler);
                }

                this.ParseCommandLinePassTwo(remainingArgs);

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                foreach (string parameter in this.invalidArgs)
                {
                    this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter));
                }

                this.invalidArgs = null;

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                if (0 == this.inputFiles.Count)
                {
                    this.showHelp = true;
                }
                else if (null == this.outputFile)
                {
                    if (1 < this.inputFiles.Count)
                    {
                        throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput());
                    }

                    this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wix"); // we'll let the linker change the extension later
                }

                this.binder.OutputFile = this.outputFile;
                this.binder.PostParseCommandLine();

                if (this.showLogo)
                {
                    AppCommon.DisplayToolHeader();
                }

                if (this.showHelp)
                {
                    this.PrintHelp();
                    AppCommon.DisplayToolFooter();
                    return(this.messageHandler.LastErrorNumber);
                }

                linker.AllowIdenticalRows         = this.allowIdenticalRows;
                linker.AllowDuplicateDirectoryIds = this.allowDuplicateDirectoryIds;
                linker.AllowUnresolvedReferences  = this.allowUnresolvedReferences;
                linker.Cultures = this.cultures;
                linker.UnreferencedSymbolsFile  = this.unreferencedSymbolsFile;
                linker.ShowPedanticMessages     = this.showPedanticMessages;
                linker.DropUnrealTables         = this.dropUnrealTables;
                linker.SuppressLocalization     = this.suppressLocalization;
                linker.SuppressMsiAssemblyTable = this.suppressMsiAssemblyTable;
                linker.WixVariableResolver      = this.wixVariableResolver;

                // set the sequence suppression options
                linker.SuppressAdminSequence     = this.suppressAdminSequence;
                linker.SuppressAdvertiseSequence = this.suppressAdvertiseSequence;
                linker.SuppressUISequence        = this.suppressUISequence;

                linker.SectionIdOnRows = this.sectionIdOnRows;

                this.binder.TempFilesLocation   = Environment.GetEnvironmentVariable("WIX_TEMP");
                this.binder.WixVariableResolver = this.wixVariableResolver;

                if (null != this.bindPaths)
                {
                    foreach (string bindPath in this.bindPaths)
                    {
                        if (-1 == bindPath.IndexOf('='))
                        {
                            this.sourcePaths.Add(bindPath);
                        }
                    }
                }

                // instantiate the localizer and load any localization files
                if (!this.suppressLocalization || 0 < this.localizationFiles.Count || null != this.cultures || !this.outputXml)
                {
                    List <Localization> localizations = new List <Localization>();
                    localizer = new Localizer();

                    localizer.Message += new MessageEventHandler(this.messageHandler.Display);

                    // load each localization file
                    foreach (string localizationFile in this.localizationFiles)
                    {
                        Localization localization = Localization.Load(localizationFile, linker.TableDefinitions, this.suppressSchema);
                        localizations.Add(localization);
                    }

                    if (null != this.cultures)
                    {
                        // add localizations in order specified in cultures
                        foreach (string culture in this.cultures)
                        {
                            foreach (Localization localization in localizations)
                            {
                                if (culture.Equals(localization.Culture, StringComparison.OrdinalIgnoreCase))
                                {
                                    localizer.AddLocalization(localization);
                                }
                            }
                        }
                    }
                    else
                    {
                        bool neutralFound = false;
                        foreach (Localization localization in localizations)
                        {
                            if (0 == localization.Culture.Length)
                            {
                                // if a neutral wxl was provided use it
                                localizer.AddLocalization(localization);
                                neutralFound = true;
                            }
                        }

                        if (!neutralFound)
                        {
                            // cultures wasn't specified and no neutral wxl are available, include all of the files
                            foreach (Localization localization in localizations)
                            {
                                localizer.AddLocalization(localization);
                            }
                        }
                    }

                    // immediately stop processing if any errors were found
                    if (this.messageHandler.EncounteredError)
                    {
                        return(this.messageHandler.LastErrorNumber);
                    }

                    // tell all of the objects about the localizer
                    linker.Localizer      = localizer;
                    this.binder.Localizer = localizer;
                    this.wixVariableResolver.Localizer = localizer;
                }

                // process loaded extensions
                foreach (WixExtension wixExtension in loadedExtensionList)
                {
                    linker.AddExtension(wixExtension);
                    this.binder.AddExtension(wixExtension);

                    // load the extension's localizations
                    Library library = wixExtension.GetLibrary(linker.TableDefinitions);
                    if (null != library)
                    {
                        // load the extension's default culture if it provides one and we don't specify any cultures
                        string[] extensionCultures = this.cultures;
                        if (null == extensionCultures && null != wixExtension.DefaultCulture)
                        {
                            extensionCultures = new string[] { wixExtension.DefaultCulture };
                        }

                        library.GetLocalizations(extensionCultures, localizer);
                    }
                }

                this.binder.ProcessExtensions(loadedExtensionList.ToArray());

                // set the message handlers
                linker.Message += new MessageEventHandler(this.messageHandler.Display);
                this.binder.AddMessageEventHandler(new MessageEventHandler(this.messageHandler.Display));

                Output output = null;

                // loop through all the believed object files
                foreach (string inputFile in this.inputFiles)
                {
                    string dirName           = Path.GetDirectoryName(inputFile);
                    string inputFileFullPath = Path.GetFullPath(inputFile);

                    if (!this.sourcePaths.Contains(dirName))
                    {
                        this.sourcePaths.Add(dirName);
                    }

                    // try loading as an object file
                    try
                    {
                        Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        sections.AddRange(intermediate.Sections);
                        continue; // next file
                    }
                    catch (WixNotIntermediateException)
                    {
                        // try another format
                    }

                    // try loading as a library file
                    try
                    {
                        Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        library.GetLocalizations(this.cultures, localizer);
                        sections.AddRange(library.Sections);
                        continue; // next file
                    }
                    catch (WixNotLibraryException)
                    {
                        // try another format
                    }

                    // try loading as an output file
                    output = Output.Load(inputFileFullPath, this.suppressVersionCheck, this.suppressSchema);
                }

                // immediately stop processing if any errors were found
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                // set the binder file manager information
                foreach (string bindPath in this.bindPaths)
                {
                    //Checking as IndexOf will return 0 if the string value is String.Empty.
                    if (String.IsNullOrEmpty(bindPath))
                    {
                        continue;
                    }

                    if (-1 == bindPath.IndexOf('='))
                    {
                        this.binder.FileManager.BindPaths.Add(bindPath);
                    }
                    else
                    {
                        string[] namedPair = bindPath.Split('=');

                        //It is ok to have duplicate key.
                        this.binder.FileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]);
                    }
                }

                foreach (string sourcePath in this.sourcePaths)
                {
                    this.binder.FileManager.SourcePaths.Add(sourcePath);
                }

                // and now for the fun part
                if (null == output)
                {
                    OutputType expectedOutputType = OutputType.Unknown;
                    if (this.outputFile != null)
                    {
                        expectedOutputType = Output.GetOutputType(Path.GetExtension(this.outputFile));
                    }

                    output = linker.Link(sections, transforms, expectedOutputType);

                    // if an error occurred during linking, stop processing
                    if (null == output)
                    {
                        return(this.messageHandler.LastErrorNumber);
                    }
                }
                else if (0 != sections.Count)
                {
                    throw new InvalidOperationException(LightStrings.EXP_CannotLinkObjFilesWithOutpuFile);
                }

                // Now that the output object is either linked or loaded, tell the binder file manager about it.
                this.binder.FileManager.Output = output;

                // only output the xml if its a patch build or user specfied to only output wixout
                if (this.outputXml || OutputType.Patch == output.Type)
                {
                    string outputExtension = Path.GetExtension(this.outputFile);
                    if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension)
                    {
                        if (OutputType.Patch == output.Type)
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".wixmsp");
                        }
                        else
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".wixout");
                        }
                    }

                    output.Save(this.outputFile, (this.bindFiles ? this.binder.FileManager : null), this.wixVariableResolver, this.binder.TempFilesLocation);
                }
                else // finish creating the MSI/MSM
                {
                    string outputExtension = Path.GetExtension(this.outputFile);
                    if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension)
                    {
                        outputExtension = Output.GetExtension(output.Type);
                        this.outputFile = Path.ChangeExtension(this.outputFile, outputExtension);
                    }

                    this.binder.Bind(output, this.outputFile);
                }
            }
            catch (WixException we)
            {
                if (we is WixInvalidIdtException)
                {
                    // make sure the IDT files stay around
                    this.tidy = false;
                }

                this.messageHandler.Display(this, we.Error);
            }
            catch (Exception e)
            {
                // make sure the files stay around for debugging
                this.tidy = false;

                this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }
            finally
            {
                if (null != binder)
                {
                    this.binder.Cleanup(this.tidy);
                }
            }

            return(this.messageHandler.LastErrorNumber);
        }
Beispiel #27
0
Datei: lit.cs Projekt: zooba/wix3
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            try
            {
                Librarian librarian = null;
                SectionCollection sections = new SectionCollection();

                // parse the command line
                this.ParseCommandLine(args);

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return this.messageHandler.LastErrorNumber;
                }

                if (0 == this.inputFiles.Count)
                {
                    this.showHelp = true;
                }
                else if (null == this.outputFile)
                {
                    if (1 < this.inputFiles.Count)
                    {
                        throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput());
                    }

                    this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wixlib");
                }

                if (this.showLogo)
                {
                    AppCommon.DisplayToolHeader();
                }

                if (this.showHelp)
                {
                    Console.WriteLine(LitStrings.HelpMessage);
                    AppCommon.DisplayToolFooter();
                    return this.messageHandler.LastErrorNumber;
                }

                foreach (string parameter in this.invalidArgs)
                {
                    this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter));
                }
                this.invalidArgs = null;

                // create the librarian
                librarian = new Librarian();
                librarian.Message += new MessageEventHandler(this.messageHandler.Display);
                librarian.ShowPedanticMessages = this.showPedanticMessages;

                if (null != this.bindPaths)
                {
                    foreach (string bindPath in this.bindPaths)
                    {
                        if (-1 == bindPath.IndexOf('='))
                        {
                            this.sourcePaths.Add(bindPath);
                        }
                    }
                }

                // load any extensions
                foreach (string extension in this.extensionList)
                {
                    WixExtension wixExtension = WixExtension.Load(extension);

                    librarian.AddExtension(wixExtension);

                    // load the binder file manager regardless of whether it will be used in case there is a collision
                    if (null != wixExtension.BinderFileManager)
                    {
                        if (null != this.binderFileManager)
                        {
                            throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, LitStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), this.binderFileManager.GetType().ToString()), "ext");
                        }

                        this.binderFileManager = wixExtension.BinderFileManager;
                    }
                }

                // add the sections to the librarian
                foreach (string inputFile in this.inputFiles)
                {
                    string inputFileFullPath = Path.GetFullPath(inputFile);
                    string dirName = Path.GetDirectoryName(inputFileFullPath);

                    if (!this.sourcePaths.Contains(dirName))
                    {
                        this.sourcePaths.Add(dirName);
                    }

                    // try loading as an object file
                    try
                    {
                        Intermediate intermediate = Intermediate.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        sections.AddRange(intermediate.Sections);
                        continue; // next file
                    }
                    catch (WixNotIntermediateException)
                    {
                        // try another format
                    }

                    // try loading as a library file
                    Library loadedLibrary = Library.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                    sections.AddRange(loadedLibrary.Sections);
                }

                // and now for the fun part
                Library library = librarian.Combine(sections);

                // save the library output if an error did not occur
                if (null != library)
                {
                    if (this.bindFiles)
                    {
                        // if the binder file manager has not been loaded yet use the built-in binder extension
                        if (null == this.binderFileManager)
                        {
                            this.binderFileManager = new BinderFileManager();
                        }

                        if (null != this.bindPaths)
                        {
                            foreach (string bindPath in this.bindPaths)
                            {
                                if (-1 == bindPath.IndexOf('='))
                                {
                                    this.binderFileManager.BindPaths.Add(bindPath);
                                }
                                else
                                {
                                    string[] namedPair = bindPath.Split('=');

                                    //It is ok to have duplicate key.
                                    this.binderFileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]);
                                }
                            }
                        }

                        foreach (string sourcePath in this.sourcePaths)
                        {
                            this.binderFileManager.SourcePaths.Add(sourcePath);
                        }
                    }
                    else
                    {
                        this.binderFileManager = null;
                    }

                    foreach (string localizationFile in this.localizationFiles)
                    {
                        Localization localization = Localization.Load(localizationFile, librarian.TableDefinitions, this.suppressSchema);

                        library.AddLocalization(localization);
                    }

                    WixVariableResolver wixVariableResolver = new WixVariableResolver();

                    wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display);

                    library.Save(this.outputFile, this.binderFileManager, wixVariableResolver);
                }
            }
            catch (WixException we)
            {
                this.messageHandler.Display(this, we.Error);
            }
            catch (Exception e)
            {
                this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }

            return this.messageHandler.LastErrorNumber;
        }
Beispiel #28
0
 public virtual void VisitSectionCollection(SectionCollection coll)
 {
 }
 public virtual void VisitSectionCollection(SectionCollection coll)
 {
 }
Beispiel #30
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            Microsoft.Tools.WindowsInstallerXml.Binder binder = null;
            Linker            linker     = null;
            Localizer         localizer  = null;
            SectionCollection sections   = new SectionCollection();
            ArrayList         transforms = new ArrayList();

            try
            {
                // parse the command line
                this.ParseCommandLine(args);

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                if (0 == this.inputFiles.Count)
                {
                    this.showHelp = true;
                }
                else if (null == this.outputFile)
                {
                    if (1 < this.inputFiles.Count)
                    {
                        throw new ArgumentException("must specify output file when using more than one input file", "-out");
                    }

                    this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wix"); // we'll let the linker change the extension later
                }

                if (this.showLogo)
                {
                    Assembly lightAssembly = Assembly.GetExecutingAssembly();

                    Console.WriteLine("Microsoft (R) Windows Installer Xml Linker version {0}", lightAssembly.GetName().Version.ToString());
                    Console.WriteLine("Copyright (C) Microsoft Corporation 2003. All rights reserved.");
                    Console.WriteLine();
                }

                if (this.showHelp)
                {
                    Console.WriteLine(" usage:  light.exe [-?] [-b basePath] [-nologo] [-out outputFile] objectFile [objectFile ...]");
                    Console.WriteLine();
                    Console.WriteLine("   -ai        allow identical rows, identical rows will be treated as a warning");
                    Console.WriteLine("   -au        (experimental) allow unresolved references, will not create a valid output");
                    Console.WriteLine("   -b         base path to locate all files (default: current directory)");
                    Console.WriteLine("   -bf        bind files into a wixout (only valid with -xo option)");
                    Console.WriteLine("   -cc        path to cache built cabinets (will not be deleted after linking)");
                    Console.WriteLine("   -ct <N>    number of threads to use when creating cabinets (default: %NUMBER_OF_PROCESSORS%)");
                    Console.WriteLine("   -cultures:<cultures>  semicolon-delimited list of localized string cultures to load from libraries");
                    Console.WriteLine("   -cub       additional .cub file containing ICEs to run");
                    Console.WriteLine("   -d<name>=<value>  define a wix variable");
                    Console.WriteLine("   -ext       extension assembly or \"class, assembly\"");
                    Console.WriteLine("   -fv        add a 'fileVersion' entry to the MsiAssemblyName table (rarely needed)");
                    Console.WriteLine("   -loc <loc.wxl>  read localization strings from .wxl file");
                    Console.WriteLine("   -nologo    skip printing light logo information");
                    Console.WriteLine("   -notidy    do not delete temporary files (useful for debugging)");
                    Console.WriteLine("   -out       specify output file (default: write to current directory)");
                    Console.WriteLine("   -pedantic  show pedantic messages");
                    Console.WriteLine("   -reusecab  reuse cabinets from cabinet cache");
                    Console.WriteLine("   -sa        suppress assemblies: do not get assembly name information for assemblies");
                    Console.WriteLine("   -sacl      suppress resetting ACLs (useful when laying out image to a network share)");
                    Console.WriteLine("   -sadmin    suppress default admin sequence actions");
                    Console.WriteLine("   -sadv      suppress default adv sequence actions");
                    Console.WriteLine("   -sdut      suppress dropping unreal tables to the output image (default with -xo)");
                    Console.WriteLine("   -sice:<ICE>  suppress an internal consistency evaluator (ICE)");
                    Console.WriteLine("   -sma       suppress processing the data in MsiAssembly table");
                    Console.WriteLine("   -sf        suppress files: do not get any file information (equivalent to -sa and -sh)");
                    Console.WriteLine("   -sh        suppress file info: do not get hash, version, language, etc");
                    Console.WriteLine("   -sl        suppress layout");
                    Console.WriteLine("   -ss        suppress schema validation of documents (performance boost)");
                    Console.WriteLine("   -sui       suppress default UI sequence actions");
                    Console.WriteLine("   -sv        suppress intermediate file version mismatch checking");
                    Console.WriteLine("   -sval      suppress MSI/MSM validation");
                    Console.WriteLine("   -sw<N>     suppress warning with specific message ID");
                    Console.WriteLine("   -ts        tag sectionId attribute on rows (default with -xo)");
                    Console.WriteLine("   -tsa       tag sectionId attribute on rows, generating when null (default with -xo)");
                    Console.WriteLine("   -usf <output.xml>  unreferenced symbols file");
                    Console.WriteLine("   -v         verbose output");
                    Console.WriteLine("   -wx        treat warnings as errors");
                    Console.WriteLine("   -xo        output xml instead of MSI format");
                    Console.WriteLine("   -?         this help information");
                    Console.WriteLine();
                    Console.WriteLine("Environment variables:");
                    Console.WriteLine("   WIX_TEMP   overrides the temporary directory used for cab creation, msm exploding, ...");
                    Console.WriteLine();
                    Console.WriteLine("Common extensions:");
                    Console.WriteLine("   .wxi    - Windows installer Xml Include file");
                    Console.WriteLine("   .wxl    - Windows installer Xml Localization file");
                    Console.WriteLine("   .wxs    - Windows installer Xml Source file");
                    Console.WriteLine("   .wixlib - Windows installer Xml Library file (in XML format)");
                    Console.WriteLine("   .wixobj - Windows installer Xml Object file (in XML format)");
                    Console.WriteLine("   .wixout - Windows installer Xml Output file (in XML format)");
                    Console.WriteLine();
                    Console.WriteLine("   .msi - Windows installer Product Database");
                    Console.WriteLine("   .msm - Windows installer Merge Module");
                    Console.WriteLine("   .msp - Windows installer Patch");
                    Console.WriteLine("   .mst - Windows installer Transform");
                    Console.WriteLine("   .pcp - Windows installer Patch Creation Package");
                    Console.WriteLine();
                    Console.WriteLine("For more information see: http://wix.sourceforge.net");

                    return(this.messageHandler.LastErrorNumber);
                }

                // create the linker, binder, and validator
                linker = new Linker();
                binder = new Microsoft.Tools.WindowsInstallerXml.Binder();

                linker.AllowIdenticalRows        = this.allowIdenticalRows;
                linker.AllowUnresolvedReferences = this.allowUnresolvedReferences;
                linker.Cultures = this.cultures;
                linker.UnreferencedSymbolsFile      = this.unreferencedSymbolsFile;
                linker.ShowPedanticMessages         = this.showPedanticMessages;
                linker.SuppressDroppingUnrealTables = this.suppressDroppingUnrealTables;
                linker.SuppressMsiAssemblyTable     = this.suppressMsiAssemblyTable;
                linker.WixVariableResolver          = this.wixVariableResolver;

                // set the sequence suppression options
                linker.SuppressAdminSequence     = this.suppressAdminSequence;
                linker.SuppressAdvertiseSequence = this.suppressAdvertiseSequence;
                linker.SuppressUISequence        = this.suppressUISequence;

                linker.SectionIdOnRows    = this.sectionIdOnRows;
                linker.GenerateSectionIds = this.generateSectionIds;

                // default the number of cabbing threads to the number of processors if it wasn't specified
                if (0 == this.cabbingThreadCount)
                {
                    string numberOfProcessors = System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");

                    try
                    {
                        if (null != numberOfProcessors)
                        {
                            this.cabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat);

                            if (0 >= this.cabbingThreadCount)
                            {
                                throw new WixException(WixErrors.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
                            }
                        }
                        else // default to 1 if the environment variable is not set
                        {
                            this.cabbingThreadCount = 1;
                        }
                    }
                    catch (ArgumentException)
                    {
                        throw new WixException(WixErrors.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
                    }
                    catch (FormatException)
                    {
                        throw new WixException(WixErrors.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
                    }
                }
                binder.CabbingThreadCount = this.cabbingThreadCount;

                binder.SuppressAclReset = this.suppressAclReset;
                binder.SetMsiAssemblyNameFileVersion = this.setMsiAssemblyNameFileVersion;
                binder.SuppressAssemblies            = this.suppressAssemblies;
                binder.SuppressFileHashAndInfo       = this.suppressFileHashAndInfo;

                if (this.suppressFiles)
                {
                    binder.SuppressAssemblies      = true;
                    binder.SuppressFileHashAndInfo = true;
                }

                binder.SuppressLayout      = this.suppressLayout;
                binder.TempFilesLocation   = Environment.GetEnvironmentVariable("WIX_TEMP");
                binder.WixVariableResolver = this.wixVariableResolver;

                validator.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP");

                if (null != this.cabCachePath || this.reuseCabinets)
                {
                    // ensure the cabinet cache path exists if we are going to use it
                    if (null != this.cabCachePath && !Directory.Exists(this.cabCachePath))
                    {
                        Directory.CreateDirectory(this.cabCachePath);
                    }
                }

                if (null != this.basePaths)
                {
                    foreach (string basePath in this.basePaths)
                    {
                        this.sourcePaths.Add(basePath);
                    }
                }

                // load any extensions
                bool binderExtensionLoaded    = false;
                bool validatorExtensionLoaded = false;
                foreach (string extension in this.extensionList)
                {
                    WixExtension wixExtension = WixExtension.Load(extension);

                    linker.AddExtension(wixExtension);

                    if (null != wixExtension.BinderExtension)
                    {
                        if (binderExtensionLoaded)
                        {
                            throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "cannot load binder extension: {0}.  light can only load one binder extension and has already loaded binder extension: {1}.", wixExtension.BinderExtension.GetType().ToString(), binder.Extension.ToString()), "ext");
                        }

                        binder.Extension      = wixExtension.BinderExtension;
                        binderExtensionLoaded = true;
                    }

                    ValidatorExtension validatorExtension = wixExtension.ValidatorExtension;
                    if (null != validatorExtension)
                    {
                        if (validatorExtensionLoaded)
                        {
                            throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "cannot load linker extension: {0}.  light can only load one link extension and has already loaded link extension: {1}.", validatorExtension.GetType().ToString(), validator.Extension.ToString()), "ext");
                        }

                        validator.Extension      = validatorExtension;
                        validatorExtensionLoaded = true;
                    }
                }

                // set the message handlers
                linker.Message += new MessageEventHandler(this.messageHandler.Display);
                binder.Message += new MessageEventHandler(this.messageHandler.Display);
                validator.Extension.Message += new MessageEventHandler(this.messageHandler.Display);

                Output output = null;

                // instantiate the localizer and load any localization files
                if (0 < this.localizationFiles.Count || null != this.cultures || !this.outputXml)
                {
                    localizer = new Localizer();

                    localizer.Message += new MessageEventHandler(this.messageHandler.Display);

                    // load each localization file
                    foreach (string localizationFile in this.localizationFiles)
                    {
                        Localization localization = Localization.Load(localizationFile, linker.TableDefinitions, this.suppressSchema);

                        localizer.AddLocalization(localization);
                    }

                    // immediately stop processing if any errors were found
                    if (this.messageHandler.EncounteredError)
                    {
                        return(this.messageHandler.LastErrorNumber);
                    }
                }

                // loop through all the believed object files
                foreach (string inputFile in this.inputFiles)
                {
                    string dirName           = Path.GetDirectoryName(inputFile);
                    string inputFileFullPath = Path.GetFullPath(inputFile);

                    if (!this.sourcePaths.Contains(dirName))
                    {
                        this.sourcePaths.Add(dirName);
                    }

                    // try loading as an object file
                    try
                    {
                        Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        sections.AddRange(intermediate.Sections);
                        continue; // next file
                    }
                    catch (WixNotIntermediateException)
                    {
                        // try another format
                    }

                    // try loading as a library file
                    try
                    {
                        Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema);
                        sections.AddRange(library.Sections);

                        // load the localization files for the selected cultures
                        if (null != this.cultures)
                        {
                            Localization localization = library.GetLocalization(this.cultures);

                            if (null != localization)
                            {
                                localizer.AddLocalization(localization);
                            }
                        }

                        continue; // next file
                    }
                    catch (WixNotLibraryException)
                    {
                        // try another format
                    }

                    // try loading as an output file
                    output = Output.Load(inputFileFullPath, this.suppressVersionCheck, this.suppressSchema);
                }

                // immediately stop processing if any errors were found
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                // set the binder extension information
                foreach (string basePath in this.basePaths)
                {
                    binder.Extension.BasePaths.Add(basePath);
                }
                binder.Extension.CabCachePath  = this.cabCachePath;
                binder.Extension.ReuseCabinets = this.reuseCabinets;
                foreach (string sourcePath in this.sourcePaths)
                {
                    binder.Extension.SourcePaths.Add(sourcePath);
                }

                // and now for the fun part
                if (null == output)
                {
                    // tell the linker about the localizer
                    linker.Localizer = localizer;
                    localizer        = null;

                    output = linker.Link(sections, transforms);

                    // if an error occurred during linking, stop processing
                    if (null == output)
                    {
                        return(this.messageHandler.LastErrorNumber);
                    }
                }
                else if (0 != sections.Count)
                {
                    throw new InvalidOperationException("Cannot link object files (.wixobj) files with an output file (.wixout)");
                }

                // Now that the output object is either linked or loaded, tell the binder extension about it.
                binder.Extension.Output = output;

                // only output the xml if its a patch build or user specfied to only output wixout
                if (this.outputXml || OutputType.Patch == output.Type)
                {
                    string outputExtension = Path.GetExtension(this.outputFile);
                    if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension)
                    {
                        if (OutputType.Patch == output.Type)
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".wixmsp");
                        }
                        else
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".wixout");
                        }
                    }
                    output.Save(this.outputFile, (this.bindFiles ? binder.Extension : null), this.wixVariableResolver, binder.TempFilesLocation);
                }
                else // finish creating the MSI/MSM
                {
                    string outputExtension = Path.GetExtension(this.outputFile);
                    if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension)
                    {
                        if (OutputType.Module == output.Type)
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".msm");
                        }
                        else if (OutputType.PatchCreation == output.Type)
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".pcp");
                        }
                        else
                        {
                            this.outputFile = Path.ChangeExtension(this.outputFile, ".msi");
                        }
                    }

                    // tell the binder about the localizer
                    binder.Localizer = localizer;

                    // tell the binder about the validator if validation isn't suppressed
                    if (!this.suppressValidation && (OutputType.Module == output.Type || OutputType.Product == output.Type))
                    {
                        // set the default cube file
                        Assembly lightAssembly  = Assembly.GetExecutingAssembly();
                        string   lightDirectory = Path.GetDirectoryName(lightAssembly.Location);
                        if (OutputType.Module == output.Type)
                        {
                            validator.AddCubeFile(Path.Combine(lightDirectory, "mergemod.cub"));
                        }
                        else // product
                        {
                            validator.AddCubeFile(Path.Combine(lightDirectory, "darice.cub"));
                        }

                        // disable ICE33 by default
                        this.suppressICEs.Add("ICE33");

                        // set the suppressed ICEs
                        string[] suppressICEArray = new string[this.suppressICEs.Count];
                        this.suppressICEs.CopyTo(suppressICEArray, 0);
                        validator.SuppressedICEs = suppressICEArray;

                        binder.Validator = validator;
                    }

                    binder.Bind(output, this.outputFile);
                }
            }
            catch (WixException we)
            {
                if (we is WixInvalidIdtException)
                {
                    // make sure the IDT files stay around
                    this.tidy = false;
                }

                this.messageHandler.Display(this, we.Error);
            }
            catch (Exception e)
            {
                // make sure the files stay around for debugging
                this.tidy = false;

                this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }
            finally
            {
                if (null != binder)
                {
                    if (this.tidy)
                    {
                        if (!binder.DeleteTempFiles())
                        {
                            Console.WriteLine("Warning, failed to delete temporary directory: {0}", binder.TempFilesLocation);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Binder temporary directory located at '{0}'.", binder.TempFilesLocation);
                    }
                }

                if (null != validator)
                {
                    if (this.tidy)
                    {
                        if (!validator.DeleteTempFiles())
                        {
                            Console.WriteLine("Warning, failed to delete temporary directory: {0}", validator.TempFilesLocation);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Validator temporary directory located at '{0}'.", validator.TempFilesLocation);
                    }
                }
            }

            return(this.messageHandler.LastErrorNumber);
        }