Skip to content

Commit 65ca84b

Browse files
committed
Fix ignored assets gets redownloaded
1 parent bc96127 commit 65ca84b

File tree

3 files changed

+15
-67
lines changed

3 files changed

+15
-67
lines changed

CollapseLauncher/Classes/InstallManagement/Zenless/ZenlessInstall.SophonPatch.cs

Lines changed: 12 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Hi3Helper.Sophon;
22
using Hi3Helper.Sophon.Infos;
3+
using Hi3Helper.Sophon.Structs;
34
using System;
45
using System.Buffers;
56
using System.Collections.Generic;
@@ -29,47 +30,16 @@ public override async Task FilterAssetList<T>(
2930
Func<T, string?> itemPathSelector,
3031
CancellationToken token)
3132
{
32-
HashSet<int> exceptMatchFieldHashSet = await GetExceptMatchFieldHashSet(token);
33+
HashSet<string> exceptMatchFieldHashSet = await GetExceptMatchFieldHashSet(token);
3334
if (exceptMatchFieldHashSet.Count == 0)
3435
{
3536
return;
3637
}
3738

38-
FilterSophonAsset(itemList, Selector, exceptMatchFieldHashSet);
39-
return;
40-
41-
string? Selector(T item)
42-
{
43-
// For Game Update
44-
if (item is SophonPatchAsset asset)
45-
{
46-
if (asset.MainAssetInfo is not { } assetSelected)
47-
{
48-
return null;
49-
}
50-
51-
token.ThrowIfCancellationRequested();
52-
ref SophonChunksInfo chunkInfo = ref Unsafe.IsNullRef(ref assetSelected)
53-
? ref Unsafe.NullRef<SophonChunksInfo>()
54-
: ref GetChunkAssetChunksInfo(assetSelected);
55-
56-
if (Unsafe.IsNullRef(ref chunkInfo))
57-
{
58-
chunkInfo = ref GetChunkAssetChunksInfoAlt(assetSelected);
59-
}
60-
61-
return Unsafe.IsNullRef(ref chunkInfo)
62-
? asset.MainAssetInfo.AssetName
63-
: chunkInfo.ChunksBaseUrl;
64-
}
65-
66-
// TODO: For Game Repair handle
67-
68-
return null;
69-
}
39+
FilterSophonAsset(itemList, exceptMatchFieldHashSet);
7040
}
7141

72-
private async Task<HashSet<int>> GetExceptMatchFieldHashSet(CancellationToken token)
42+
private async Task<HashSet<string>> GetExceptMatchFieldHashSet(CancellationToken token)
7343
{
7444
string gameExecDataName =
7545
Path.GetFileNameWithoutExtension(GameVersionManager.GamePreset.GameExecutableName) ?? "ZenlessZoneZero";
@@ -82,38 +52,20 @@ private async Task<HashSet<int>> GetExceptMatchFieldHashSet(CancellationToken to
8252
return [];
8353
}
8454

85-
string exceptMatchFieldContent = await File.ReadAllTextAsync(gameExceptMatchFieldFile, token);
86-
HashSet<int> exceptMatchFieldHashSet = CreateExceptMatchFieldHashSet<int>(exceptMatchFieldContent);
55+
string exceptMatchFieldContent = await File.ReadAllTextAsync(gameExceptMatchFieldFile, token);
56+
HashSet<string> exceptMatchFieldHashSet = CreateExceptMatchFieldHashSet(exceptMatchFieldContent);
8757

8858
return exceptMatchFieldHashSet;
8959
}
9060

9161
// ReSharper disable once IdentifierTypo
92-
private static void FilterSophonAsset<T>(List<T> itemList, Func<T, string?> assetSelector, HashSet<int> exceptMatchFieldHashSet)
62+
private static void FilterSophonAsset<T>(List<T> itemList, HashSet<string> exceptMatchFieldHashSet)
9363
{
94-
const string separators = "/\\";
95-
scoped Span<Range> urlPathRanges = stackalloc Range[32];
96-
9764
List<T> filteredList = [];
9865
foreach (T asset in itemList)
9966
{
100-
string? assetPath = assetSelector(asset);
101-
if (assetPath == null)
102-
{
103-
filteredList.Add(asset);
104-
continue;
105-
}
106-
107-
ReadOnlySpan<char> manifestUrl = assetPath;
108-
int rangeLen = manifestUrl.SplitAny(urlPathRanges, separators, SplitOptions);
109-
if (rangeLen <= 0)
110-
{
111-
continue;
112-
}
113-
114-
ReadOnlySpan<char> manifestStr = manifestUrl[urlPathRanges[rangeLen - 1]];
115-
if (int.TryParse(manifestStr, null, out int lookupNumber) &&
116-
exceptMatchFieldHashSet.Contains(lookupNumber))
67+
if (asset is SophonIdentifiableProperty { MatchingField: { } assetMatchingField } &&
68+
exceptMatchFieldHashSet.Contains(assetMatchingField))
11769
{
11870
continue;
11971
}
@@ -130,11 +82,10 @@ private static void FilterSophonAsset<T>(List<T> itemList, Func<T, string?> asse
13082
itemList.AddRange(filteredList);
13183
}
13284

133-
internal static HashSet<T> CreateExceptMatchFieldHashSet<T>(string exceptMatchFieldContent)
134-
where T : ISpanParsable<T>
85+
internal static HashSet<string> CreateExceptMatchFieldHashSet(string exceptMatchFieldContent)
13586
{
13687
const string lineFeedSeparators = "\r\n";
137-
HashSet<T> hashSetReturn = [];
88+
HashSet<string> hashSetReturn = new(StringComparer.OrdinalIgnoreCase);
13889
scoped Span<Range> contentLineRange = stackalloc Range[2];
13990

14091
ReadOnlySpan<char> contentSpan = exceptMatchFieldContent.AsSpan();
@@ -157,10 +108,7 @@ internal static HashSet<T> CreateExceptMatchFieldHashSet<T>(string exceptMatchFi
157108
}
158109

159110
ReadOnlySpan<char> contentMatch = contentSpan[contentMatchRange].Trim(separatorsChars);
160-
if (T.TryParse(contentMatch, null, out T? result))
161-
{
162-
hashSetReturn.Add(result);
163-
}
111+
hashSetReturn.Add(contentMatch.ToString());
164112
}
165113

166114
return hashSetReturn;

CollapseLauncher/Classes/RepairManagement/Zenless/ZenlessRepair.Fetch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void FilterExcludedAssets(List<FilePropertiesRemote> assetList)
107107
}
108108

109109
string exceptMatchFieldContent = File.ReadAllText(gameExceptMatchFieldFile);
110-
HashSet<int> exceptMatchFieldHashSet = ZenlessInstall.CreateExceptMatchFieldHashSet<int>(exceptMatchFieldContent);
110+
HashSet<string> exceptMatchFieldHashSet = ZenlessInstall.CreateExceptMatchFieldHashSet(exceptMatchFieldContent);
111111

112112
List<FilePropertiesRemote> filteredList = [];
113113
foreach (FilePropertiesRemote asset in assetList)
@@ -120,7 +120,7 @@ private void FilterExcludedAssets(List<FilePropertiesRemote> assetList)
120120
continue;
121121
}
122122

123-
bool isExceptionFound = zenlessResAsset.PackageMatchingIds.Any(exceptMatchFieldHashSet.Contains);
123+
bool isExceptionFound = zenlessResAsset.PackageMatchingIds.Any(x => exceptMatchFieldHashSet.Contains($"{x}"));
124124
if (isExceptionFound)
125125
{
126126
continue;

0 commit comments

Comments
 (0)