SharpHDiffPatch.Core 2.2.8

dotnet add package SharpHDiffPatch.Core --version 2.2.8                
NuGet\Install-Package SharpHDiffPatch.Core -Version 2.2.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpHDiffPatch.Core" Version="2.2.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpHDiffPatch.Core --version 2.2.8                
#r "nuget: SharpHDiffPatch.Core, 2.2.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SharpHDiffPatch.Core as a Cake Addin
#addin nuget:?package=SharpHDiffPatch.Core&version=2.2.8

// Install SharpHDiffPatch.Core as a Cake Tool
#tool nuget:?package=SharpHDiffPatch.Core&version=2.2.8                

SharpHDiffPatch

NuGet Downloads NuGet version

SharpHDiffPatch is a patching library for HDiffPatch format written in C#, purposedly as a port of HPatchZ implementation (from HDiffPatch by housisong). This project doesn't support making diff file and only works for patching.

Supporting file and directory patching with these compression formats:

  • BZip2
  • Deflate
  • Zstd
  • LZMA2 (not LZMA)
  • No Compression.

Unfortunately, the HDIFFSF20 (Single Compressed) format is still unsupported. But we are planning to add it in the future.

This project is used as a part submodule of our main project: Collapse Launcher.

Usage Example

Patching with a simple progress indicator

using SharpHDiffPatch.Core;
using SharpHDiffPatch.Core.Event;

string oldPath = "C:\\test\\Music1.pck";
string diffPath = "C:\\test\\Music1.pck.hdiff";
string newPath = "C:\\test\\Music1.pck.new";

// Initialize the patcher instance
HDiffPatch patcher = new HDiffPatch();
// Set the verbosity of the logging
// Available Options: Quiet, Info (default), Verbose, Debug
HDiffPatch.LogVerbosity = Verbosity.Verbose;

// Subscribe an event listener to logging
EventListener.LoggerEvent += EventListener_LoggerEvent;
// Subscribe an event listener to patching progress
EventListener.PatchEvent += EventListener_PatchEvent;

// Initialize the diff file
patcher.Initialize(diffPath);
// Start the patching process
// This method has some arguments you can tweak as below:
//     Patch(string inputPath, string outputPath, bool useBufferedPatch,
//           CancellationToken token = default, bool useFullBuffer = false,
//           bool useFastBuffer = false)
// 
//     Description:
//      - inputPath             -> Path of the old/source file/folder.
//      - outputPath            -> Path of the new/target file/folder.
//      - useBufferedPatch      -> Use array-based buffer for RLE Control and Code clips.
//      - token                 -> Cancellation token.
//      - useFullBuffer         -> Buffer the RLE New Data to the MemoryStream.
//      - useFastBuffer         -> Buffer the RLE Control and Code clips to ArrayPool.
patcher.Patch(inputPath, outputPath, true, default, false, true);

// Unsubscribe an event listener to logging
EventListener.LoggerEvent -= EventListener_LoggerEvent;
// Unsubscribe an event listener to patching progress
EventListener.PatchEvent -= EventListener_PatchEvent;

// Implement logging listener
private void EventListener_LoggerEvent(object? sender, LoggerEvent e)
{
    string label = e.LogLevel switch
    {
        Verbosity.Info => $"[Info] ",
        Verbosity.Verbose => $"[Verbose] ",
        Verbosity.Debug => $"[Debug] ",
        _ => ""
    };
    Console.WriteLine($"{label}{e.Message}");
}

// Implement patching progress listener
private void EventListener_PatchEvent(object? sender, PatchEvent e)
{
    Console.Write($"Patching: {e.ProgressPercentage}% | {SummarizeSizeSimple(e.CurrentSizePatched)}/{SummarizeSizeSimple(e.TotalSizeToBePatched)} @{SummarizeSizeSimple(e.Speed)}/s    \r");
}

Get the New file size from diff file.

using SharpHDiffPatch.Core;

string diffPath = "C:\\test\\Music1.pck.hdiff";
long newFileSize = HDiffPatch.GetHDiffNewSize(diffPath);

Console.WriteLine($"The new file size is: {newFileSize} bytes");
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on SharpHDiffPatch.Core:

Repository Stars
CollapseLauncher/Collapse
An Advanced Launcher for miHoYo/HoYoverse Games
Version Downloads Last updated
2.2.8 278 10/2/2024
2.2.7 215 8/1/2024
2.2.6 287 6/9/2024
2.2.5 186 5/17/2024
2.2.3 530 1/3/2024