Skip to content

Commit

Permalink
list game packages in a page
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jul 11, 2024
1 parent 478aea1 commit c6f17ae
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 79 deletions.
17 changes: 17 additions & 0 deletions src/Starward/Pages/GameLauncherPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,23 @@
Glyph=""
IsTextScaleFactorEnabled="False" />
</Button>
<!-- Game Package -->
<Button Width="40"
Height="40"
Margin="4"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderThickness="0"
Command="{x:Bind OpenGamePackageWindowCommand}"
CornerRadius="8"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
ToolTipService.ToolTip="{x:Bind lang:Lang.FileSettingPage_GameResource}">
<FontIcon FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Glyph="&#xF012;"
IsTextScaleFactorEnabled="False" />
</Button>

</StackPanel>

Expand Down
7 changes: 7 additions & 0 deletions src/Starward/Pages/GameLauncherPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,13 @@ private void OpenGameNoticesWindow()
}


[RelayCommand]
private void OpenGamePackageWindow()
{
MainWindow.Current.OverlayFrameNavigateTo(typeof(GameResourcePage), CurrentGameBiz);
}


#endregion


Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Pages/GameResourcePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<Page.Resources>
<DataTemplate x:Key="PackageGroupsDataTemplate">
<Expander HorizontalAlignment="Stretch" Background="{ThemeResource CustomOverlayAcrylicBrush}">
<Expander HorizontalAlignment="Stretch" Background="#40000000">
<Expander.Header>
<Grid>
<TextBlock VerticalAlignment="Center"
Expand Down
139 changes: 61 additions & 78 deletions src/Starward/Pages/GameResourcePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Controls;
using Starward.Core;
using Starward.Core.Launcher;
using Starward.Core.HoYoPlay;
using Starward.Helpers;
using Starward.Services;
using Starward.Services.Launcher;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -27,7 +26,9 @@ public sealed partial class GameResourcePage : PageBase

private readonly ILogger<GameResourcePage> _logger = AppConfig.GetLogger<GameResourcePage>();

private readonly GameResourceService _gameResourceService = AppConfig.GetService<GameResourceService>();
private readonly GamePackageService _gamePackageService = AppConfig.GetService<GamePackageService>();

private readonly HoYoPlayClient _hoyoPlayClient = AppConfig.GetService<HoYoPlayClient>();


public GameResourcePage()
Expand All @@ -41,7 +42,7 @@ public GameResourcePage()



private LauncherGameResource launcherGameResource;
private GamePackage gamePackage;

[ObservableProperty]
private string latestVersion;
Expand All @@ -61,29 +62,33 @@ protected override async void OnLoaded()
{
try
{
launcherGameResource = await _gameResourceService.GetGameResourceAsync(CurrentGameBiz);
LatestVersion = launcherGameResource.Game.Latest.Version;
var list = GetGameResourcePackageGroups(launcherGameResource.Game);
if (CurrentGameBiz.IsBilibiliServer() && launcherGameResource.Sdk is not null)
gamePackage = await _gamePackageService.GetGamePackageAsync(CurrentGameBiz);
LatestVersion = gamePackage.Main.Major!.Version;
var list = GetGameResourcePackageGroups(gamePackage.Main);
if (CurrentGameBiz.IsBilibiliServer())
{
list.Add(new PackageGroup
var sdk = await _hoyoPlayClient.GetGameChannelSDKAsync(LauncherId.FromGameBiz(CurrentGameBiz)!, "", GameId.FromGameBiz(CurrentGameBiz)!);
if (sdk is not null)
{
Name = "Bilibili SDK",
Items = [new PackageItem
list.Add(new PackageGroup
{
FileName = Path.GetFileName(launcherGameResource.Sdk.Path),
Url = launcherGameResource.Sdk.Path,
Md5 = launcherGameResource.Sdk.Md5,
PackageSize = launcherGameResource.Sdk.PackageSize,
DecompressSize = launcherGameResource.Sdk.Size,
}],
});
Name = "Bilibili SDK",
Items = [new PackageItem
{
FileName = Path.GetFileName(sdk.ChannelSDKPackage.Url),
Url = sdk.ChannelSDKPackage.Url,
Md5 = sdk.ChannelSDKPackage.MD5,
PackageSize = sdk.ChannelSDKPackage.Size,
DecompressSize = sdk.ChannelSDKPackage.DecompressedSize,
}],
});
}
}
LatestPackageGroups = list;
if (launcherGameResource.PreDownloadGame is not null)
if (!string.IsNullOrWhiteSpace(gamePackage.PreDownload?.Major?.Version))
{
PreInstallVersion = launcherGameResource.PreDownloadGame.Latest.Version;
PreInstallPackageGroups = GetGameResourcePackageGroups(launcherGameResource.PreDownloadGame);
PreInstallVersion = gamePackage.PreDownload.Major.Version;
PreInstallPackageGroups = GetGameResourcePackageGroups(gamePackage.PreDownload);
}
}
catch (Exception ex)
Expand All @@ -95,87 +100,65 @@ protected override async void OnLoaded()



