Skip to content

Commit

Permalink
install game feature adapt to bilibili server
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 28, 2024
1 parent 7eeac93 commit cedfa8d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Starward/Services/InstallGame/DownloadFileTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Starward.Services.InstallGame;

internal class DownloadFileTask
public class DownloadFileTask
{

public string FileName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public override async Task StartAsync(bool skipVerify = false)
State = InstallGameState.Prepare;
await PrepareForDownloadAsync().ConfigureAwait(false);
}
PrepareBilibiliServerGameSDK();
}

if (_inState is InstallGameState.Download)
Expand Down Expand Up @@ -87,6 +88,8 @@ public override async Task StartAsync(bool skipVerify = false)
await DownloadBH3BaseAsync(cancellationTokenSource.Token).ConfigureAwait(false);
}

DecompressBilibiliServerGameSDK();

await ClearDeprecatedFilesAsync().ConfigureAwait(false);

if (!IsPreInstall)
Expand Down
77 changes: 72 additions & 5 deletions src/Starward/Services/InstallGame/InstallGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public InstallGameState State
protected List<DownloadFileTask> downloadTasks;


protected GameSDK? gameSDK;


protected LauncherGameResource launcherGameResource;


Expand Down Expand Up @@ -225,6 +228,7 @@ public virtual async Task StartAsync(bool skipVerify = false)
State = InstallGameState.Prepare;
await PrepareForDownloadAsync().ConfigureAwait(false);
}
PrepareBilibiliServerGameSDK();
}

if (_inState is InstallGameState.Download)
Expand Down Expand Up @@ -253,6 +257,8 @@ public virtual async Task StartAsync(bool skipVerify = false)
await DecompressAndApplyDiffPackagesAsync(cancellationTokenSource.Token).ConfigureAwait(false);
}

DecompressBilibiliServerGameSDK();

await ClearDeprecatedFilesAsync().ConfigureAwait(false);

if (!IsPreInstall)
Expand Down Expand Up @@ -285,7 +291,7 @@ protected async Task PrepareForDownloadAsync()
{
_logger.LogInformation("Prepare for download.");

var localVersion = await _gameResourceService.GetGameLocalVersionAsync(CurrentGameBiz, InstallPath).ConfigureAwait(false);
var localVersion = await _gameResourceService.GetLocalGameVersionAsync(CurrentGameBiz, InstallPath).ConfigureAwait(false);

Check failure on line 294 in src/Starward/Services/InstallGame/InstallGameService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

'GameResourceService' does not contain a definition for 'GetLocalGameVersionAsync' and no accessible extension method 'GetLocalGameVersionAsync' accepting a first argument of type 'GameResourceService' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 294 in src/Starward/Services/InstallGame/InstallGameService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

'GameResourceService' does not contain a definition for 'GetLocalGameVersionAsync' and no accessible extension method 'GetLocalGameVersionAsync' accepting a first argument of type 'GameResourceService' could be found (are you missing a using directive or an assembly reference?)
launcherGameResource = await _gameResourceService.GetGameResourceAsync(CurrentGameBiz).ConfigureAwait(false);
(Version? latestVersion, Version? preDownloadVersion) = await _gameResourceService.GetGameResourceVersionAsync(CurrentGameBiz).ConfigureAwait(false);
GameResource? gameResource = null;
Expand Down Expand Up @@ -475,6 +481,50 @@ await Parallel.ForEachAsync(separateResources, cancellationToken, async (item, t
}


/// <summary>
/// B服SDK
/// </summary>
protected void PrepareBilibiliServerGameSDK()
{
if (!IsPreInstall && CurrentGameBiz.IsBilibiliServer())
{
gameSDK = launcherGameResource.Sdk;
if (gameSDK is not null)
{
_logger.LogInformation("Bilibili sdk version: {version}", gameSDK.Version);
downloadTasks.Add(new DownloadFileTask
{
FileName = Path.GetFileName(gameSDK.Path),
Url = gameSDK.Path,
Size = gameSDK.PackageSize,
MD5 = gameSDK.Md5,
});
}
}
}


/// <summary>
/// 解压B服SDK
/// </summary>
protected void DecompressBilibiliServerGameSDK()
{
if (!IsPreInstall && CurrentGameBiz.IsBilibiliServer())
{
if (gameSDK is not null)
{
string file = Path.Combine(InstallPath, Path.GetFileName(gameSDK.Path));
if (File.Exists(file))
{
_logger.LogInformation("Decompress Bilibili sdk: {file}", file);
ZipFile.ExtractToDirectory(file, InstallPath, true);
File.Delete(file);
}
}
}
}


/// <summary>
/// 更新已下载大小
/// </summary>
Expand Down Expand Up @@ -720,13 +770,30 @@ await Task.Run(() =>
protected async Task WriteConfigFileAsync()
{
string version = launcherGameResource.Game.Latest.Version;
string sdk_version = gameSDK?.Version ?? "";
string cps = "", channel = "1", sub_channel = "1";
if (CurrentGameBiz.IsBilibiliServer())
{
cps = "bilibili";
channel = "14";
sub_channel = "0";
}
else if (CurrentGameBiz.IsChinaServer())
{
cps = "mihoyo";
}
else if (CurrentGameBiz.IsGlobalServer())
{
cps = "hoyoverse";
}
string config = $"""
[General]
channel=1
cps=
channel={channel}
cps={cps}
game_version={version}
sub_channel=1
sdk_version=
sub_channel={sub_channel}
sdk_version={sdk_version}
game_biz={CurrentGameBiz}
""";
_logger.LogInformation("Write config.ini (game_version={version})", version);
await File.WriteAllTextAsync(Path.Combine(InstallPath, "config.ini"), config).ConfigureAwait(false);
Expand Down

0 comments on commit cedfa8d

Please sign in to comment.