Skip to content

Commit

Permalink
Code QA (hopefully?)
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Aug 29, 2024
1 parent 5a1f3aa commit eb1348c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
35 changes: 14 additions & 21 deletions CollapseLauncher/Classes/RepairManagement/StarRail/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private async Task Fetch(List<FilePropertiesRemote> assetIndex, CancellationToke
// Initialize the metadata tool (including dispatcher and gateway).
// Perform this if only base._isVersionOverride is false to indicate that the repair performed is
// not for delta patch integrity check.
if (!base._isVersionOverride && !this._isOnlyRecoverMain && await _innerGameVersionManager.StarRailMetadataTool.Initialize(token, downloadClient, _httpClient_FetchAssetProgress, GetExistingGameRegionID(), Path.Combine(_gamePath, $"{Path.GetFileNameWithoutExtension(_innerGameVersionManager.GamePreset.GameExecutableName)}_Data\\Persistent")))
if (!_isVersionOverride && !this._isOnlyRecoverMain && await _innerGameVersionManager.StarRailMetadataTool.Initialize(token, downloadClient, _httpClient_FetchAssetProgress, GetExistingGameRegionID(), Path.Combine(_gamePath, $"{Path.GetFileNameWithoutExtension(_innerGameVersionManager.GamePreset.GameExecutableName)}_Data\\Persistent")))
{
// Read block metadata and convert to FilePropertiesRemote
await _innerGameVersionManager.StarRailMetadataTool.ReadAsbMetadataInformation(downloadClient, _httpClient_FetchAssetProgress, token);
Expand Down Expand Up @@ -223,35 +223,28 @@ private void ConvertPkgVersionToAssetIndex(List<PkgVersionProperties> pkgVersion
#endregion

#region Utilities
private FilePropertiesRemote GetNormalizedFilePropertyTypeBased(string remoteAbsolutePath, string remoteRelativePath, long fileSize,
string hash, FileType type, bool isPatchApplicable, bool isHasHashMark) =>
GetNormalizedFilePropertyTypeBased(remoteAbsolutePath, remoteRelativePath, fileSize,
hash, type, false, isPatchApplicable, isHasHashMark);

private FilePropertiesRemote GetNormalizedFilePropertyTypeBased(string remoteParentURL,
string remoteRelativePath,
long fileSize,
string hash,
FileType type = FileType.Generic,
bool isPkgVersion = true,
bool isPatchApplicable = false,
bool isHasHashMark = false)
{
string localAbsolutePath,
remoteAbsolutePath = type switch
{
FileType.Generic => CombineURLFromString(remoteParentURL, remoteRelativePath),
_ => remoteParentURL
},
string remoteAbsolutePath = type switch
{
FileType.Generic => CombineURLFromString(remoteParentURL, remoteRelativePath),
_ => remoteParentURL
},
typeAssetRelativeParentPath = string.Format(type switch
{
FileType.Blocks => _assetGameBlocksStreamingPath,
FileType.Audio => _assetGameAudioStreamingPath,
FileType.Video => _assetGameVideoStreamingPath,
_ => string.Empty
}, _execName);

localAbsolutePath = Path.Combine(_gamePath, typeAssetRelativeParentPath, NormalizePath(remoteRelativePath));
{
FileType.Blocks => _assetGameBlocksStreamingPath,
FileType.Audio => _assetGameAudioStreamingPath,
FileType.Video => _assetGameVideoStreamingPath,
_ => string.Empty
}, _execName);

var localAbsolutePath = Path.Combine(_gamePath, typeAssetRelativeParentPath, NormalizePath(remoteRelativePath));

return new FilePropertiesRemote
{
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/Classes/RepairManagement/StarRail/Repair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private async Task RepairAssetTypeGeneric((FilePropertiesRemote AssetIndex, IAss
// If asset type is unused, then delete it
if (asset.AssetIndex.FT == FileType.Unused)
{
FileInfo fileInfo = new FileInfo(asset.AssetIndex.N);
FileInfo fileInfo = new FileInfo(asset.AssetIndex.N!);
if (fileInfo.Exists)
{
fileInfo.IsReadOnly = false;
Expand All @@ -122,7 +122,7 @@ private async Task RepairAssetTypeGeneric((FilePropertiesRemote AssetIndex, IAss
else
{
// Start asset download task
await RunDownloadTask(asset.AssetIndex.S, asset.AssetIndex.N, asset.AssetIndex.RN, downloadClient, downloadProgress, token);
await RunDownloadTask(asset.AssetIndex.S, asset.AssetIndex.N!, asset.AssetIndex.RN, downloadClient, downloadProgress, token);
LogWriteLine($"File [T: {asset.AssetIndex.FT}] {(asset.AssetIndex.FT == FileType.Blocks ? asset.AssetIndex.CRC : asset.AssetIndex.N)} has been downloaded!", LogType.Default, true);
}

Expand Down

0 comments on commit eb1348c

Please sign in to comment.