/// <summary> /// This returns all the installed package files (does not include satellite files) /// </summary> public static IEnumerable <ZipFilePair> GetInstalledPackageFiles( PackageArchiveReader packageReader, PackageIdentity packageIdentity, PackagePathResolver packagePathResolver, PackageSaveMode packageSaveMode) { var installedPackageFiles = Enumerable.Empty <ZipFilePair>(); var packageDirectory = packagePathResolver.GetInstalledPath(packageIdentity); if (!string.IsNullOrEmpty(packageDirectory)) { var packageFiles = packageReader.GetPackageFiles(packageSaveMode); var entries = packageReader.EnumeratePackageEntries(packageFiles, packageDirectory); installedPackageFiles = entries.Where(e => e.IsInstalled()); } return(installedPackageFiles.ToList()); }
public static IEnumerable <string> ExtractPackage( Stream packageStream, PackagePathResolver packagePathResolver, PackageExtractionContext packageExtractionContext, CancellationToken token) { if (packageStream == null) { throw new ArgumentNullException(nameof(packageStream)); } if (!packageStream.CanSeek) { throw new ArgumentException(Strings.PackageStreamShouldBeSeekable); } if (packagePathResolver == null) { throw new ArgumentNullException(nameof(packagePathResolver)); } if (packageExtractionContext == null) { throw new ArgumentNullException(nameof(packageExtractionContext)); } var packageSaveMode = packageExtractionContext.PackageSaveMode; var filesAdded = new List <string>(); var nupkgStartPosition = packageStream.Position; using (var packageReader = new PackageArchiveReader(packageStream, leaveStreamOpen: true)) { var packageIdentityFromNuspec = packageReader.GetIdentity(); var installPath = packagePathResolver.GetInstallPath(packageIdentityFromNuspec); var packageDirectoryInfo = Directory.CreateDirectory(installPath); var packageDirectory = packageDirectoryInfo.FullName; var packageFiles = packageReader.GetPackageFiles(packageSaveMode); if ((packageSaveMode & PackageSaveMode.Nuspec) == PackageSaveMode.Nuspec) { var sourceNuspecFile = packageFiles.Single(p => PackageHelper.IsManifest(p)); var targetNuspecPath = Path.Combine( packageDirectory, packagePathResolver.GetManifestFileName(packageIdentityFromNuspec)); // Extract the .nuspec file with a well known file name. filesAdded.Add(packageReader.ExtractFile( sourceNuspecFile, targetNuspecPath, packageExtractionContext.Logger)); packageFiles = packageFiles.Except(new[] { sourceNuspecFile }); } var packageFileExtractor = new PackageFileExtractor(packageFiles, packageExtractionContext.XmlDocFileSaveMode); filesAdded.AddRange(packageReader.CopyFiles( packageDirectory, packageFiles, packageFileExtractor.ExtractPackageFile, packageExtractionContext.Logger, token)); if ((packageSaveMode & PackageSaveMode.Nupkg) == PackageSaveMode.Nupkg) { // During package extraction, nupkg is the last file to be created // Since all the packages are already created, the package stream is likely positioned at its end // Reset it to the nupkgStartPosition packageStream.Seek(nupkgStartPosition, SeekOrigin.Begin); var nupkgFilePath = Path.Combine( packageDirectory, packagePathResolver.GetPackageFileName(packageIdentityFromNuspec)); filesAdded.Add(packageStream.CopyToFile(nupkgFilePath)); } // Now, copy satellite files unless requested to not copy them if (packageExtractionContext.CopySatelliteFiles) { filesAdded.AddRange(CopySatelliteFiles( packageReader, packagePathResolver, packageSaveMode, packageExtractionContext, token)); } } return(filesAdded); }