Skip to content

Commit 68399a7

Browse files
committed
[HI3 Repair] Adjustment due to hash type changes
1 parent f872367 commit 68399a7

File tree

4 files changed

+293
-55
lines changed

4 files changed

+293
-55
lines changed

CollapseLauncher/Classes/RepairManagement/Honkai/Check.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,15 @@ private void RemoveSkipableAssets(List<FilePropertiesRemote> assetIndex)
375375
#endregion
376376

377377
#region BlocksCheck
378-
private static BlockPatchInfo? TryGetPossibleOldBlockLinkedPatch(string directory, FilePropertiesRemote block)
378+
private static BlockPatchInfo TryGetPossibleOldBlockLinkedPatch(string directory, FilePropertiesRemote block)
379379
{
380-
BlockOldPatchInfo? existingOldBlockPair = block.BlockPatchInfo?.PatchPairs?
381-
.Where(x => File.Exists(
382-
Path.Combine(directory, x.OldHashStr) + ".wmv"
383-
)).FirstOrDefault();
380+
BlockOldPatchInfo existingOldBlockPair = block.BlockPatchInfo?.PatchPairs?
381+
.Where(x => File.Exists(Path.Combine(directory, x.OldName)))
382+
.FirstOrDefault();
384383

385-
if (!existingOldBlockPair.HasValue || string.IsNullOrEmpty(existingOldBlockPair.Value.PatchHashStr)) return null;
384+
if (string.IsNullOrEmpty(existingOldBlockPair?.PatchName)) return null;
386385

387-
BlockOldPatchInfo oldBlockPairCopy = existingOldBlockPair.Value;
386+
BlockOldPatchInfo oldBlockPairCopy = existingOldBlockPair;
388387

389388
block.BlockPatchInfo?.PatchPairs.Clear();
390389
block.BlockPatchInfo?.PatchPairs.Add(oldBlockPairCopy);
@@ -409,9 +408,9 @@ private async Task CheckAssetTypeBlocks(FilePropertiesRemote asset, List<FilePro
409408
string filePath = Path.Combine(GamePath, asset.N);
410409
FileInfo file = new FileInfo(filePath);
411410

412-
BlockPatchInfo? patchInfo = TryGetPossibleOldBlockLinkedPatch(blockPath, asset);
413-
string filePathOld = patchInfo.HasValue ? Path.Combine(GamePath, ConverterTool.NormalizePath(BlockBasePath), asset.BlockPatchInfo?.PatchPairs[0].OldHashStr + ".wmv") : null;
414-
FileInfo fileOld = patchInfo.HasValue ? new FileInfo(filePathOld) : null;
411+
BlockPatchInfo patchInfo = TryGetPossibleOldBlockLinkedPatch(blockPath, asset);
412+
string filePathOld = patchInfo != null ? Path.Combine(GamePath, ConverterTool.NormalizePath(BlockBasePath), asset.BlockPatchInfo?.PatchPairs[0].OldName) : null;
413+
FileInfo fileOld = patchInfo != null ? new FileInfo(filePathOld) : null;
415414

416415
// If old block exist but current block doesn't, check if the hash of the old block matches and patchable
417416
if ((fileOld?.Exists ?? false) && !file.Exists)
@@ -422,10 +421,10 @@ private async Task CheckAssetTypeBlocks(FilePropertiesRemote asset, List<FilePro
422421
byte[] localOldCrc = await GetCryptoHashAsync<MD5>(fileOldFs, null, true, false, token);
423422

424423
// If the hash matches, then add the patch
425-
if (IsArrayMatch(localOldCrc, patchInfo.Value.PatchPairs[0].OldHash))
424+
if (IsArrayMatch(localOldCrc, patchInfo.PatchPairs[0].OldHash))
426425
{
427426
// Update the total progress and found counter
428-
ProgressAllSizeFound += patchInfo.Value.PatchPairs[0].PatchSize;
427+
ProgressAllSizeFound += patchInfo.PatchPairs[0].PatchSize;
429428
ProgressAllCountFound++;
430429

431430
// Set the per size progress
@@ -434,12 +433,11 @@ private async Task CheckAssetTypeBlocks(FilePropertiesRemote asset, List<FilePro
434433
// Increment the total current progress
435434
ProgressAllSizeCurrent += asset.S;
436435

437-
Dispatch(() => AssetEntry.Add(
438-
new AssetProperty<RepairAssetType>(
436+
Dispatch(() => AssetEntry.Add(new AssetProperty<RepairAssetType>(
439437
Path.GetFileName(asset.N),
440438
RepairAssetType.BlockUpdate,
441-
Path.GetDirectoryName(asset.N) + $" (MetaVer: {string.Join('.', patchInfo.Value.PatchPairs[0].OldVersion)})",
442-
patchInfo.Value.PatchPairs[0].PatchSize,
439+
Path.GetDirectoryName(asset.N) + $" (MetaVer: {string.Join('.', patchInfo.PatchPairs[0].OldVersion)})",
440+
patchInfo.PatchPairs[0].PatchSize,
443441
localOldCrc,
444442
asset.CRCArray
445443
)
@@ -568,9 +566,9 @@ private void BuildAssetIndexCatalog(HashSet<string> catalog, List<FileProperties
568566
{
569567
case FileType.Block:
570568
catalog.Add(path);
571-
if (asset.BlockPatchInfo.HasValue)
569+
if (asset.BlockPatchInfo != null)
572570
{
573-
string oldBlockPath = Path.Combine(GamePath, ConverterTool.NormalizePath(BlockBasePath), asset.BlockPatchInfo?.PatchPairs[0].OldHashStr + ".wmv");
571+
string oldBlockPath = Path.Combine(GamePath, ConverterTool.NormalizePath(BlockBasePath), asset.BlockPatchInfo?.PatchPairs[0].OldName);
574572
catalog.Add(oldBlockPath);
575573
}
576574
break;

0 commit comments

Comments
 (0)