Skip to content

Commit

Permalink
Bring main changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bagusnl committed Apr 3, 2024
2 parents 44c2b4f + ad0ac27 commit 7af90dc
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 41 deletions.
23 changes: 16 additions & 7 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"mentoring",
"maintenance",
"review",
"projectManagement"
"projectManagement"
]
},
{
Expand All @@ -33,7 +33,7 @@
"code",
"maintenance",
"review",
"projectManagement"
"projectManagement"
]
},
{
Expand All @@ -43,11 +43,11 @@
"profile": "https://github.com/bagusnl",
"contributions": [
"code",
"maintenance",
"review",
"promotion",
"infra",
"projectManagement"
"maintenance",
"review",
"promotion",
"infra",
"projectManagement"
]
},
{
Expand Down Expand Up @@ -196,6 +196,15 @@
"contributions": [
"bug"
]
},
{
"login": "IhoFox",
"name": "IhoFox",
"avatar_url": "https://avatars.githubusercontent.com/u/133899447?v=4",
"profile": "https://github.com/IhoFox",
"contributions": [
"translation"
]
}
],
"repoType": "github"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ jobs:
dotnet publish CollapseLauncher -p:PublishProfile=Publish-PreviewRelease -p:PublishDir=".\preview-build\"
- name: Upload Artifact (Release)
uses: actions/upload-artifact@v3.1.2
uses: actions/upload-artifact@v4.3.1
if: ${{ matrix.configuration == 'Release' }}
with:
name: collapse_${{ matrix.platform }}-${{ matrix.configuration }}_${{ matrix.framework }}_${{ github.sha }}
path: ./CollapseLauncher/preview-build/
compression-level: 9

- name: Notify Discord
uses: sarisia/[email protected]
Expand Down
122 changes: 90 additions & 32 deletions CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Hi3Helper.Shared.ClassStruct;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
Expand Down Expand Up @@ -63,7 +62,7 @@ private async ValueTask<List<PkgVersionProperties>> Fetch(List<PkgVersionPropert
{
// Unsubscribe and dispose the _httpClient
_httpClient.DownloadProgress -= _httpClient_FetchManifestAssetProgress;
_httpClient?.Dispose();
_httpClient.Dispose();
}
}

