Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            Messaging   messaging = new Messaging();
            CommandLine commandline;

            if (!CommandLine.TryParseArguments(args, messaging, out commandline))
            {
                return(1);
            }

            if (commandline.Help)
            {
                SimplifiedWixCompiler.ShowLogo();
                SimplifiedWixCompiler.ShowHelp();
                return(0);
            }

            if (!commandline.NoLogo)
            {
                SimplifiedWixCompiler.ShowLogo();
            }

            SimplifiedWixCompiler self = new SimplifiedWixCompiler();

            self.Architecture        = commandline.Architecture;
            self.Extensions          = commandline.Extensions.ToArray();
            self.Languages           = commandline.Languages.ToArray();
            self.Type                = commandline.Type;
            self.PreprocessorDefines = commandline.PreprocessorDefines.ToArray();
            self.SourcePaths         = commandline.Files.ToArray();
            self.SearchPaths         = commandline.SearchPaths.ToArray();
            self.OutputPath          = commandline.Output;

            return(self.Run(messaging) ? 0 : -1);
        }
Exemplo n.º 2
0
        private bool Run(Messaging messaging)
        {
            if (this.SourcePaths.Length == 0)
            {
                messaging.OnError(null, "No inputs specified. Specify at least one file.");
            }

            if (String.IsNullOrEmpty(this.Type))
            {
                if (this.OutputPath == null)
                {
                    messaging.OnError(this, "Package type cannot be inferred from output path. Explicitly specify PackageType in your MSBuild project or -type from the swc.exe command-line. Valid options are: appx, msi, vsix, or wixlib");
                }
                else
                {
                    this.Type = Path.GetExtension(this.OutputPath.ItemSpec);
                }
            }
            else if (this.OutputPath == null && this.SourcePaths.Length > 0)
            {
                string outputPath = Path.ChangeExtension(this.SourcePaths[0].ItemSpec, this.Type.ToLowerInvariant());
                this.OutputPath = new FilePathTaskItem(outputPath);
            }

            PackageArchitecture architecture = PackageArchitecture.Unknown;

            if (String.IsNullOrEmpty(this.Architecture))
            {
                messaging.OnError(this, "A package architecture must specified. Set the PackageArchitecture in your MSBuild project or -arch from the swc.exe command-line. Valid options are: arm, x64, x86 or neutral");
            }
            else if (!SimplifiedWixCompiler.TryConvertPackageArchitecture(this.Architecture, out architecture))
            {
                messaging.OnError(this, "Unknown architecture specified: {0}. Valid options are: arm, x64, x86 or neutral", this.Architecture);
            }

            List <CultureInfo> locales = new List <CultureInfo>();

            if (this.Languages != null)
            {
                foreach (string language in this.Languages)
                {
                    try
                    {
                        CultureInfo locale;

                        int lcid = 0;
                        if (Int32.TryParse(language, out lcid))
                        {
                            locale = new CultureInfo(lcid);
                        }
                        else
                        {
                            locale = new CultureInfo(language);
                        }

                        locales.Add(locale);
                    }
                    catch (CultureNotFoundException)
                    {
                        messaging.OnError(this, "Unknown language: {0}", language);
                    }
                }
            }

            PackageType type = PackageType.Unknown;

            if (String.IsNullOrEmpty(this.Type))
            {
                messaging.OnError(this, "A package type must specified. Use the PackageType in your MSBuild project or -type from the swc.exe command-line. Valid options are: appx, msi, vsix or wixlib");
            }
            else if (!SimplifiedWixCompiler.TryConvertPackageType(this.Type, out type))
            {
                messaging.OnError(this, "Unknown package type specified: {0}. Valid options are: appx, msi, vsix or wixlib", this.Type);
            }

            if (type == PackageType.Appx && locales.Count == 0)
            {
                messaging.OnError(this, "AppX packages do not support language neutral packages. At least one language to be specified. Use the PackageLanguages property in your MSBuild project or -lang from the swc.exe command-line.");
            }

            if (!messaging.Errored)
            {
                SimplifiedCompiler compiler = new SimplifiedCompiler();
                compiler.Messages += messaging.MessageDelegate;

                if (this.SearchPaths != null)
                {
                    foreach (ITaskItem searchPath in this.SearchPaths)
                    {
                        compiler.SearchPaths.Add(searchPath.ItemSpec);
                    }
                }

                if (this.PreprocessorDefines != null)
                {
                    foreach (string define in this.PreprocessorDefines)
                    {
                        string[] defineSplit = define.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                        compiler.PreprocessorDefines.Add(defineSplit[0], defineSplit.Length > 1 ? defineSplit[1] : null);
                    }
                }

                // Load the extensions.
                if (this.Extensions != null)
                {
                    SimplifiedWixCompiler.LoadExtensions(compiler, messaging, this.Extensions);
                }

                // Finally, load the sources and compile!
                if (!messaging.Errored)
                {
                    SimplifiedWixCompiler.LoadPackageSources(compiler, this.SourcePaths);
                    compiler.Compile(type, architecture, locales.ToArray(), this.OutputPath.ItemSpec);
                }
            }

            return(!messaging.Errored);
        }