Exemple #1
0
        /// <summary>
        /// Load sections from the input files.
        /// </summary>
        /// <returns>Returns a section collection.</returns>
        private Dictionary <Section, string> LoadFragments()
        {
            // we need a Linker and the extensions for their table definitions
            Linker linker = new Linker();

            if (null != this.extensionList)
            {
                ExtensionManager extensionManager = new ExtensionManager();
                foreach (string extension in this.extensionList)
                {
                    extensionManager.Load(extension);
                }

                foreach (IExtensionData data in extensionManager.Create <IExtensionData>())
                {
                    linker.AddExtensionData(data);
                }
            }

            // load each intermediate and library file and get their sections
            Dictionary <Section, string> sectionFiles = new Dictionary <Section, string>();

            if (null != this.inputFiles)
            {
                foreach (string inputFile in this.inputFiles)
                {
                    string inputFileFullPath = Path.GetFullPath(inputFile);
                    if (File.Exists(inputFileFullPath))
                    {
                        FileFormat format = FileStructure.GuessFileFormatFromExtension(Path.GetExtension(inputFileFullPath));
                        bool       retry;
                        do
                        {
                            retry = false;

                            try
                            {
                                switch (format)
                                {
                                case FileFormat.Wixobj:
                                    Intermediate intermediate = Intermediate.Load(inputFile, linker.TableDefinitions, false);
                                    Generator.LoadSections(inputFile, sectionFiles, intermediate.Sections);
                                    break;

                                default:
                                    Library library = Library.Load(inputFile, linker.TableDefinitions, false);
                                    Generator.LoadSections(inputFile, sectionFiles, library.Sections);
                                    break;
                                }
                            }
                            catch (WixUnexpectedFileFormatException e)
                            {
                                format = e.FileFormat;
                                retry  = (FileFormat.Wixobj != format && FileFormat.Wixlib != format); // .wixobj and .wixout are supported by lux.
                                if (!retry)
                                {
                                    this.OnMessage(LuxBuildErrors.CouldntLoadInput(inputFile));
                                }
                            }
                        } while (retry);
                    }
                }
            }

            return(sectionFiles);
        }
Exemple #2
0
        private void Run(IMessaging messaging)
        {
#if false
            // 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.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;
            if (this.commandLine.DefaultCompressionLevel.HasValue)
            {
                binder.DefaultCompressionLevel = this.commandLine.DefaultCompressionLevel.Value;
            }
            binder.Ices.AddRange(this.commandLine.Ices);
            binder.SuppressIces.AddRange(this.commandLine.SuppressIces);
            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   = AppCommon.GetTempLocation();
            binder.WixVariableResolver = wixVariableResolver;

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

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

            // Initialize the localizer.
            Localizer localizer = this.InitializeLocalization(linker.TableDefinitions);
            if (messaging.EncounteredError)
            {
                return;
            }

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

            // Loop through all the believed object files.
            List <Section> sections = new List <Section>();
            Output         output   = null;
            foreach (string inputFile in this.commandLine.Files)
            {
                string     inputFileFullPath = Path.GetFullPath(inputFile);
                FileFormat format            = FileStructure.GuessFileFormatFromExtension(Path.GetExtension(inputFileFullPath));
                bool       retry;
                do
                {
                    retry = false;

                    try
                    {
                        switch (format)
                        {
                        case FileFormat.Wixobj:
                            Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck);
                            sections.AddRange(intermediate.Sections);
                            break;

                        case FileFormat.Wixlib:
                            Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.commandLine.SuppressVersionCheck);
                            AddLibraryLocalizationsToLocalizer(library, this.commandLine.Cultures, localizer);
                            sections.AddRange(library.Sections);
                            break;

                        default:
                            output = Output.Load(inputFileFullPath, this.commandLine.SuppressVersionCheck);
                            break;
                        }
                    }
                    catch (WixUnexpectedFileFormatException e)
                    {
                        format = e.FileFormat;
                        retry  = (FileFormat.Wixobj == format || FileFormat.Wixlib == format || FileFormat.Wixout == format); // .wixobj, .wixout and .wixout are supported by light.
                        if (!retry)
                        {
                            messaging.OnMessage(e.Error);
                        }
                    }
                } while (retry);
            }

            // Stop processing if any errors were found loading object files.
            if (messaging.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));
                }

                output = linker.Link(sections, 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);
                }
                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;
#endif
        }
Exemple #3
0
        /// <summary>
        /// Create the library.
        /// </summary>
        private void Run()
        {
            // Create the librarian and add the extension data.
            Librarian librarian = new Librarian();

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

            // Add the sections to the librarian
            List <Section> sections = new List <Section>();

            foreach (string file in this.commandLine.Files)
            {
                string     inputFile = Path.GetFullPath(file);
                FileFormat format    = FileStructure.GuessFileFormatFromExtension(Path.GetExtension(inputFile));
                bool       retry;
                do
                {
                    retry = false;

                    try
                    {
                        switch (format)
                        {
                        case FileFormat.Wixobj:
                            Intermediate intermediate = Intermediate.Load(inputFile, librarian.TableDefinitions, this.commandLine.SuppressVersionCheck);
                            sections.AddRange(intermediate.Sections);
                            break;

                        default:
                            Library loadedLibrary = Library.Load(inputFile, librarian.TableDefinitions, this.commandLine.SuppressVersionCheck);
                            sections.AddRange(loadedLibrary.Sections);
                            break;
                        }
                    }
                    catch (WixUnexpectedFileFormatException e)
                    {
                        format = e.FileFormat;
                        retry  = (FileFormat.Wixobj == format || FileFormat.Wixlib == format); // .wixobj and .wixout are supported by lit.
                        if (!retry)
                        {
                            Messaging.Instance.OnMessage(e.Error);
                        }
                    }
                } while (retry);
            }

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

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

            // Add any localization files and save the library output if an error did not occur
            if (null != library)
            {
                foreach (string localizationFile in this.commandLine.LocalizationFiles)
                {
                    Localization localization = Localizer.ParseLocalizationFile(localizationFile, librarian.TableDefinitions);
                    if (null != localization)
                    {
                        library.AddLocalization(localization);
                    }
                }

                // If there was an error adding localization files, then bail.
                if (Messaging.Instance.EncounteredError)
                {
                    return;
                }

                LibraryBinaryFileResolver resolver = null;
                if (this.commandLine.BindFiles)
                {
                    resolver = new LibraryBinaryFileResolver();
                    resolver.FileManagers     = this.fileManagers;
                    resolver.VariableResolver = new WixVariableResolver();

                    BinderFileManagerCore core = new BinderFileManagerCore();
                    core.AddBindPaths(this.commandLine.BindPaths, BindStage.Normal);

                    foreach (IBinderFileManager fileManager in resolver.FileManagers)
                    {
                        fileManager.Core = core;
                    }
                }

                library.Save(this.commandLine.OutputFile, resolver);
            }
        }