private static Uri GetIcon(AppxManifest manifest, AppxManifestApplication app)
        {
            var icon = manifest.Logo ?? app.Logo
                       ?? app.Images.FirstOrDefault()
                       ?? app.SmallLogo;

            return(icon?.Path.ToUri("uwp", new Dictionary <string, string>
            {
                { "bg", app.BackgroundColor }
            }));
        }
        /// <summary>
        /// Generates the final output from a set of intermediates.
        /// </summary>
        /// <param name="intermediates">Intermediates that provide data to be generated.</param>
        /// <param name="outputPath">Path for output file to be generated.</param>
        public override void Generate(IEnumerable <Intermediate> intermediates, string outputPath)
        {
            AppxManifest manifest = new AppxManifest(this);

            manifest.ProcessIntermediates(intermediates);
            if (this.EncounteredError)
            {
                return;
            }

            manifest.Validate(this.ValidationErrorHandler);
            if (this.EncounteredError)
            {
                string tempPath = Path.GetTempFileName();
                this.OnMessage(new CompilerMessageEventArgs(CompilerMessage.SavedManifest(tempPath), null, 0, 0));

                this.SaveManifest(manifest, tempPath);
                return;
            }

            FileTransfer appxPackageTransfer = FileTransfer.Create(null, Path.GetTempFileName(), outputPath, "AppxPackage", true);

            using (Stream packageStream = File.Open(appxPackageTransfer.Source, FileMode.Create, FileAccess.ReadWrite, FileShare.Delete))
            {
                AppxPackage package = new AppxPackage(packageStream);

                foreach (PackageFile file in manifest.Files)
                {
                    using (Stream fileStream = File.Open(file.SourcePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        this.OnMessage(new CompilerMessageEventArgs(CompilerMessage.CompressFile(file.SourcePath), file.File.LineNumber));
                        package.AddFile(fileStream, file.PartUri, file.MimeType, CompressionLevel.DefaultCompression);
                    }
                }

                using (Stream manifestStream = manifest.GetStream())
                {
                    package.Finish(manifestStream);
                }
            }

            FileTransfer.ExecuteTransfer(this, appxPackageTransfer);
        }
        /// <summary>
        /// Finishes the manifest applcation XML.
        /// </summary>
        /// <param name="backend">Compiler backend used for sending messages.</param>
        public void Finish(BackendCompiler backend)
        {
            // Visual elements is required.
            XElement xVisualElements = new XElement(AppxManifest.AppxNamespace + "VisualElements");

            this.Xml.Add(xVisualElements);

            if (this.Tile != null)
            {
                Application      application = (Application)this.Item;
                AppxLexicon.Tile tile        = (AppxLexicon.Tile) this.Tile.Item;

                // Display name is required.
                if (!String.IsNullOrEmpty(application.DisplayName))
                {
                    xVisualElements.Add(new XAttribute("DisplayName", application.DisplayName));
                }
                else
                {
                    backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("Application", "DisplayName"), this.Item));
                }

                // Description is required.
                if (!String.IsNullOrEmpty(application.Description))
                {
                    xVisualElements.Add(new XAttribute("Description", application.Description));
                }
                else
                {
                    backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("Application", "Description"), this.Item));
                }

                // Image is required.
                string logo = tile.Image == null ? null : tile.Image.NonqualifiedName;
                if (!String.IsNullOrEmpty(logo))
                {
                    xVisualElements.Add(new XAttribute("Logo", logo));
                }
                else
                {
                    backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("Tile", "Image"), this.Item));
                }

                // Small image is required.
                string smallLogo = tile.SmallImage == null ? null : tile.SmallImage.NonqualifiedName;
                if (!String.IsNullOrEmpty(smallLogo))
                {
                    xVisualElements.Add(new XAttribute("SmallLogo", smallLogo));
                }
                else
                {
                    backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredAttribute("Tile", "SmallImage"), this.Item));
                }

                // Foreground is required.
                xVisualElements.Add(new XAttribute("ForegroundText", tile.Foreground));

                // Background is required.
                string color = AppxManifest.GetColor(tile.Background);
                if (!String.IsNullOrEmpty(color))
                {
                    xVisualElements.Add(new XAttribute("BackgroundColor", color));
                }
                else
                {
                    backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.InvalidAttributeValue("Tile", "Background", tile.Background), tile));
                }

                // Toast capable is optional.
                bool?toast = AppxLexicon.Application.GetToastCapable(application);
                if (toast.HasValue && toast.Value)
                {
                    xVisualElements.Add(new XAttribute("ToastCapable", true));
                }

                // Default tile is optional.
                string wideLogo = (tile.WideImage == null) ? null : tile.WideImage.NonqualifiedName;
                if (!String.IsNullOrEmpty(wideLogo) || !String.IsNullOrEmpty(tile.ShortName) || tile.ShowName != AppxLexicon.TileShowName.Invalid)
                {
                    XElement xDefautTile = new XElement(AppxManifest.AppxNamespace + "DefaultTile");

                    if (!String.IsNullOrEmpty(tile.ShortName))
                    {
                        xDefautTile.Add(new XAttribute("ShortName", tile.ShortName));
                    }

                    if (tile.ShowName != AppxLexicon.TileShowName.Invalid)
                    {
                        if (tile.ShowName != AppxLexicon.TileShowName.Invalid)
                        {
                            xDefautTile.Add(new XAttribute("ShowName", tile.ShowName));
                        }
                    }

                    if (!String.IsNullOrEmpty(wideLogo))
                    {
                        xDefautTile.Add(new XAttribute("WideLogo", wideLogo));
                    }

                    xVisualElements.Add(xDefautTile);
                }
            }
            else
            {
                backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredElement("Application", "Tile"), this.Item));
            }

            // Lock screen is optional.
            if (this.LockScreen != null && this.LockScreen.Xml != null && this.LockScreen.Xml.HasAttributes)
            {
                xVisualElements.Add(this.LockScreen.Xml);
            }

            // Splash screen is required.
            if (this.SplashScreen != null && this.SplashScreen.Xml != null && this.SplashScreen.Xml.HasAttributes)
            {
                xVisualElements.Add(this.SplashScreen.Xml);
            }
            else
            {
                backend.OnMessage(new CompilerMessageEventArgs(CompilerMessage.RequiredElement("Application", "SplashScreen"), this.Item));
            }

            // Orientation preferences are optional.
            if (this.initialRotationPreferences != null && this.initialRotationPreferences.HasElements)
            {
                xVisualElements.Add(initialRotationPreferences);
            }

            // Extensions are optional.
            if (this.extensions != null && this.extensions.HasElements)
            {
                this.Xml.Add(this.extensions);
            }

            // Content URI rules are optional.
            if (this.contentUriRules != null && this.contentUriRules.HasElements)
            {
                this.Xml.Add(this.contentUriRules);
            }
        }
 public HockeyPlatformHelper81()
 {
     AppxManifest.InitializeManifest();
     clientDeviceInfo = new EasClientDeviceInformation();
 }
 public AppxManifestDisplayProxy(AppxManifest original)
 {
     SubType            = original.SubType;
     UnevaluatedInclude = original.UnevaluatedInclude;
 }