Skip to content

Commit bf4f646

Browse files
committed
Fix rare issue while Sophon API doesn't override package API
This fixes an issue where some games with no latest package for normal update (ex: Genshin) isn't available and Sophon sometimes didn't get forcefully applied. This was caused by unfinished task after the URL is re-associated.
1 parent 8861508 commit bf4f646

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

CollapseLauncher/Classes/Helper/LauncherApiLoader/LauncherApiBase.cs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ protected virtual void AddFakeVersionInfo(HoYoPlayGameInfoBranchField branchFiel
222222
}
223223
}
224224

225-
protected virtual Task LoadLauncherGameResourceSophon(ActionOnTimeOutRetry? onTimeoutRoutine,
225+
protected virtual async Task LoadLauncherGameResourceSophon(ActionOnTimeOutRetry? onTimeoutRoutine,
226226
CancellationToken token)
227227
{
228228
EnsurePresetConfigNotNull();
229229

230230
SophonChunkUrls? sophonUrls = PresetConfig?.LauncherResourceChunksURL;
231231
if (sophonUrls == null)
232232
{
233-
return Task.CompletedTask;
233+
return;
234234
}
235235

236236
string? sophonBranchUrl = sophonUrls.BranchUrl;
@@ -239,33 +239,31 @@ protected virtual Task LoadLauncherGameResourceSophon(ActionOnTimeOutRetry? onTi
239239
Logger.LogWriteLine("This game/region doesn't have Sophon->BranchUrl or PresetConfig->LauncherBizName property defined! This might cause the launcher inaccurately check the version if Zip download is unavailable", LogType.Warning, true);
240240
}
241241

242-
return sophonUrls
243-
.EnsureReassociated(ApiGeneralHttpClient,
244-
sophonBranchUrl,
245-
PresetConfig.LauncherBizName!,
246-
false,
247-
token)
248-
.ContinueWith(async _ =>
249-
{
250-
sophonUrls.ResetAssociation(); // Reset association so it won't conflict with preload/update/install activity
251-
252-
ActionTimeoutTaskAwaitableCallback<HoYoPlayLauncherGameInfo?> launcherSophonBranchCallback =
253-
innerToken =>
254-
ApiGeneralHttpClient
255-
.GetFromCachedJsonAsync(PresetConfig.LauncherResourceChunksURL?.BranchUrl,
256-
HoYoPlayLauncherGameInfoJsonContext.Default.HoYoPlayLauncherGameInfo,
257-
null,
258-
innerToken)
259-
.ConfigureAwait(false);
260-
261-
await launcherSophonBranchCallback
262-
.WaitForRetryAsync(ExecutionTimeout,
263-
ExecutionTimeoutStep,
264-
ExecutionTimeoutAttempt,
265-
onTimeoutRoutine,
266-
result => LauncherGameResourceSophon = result,
267-
token);
268-
}, token);
242+
// Ensure associated
243+
await sophonUrls.EnsureReassociated(ApiGeneralHttpClient,
244+
sophonBranchUrl,
245+
PresetConfig.LauncherBizName!,
246+
false,
247+
token);
248+
249+
sophonUrls.ResetAssociation(); // Reset association so it won't conflict with preload/update/install activity
250+
251+
ActionTimeoutTaskAwaitableCallback<HoYoPlayLauncherGameInfo?> launcherSophonBranchCallback =
252+
innerToken =>
253+
ApiGeneralHttpClient
254+
.GetFromCachedJsonAsync(PresetConfig.LauncherResourceChunksURL?.BranchUrl,
255+
HoYoPlayLauncherGameInfoJsonContext.Default.HoYoPlayLauncherGameInfo,
256+
null,
257+
innerToken)
258+
.ConfigureAwait(false);
259+
260+
await launcherSophonBranchCallback
261+
.WaitForRetryAsync(ExecutionTimeout,
262+
ExecutionTimeoutStep,
263+
ExecutionTimeoutAttempt,
264+
onTimeoutRoutine,
265+
result => LauncherGameResourceSophon = result,
266+
token);
269267
}
270268

271269
protected virtual Task LoadLauncherGameResource(ActionOnTimeOutRetry? onTimeoutRoutine,

0 commit comments

Comments
 (0)