Skip to content

Commit

Permalink
Handle the Bilibili SDK download
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Oct 7, 2023
1 parent 907c798 commit 70a68d8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,17 @@ public GameInstallStateEnum GetGameState()

public virtual List<RegionResourceVersion> GetGameLatestZip(GameInstallStateEnum gameState)
{
// Initialize the return list
List<RegionResourceVersion> returnList = new List<RegionResourceVersion>();

// If the GameVersion is not installed, then return the latest one
if (gameState == GameInstallStateEnum.NotInstalled || gameState == GameInstallStateEnum.GameBroken)
{
return new List<RegionResourceVersion> { GameAPIProp.data.game.latest };
// Add the latest prop to the return list
returnList.Add(GameAPIProp.data.game.latest);
// If the game SDK is not null (Bilibili SDK zip), then add it to the return list
if (GameAPIProp.data.sdk != null) returnList.Add(GameAPIProp.data.sdk);
return returnList;
}

// Try get the diff file by the first or default (null)
Expand All @@ -190,11 +197,17 @@ public virtual List<RegionResourceVersion> GetGameLatestZip(GameInstallStateEnum
.FirstOrDefault();

// Return if the diff is null, then get the latest. If found, then return the diff one.
return new List<RegionResourceVersion> { diff == null ? GameAPIProp.data.game.latest : diff };
// If the game SDK is not null (Bilibili SDK zip), then add it to the return list
returnList.Add(diff == null ? GameAPIProp.data.game.latest : diff);
if (GameAPIProp.data.sdk != null) returnList.Add(GameAPIProp.data.sdk);
return returnList;
}

public virtual List<RegionResourceVersion> GetGamePreloadZip()
{
// Initialize the return list
List<RegionResourceVersion> returnList = new List<RegionResourceVersion>();

// If the preload is not exist, then return null
if (GameAPIProp.data.pre_download_game == null) return null;

Expand All @@ -204,7 +217,9 @@ public virtual List<RegionResourceVersion> GetGamePreloadZip()
.FirstOrDefault();

// Return if the diff is null, then get the latest. If found, then return the diff one.
return new List<RegionResourceVersion> { diff == null ? GameAPIProp.data.pre_download_game.latest : diff };
returnList.Add(diff == null ? GameAPIProp.data.pre_download_game.latest : diff);
if (GameAPIProp.data.sdk != null) returnList.Add(GameAPIProp.data.sdk);
return returnList;
}

public virtual DeltaPatchProperty GetDeltaPatchInfo() => null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ private async ValueTask<int> CheckExistingOrAskFolderDialog()
#endregion
#region Virtual Methods - GetInstallationPath
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
protected virtual async ValueTask TryAddResourceVersionList(RegionResourceVersion asset, List<GameInstallPackage> packageList)
protected virtual async ValueTask<bool> TryAddResourceVersionList(RegionResourceVersion asset, List<GameInstallPackage> packageList)
{
// Try add the package into
GameInstallPackage package = new GameInstallPackage(asset, _gamePath) { PackageType = GameInstallPackageType.General };
Expand All @@ -1083,9 +1083,15 @@ protected virtual async ValueTask TryAddResourceVersionList(RegionResourceVersio
{
LogWriteLine($"Adding segmented package: {segment.Name} to the list (Hash: {segment.HashString})", LogType.Default, true);
}
return;
return true;
}
LogWriteLine($"Adding general package: {package.Name} to the list (Hash: {package.HashString})", LogType.Default, true);

// If the voice packs don't exist, then skip it
if (asset.voice_packs == null) return false;

// Otherwise, return true
return true;
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ private void WriteAudioLangList()
#endregion

#region Override Methods - GetInstallationPath
protected override async ValueTask TryAddResourceVersionList(RegionResourceVersion asset, List<GameInstallPackage> packageList)
protected override async ValueTask<bool> TryAddResourceVersionList(RegionResourceVersion asset, List<GameInstallPackage> packageList)
{
// Do action from base method first
await base.TryAddResourceVersionList(asset, packageList);
if (!await base.TryAddResourceVersionList(asset, packageList)) return false;

// Initialize langID
int langID;
Expand Down Expand Up @@ -203,6 +203,8 @@ protected override async ValueTask TryAddResourceVersionList(RegionResourceVersi

LogWriteLine($"Adding primary {package.LanguageName} audio package: {package.Name} to the list (Hash: {package.HashString})", LogType.Default, true);
}

return true;
}
#endregion
#region Private Methods - GetInstallationPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protected override async Task StartPackageInstallationInner()
#endregion

#region Override Methods - GetInstallationPath
protected override async ValueTask TryAddResourceVersionList(RegionResourceVersion asset, List<GameInstallPackage> packageList)
protected override async ValueTask<bool> TryAddResourceVersionList(RegionResourceVersion asset, List<GameInstallPackage> packageList)
{
// Do action from base method first
await base.TryAddResourceVersionList(asset, packageList);
if (!await base.TryAddResourceVersionList(asset, packageList)) return false;

// Initialize langID
int langID;
Expand All @@ -59,6 +59,7 @@ protected override async ValueTask TryAddResourceVersionList(RegionResourceVersi
}

LogWriteLine($"Setting audio ID to: {_gameVersionManager.GamePreset.GetStarRailVoiceLanguageFullNameByID(_gameVoiceLanguageID)}", LogType.Default, true);
return true;
}

private List<string> EnumerateAudioLanguageString()
Expand Down
36 changes: 7 additions & 29 deletions CollapseLauncher/Classes/RegionManagement/RegionClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,12 @@ public class RegionResourceProp : IRegionResourceCopyable<RegionResourceProp>
};
}

public class RegionResourceSdk : IRegionResourceCopyable<RegionResourceSdk>
{
public string version { get; set; }
public string path { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public long size { get; set; }
public string md5 { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public long package_size { get; set; }
public string pkg_version { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int? channel_id { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int? sub_channel_id { get; set; }
public RegionResourceSdk Copy() => new RegionResourceSdk()
{
version = version,
path = path,
size = size,
md5 = md5,
package_size = package_size,
pkg_version = pkg_version,
channel_id = channel_id,
sub_channel_id = sub_channel_id
};
}

public class RegionResourceGame : IRegionResourceCopyable<RegionResourceGame>
{
public RegionResourceLatest game { get; set; }
public RegionResourceLatest pre_download_game { get; set; }
public RegionBackgroundProp adv { get; set; }
public RegionResourceSdk sdk { get; set; }
public RegionResourceVersion sdk { get; set; }
public IList<RegionSocMedProp> banner { get; set; }
public IList<RegionSocMedProp> icon { get; set; }
public IList<RegionSocMedProp> post { get; set; }
Expand All @@ -92,7 +65,7 @@ public class RegionResourceGame : IRegionResourceCopyable<RegionResourceGame>
sdk = sdk?.Copy(),
banner = banner?.Copy(),
icon = icon?.Copy(),
post = post?.Copy(),
post = post?.Copy()
};
}

Expand Down Expand Up @@ -122,6 +95,11 @@ public class RegionResourceVersion : IRegionResourceCopyable<RegionResourceVersi
public int? languageID { get; set; }
public bool is_recommended_update { get; set; }
public string entry { get; set; }
public string pkg_version { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int? channel_id { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int? sub_channel_id { get; set; }
public IList<RegionResourceVersion> voice_packs { get; set; }
public IList<RegionResourceVersion> segments { get; set; }
public RegionResourceVersion Copy() => new RegionResourceVersion()
Expand Down

0 comments on commit 70a68d8

Please sign in to comment.