Expand All @@ -81,7 +80,7 @@ private void EliminatePluginAssetIndex(List<PkgVersionProperties> assetIndex)
private List<PkgVersionProperties> EliminateUnnecessaryAssetIndex(IEnumerable<PkgVersionProperties> assetIndex)
{
// Section: Eliminate unused audio files
List<string> audioLangList = (_gameVersionManager as GameTypeGenshinVersion)._audioVoiceLanguageList;
List<string> audioLangList = (_gameVersionManager as GameTypeGenshinVersion)!._audioVoiceLanguageList;
string audioLangListPath = Path.Combine(_gamePath, $"{_execPrefix}_Data", "Persistent", "audio_lang_14");

// Get the list of audio lang list
Expand All @@ -106,28 +105,69 @@ private async Task BuildPrimaryManifest(Http _httpClient, List<PkgVersionPropert
string ManifestPath = Path.Combine(_gamePath, "pkg_version");

// Download basic package version list
await _httpClient.Download(CombineURLFromString(_gameRepoURL, "pkg_version"), EnsureCreationOfDirectory(ManifestPath), true, null, null, token);
var basicVerURL = CombineURLFromString(_gameRepoURL, "pkg_version");
#if DEBUG
LogWriteLine($"Downloading pkg_version...\r\n\t{basicVerURL}", LogType.Debug, true);
#endif
await _httpClient.Download(basicVerURL, EnsureCreationOfDirectory(ManifestPath),
true, null, null, token);

// Download additional package lists
await _httpClient.Download(CombineURLFromString(_gameRepoURL, $"{_execPrefix}_Data\\StreamingAssets\\data_versions_streaming"), EnsureCreationOfDirectory(Path.Combine(_gamePath, $"{_execPrefix}_Data\\StreamingAssets\\data_versions_streaming")), true, null, null, token);
await _httpClient.Download(CombineURLFromString(_gameRepoURL, $"{_execPrefix}_Data\\StreamingAssets\\silence_versions_streaming"), EnsureCreationOfDirectory(Path.Combine(_gamePath, $"{_execPrefix}_Data\\StreamingAssets\\silence_versions_streaming")), true, null, null, token);
await _httpClient.Download(CombineURLFromString(_gameRepoURL, $"{_execPrefix}_Data\\StreamingAssets\\res_versions_streaming"), EnsureCreationOfDirectory(Path.Combine(_gamePath, $"{_execPrefix}_Data\\StreamingAssets\\res_versions_streaming")), true, null, null, token);
await _httpClient.Download(CombineURLFromString(_gameRepoURL, $"{_execPrefix}_Data\\StreamingAssets\\VideoAssets\\video_versions_streaming"), EnsureCreationOfDirectory(Path.Combine(_gamePath, $"{_execPrefix}_Data\\StreamingAssets\\VideoAssets\\video_versions_streaming")), true, null, null, token);
var dataVerPath = $@"{_execPrefix}_Data\StreamingAssets\data_versions_streaming";
var dataVerURL = CombineURLFromString(_gameRepoURL, dataVerPath);
#if DEBUG
LogWriteLine($"Downloading data_versions_streaming...\r\n\t{dataVerURL}", LogType.Debug, true);
#endif
await _httpClient.Download(dataVerURL, EnsureCreationOfDirectory(Path.Combine(_gamePath, dataVerPath)),
true, null, null, token);

var silenceVerPath = $@"{_execPrefix}_Data\StreamingAssets\silence_versions_streaming";
var silenceVerURL = CombineURLFromString(_gameRepoURL, silenceVerPath);
#if DEBUG
LogWriteLine($"Downloading silence_versions_streaming...\r\n\t{silenceVerURL}", LogType.Debug, true);
#endif
await _httpClient.Download(silenceVerURL, EnsureCreationOfDirectory(Path.Combine(_gamePath, silenceVerPath)),
true, null, null, token);

var resVerPath = $@"{_execPrefix}_Data\StreamingAssets\res_versions_streaming";
var resVerURL = CombineURLFromString(_gameRepoURL, resVerPath);
#if DEBUG
LogWriteLine($"Downloading res_versions_streaming...\r\n\t{resVerURL}", LogType.Debug, true);
#endif
await _httpClient.Download(resVerURL, EnsureCreationOfDirectory(Path.Combine(_gamePath, resVerPath)),
true, null, null, token);

var videoVerPath = $@"{_execPrefix}_Data\StreamingAssets\VideoAssets\video_versions_streaming";
var videoVerURL = CombineURLFromString(_gameRepoURL, videoVerPath);
#if DEBUG
LogWriteLine($"Downloading video_versions_streaming...\r\n\t{videoVerURL}", LogType.Debug, true);
#endif
await _httpClient.Download(videoVerURL, EnsureCreationOfDirectory(Path.Combine(_gamePath, videoVerPath)),
true, null, null, token);

// Parse basic package version.
ParseManifestToAssetIndex(ManifestPath, assetIndex, hashtableManifest, "", "", _gameRepoURL, true);

// Build additional blks entry.
EnumerateManifestToAssetIndex($"{_execPrefix}_Data\\StreamingAssets", "data_versions_*", assetIndex, hashtableManifest, $"{_execPrefix}_Data\\StreamingAssets\\AssetBundles", "", _gameRepoURL, true);
EnumerateManifestToAssetIndex($"{_execPrefix}_Data\\StreamingAssets", "silence_versions_*", assetIndex, hashtableManifest, $"{_execPrefix}_Data\\StreamingAssets\\AssetBundles", "", _gameRepoURL, true);
EnumerateManifestToAssetIndex($"{_execPrefix}_Data\\StreamingAssets", "res_versions_*", assetIndex, hashtableManifest, $"{_execPrefix}_Data\\StreamingAssets\\AssetBundles", ".blk", _gameRepoURL, true);
var streamingAssetsPath = $"{_execPrefix}_Data\\StreamingAssets";
var assetBundlesPath = $@"{_execPrefix}_Data\StreamingAssets\AssetBundles";

EnumerateManifestToAssetIndex(streamingAssetsPath, "data_versions_*", assetIndex, hashtableManifest,
assetBundlesPath, "", _gameRepoURL, true);
EnumerateManifestToAssetIndex(streamingAssetsPath, "silence_versions_*", assetIndex, hashtableManifest,
assetBundlesPath, "", _gameRepoURL, true);
EnumerateManifestToAssetIndex(streamingAssetsPath, "res_versions_*", assetIndex, hashtableManifest,
assetBundlesPath, ".blk", _gameRepoURL, true);

// Build cutscenes entry.
EnumerateManifestToAssetIndex($"{_execPrefix}_Data\\StreamingAssets\\VideoAssets", "*_versions_*", assetIndex, hashtableManifest, $"{_execPrefix}_Data\\StreamingAssets\\VideoAssets", "", _gameRepoURL, true);
var videoAssetsPath = $@"{_execPrefix}_Data\StreamingAssets\VideoAssets";
EnumerateManifestToAssetIndex(videoAssetsPath, "*_versions_*", assetIndex, hashtableManifest,
videoAssetsPath, "", _gameRepoURL, true);
}
catch (Exception ex)
{
LogWriteLine($"Parsing primary manifest has failed!\r\n{ex}", LogType.Error, true);
ErrorSender.SendException(ex, ErrorType.Unhandled);
ErrorSender.SendException(ex);
}
}

