Skip to content

Commit

Permalink
Remove HDiff source file if path isn't identical
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Jan 14, 2025
1 parent 7fc46d8 commit 8d29f77
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1786,6 +1789,11 @@ await Task.Factory.StartNew(state =>
_ = patchPath.TryDeleteFile();
}

if (isSuccess && !isSourceTargetSameName)
{
_ = sourcePath.TryDeleteFile();
}

_ = targetPathTemp.TryMoveTo(targetPath);
}
});
Expand Down

0 comments on commit 8d29f77

Please sign in to comment.