Пример #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();

            linker.Message += new MessageEventHandler(this.Message);

            if (null != this.extensionList)
            {
                foreach (string extension in this.extensionList)
                {
                    WixExtension wixExtension = WixExtension.Load(extension);
                    linker.AddExtension(wixExtension);
                }
            }

            // 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))
                    {
                        // try loading as an object file
                        try
                        {
                            Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, false, false);
                            Generator.LoadSections(inputFile, sectionFiles, intermediate.Sections);
                            continue; // next file
                        }
                        catch (WixNotIntermediateException)
                        {
                            // try another format
                        }

                        // try loading as a library file
                        try
                        {
                            Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, false, false);
                            Generator.LoadSections(inputFile, sectionFiles, library.Sections);
                            continue; // next file
                        }
                        catch (WixNotLibraryException)
                        {
                            this.OnMessage(LuxBuildErrors.CouldntLoadInput(inputFile));
                        }
                    }
                }
            }

            return(sectionFiles);
        }
Пример #2
0
        /// <summary>
        /// Scan the input files for unit tests and, if specified, generate a test package source file.
        /// </summary>
        /// <returns>True if successful or False if there were no unit tests in the input files or a test package couldn't be created.</returns>
        public bool Generate()
        {
            // get the unit tests included in all the objects
            var unitTestIds = this.FindUnitTests();

            if (!unitTestIds.Any())
            {
                this.OnMessage(LuxBuildErrors.NoUnitTests());
                return(false);
            }

            // and write the WiX source that consumes them all
            if (!String.IsNullOrEmpty(this.outputFile))
            {
                this.GenerateTestSource(unitTestIds);
            }

            return(true);
        }
Пример #3
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);
        }
Пример #4
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
            {
                // 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 (this.showLogo)
                {
                    AppCommon.DisplayToolHeader();
                }

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

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

                this.invalidArgs = null;

                // gotta have something to do
                if (0 == this.inputFiles.Count || String.IsNullOrEmpty(this.outputFile))
                {
                    Console.WriteLine(LuxStrings.HelpMessage);
                    this.messageHandler.Display(this, LuxBuildErrors.MalfunctionNeedInput());
                    return(this.messageHandler.LastErrorNumber);
                }

                if (String.IsNullOrEmpty(Path.GetExtension(this.outputFile)))
                {
                    this.outputFile = Path.ChangeExtension(this.outputFile, ".wxs");
                }

                // get extensions from lux.exe.config
                AppCommon.ReadConfiguration(this.extensionList);

                List <string> inputFragments = new List <string>();
                Generator.Generate(this.extensionList, this.inputFiles, this.outputFile, this.messageHandler.Display, out inputFragments);
            }
            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);
        }
Пример #5
0
        /// <summary>
        /// Load sections from the input files.
        /// </summary>
        /// <returns>Returns a section collection.</returns>
        private Dictionary <Section, string> LoadSections()
        {
            // 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))
                    {
                        // try loading as an object file
                        try
                        {
                            Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, false, false);
                            foreach (Section section in intermediate.Sections)
                            {
                                sectionFiles[section] = inputFile;
                            }
                            continue; // next file
                        }
                        catch (WixNotIntermediateException)
                        {
                            // try another format
                        }

                        // try loading as a library file
                        try
                        {
                            Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, false, false);
                            foreach (Section section in library.Sections)
                            {
                                sectionFiles[section] = inputFile;
                            }
                            continue; // next file
                        }
                        catch (WixNotLibraryException)
                        {
                            this.OnMessage(LuxBuildErrors.CouldntLoadInput(inputFile));
                        }
                    }
                }
            }

            return(sectionFiles);
        }