From a22fccd42d0b3b75e499adf8befcdfc4b41fc858 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:36:06 -0700 Subject: [PATCH] Switch patch apply to use XDeltaSharp - This resolves the persistent `-1073741819` error some users receive during patching - XDeltaSharp doesn't support creating deltas, so patch creation still depends on xdelta3.exe --- Patcher/PatcherUtils/PatchHelper.cs | 45 ++++++++++-------------- Patcher/PatcherUtils/PatcherUtils.csproj | 3 +- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Patcher/PatcherUtils/PatchHelper.cs b/Patcher/PatcherUtils/PatchHelper.cs index 698336e..bdca657 100644 --- a/Patcher/PatcherUtils/PatchHelper.cs +++ b/Patcher/PatcherUtils/PatchHelper.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; -using PatcherUtils.Helpers; +using PleOps.XdeltaSharp.Decoder; namespace PatcherUtils { @@ -114,37 +114,30 @@ namespace PatcherUtils { string decodedPath = SourceFilePath + ".decoded"; - var xdeltaArgs = $"-d {(debugOutput ? "-v -v" : "")} -f -s"; - - var xdeltaHelper = - new XdeltaProcessHelper(xdeltaArgs, SourceFilePath, DeltaFilePath, decodedPath, debugOutput); - - if (!xdeltaHelper.Run()) + try { - return (false, "something went wrong during the xdelta3 process"); + 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(); + } + catch (Exception ex) + { + PatchLogger.LogException(ex); + return (false, ex.Message); } - if (File.Exists(decodedPath)) + try { - PatchLogger.LogInfo($"File delta decoded: {SourceFilePath}"); - - try - { - File.Move(decodedPath, SourceFilePath, true); - PatchLogger.LogInfo($"Delta applied: {DeltaFilePath}"); - return (true, ""); - } - catch (Exception ex) - { - PatchLogger.LogException(ex); - return (false, ex.Message); - } + File.Move(decodedPath, SourceFilePath, true); + PatchLogger.LogInfo($"Delta applied: {DeltaFilePath}"); + return (true, ""); } - else + catch (Exception ex) { - string error = $"Failed to decode file delta: {SourceFilePath}"; - PatchLogger.LogError(error); - return (false, error); + PatchLogger.LogException(ex); + return (false, ex.Message); } } diff --git a/Patcher/PatcherUtils/PatcherUtils.csproj b/Patcher/PatcherUtils/PatcherUtils.csproj index f33f9d4..a2175d2 100644 --- a/Patcher/PatcherUtils/PatcherUtils.csproj +++ b/Patcher/PatcherUtils/PatcherUtils.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -22,6 +22,7 @@ + -- 2.47.1