Skip to content

Commit c1ff034

Browse files
committed
[GenshinRepair] Save PatchDone content
1 parent 690fa0c commit c1ff034

File tree

1 file changed

+34
-12
lines changed
  • CollapseLauncher/Classes/RepairManagement/Genshin

1 file changed

+34
-12
lines changed

CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ await ParseManifestToAssetIndex(downloadClient, downloadProgress, dataSilURL, ""
292292
basePersistentPath, baseStreamingAssetsPath, assetIndex, hashtableManifest, token, true, dataSilIgnoreContainsParams);
293293

294294
// Save persistent manifest numbers
295-
SavePersistentRevision(queryProperty);
295+
await SavePersistentRevision(downloadClient, queryProperty, token);
296296
return true;
297297
}
298298
catch (Exception ex)
@@ -479,40 +479,62 @@ private static void ParsePkgVersionManifest(string
479479
}
480480
}
481481

482-
private void SavePersistentRevision(QueryProperty dispatchQuery)
482+
private async Task SavePersistentRevision(DownloadClient downloadClient, QueryProperty dispatchQuery, CancellationToken token)
483483
{
484484
string persistentPath = Path.Combine(GamePath, $"{ExecPrefix}_Data\\Persistent");
485485

486486
// Get base_res_version_hash content
487487
string filePath = Path.Combine(GamePath, $@"{ExecPrefix}_Data\StreamingAssets\res_versions_streaming");
488-
using FileStream resVersionStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
488+
await using FileStream resVersionStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
489489
byte[] hashBytes = Hash.GetCryptoHash<MD5>(resVersionStream);
490490
string hash = Convert.ToHexStringLower(hashBytes);
491491

492492
#nullable enable
493493
// Write DownloadPref template
494494
byte[]? prefTemplateBytes = (GameVersionManager as GameTypeGenshinVersion)?.GamePreset
495495
.GetGameDataTemplate("DownloadPref", GameVersion.VersionArrayManifest.Select(x => (byte)x).ToArray());
496-
if (prefTemplateBytes != null) File.WriteAllBytes(persistentPath + "\\DownloadPref", prefTemplateBytes);
496+
if (prefTemplateBytes != null) await File.WriteAllBytesAsync(persistentPath + "\\DownloadPref", prefTemplateBytes, token);
497497
#nullable disable
498498

499499
// Get base_res_version_hash content
500-
File.WriteAllText(persistentPath + "\\base_res_version_hash", hash);
500+
await File.WriteAllTextAsync(persistentPath + "\\base_res_version_hash", hash, token);
501501
// Get data_revision content
502-
File.WriteAllText(persistentPath + "\\data_revision", $"{dispatchQuery.DataRevisionNum}");
502+
await File.WriteAllTextAsync(persistentPath + "\\data_revision", $"{dispatchQuery.DataRevisionNum}", token);
503503
// Get res_revision content
504-
File.WriteAllText(persistentPath + "\\res_revision", $"{dispatchQuery.ResRevisionNum}");
504+
await File.WriteAllTextAsync(persistentPath + "\\res_revision", $"{dispatchQuery.ResRevisionNum}", token);
505505
// Get res_revision_eternal content (Yes, you hear it right. It's called "eternal", not "external")...
506506
// or HoYo just probably typoed it (as usual).
507-
File.WriteAllText(persistentPath + "\\res_revision_eternal", $"{dispatchQuery.ResRevisionNum}");
507+
await File.WriteAllTextAsync(persistentPath + "\\res_revision_eternal", $"{dispatchQuery.ResRevisionNum}", token);
508508
// Get silence_revision content
509-
File.WriteAllText(persistentPath + "\\silence_revision", $"{dispatchQuery.SilenceRevisionNum}");
509+
await File.WriteAllTextAsync(persistentPath + "\\silence_revision", $"{dispatchQuery.SilenceRevisionNum}", token);
510510
// Get audio_revision content
511-
File.WriteAllText(persistentPath + "\\audio_revision", $"{dispatchQuery.AudioRevisionNum}");
511+
await File.WriteAllTextAsync(persistentPath + "\\audio_revision", $"{dispatchQuery.AudioRevisionNum}", token);
512512
// Get ChannelName content
513-
File.WriteAllText(persistentPath + "\\ChannelName", $"{dispatchQuery.ChannelName}");
513+
await File.WriteAllTextAsync(persistentPath + "\\ChannelName", $"{dispatchQuery.ChannelName}", token);
514514
// Get ScriptVersion content
515-
File.WriteAllText(persistentPath + "\\ScriptVersion", $"{dispatchQuery.GameVersion}");
515+
await File.WriteAllTextAsync(persistentPath + "\\ScriptVersion", $"{dispatchQuery.GameVersion}", token);
516+
// Get PatchDone content
517+
HttpClient client = downloadClient.GetHttpClient();
518+
string baseRevisionUrl = CombineURLFromString(dispatchQuery.ClientGameResURL, "StandaloneWindows64", "base_revision");
519+
HttpResponseMessage response = await client.GetAsync(baseRevisionUrl, HttpCompletionOption.ResponseHeadersRead, token);
520+
if (!response.IsSuccessStatusCode)
521+
{
522+
return;
523+
}
524+
string responseString = await response.Content.ReadAsStringAsync(token);
525+
if (string.IsNullOrEmpty(responseString))
526+
{
527+
return;
528+
}
529+
string[] responseData = responseString.Split(' ');
530+
if (responseData.Length < 2)
531+
{
532+
return;
533+
}
534+
if (long.TryParse(responseData[0], out long patchDoneRevision))
535+
{
536+
await File.WriteAllTextAsync(persistentPath + "\\PatchDone", $"{patchDoneRevision}", token);
537+
}
516538
}
517539
#endregion
518540

0 commit comments

Comments
 (0)