public ReleasePackage CreateDeltaPackage(ReleasePackage basePackage, ReleasePackage newPackage, string outputFile) { if (basePackage.Version > newPackage.Version) { throw new InvalidOperationException($"You cannot create a delta package based on version {basePackage.Version} as it is a later version than {newPackage.Version}"); } if (basePackage.ReleasePackageFile == null) { throw new ArgumentException("The base package's release file is null", "basePackage"); } if (!File.Exists(basePackage.ReleasePackageFile)) { throw new FileNotFoundException("The base package release does not exist", basePackage.ReleasePackageFile); } if (!File.Exists(newPackage.ReleasePackageFile)) { throw new FileNotFoundException("The new package release does not exist", newPackage.ReleasePackageFile); } string path = null; string str2 = null; using (Utility.WithTempDirectory(out path, null)) { using (Utility.WithTempDirectory(out str2, null)) { DirectoryInfo baseTempInfo = new DirectoryInfo(path); DirectoryInfo workingDirectory = new DirectoryInfo(str2); this.Log <DeltaPackageBuilder>().Info <string, string, string>("Extracting {0} and {1} into {2}", basePackage.ReleasePackageFile, newPackage.ReleasePackageFile, str2); FastZip zip = new FastZip(); zip.ExtractZip(basePackage.ReleasePackageFile, baseTempInfo.FullName, null); zip.ExtractZip(newPackage.ReleasePackageFile, workingDirectory.FullName, null); Dictionary <string, string> baseFileListing = Enumerable.ToDictionary <FileInfo, string, string>(from x in baseTempInfo.GetAllFilesRecursively() where x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar.ToString()) select x, k => k.FullName.Replace(baseTempInfo.FullName, ""), v => v.FullName); foreach (FileInfo info2 in Enumerable.First <DirectoryInfo>(workingDirectory.GetDirectories(), x => x.Name.ToLowerInvariant() == "lib").GetAllFilesRecursively()) { this.createDeltaForSingleFile(info2, workingDirectory, baseFileListing); } ReleasePackage.addDeltaFilesToContentTypes(workingDirectory.FullName); zip.CreateZip(outputFile, workingDirectory.FullName, true, null); } } return(new ReleasePackage(outputFile, false)); }
public ReleasePackage CreateDeltaPackage(ReleasePackage basePackage, ReleasePackage newPackage, string outputFile) { Contract.Requires(basePackage != null); Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile)); if (basePackage.Version > newPackage.Version) { var message = String.Format( "You cannot create a delta package based on version {0} as it is a later version than {1}", basePackage.Version, newPackage.Version); throw new InvalidOperationException(message); } if (basePackage.ReleasePackageFile == null) { throw new ArgumentException("The base package's release file is null", "basePackage"); } if (!File.Exists(basePackage.ReleasePackageFile)) { throw new FileNotFoundException("The base package release does not exist", basePackage.ReleasePackageFile); } if (!File.Exists(newPackage.ReleasePackageFile)) { throw new FileNotFoundException("The new package release does not exist", newPackage.ReleasePackageFile); } string baseTempPath = null; string tempPath = null; using (Utility.WithTempDirectory(out baseTempPath, null)) using (Utility.WithTempDirectory(out tempPath, null)) { var baseTempInfo = new DirectoryInfo(baseTempPath); var tempInfo = new DirectoryInfo(tempPath); this.Log().Info("Extracting {0} and {1} into {2}", basePackage.ReleasePackageFile, newPackage.ReleasePackageFile, tempPath); var fz = new FastZip(); fz.ExtractZip(basePackage.ReleasePackageFile, baseTempInfo.FullName, null); fz.ExtractZip(newPackage.ReleasePackageFile, tempInfo.FullName, null); // Collect a list of relative paths under 'lib' and map them // to their full name. We'll use this later to determine in // the new version of the package whether the file exists or // not. var baseLibFiles = baseTempInfo.GetAllFilesRecursively() .Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar)) .ToDictionary(k => k.FullName.Replace(baseTempInfo.FullName, ""), v => v.FullName); var newLibDir = tempInfo.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib"); foreach (var libFile in newLibDir.GetAllFilesRecursively()) { createDeltaForSingleFile(libFile, tempInfo, baseLibFiles); } ReleasePackage.addDeltaFilesToContentTypes(tempInfo.FullName); fz.CreateZip(outputFile, tempInfo.FullName, true, null); } return(new ReleasePackage(outputFile)); }