Esempio n. 1
0
        private void Analyze_Async_Compare(object state)
        {
            AppxPackageComparisonResult resultNoResource   = new AppxPackageComparisonResult();
            AppxPackageComparisonResult resultWithResource = new AppxPackageComparisonResult();

            try
            {
                List <string> packagePaths = state as List <string>;

                List <AppxPackageReader> readerList          = new List <AppxPackageReader>();
                List <AppxPackage>       allMainPackages     = new List <AppxPackage>();
                List <AppxPackage>       allResourcePackages = new List <AppxPackage>();

                foreach (string path in packagePaths)
                {
                    AppxPackageReader r = new AppxPackageReader(path);
                    readerList.Add(r);
                    r.Run(); // async
                }

                foreach (AppxPackageReader r in readerList)
                {
                    r.Wait(); // make sure package reader has completed

                    if (r.ErrorEncountered)
                    {
                        ShowError("Error Reading Package.", r.ErrorText);
                        return;
                    }

                    allMainPackages.AddRange(r.MainPackages);
                    allResourcePackages.AddRange(r.ResourcePackages);
                }

                List <AppxPackage> allPackages = new List <AppxPackage>();
                allPackages.AddRange(allMainPackages);
                allPackages.AddRange(allResourcePackages);

                // Get the result for no resource packages
                resultNoResource = GetInterPackageDupFiles(resultNoResource, allMainPackages);
                resultNoResource = GetCrossPackageDeDupdFiles(resultNoResource, allMainPackages);
                resultNoResource = AnalyzeFileSpaceSavings(resultNoResource, allMainPackages);

                // Get the result with resource packages
                resultWithResource = GetInterPackageDupFiles(resultWithResource, allResourcePackages);
                resultWithResource = GetCrossPackageDeDupdFiles(resultWithResource, allPackages);
                resultWithResource = AnalyzeFileSpaceSavings(resultWithResource, allPackages);
            }
            catch
            {
                // TBD
            }

            // update UI on main thread
            this.Dispatcher.BeginInvoke(new OutputComparisonDataToUIDelegate(OutputComparisonDataToUI), resultNoResource, resultWithResource);
        }
Esempio n. 2
0
        private List <AppxPackage> GetContainedPackagesFromBundle(IStream stream)
        {
            List <AppxPackage> containedPackages = new List <AppxPackage>();

            try
            {
                var bundleFactory               = (IAppxBundleFactory) new AppxBundleFactory();
                var bundlePackageReader         = bundleFactory.CreateBundleReader(stream);
                var bundleManifestReader        = bundlePackageReader.GetManifest();
                var bundleManifestInfoItemsEnum = bundleManifestReader.GetPackageInfoItems();

                List <AppxPackageReader> allPackageReadersFromBundle = new List <AppxPackageReader>();
                while (bundleManifestInfoItemsEnum.GetHasCurrent())
                {
                    var bundleManifestPackageInfo = bundleManifestInfoItemsEnum.GetCurrent();

                    // get represented file
                    var appxFile = bundlePackageReader.GetPayloadPackage(bundleManifestPackageInfo.GetFileName());

                    // get the appxpackage
                    AppxPackageReader r = new AppxPackageReader(appxFile.GetStream());
                    allPackageReadersFromBundle.Add(r);
                    r.Run();

                    bundleManifestInfoItemsEnum.MoveNext();

                    Marshal.ReleaseComObject(bundleManifestPackageInfo);
                }

                foreach (AppxPackageReader r in allPackageReadersFromBundle)
                {
                    r.Wait();
                    containedPackages.AddRange(r.MainPackages);
                    containedPackages.AddRange(r.ResourcePackages);
                }

                Marshal.ReleaseComObject(bundleManifestInfoItemsEnum);
                Marshal.ReleaseComObject(bundleManifestReader);
                Marshal.ReleaseComObject(bundlePackageReader);
                Marshal.ReleaseComObject(bundleFactory);
            }
            catch
            {
                // TBD
            }
            return(containedPackages);
        }