public async Task <UpdateImpactResults> Analyze( string msixPath1, string msixPath2, bool ignoreVersionCheck = false, CancellationToken cancellationToken = default, IProgress <ProgressData> progressReporter = default) { if (msixPath1 == null) { throw new ArgumentNullException(nameof(msixPath1)); } if (msixPath2 == null) { throw new ArgumentNullException(nameof(msixPath2)); } if (!IsMsixPackage(msixPath1)) { throw new ArgumentException($"File {Path.GetFileName(msixPath1)} is not a valid MSIX."); } if (!IsMsixPackage(msixPath2)) { throw new ArgumentException($"File {Path.GetFileName(msixPath2)} is not a valid MSIX."); } progressReporter?.Report(new ProgressData(0, "Comparing files...")); using (IAppxFileReader fileReader1 = new ZipArchiveFileReaderAdapter(msixPath1)) { using (IAppxFileReader fileReader2 = new ZipArchiveFileReaderAdapter(msixPath2)) { await using (var file1 = fileReader1.GetFile("AppxBlockMap.xml")) { await using (var file2 = fileReader2.GetFile("AppxBlockMap.xml")) { var reader = new AppxBlockMapUpdateImpactAnalyzer(); var result = await reader.Analyze(file1, file2, cancellationToken, progressReporter).ConfigureAwait(false); result.OldPackage = msixPath1; result.NewPackage = msixPath2; return(result); } } } } }
public async Task <UpdateImpactResults> Analyze( string package1Path, string package2Path, bool ignoreVersionCheck = false, CancellationToken cancellationToken = default, IProgress <ProgressData> progressReporter = default) { var type1 = GetPackageTypeFromFile(package1Path); if (type1 == PackageType.Unsupported) { throw new ArgumentException($"File {Path.GetFileName(package1Path)} is not supported."); } var type2 = GetPackageTypeFromFile(package2Path); if (type2 == PackageType.Unsupported) { throw new ArgumentException($"File {Path.GetFileName(package2Path)} is not supported."); } await AssertPackagesUpgradable(package1Path, package2Path, ignoreVersionCheck).ConfigureAwait(false); if (type1 == type2) { switch (type1) { case PackageType.Msix: { var comparer = new MsixUpdateImpactAnalyzer(); var result = await comparer.Analyze(package1Path, package2Path, ignoreVersionCheck, cancellationToken, progressReporter).ConfigureAwait(false); result.OldPackage = package1Path; result.NewPackage = package2Path; return(result); } case PackageType.Manifest: { var comparer = new AppxBlockMapUpdateImpactAnalyzer(); var appxBlock1 = Path.Join(Path.GetDirectoryName(package1Path), "AppxBlockMap.xml"); var appxBlock2 = Path.Join(Path.GetDirectoryName(package2Path), "AppxBlockMap.xml"); var result = await comparer.Analyze(appxBlock1, appxBlock2, ignoreVersionCheck, cancellationToken, progressReporter).ConfigureAwait(false); result.OldPackage = package1Path; result.NewPackage = package2Path; return(result); } case PackageType.Bundle: { var comparer = new BundleUpdateImpactAnalyzer(); var result = await comparer.Analyze(package1Path, package2Path, ignoreVersionCheck, cancellationToken, progressReporter).ConfigureAwait(false); result.OldPackage = package1Path; result.NewPackage = package2Path; return(result); } case PackageType.AppxBlockMap: { var comparer = new AppxBlockMapUpdateImpactAnalyzer(); var result = await comparer.Analyze(package1Path, package2Path, ignoreVersionCheck, cancellationToken, progressReporter).ConfigureAwait(false); result.OldPackage = package1Path; result.NewPackage = package2Path; return(result); } } } else { if (type2 == PackageType.Bundle || type1 == PackageType.Bundle) { throw new NotSupportedException("A bundle can be only compared to another bundle."); } string appxBlock1 = null; string appxBlock2 = null; var tempPaths = new List <string>(); try { switch (type1) { case PackageType.Msix: using (IAppxFileReader fileReader = new ZipArchiveFileReaderAdapter(package1Path)) { using (var msixStream = fileReader.GetFile("AppxBlockMap.xml")) { var tempFile = Path.Join(Path.GetTempPath(), "msix-hero-cp-" + Guid.NewGuid().ToString("N").Substring(0, 8)); using (var fs = File.OpenWrite(tempFile)) { await msixStream.CopyToAsync(fs, cancellationToken).ConfigureAwait(false); await fs.FlushAsync(cancellationToken).ConfigureAwait(false); } tempPaths.Add(tempFile); appxBlock1 = tempFile; } } break; case PackageType.Manifest: appxBlock1 = Path.Join(Path.GetDirectoryName(package1Path), "AppxBlockMap.xml"); break; case PackageType.AppxBlockMap: appxBlock1 = package1Path; break; } switch (type2) { case PackageType.Msix: using (IAppxFileReader fileReader = new ZipArchiveFileReaderAdapter(package2Path)) { using (var msixStream = fileReader.GetFile("AppxBlockMap.xml")) { var tempFile = Path.Join(Path.GetTempPath(), "msix-hero-cp-" + Guid.NewGuid().ToString("N").Substring(0, 8)); using (var fs = File.OpenWrite(tempFile)) { await msixStream.CopyToAsync(fs, cancellationToken).ConfigureAwait(false); await fs.FlushAsync(cancellationToken).ConfigureAwait(false); } tempPaths.Add(tempFile); appxBlock2 = tempFile; } } break; case PackageType.Manifest: appxBlock2 = Path.Join(Path.GetDirectoryName(package2Path), "AppxBlockMap.xml"); break; case PackageType.AppxBlockMap: appxBlock2 = package2Path; break; } var comparer = new AppxBlockMapUpdateImpactAnalyzer(); var result = await comparer.Analyze(appxBlock1, appxBlock2, ignoreVersionCheck, cancellationToken, progressReporter).ConfigureAwait(false); result.OldPackage = package1Path; result.NewPackage = package2Path; return(result); } finally { foreach (var item in tempPaths.Where(File.Exists)) { File.Delete(item); } } } throw new NotSupportedException(); }