Пример #1
0
        private void Initialize(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(string.Format("{0} not found", filePath));
            }

            this.FilePath = filePath;
            IStream            bundleStream  = StreamUtils.CreateInputStreamOnFile(this.FilePath);
            IAppxBundleFactory bundleFactory = (IAppxBundleFactory) new AppxBundleFactory();

            this.AppxBundleReader = bundleFactory.CreateBundleReader(bundleStream);

            this.BlockmapStream = this.AppxBundleReader.GetBlockMap().GetStream();

            this.manifestReader = this.AppxBundleReader.GetManifest();
            this.ManifestStream = this.manifestReader.GetStream();
            IAppxManifestPackageId packageId = this.manifestReader.GetPackageId();

            this.PackageName       = packageId.GetName();
            this.PackageFamilyName = packageId.GetPackageFamilyName();
            this.PackageFullName   = packageId.GetPackageFullName();
            this.Publisher         = packageId.GetPublisher();
            this.Version           = new VersionInfo(packageId.GetVersion());

            this.PopulateCommonFields();

            this.PopulateChildAppxPackages();
            this.PopulateOptionalAppxPackagesAndBundles();
        }
Пример #2
0
        private void Initialize(IRandomAccessStream randomAccessStream)
        {
            if (randomAccessStream == null)
            {
                throw new ArgumentNullException("file is null");
            }

            //IStream bundleStream = StreamUtils.CreateInputStreamOnFile(this.FilePath);
            Guid               guid          = new Guid("0000000c-0000-0000-C000-000000000046");
            IStream            bundleStream  = StreamUtils.CreateStreamOverRandomAccessStream(randomAccessStream, ref guid);
            IAppxBundleFactory bundleFactory = (IAppxBundleFactory) new AppxBundleFactory();

            this.AppxBundleReader = bundleFactory.CreateBundleReader(bundleStream);

            this.BlockmapStream = this.AppxBundleReader.GetBlockMap().GetStream();

            this.manifestReader = this.AppxBundleReader.GetManifest();
            this.ManifestStream = this.manifestReader.GetStream();
            IAppxManifestPackageId packageId = this.manifestReader.GetPackageId();

            this.PackageName       = packageId.GetName();
            this.PackageFamilyName = packageId.GetPackageFamilyName();
            this.PackageFullName   = packageId.GetPackageFullName();
            this.Publisher         = packageId.GetPublisher();
            this.Version           = new VersionInfo(packageId.GetVersion());

            this.PopulateCommonFields();

            this.PopulateChildAppxPackages();
            this.PopulateOptionalAppxPackagesAndBundles();
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the AppxMetadata class for an appx package.
        /// </summary>
        /// <param name="filePath">the path to the appx file</param>
        public AppxMetadata(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(string.Format("{0} not found", filePath));
            }

            this.FilePath = filePath;
            IStream      packageStream  = StreamUtils.CreateInputStreamOnFile(this.FilePath);
            IAppxFactory packageFactory = (IAppxFactory) new AppxFactory();

            this.AppxReader = packageFactory.CreatePackageReader(packageStream);

            this.BlockmapStream = this.AppxReader.GetBlockMap().GetStream();

            IAppxManifestReader appxManifestReader = this.AppxReader.GetManifest();

            this.ManifestStream = appxManifestReader.GetStream();
            IAppxManifestPackageId packageId = appxManifestReader.GetPackageId();

            this.PackageName       = packageId.GetName();
            this.PackageFamilyName = packageId.GetPackageFamilyName();
            this.PackageFullName   = packageId.GetPackageFullName();
            this.Publisher         = packageId.GetPublisher();
            this.Version           = new VersionInfo(packageId.GetVersion());

            IAppxManifestProperties packageProperties = appxManifestReader.GetProperties();
            string displayName;

            packageProperties.GetStringValue("DisplayName", out displayName);
            this.DisplayName = displayName;

            string publisherDisplayName;

            packageProperties.GetStringValue("PublisherDisplayName", out publisherDisplayName);
            this.PublisherDisplayName = publisherDisplayName;

            // Get the min versions
            IAppxManifestReader3 appxManifestReader3 = (IAppxManifestReader3)appxManifestReader;
            IAppxManifestTargetDeviceFamiliesEnumerator targetDeviceFamiliesEnumerator = appxManifestReader3.GetTargetDeviceFamilies();

            while (targetDeviceFamiliesEnumerator.GetHasCurrent())
            {
                IAppxManifestTargetDeviceFamily targetDeviceFamily = targetDeviceFamiliesEnumerator.GetCurrent();
                this.TargetDeviceFamiliesMinVersions.Add(
                    targetDeviceFamily.GetName(),
                    new VersionInfo(targetDeviceFamily.GetMinVersion()));

                targetDeviceFamiliesEnumerator.MoveNext();
            }

            this.MinOSVersion = this.TargetDeviceFamiliesMinVersions.OrderBy(t => t.Value).FirstOrDefault().Value;

            this.PopulateCommonFields();
        }