private List<PackageGroup> GetGameResourcePackageGroups(GameResource gameResource)
private List<PackageGroup> GetGameResourcePackageGroups(GamePackageVersion gameResource)
{
var list = new List<PackageGroup>();
var fullPackageGroup = new PackageGroup
{
Name = Lang.GameResourcePage_FullPackages,
Items = new List<PackageItem>()
};
if (string.IsNullOrWhiteSpace(gameResource.Latest.Path))
{
// segment
if (gameResource.Latest.Segments.FirstOrDefault() is Segment first)
{
fullPackageGroup.Items.Add(new PackageItem
{
FileName = $"{Path.GetFileNameWithoutExtension(first.Path)}.*",
Md5 = gameResource.Latest.Md5,
PackageSize = gameResource.Latest.PackageSize,
DecompressSize = gameResource.Latest.Size,
});
}
foreach (var segment in gameResource.Latest.Segments)
{
fullPackageGroup.Items.Add(new PackageItem
{
FileName = Path.GetFileName(segment.Path),
Url = segment.Path,
Md5 = segment.Md5,
PackageSize = segment.PackageSize,
});
}
}
else
foreach (var item in gameResource.Major?.GamePackages ?? [])
{
// no segment
var latest = gameResource.Latest;
fullPackageGroup.Items.Add(new PackageItem
{
FileName = Path.GetFileName(latest.Path),
Url = latest.Path,
Md5 = latest.Md5,
PackageSize = latest.PackageSize,
DecompressSize = latest.Size,
FileName = Path.GetFileName(item.Url),
Url = item.Url,
Md5 = item.MD5,
PackageSize = item.Size,
DecompressSize = item.DecompressedSize,
});
}
foreach (var voice in gameResource.Latest.VoicePacks)
foreach (var item in gameResource.Major?.AudioPackages ?? [])
{
fullPackageGroup.Items.Add(new PackageItem
{
FileName = Path.GetFileName(voice.Path),
Url = voice.Path,
Md5 = voice.Md5,
PackageSize = voice.PackageSize,
DecompressSize = voice.Size,
FileName = Path.GetFileName(item.Url),
Url = item.Url,
Md5 = item.MD5,
PackageSize = item.Size,
DecompressSize = item.DecompressedSize,
});
}
list.Add(fullPackageGroup);
foreach (var diff in gameResource.Diffs)

foreach (var patch in gameResource.Patches ?? [])
{
var diffPackageGroup = new PackageGroup
{
Name = $"{Lang.GameResourcePage_DiffPackages} {diff.Version}",
Name = $"{Lang.GameResourcePage_DiffPackages} {patch.Version}",
Items = new List<PackageItem>()
};
diffPackageGroup.Items.Add(new PackageItem
foreach (var item in patch.GamePackages ?? [])
{
FileName = Path.GetFileName(diff.Path),
Url = diff.Path,
Md5 = diff.Md5,
PackageSize = diff.PackageSize,
DecompressSize = diff.Size,
});
foreach (var voice in diff.VoicePacks)
diffPackageGroup.Items.Add(new PackageItem
{
FileName = Path.GetFileName(item.Url),
Url = item.Url,
Md5 = item.MD5,
PackageSize = item.Size,
DecompressSize = item.DecompressedSize,
});
}
foreach (var item in patch.AudioPackages ?? [])
{
diffPackageGroup.Items.Add(new PackageItem
{
FileName = Path.GetFileName(voice.Path),
Url = voice.Path,
Md5 = voice.Md5,
PackageSize = voice.PackageSize,
DecompressSize = voice.Size,
FileName = Path.GetFileName(item.Url),
Url = item.Url,
Md5 = item.MD5,
PackageSize = item.Size,
DecompressSize = item.DecompressedSize,
});
}
list.Add(diffPackageGroup);
Expand Down Expand Up @@ -206,7 +189,7 @@ private async void Button_CopyUrl_Click(object sender, Microsoft.UI.Xaml.RoutedE
sb.AppendLine(item.Url);
}
}
string url = sb.ToString();
string url = sb.ToString().TrimEnd();
if (!string.IsNullOrWhiteSpace(url))
{
ClipboardHelper.SetText(url);
Expand Down Expand Up @@ -266,7 +249,7 @@ private void Close()



public partial class PackageGroup
public class PackageGroup
{
public string Name { get; set; }

Expand Down

0 comments on commit c6f17ae

Please sign in to comment.