private void InstallArchive(Archive archive, string absolutePath, IGrouping <string, FromArchive> grouping) { Status($"Extracting {archive.Name}"); var vfiles = grouping.Select(g => { var file = VFS.FileForArchiveHashPath(g.ArchiveHashPath); g.FromFile = file; return(g); }).ToList(); var on_finish = VFS.Stage(vfiles.Select(f => f.FromFile).Distinct()); Status("Copying files for {0}", archive.Name); vfiles.DoIndexed((idx, file) => { Utils.Status($"Installing files", idx * 100 / vfiles.Count); File.Copy(file.FromFile.StagedPath, Path.Combine(Outputfolder, file.To)); }); Status("Unstaging files"); on_finish(); // Now patch all the files from this archive foreach (var to_patch in grouping.OfType <PatchedFromArchive>()) { using (var patch_stream = new MemoryStream()) { Status("Patching {0}", Path.GetFileName(to_patch.To)); // Read in the patch data var patch_data = to_patch.Patch.FromBase64(); var to_file = Path.Combine(Outputfolder, to_patch.To); MemoryStream old_data = new MemoryStream(File.ReadAllBytes(to_file)); // Remove the file we're about to patch File.Delete(to_file); // Patch it using (var out_stream = File.OpenWrite(to_file)) { BSDiff.Apply(old_data, () => new MemoryStream(patch_data), out_stream); } } } }
private void BuildArchivePatches(string archive_sha, IEnumerable <PatchedFromArchive> group, Dictionary <string, string> absolute_paths) { var archive = VFS.HashIndex[archive_sha]; using (var files = VFS.StageWith(group.Select(g => VFS.FileForArchiveHashPath(g.ArchiveHashPath)))) { var by_path = files.GroupBy(f => string.Join("|", f.Paths.Skip(1))).ToDictionary(f => f.Key, f => f.First()); // Now Create the patches group.PMap(entry => { Info("Patching {0}", entry.To); using (var origin = by_path[string.Join("|", entry.ArchiveHashPath.Skip(1))].OpenRead()) using (var output = new MemoryStream()) { var a = origin.ReadAll(); var b = LoadDataForTo(entry.To, absolute_paths); BSDiff.Create(a, b, output); entry.Patch = output.ToArray().ToBase64(); Info($"Patch size {entry.Patch.Length} for {entry.To}"); } }); } }