Пример #4
0
        public AppxMetadata(IRandomAccessStream randomAccessStream)
        {
            if (randomAccessStream == null)
            {
                throw new ArgumentNullException("file is null");
            }

            Guid    guid          = new Guid("0000000c-0000-0000-C000-000000000046");
            IStream packageStream = StreamUtils.CreateStreamOverRandomAccessStream(randomAccessStream, ref guid);

            IAppxFactory packageFactory = (IAppxFactory) new AppxFactory();

            packageFactory.CreatePackageReader(packageStream);

            this.AppxReader = packageFactory.CreatePackageReader(packageStream);

            this.BlockmapStream = this.AppxReader.GetBlockMap().GetStream();

            IAppxManifestReader appxManifestReader = this.AppxReader.GetManifest();

            this.ManifestStream = appxManifestReader.GetStream();
            IAppxManifestPackageId packageId = appxManifestReader.GetPackageId();

            this.PackageName       = packageId.GetName();
            this.PackageFamilyName = packageId.GetPackageFamilyName();
            this.PackageFullName   = packageId.GetPackageFullName();
            this.Publisher         = packageId.GetPublisher();
            this.Version           = new VersionInfo(packageId.GetVersion());

            IAppxManifestProperties packageProperties = appxManifestReader.GetProperties();
            string displayName;

            packageProperties.GetStringValue("DisplayName", out displayName);
            this.DisplayName = displayName;

            string publisherDisplayName;

            packageProperties.GetStringValue("PublisherDisplayName", out publisherDisplayName);
            this.PublisherDisplayName = publisherDisplayName;

            // Get the min versions
            IAppxManifestReader3 appxManifestReader3 = (IAppxManifestReader3)appxManifestReader;
            IAppxManifestTargetDeviceFamiliesEnumerator targetDeviceFamiliesEnumerator = appxManifestReader3.GetTargetDeviceFamilies();

            while (targetDeviceFamiliesEnumerator.GetHasCurrent())
            {
                IAppxManifestTargetDeviceFamily targetDeviceFamily = targetDeviceFamiliesEnumerator.GetCurrent();
                this.TargetDeviceFamiliesMinVersions.Add(
                    targetDeviceFamily.GetName(),
                    new VersionInfo(targetDeviceFamily.GetMinVersion()));

                targetDeviceFamiliesEnumerator.MoveNext();
            }

            this.MinOSVersion = this.TargetDeviceFamiliesMinVersions.OrderBy(t => t.Value).FirstOrDefault().Value;

            this.PopulateCommonFields();
        }