Expand All @@ -144,7 +184,8 @@ private void TryDeleteDownloadPref()
#endregion

#region PersistentManifest
private async Task<bool> BuildPersistentManifest(Http _httpClient, List<PkgVersionProperties> assetIndex, Dictionary<string, PkgVersionProperties> hashtableManifest, CancellationToken token)
private async Task<bool> BuildPersistentManifest(Http _httpClient, List<PkgVersionProperties> assetIndex,
Dictionary<string, PkgVersionProperties> hashtableManifest, CancellationToken token)
{
try
{
Expand All @@ -168,24 +209,37 @@ private async Task<bool> BuildPersistentManifest(Http _httpClient, List<PkgVersi
Directory.CreateDirectory(streamingAssetsFolder);
}

string primaryParentURL;
string secondaryParentURL;

// Parse res_versions_external
primaryParentURL = CombineURLFromString(queryProperty.ClientGameResURL, "StandaloneWindows64");
secondaryParentURL = CombineURLFromString(queryProperty.ClientAudioAssetsURL, "StandaloneWindows64");
var primaryParentURL =
CombineURLFromString(queryProperty.ClientGameResURL, "StandaloneWindows64");
var secondaryParentURL = CombineURLFromString(queryProperty.ClientAudioAssetsURL, "StandaloneWindows64");
#if DEBUG
LogWriteLine($"Downloading res_versions_external...\r\n\t" +
$"pri: {primaryParentURL}\r\n\t"+
$"sec: {secondaryParentURL}", LogType.Debug, true);
#endif
await ParseManifestToAssetIndex(_httpClient, primaryParentURL, secondaryParentURL, "res_versions_external",
"res_versions_external_persist", basePersistentPath, baseStreamingAssetsPath, assetIndex, hashtableManifest, token);

// Parse data_versions
primaryParentURL = queryProperty.ClientDesignDataURL;
await ParseManifestToAssetIndex(_httpClient, primaryParentURL, "", CombineURLFromString("AssetBundles", "data_versions"),
"data_versions_persist", basePersistentPath, baseStreamingAssetsPath, assetIndex, hashtableManifest, token, true, true);
var dataVerURL = queryProperty.ClientDesignDataURL;
#if DEBUG
LogWriteLine($"Downloading data_versions_persist...\r\n\t" +
$"{dataVerURL}", LogType.Debug, true);
#endif
await ParseManifestToAssetIndex(_httpClient, dataVerURL, "",
CombineURLFromString("AssetBundles", "data_versions"), "data_versions_persist", basePersistentPath,
baseStreamingAssetsPath, assetIndex, hashtableManifest, token, true, true);

// Parse data_versions (silence)
primaryParentURL = queryProperty.ClientDesignDataSilURL;
await ParseManifestToAssetIndex(_httpClient, primaryParentURL, "", CombineURLFromString("AssetBundles", "data_versions"),
"silence_data_versions_persist", basePersistentPath, baseStreamingAssetsPath, assetIndex, hashtableManifest, token, true, true);
var dataSilURL = queryProperty.ClientDesignDataSilURL;
#if DEBUG
LogWriteLine($"Downloading silence_data_versions_persist...\r\n\t" +
$"{dataSilURL}", LogType.Debug, true);
#endif
await ParseManifestToAssetIndex(_httpClient, dataSilURL, "",
CombineURLFromString("AssetBundles", "data_versions"), "silence_data_versions_persist",
basePersistentPath, baseStreamingAssetsPath, assetIndex, hashtableManifest, token, true, true);

// Save persistent manifest numbers
SavePersistentRevision(queryProperty);
Expand Down Expand Up @@ -343,7 +397,7 @@ private void SavePersistentRevision(QueryProperty dispatchQuery)

#nullable enable
// Write DownloadPref template
byte[]? PrefTemplateBytes = (base._gameVersionManager as GameTypeGenshinVersion)?.GamePreset
byte[]? PrefTemplateBytes = (_gameVersionManager as GameTypeGenshinVersion)?.GamePreset
.GetGameDataTemplate("DownloadPref", _gameVersion.VersionArrayManifest.Select(x => (byte)x).ToArray());
if (PrefTemplateBytes != null) File.WriteAllBytes(PersistentPath + "\\DownloadPref", PrefTemplateBytes);
#nullable disable
Expand All @@ -366,6 +420,7 @@ private void SavePersistentRevision(QueryProperty dispatchQuery)
#endregion

#region DispatcherParser
// ReSharper disable once UnusedParameter.Local
private async Task<QueryProperty> GetDispatcherQuery(Http _httpClient, CancellationToken token)
{
// Initialize dispatch helper
Expand All @@ -386,7 +441,7 @@ private async Task<QueryProperty> GetDispatcherQuery(Http _httpClient, Cancellat
LogWriteLine(dFormat);
#endif
// Write the decrypted query response in the log (for diagnostic)
WriteLog(dFormat, LogType.Default);
WriteLog(dFormat);

// Try decrypt the dispatcher, parse it and return it
return await TryDecryptAndParseDispatcher(dispatchInfo, dispatchDecryptor, dispatchHelper);
Expand Down Expand Up @@ -429,7 +484,7 @@ private async Task<QueryProperty> TryDecryptAndParseDispatcher(YSDispatchInfo di
#if DEBUG
LogWriteLine(dFormat);
#endif
WriteLog(dFormat, LogType.Default);
WriteLog(dFormat);

// Parse the dispatcher data in protobuf format and return it as QueryProperty
await dispatchHelper.LoadDispatch(decryptedData);
Expand Down Expand Up @@ -462,11 +517,14 @@ private void EnumerateManifestToAssetIndex(string path, string filter, List<PkgV
/// <param name="parentPath"></param>
/// <param name="acceptedExtension"></param>
/// <param name="parentURL"></param>
/// <param name="forceStoreInStreaming"></param>
private void ParseManifestToAssetIndex(string manifestPath, List<PkgVersionProperties> assetIndex, Dictionary<string, PkgVersionProperties> hashtable, string parentPath, string acceptedExtension, string parentURL, bool forceStoreInStreaming = false)
{
// Initialize local entry.
// ReSharper disable TooWideLocalVariableScope
PkgVersionProperties entry;
bool isHashHasValue = false;
bool isHashHasValue;
// ReSharper restore TooWideLocalVariableScope

// Iterate JSON that only contains defined extensions.
foreach (string data in File.ReadAllLines(manifestPath).Where(x => x.EndsWith(acceptedExtension, StringComparison.OrdinalIgnoreCase)))
Expand All @@ -477,12 +535,12 @@ private void ParseManifestToAssetIndex(string manifestPath, List<PkgVersionPrope
// If the parent path is not defined, then use already-defined parent path from JSON and append it as remote name.
if (!string.IsNullOrEmpty(parentPath))
{
entry.remoteName = $"{parentPath.Replace('\\', '/')}/{entry.remoteName}";
entry!.remoteName = $"{parentPath.Replace('\\', '/')}/{entry.remoteName}";
}

// Append remote URL for download later.
entry.remoteURL = CombineURLFromString(parentURL, entry.remoteName);
entry.isForceStoreInStreaming = forceStoreInStreaming;
entry!.remoteURL = CombineURLFromString(parentURL, entry.remoteName);
entry!.isForceStoreInStreaming = forceStoreInStreaming;

// Check if the entry is duplicated. If not, then add to asset index.
isHashHasValue = hashtable.ContainsKey(entry.remoteName);
Expand Down
3 changes: 2 additions & 1 deletion CollapseLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace CollapseLauncher
{
public static class MainEntryPoint
{
public static readonly int InstanceCount = InvokeProp.GetInstanceCount();
public static int InstanceCount;

[DllImport("Microsoft.ui.xaml.dll")]
private static extern void XamlCheckProcessRequirements();
Expand All @@ -35,6 +35,7 @@ public static void Main(params string[] args)
#if PREVIEW
IsPreview = true;
#endif
InstanceCount = InvokeProp.GetInstanceCount();
AppCurrentVersion = new GameVersion(Assembly.GetExecutingAssembly().GetName().Version);
AppCurrentVersionString = AppCurrentVersion.VersionString;

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Made by all captains around the world with ❤️. Fight for all that is beautif
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Arikatsu"><img src="https://avatars.githubusercontent.com/u/104459145?v=4?s=100" width="100px;" alt="Scald"/><br /><sub><b>Scald</b></sub></a><br /><a href="https://github.com/CollapseLauncher/Collapse/commits?author=Arikatsu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/muscularcandy67"><img src="https://avatars.githubusercontent.com/u/12277635?v=4?s=100" width="100px;" alt="Iskandar Montano"/><br /><sub><b>Iskandar Montano</b></sub></a><br /><a href="https://github.com/CollapseLauncher/Collapse/commits?author=muscularcandy67" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Scighost"><img src="https://avatars.githubusercontent.com/u/61003590?v=4?s=100" width="100px;" alt="Scighost"/><br /><sub><b>Scighost</b></sub></a><br /><a href="https://github.com/CollapseLauncher/Collapse/issues?q=author%3AScighost" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/IhoFox"><img src="https://avatars.githubusercontent.com/u/133899447?v=4?s=100" width="100px;" alt="IhoFox"/><br /><sub><b>IhoFox</b></sub></a><br /><a href="#translation-IhoFox" title="Translation">🌍</a></td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 7af90dc

Please sign in to comment.