diff --git a/Patcher/PatcherUtils/Helpers/XdeltaProcessHelper.cs b/Patcher/PatcherUtils/Helpers/XdeltaProcessHelper.cs
deleted file mode 100644
index b164530..0000000
--- a/Patcher/PatcherUtils/Helpers/XdeltaProcessHelper.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Text;
-using System.Threading;
-using PatcherUtils.Model;
-
-namespace PatcherUtils.Helpers;
-
-public class XdeltaProcessHelper
-{
- private readonly int _timeout = (int)TimeSpan.FromMinutes(10).TotalMilliseconds;
- private string _args;
- private string _sourcePath;
- private string _deltaPath;
- private string _decodedPath;
- private bool _isDebug;
-
- public XdeltaProcessHelper(string args, string sourcePath, string deltaPath, string decodedPath, bool isDebug)
- {
- _args = args;
- _sourcePath = sourcePath;
- _deltaPath = deltaPath;
- _decodedPath = decodedPath;
- _isDebug = isDebug;
- }
-
- public bool Run() => _isDebug ? RunDebug() : RunNormal();
-
- private bool RunNormal()
- {
- try
- {
- using var proc = new Process();
-
- proc.StartInfo = new ProcessStartInfo
- {
- FileName = LazyOperations.XDelta3Path,
- Arguments = $"{_args} \"{_sourcePath}\" \"{_deltaPath}\" \"{_decodedPath}\"",
- CreateNoWindow = true
- };
-
- proc.Start();
-
- if (!proc.WaitForExit(_timeout))
- {
- PatchLogger.LogError("xdelta3 process timed out");
- PatchLogger.LogDebug($"xdelta exit code: {proc.ExitCode}");
- return false;
- }
-
- PatchLogger.LogDebug($"xdelta exit code: {proc.ExitCode}");
- return true;
- }
- catch (Exception ex)
- {
- PatchLogger.LogException(ex);
- return false;
- }
- }
-
- private bool DebugPathsCheck()
- {
- try
- {
- var stream = File.Open(_sourcePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
- stream.Close();
- stream.Dispose();
- PatchLogger.LogDebug($"File is openable: {_sourcePath}");
- }
- catch (Exception ex)
- {
- PatchLogger.LogException(ex);
- return false;
- }
-
- try
- {
- var stream = File.Open(_deltaPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
- stream.Close();
- stream.Dispose();
- PatchLogger.LogDebug($"File is openable: {_deltaPath}");
- }
- catch (Exception ex)
- {
- PatchLogger.LogException(ex);
- return false;
- }
-
- return true;
- }
-
- private bool RunDebug()
- {
- if (!DebugPathsCheck())
- {
- return false;
- }
-
- using var proc = new Process();
-
- proc.StartInfo = new ProcessStartInfo
- {
- FileName = LazyOperations.XDelta3Path,
- Arguments = $"{_args} \"{_sourcePath}\" \"{_deltaPath}\" \"{_decodedPath}\"",
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- CreateNoWindow = true
- };
-
- var outputBuilder = new StringBuilder();
- var errorBuilder = new StringBuilder();
-
- using AutoResetEvent outputWaitHandle = new AutoResetEvent(false);
- using AutoResetEvent errorWaitHandle = new AutoResetEvent(false);
-
- proc.OutputDataReceived += (s, e) =>
- {
- if (e.Data == null)
- {
- outputWaitHandle.Set();
- }
- else
- {
- outputBuilder.AppendLine(e.Data);
- }
- };
-
- proc.ErrorDataReceived += (s, e) =>
- {
- if (e.Data == null)
- {
- errorWaitHandle.Set();
- }
- else
- {
- errorBuilder.AppendLine(e.Data);
- }
- };
-
- proc.Start();
-
- proc.BeginOutputReadLine();
- proc.BeginErrorReadLine();
-
- if (!proc.WaitForExit(_timeout) || !outputWaitHandle.WaitOne(_timeout) || !errorWaitHandle.WaitOne(_timeout))
- {
- PatchLogger.LogError("xdelta3 process timed out");
- PatchLogger.LogDebug($"xdelta exit code: {proc.ExitCode}");
- return false;
- }
-
- PatchLogger.LogDebug("__xdelta stdout__");
- PatchLogger.LogDebug(outputBuilder.ToString());
- PatchLogger.LogDebug("__xdelta stderr__");
- PatchLogger.LogDebug(errorBuilder.ToString());
- PatchLogger.LogDebug($"xdelta exit code: {proc.ExitCode}");
-
- return true;
- }
-}
\ No newline at end of file
diff --git a/Patcher/PatcherUtils/LazyOperations.cs b/Patcher/PatcherUtils/LazyOperations.cs
index ffface6..8ed0c83 100644
--- a/Patcher/PatcherUtils/LazyOperations.cs
+++ b/Patcher/PatcherUtils/LazyOperations.cs
@@ -32,12 +32,12 @@ namespace PatcherUtils
///
public static string PatcherClientPath = $"{TempDir}\\{PatcherClient}";
- private static string XDelta3EXE = "xdelta3.exe";
+ private static string HDiffEXE = "hdiffz.exe";
///
- /// The path to the xdelta3.exe flie in the
+ /// The path to the hdiffz.exe file in the
///
- public static string XDelta3Path = $"{TempDir}\\{XDelta3EXE}";
+ public static string HDiffPath = $"{TempDir}\\{HDiffEXE}";
///
/// Streams embedded resources out of the assembly
@@ -90,9 +90,9 @@ namespace PatcherUtils
StreamResourceOut(assembly, resource, PatcherClientPath);
break;
}
- case string a when a.EndsWith(XDelta3EXE):
+ case string a when a.EndsWith(HDiffEXE):
{
- StreamResourceOut(assembly, resource, XDelta3Path);
+ StreamResourceOut(assembly, resource, HDiffPath);
break;
}
}
diff --git a/Patcher/PatcherUtils/PatchHelper.cs b/Patcher/PatcherUtils/PatchHelper.cs
index fbb4422..e45ea9c 100644
--- a/Patcher/PatcherUtils/PatchHelper.cs
+++ b/Patcher/PatcherUtils/PatchHelper.cs
@@ -1,5 +1,6 @@
using PatchClient.Models;
using PatcherUtils.Model;
+using SharpHDiffPatch.Core;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -9,7 +10,6 @@ using System.Linq;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
-using PleOps.XdeltaSharp.Decoder;
namespace PatcherUtils
{
@@ -116,11 +116,11 @@ namespace PatcherUtils
try
{
- using var inputFile = new FileStream(SourceFilePath, FileMode.Open);
- using var patchFile = new FileStream(DeltaFilePath, FileMode.Open);
- using var decodedFile = new FileStream(decodedPath, FileMode.Create);
- using var decoder = new Decoder(inputFile, patchFile, decodedFile);
- decoder.Run();
+ HDiffPatch patcher = new HDiffPatch();
+ HDiffPatch.LogVerbosity = Verbosity.Quiet;
+
+ patcher.Initialize(DeltaFilePath);
+ patcher.Patch(SourceFilePath, decodedPath, true, default, false, true);
}
catch (Exception ex)
{
@@ -162,10 +162,11 @@ namespace PatcherUtils
PatchLogger.LogException(ex);
}
+ // The parameters we use here are important to allow patch application using the SharpHDiffPatch.Core library, please don't change them
Process.Start(new ProcessStartInfo
{
- FileName = LazyOperations.XDelta3Path,
- Arguments = $"-0 -e -f -S none -s \"{SourceFilePath}\" \"{TargetFilePath}\" \"{deltaPath}\"",
+ FileName = LazyOperations.HDiffPath,
+ Arguments = $"-s-64 -c-zstd-21-24 -d \"{SourceFilePath}\" \"{TargetFilePath}\" \"{deltaPath}\"",
CreateNoWindow = true
})
.WaitForExit();
@@ -302,7 +303,7 @@ namespace PatcherUtils
Parallel.ForEach(targetFiles,
- new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile =>
+ new ParallelOptions() { MaxDegreeOfParallelism = 10 }, targetFile =>
{
//find a matching source file based on the relative path of the file
FileInfo sourceFile = sourceFiles.Find(f =>
diff --git a/Patcher/PatcherUtils/PatcherUtils.csproj b/Patcher/PatcherUtils/PatcherUtils.csproj
index 9681def..655ce67 100644
--- a/Patcher/PatcherUtils/PatcherUtils.csproj
+++ b/Patcher/PatcherUtils/PatcherUtils.csproj
@@ -6,13 +6,9 @@
2.15.3
-
-
-
-
-
+
@@ -22,7 +18,7 @@
-
+
diff --git a/Patcher/PatcherUtils/Resources/hdiffz.exe b/Patcher/PatcherUtils/Resources/hdiffz.exe
new file mode 100644
index 0000000..38c092d
Binary files /dev/null and b/Patcher/PatcherUtils/Resources/hdiffz.exe differ
diff --git a/Patcher/PatcherUtils/Resources/xdelta3.exe b/Patcher/PatcherUtils/Resources/xdelta3.exe
deleted file mode 100644
index 1cce3c5..0000000
Binary files a/Patcher/PatcherUtils/Resources/xdelta3.exe and /dev/null differ