Пример #5
0
        /// <summary>
        /// Initializes this instance of the AppxMetadata class from an msix stream.
        /// </summary>
        /// <param name="packageStream">the msix package stream.</param>
        private void Initialize(IStream packageStream)
        {
            IAppxFactory packageFactory = (IAppxFactory) new AppxFactory();

            this.AppxReader = packageFactory.CreatePackageReader(packageStream);

            this.BlockmapStream = this.AppxReader.GetBlockMap().GetStream();

            IAppxManifestReader appxManifestReader = this.AppxReader.GetManifest();

            this.ManifestStream = appxManifestReader.GetStream();
            IAppxManifestPackageId packageId = appxManifestReader.GetPackageId();

            this.PackageName       = packageId.GetName();
            this.PackageFamilyName = packageId.GetPackageFamilyName();
            this.PackageFullName   = packageId.GetPackageFullName();
            this.Publisher         = packageId.GetPublisher();
            this.Version           = new VersionInfo(packageId.GetVersion());

            IAppxManifestProperties packageProperties = appxManifestReader.GetProperties();
            string displayName;

            packageProperties.GetStringValue("DisplayName", out displayName);
            this.DisplayName = displayName;

            string publisherDisplayName;

            packageProperties.GetStringValue("PublisherDisplayName", out publisherDisplayName);
            this.PublisherDisplayName = publisherDisplayName;

            // Get the min versions
            IAppxManifestReader3 appxManifestReader3 = (IAppxManifestReader3)appxManifestReader;
            IAppxManifestTargetDeviceFamiliesEnumerator targetDeviceFamiliesEnumerator = appxManifestReader3.GetTargetDeviceFamilies();

            while (targetDeviceFamiliesEnumerator.GetHasCurrent())
            {
                IAppxManifestTargetDeviceFamily targetDeviceFamily = targetDeviceFamiliesEnumerator.GetCurrent();
                this.TargetDeviceFamiliesMinVersions.Add(
                    targetDeviceFamily.GetName(),
                    new VersionInfo(targetDeviceFamily.GetMinVersion()));

                targetDeviceFamiliesEnumerator.MoveNext();
            }

            this.MinOSVersion = this.TargetDeviceFamiliesMinVersions.OrderBy(t => t.Value).FirstOrDefault().Value;

            this.PopulateCommonFields();
        }
Пример #6
0
        /// <summary>
        /// Reads the manifest and populates the ExternalAppxPackagesRelativePaths and InternalAppxPackagesRelativePaths lists.
        /// </summary>
        private void PopulateChildAppxPackages()
        {
            IAppxBundleManifestPackageInfoEnumerator subPackagesEnumerator = this.manifestReader.GetPackageInfoItems();

            while (subPackagesEnumerator.GetHasCurrent())
            {
                IAppxBundleManifestPackageInfo subPackageInfo = subPackagesEnumerator.GetCurrent();
                IAppxManifestPackageId         subPackageId   = subPackageInfo.GetPackageId();
                string filePath = subPackageInfo.GetFileName();

                // If the package is not contained within the bundle, the corresponding package element in the bundle manifest
                // would not have an offset field. In such a case and only in that case, the AppxPackaging APIs would return 0
                // when retrieving the offset.
                if (subPackageInfo.GetOffset() == 0)
                {
                    this.ExternalAppxPackages.Add(new ExternalPackageReference(
                                                      this,
                                                      subPackageId.GetPackageFullName(),
                                                      filePath,
                                                      isOptional: false));
                }
                else
                {
                    var childPackageMetadata = new ChildPackageMetadata(
                        this,
                        subPackageId.GetPackageFullName(),
                        filePath,
                        subPackageInfo.GetPackageType(),
                        subPackageInfo.GetSize(),
                        subPackageId.GetVersion(),
                        subPackageId.GetResourceId());

                    this.ChildAppxPackages.Add(childPackageMetadata);

#pragma warning disable CS0612 // Type or member is obsolete
                    this.InternalAppxPackagesRelativePaths.Add(filePath);
#pragma warning restore CS0612 // Type or member is obsolete
                }

                subPackagesEnumerator.MoveNext();
            }
        }