public static Stream CreateSDVPatch(string sdv_origin, string sdv_patched) { Stream output = new MemoryStream(); BinaryPatchUtility.Create(File.ReadAllBytes(sdv_origin), File.ReadAllBytes(sdv_patched), output); return(output); }
public static Stream CreatePatch(byte[] origin, byte[] dest) { Stream output = new MemoryStream(); BinaryPatchUtility.Create(origin, dest, output); return(output); }
public void Apply_bs_diff() { FileHelper.InitDir("test/bin", "test/update"); File.WriteAllText("test/bin/app.exe", "123"); using (var diff = File.Create("test/update/app.exe.bsdiff")) BinaryPatchUtility.Create(Encoding.UTF8.GetBytes("123"), Encoding.UTF8.GetBytes("123456"), diff); File.WriteAllText("test/update/version.txt", "1.0"); MainWindow.Update(-1, "test/bin/app.exe", "test/update"); var files = Directory.GetFiles("test/bin").Select(f => Path.GetFileName(f)); Assert.AreEqual("app.exe", files.Implode()); Assert.AreEqual("123456", File.ReadAllText("test/bin/app.exe")); }
/// <inheritdoc cref="IDeltaUpdate.CreateDeltaFile"/> public bool CreateDeltaFile( TemporaryFolder tempFolder, string originalFileLocation, string newFileLocation, string deltaFileLocation, out Stream?deltaFileStream, Action <double>?progress = null) { deltaFileStream = new MemoryStream(); var success = BinaryPatchUtility.Create( File.ReadAllBytes(originalFileLocation), File.ReadAllBytes(newFileLocation), deltaFileStream, progress); if (!success) { deltaFileStream.Dispose(); deltaFileStream = null; } deltaFileStream?.Seek(0, SeekOrigin.Begin); return(success); }
private void BuildPatchFile(MyFileInfo oldFile, MyFileInfo newFile, string patchFile) { using (var outputStream = File.OpenWrite(patchFile)) BinaryPatchUtility.Create(oldFile.ReadBytes(), newFile.ReadBytes(), outputStream); }
public void Create(GameState fromState, GameState toState) { Sequence = toState.Sequence; FromSequence = fromState.Sequence; BinaryPatchUtility.Create(fromState.GetSerializedDataBuffer(), toState.GetSerializedDataBuffer(), deltaBytes); }
private void CreateDeltaForSingleFile(FileInfo targetFile, DirectoryInfo workingDirectory, Dictionary <string, string> baseFileListing) { // NB: There are three cases here that we'll handle: // // 1. Exists only in new => leave it alone, we'll use it directly. // 2. Exists in both old and new => write a dummy file so we know // to keep it. // 3. Exists in old but changed in new => create a delta file // // The fourth case of "Exists only in old => delete it in new" // is handled when we apply the delta package var relativePath = targetFile.FullName.Replace(workingDirectory.FullName, ""); if (!baseFileListing.ContainsKey(relativePath)) { Log.InfoFormat("{0} not found in base package, marking as new", relativePath); return; } var oldData = File.ReadAllBytes(baseFileListing[relativePath]); var newData = File.ReadAllBytes(targetFile.FullName); if (BytesAreIdentical(oldData, newData)) { Log.InfoFormat("{0} hasn't changed, writing dummy file", relativePath); File.Create(targetFile.FullName + ".diff").Dispose(); File.Create(targetFile.FullName + ".shasum").Dispose(); targetFile.Delete(); return; } Log.InfoFormat("Delta patching {0} => {1}", baseFileListing[relativePath], targetFile.FullName); var msDelta = new MsDeltaCompression(); if (targetFile.Extension.Equals(".exe", StringComparison.OrdinalIgnoreCase) || targetFile.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase) || targetFile.Extension.Equals(".node", StringComparison.OrdinalIgnoreCase)) { try { msDelta.CreateDelta(baseFileListing[relativePath], targetFile.FullName, targetFile.FullName + ".diff"); goto exit; } catch (Exception) { Log.WarnFormat("We couldn't create a delta for {0}, attempting to create bsdiff", targetFile.Name); } } try { using (var of = File.Create(targetFile.FullName + ".bsdiff")) { BinaryPatchUtility.Create(oldData, newData, of); // NB: Create a dummy corrupt .diff file so that older // versions which don't understand bsdiff will fail out // until they get upgraded, instead of seeing the missing // file and just removing it. File.WriteAllText(targetFile.FullName + ".diff", "1"); } } catch (Exception ex) { Log.Warn($"We really couldn't create a delta for {targetFile.Name}", ex); Utility.DeleteFileHarder(targetFile.FullName + ".bsdiff", true); Utility.DeleteFileHarder(targetFile.FullName + ".diff", true); return; } exit: var rl = ReleaseEntry.GenerateFromFile(new MemoryStream(newData), targetFile.Name + ".shasum"); File.WriteAllText(targetFile.FullName + ".shasum", rl.EntryAsString, Encoding.UTF8); targetFile.Delete(); }