/// <summary> /// Parses the package. /// </summary> /// <param name="manifestPath">The manifest path.</param> private void ParsePackage(Package package) { var manifestPath = Path.Combine( package.InstalledLocation.Path, "AppxManifest.xml"); var xManifest = XDocument.Load( manifestPath, LoadOptions.None); var xDefaultNamespace = xManifest.Root.GetDefaultNamespace(); // Find all of the namespaces that we can ignore. var ignorableNamespaces = new List <string>(); var xIgnoredNamespaces = xManifest.Root.Attribute("IgnorableNamespaces"); if (xIgnoredNamespaces != null) { ignorableNamespaces = xIgnoredNamespaces.Value.Split(' ').ToList(); } // Find useable namespaces for this manifest var manifestNamespaces = xManifest.Root .Attributes() .Where( attr => attr.IsNamespaceDeclaration && !ignorableNamespaces.Contains(attr.Value)) .Select(ns => XNamespace.Get(ns.Value)) .OrderBy(ns => ns == xDefaultNamespace ? 0 : 1); var xApplications = xManifest.Root.Element(xDefaultNamespace + "Applications"); if (xApplications != null) { foreach (var xApplication in xApplications.Elements(xDefaultNamespace + "Application")) { var applicationId = xApplication.Attribute("Id").Value; foreach (var xNamespace in manifestNamespaces) { var xVisualElements = xApplication.Element(xNamespace + "VisualElements"); if (xVisualElements != null) { // Name var displayNameAttribute = xVisualElements.Attribute("DisplayName"); var displayName = displayNameAttribute != null ? displayNameAttribute.Value : null; // Description var descriptionAttribute = xVisualElements.Attribute("Description"); var description = descriptionAttribute != null ? descriptionAttribute.Value : null; // Icon var smallIconPathAttribute = xVisualElements.Attribute("Square30x30Logo"); if (smallIconPathAttribute == null) { smallIconPathAttribute = xVisualElements.Attribute("SmallLogo"); } var smallIconPath = smallIconPathAttribute != null ? smallIconPathAttribute.Value : null; var application = new MetroApplication() { ApplicationId = applicationId, AppUserModelId = ResolveAppUserModelId(package.Id.FullName, applicationId), Name = ResolveManifestString(displayName, package.Id.Name, package.InstalledLocation.Path), Description = ResolveManifestString(description, package.Id.Name, package.InstalledLocation.Path), Icon = ResolveIcon(smallIconPath, package.InstalledLocation.Path) }; this.Applications.Add(application); break; } } } } }
/// <summary> /// Parses the package. /// </summary> /// <param name="manifestPath">The manifest path.</param> private void ParsePackage(Package package) { var manifestPath = Path.Combine( package.InstalledLocation.Path, "AppxManifest.xml"); var xManifest = XDocument.Load( manifestPath, LoadOptions.None); var xDefaultNamespace = xManifest.Root.GetDefaultNamespace(); // Find all of the namespaces that we can ignore. var ignorableNamespaces = new List<string>(); var xIgnoredNamespaces = xManifest.Root.Attribute("IgnorableNamespaces"); if (xIgnoredNamespaces != null) { ignorableNamespaces = xIgnoredNamespaces.Value.Split(' ').ToList(); } // Find useable namespaces for this manifest var manifestNamespaces = xManifest.Root .Attributes() .Where( attr => attr.IsNamespaceDeclaration && !ignorableNamespaces.Contains(attr.Value)) .Select(ns => XNamespace.Get(ns.Value)) .OrderBy(ns => ns == xDefaultNamespace ? 0 : 1); var xApplications = xManifest.Root.Element(xDefaultNamespace + "Applications"); if (xApplications != null) { foreach (var xApplication in xApplications.Elements(xDefaultNamespace + "Application")) { var applicationId = xApplication.Attribute("Id").Value; foreach (var xNamespace in manifestNamespaces) { var xVisualElements = xApplication.Element(xNamespace + "VisualElements"); if (xVisualElements != null) { // Name var displayNameAttribute = xVisualElements.Attribute("DisplayName"); var displayName = displayNameAttribute != null ? displayNameAttribute.Value : null; // Description var descriptionAttribute = xVisualElements.Attribute("Description"); var description = descriptionAttribute != null ? descriptionAttribute.Value : null; // Icon var smallIconPathAttribute = xVisualElements.Attribute("Square30x30Logo"); if (smallIconPathAttribute == null) { smallIconPathAttribute = xVisualElements.Attribute("SmallLogo"); } var smallIconPath = smallIconPathAttribute != null ? smallIconPathAttribute.Value : null; var application = new MetroApplication() { ApplicationId = applicationId, AppUserModelId = ResolveAppUserModelId(package.Id.FullName, applicationId), Name = ResolveManifestString(displayName, package.Id.Name, package.InstalledLocation.Path), Description = ResolveManifestString(description, package.Id.Name, package.InstalledLocation.Path), Icon = ResolveIcon(smallIconPath, package.InstalledLocation.Path) }; this.Applications.Add(application); break; } } } } }