From 8d29f77e380f67726750283086ae918797f84a36 Mon Sep 17 00:00:00 2001 From: Kemal Setya Adhi Date: Tue, 14 Jan 2025 15:16:41 +0700 Subject: [PATCH] Remove HDiff source file if path isn't identical --- .../InstallManagement/Base/InstallManagerBase.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.cs b/CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.cs index 442729420..e6ac4caf0 100644 --- a/CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.cs +++ b/CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.cs @@ -1693,8 +1693,10 @@ protected virtual async Task ApplyHDiffMap() $"{Lang._Misc.Patching}: {string.Format(Lang._Misc.PerFromTo, _progressAllCountTotal, _progressAllCountFound)}"; - bool isUseSameName = string.IsNullOrEmpty(entry.SourceFileName); - string sourceFileNameToUse = (isUseSameName ? entry.SourceFileName : entry.TargetFileName) ?? ""; + bool isUseSameName = string.IsNullOrEmpty(entry.SourceFileName); + bool isSourceTargetSameName = entry.SourceFileName?.Equals(entry.TargetFileName, StringComparison.OrdinalIgnoreCase) ?? false; + bool isSuccess = false; + string sourceFileNameToUse = (isUseSameName ? entry.SourceFileName : entry.TargetFileName) ?? ""; FileInfo sourcePath = new FileInfo(Path.Combine(gameDir, sourceFileNameToUse)) .EnsureNoReadOnly(out bool isSourceExist); @@ -1740,6 +1742,7 @@ await Task.Factory.StartNew(state => HDiffPatch patcher = new HDiffPatch(); patcher.Initialize(patchPath.FullName); patcher.Patch(sourcePath.FullName, targetPathTemp.FullName, true, thisInnerCtx, false, true); + isSuccess = true; } catch (InvalidDataException ex) when (!thisInnerCtx.IsCancellationRequested) { @@ -1786,6 +1789,11 @@ await Task.Factory.StartNew(state => _ = patchPath.TryDeleteFile(); } + if (isSuccess && !isSourceTargetSameName) + { + _ = sourcePath.TryDeleteFile(); + } + _ = targetPathTemp.TryMoveTo(targetPath); } });