Skip to content

Commit 3c99779

Browse files
committed
Fix processing patched diff files
1 parent ba0b484 commit 3c99779

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -568,28 +568,37 @@ private void PatchFile(
568568
{
569569
_logger.LogDebug("Patching is necessary. Generating new file with patched content...");
570570

571-
var sourceDeltaFilePath = Path.Combine(packageDirPath, fileName + suffix);
572-
_logger.LogTrace("sourceDeltaFilePath = " + sourceDeltaFilePath);
573-
574-
if (!File.Exists(sourceDeltaFilePath))
571+
string nameHash;
572+
if (_mapHashExtractedFiles.TryGetHash(fileName, out nameHash))
575573
{
576-
throw new MissingFileFromPackageException(string.Format("Cannot find delta file {0} in diff package.",
577-
fileName));
578-
}
574+
var sourceDeltaFilePath = Path.Combine(packageDirPath, nameHash + suffix);
575+
_logger.LogTrace("sourceDeltaFilePath = " + sourceDeltaFilePath);
579576

580-
var newFilePath = tempDiffDir.GetUniquePath();
581-
_logger.LogTrace("newFilePath = " + newFilePath);
577+
if (!File.Exists(sourceDeltaFilePath))
578+
{
579+
throw new MissingFileFromPackageException(string.Format(
580+
"Cannot find delta file {0} in diff package.",
581+
fileName));
582+
}
582583

583-
var filePatcher = new FilePatcher(filePath, sourceDeltaFilePath, newFilePath);
584-
filePatcher.Patch();
584+
var newFilePath = tempDiffDir.GetUniquePath();
585+
_logger.LogTrace("newFilePath = " + newFilePath);
585586

586-
_logger.LogDebug("New file generated. Deleting old file in local data...");
587-
FileOperations.Delete(filePath, cancellationToken);
587+
var filePatcher = new FilePatcher(filePath, sourceDeltaFilePath, newFilePath);
588+
filePatcher.Patch();
588589

589-
_logger.LogDebug("Old file deleted. Moving new file to local data...");
590-
FileOperations.Move(newFilePath, filePath, cancellationToken);
590+
_logger.LogDebug("New file generated. Deleting old file in local data...");
591+
FileOperations.Delete(filePath, cancellationToken);
591592

592-
_logger.LogDebug("New file moved.");
593+
_logger.LogDebug("Old file deleted. Moving new file to local data...");
594+
FileOperations.Move(newFilePath, filePath, cancellationToken);
595+
596+
_logger.LogDebug("New file moved.");
597+
}
598+
else
599+
{
600+
throw new InstallerException(string.Format("Cannot find hash for file {0} in mapHash.", fileName));
601+
}
593602
}
594603
else
595604
{

0 commit comments

Comments
 (0)