Skip to content

Commit

Permalink
ipdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jul 27, 2024
1 parent 03299a8 commit 603f2d5
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 116 deletions.
117 changes: 85 additions & 32 deletions src/Starward/Controls/InstallGameController.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
</Grid>

<Button.Flyout>
<Flyout Placement="RightEdgeAlignedBottom">
<Flyout x:Name="Flyout_InstallGame" Placement="RightEdgeAlignedBottom">
<Flyout.FlyoutPresenterStyle>
<Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
<!--<Setter Property="MaxHeight" Value="758" />-->
</Style>
</Flyout.FlyoutPresenterStyle>
<Grid Width="240">
<Grid Width="320">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
Expand All @@ -36,16 +36,27 @@
<ItemsControl Grid.Row="1" ItemsSource="{x:Bind InstallServices}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Spacing="8" />
<StackPanel Spacing="12" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="44">
<Grid Width="44"
<Grid Height="44"
ColumnSpacing="16"
RowSpacing="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Grid Grid.RowSpan="3"
Width="44"
Height="44"
HorizontalAlignment="Left"
VerticalAlignment="Top"
CornerRadius="8">
<Image Width="44"
Height="44"
Expand All @@ -59,43 +70,85 @@
</Grid>


<ProgressBar MinHeight="4"
Margin="56,0,0,0"
<TextBlock Grid.Column="1"
FontSize="14"
IsTextScaleFactorEnabled="False"
Text="{Binding StateText}" />

<ProgressBar Grid.Row="1"
Grid.Column="1"
MinHeight="4"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Value="{Binding Progress}">
<ProgressBar.Resources>
<x:Double x:Key="ProgressBarTrackHeight">4</x:Double>
<CornerRadius x:Key="ProgressBarTrackCornerRadius">4</CornerRadius>
</ProgressBar.Resources>
</ProgressBar>

<TextBlock Margin="56,0,0,0"
FontSize="12"
Text="{Binding StateText}" />

<TextBlock Margin="56,0,0,10"
VerticalAlignment="Bottom"
FontSize="12"
Text="{Binding ProgressText}" />

<StackPanel HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal">
<Button Width="28"
Height="28"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Command="{Binding ActionButtonCommand}"
IsEnabled="{Binding IsActionButtonEnabled}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon FontSize="16"
Glyph="{Binding ButtonGlyph}"
IsTextScaleFactorEnabled="False" />
</Button>
<StackPanel Grid.Row="2"
Grid.Column="1"
Orientation="Horizontal"
Spacing="4">
<TextBlock FontSize="12"
IsTextScaleFactorEnabled="False"
Text="{Binding ProgressText}" />
<AppBarSeparator Padding="2" Visibility="{Binding SpeedText, Converter={StaticResource ObjectToVisibilityConverter}}" />
<TextBlock FontSize="12"
IsTextScaleFactorEnabled="False"
Text="{Binding SpeedText}"
Visibility="{Binding SpeedText, Converter={StaticResource ObjectToVisibilityConverter}}" />
<AppBarSeparator Padding="2" Visibility="{Binding RemainingTimeText, Converter={StaticResource ObjectToVisibilityConverter}}" />
<TextBlock FontSize="12"
IsTextScaleFactorEnabled="False"
Text="{Binding RemainingTimeText}"
Visibility="{Binding RemainingTimeText, Converter={StaticResource ObjectToVisibilityConverter}}" />
</StackPanel>

<Grid x:Name="Grid_ActionButtonOverlay"
Grid.RowSpan="3"
Grid.ColumnSpan="2"
Background="Transparent"
Opacity="0"
PointerEntered="Grid_ActionButtonOverlay_PointerEntered"
PointerExited="Grid_ActionButtonOverlay_PointerExited">
<Grid.OpacityTransition>
<ScalarTransition />
</Grid.OpacityTransition>
<StackPanel Margin="0,-6,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Orientation="Horizontal"
Spacing="4">
<Button Width="28"
Height="28"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Command="{Binding ContinueOrPauseCommand}"
IsEnabled="{Binding IsContinueOrPauseButtonEnabled}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon FontSize="14"
Glyph="{Binding ButtonGlyph}"
IsTextScaleFactorEnabled="False" />
</Button>
<Button Width="28"
Height="28"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Command="{Binding CancelCommand}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon FontSize="14"
Glyph="&#xE711;"
IsTextScaleFactorEnabled="False" />
</Button>
</StackPanel>
</Grid>

</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
21 changes: 21 additions & 0 deletions src/Starward/Controls/InstallGameController.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void _installGameManager_InstallTaskRemoved(object? sender, InstallGameS
{
_timer.Stop();
Button_Controller.Visibility = Visibility.Collapsed;
Flyout_InstallGame.Hide();
}
}
finally
Expand Down Expand Up @@ -105,4 +106,24 @@ private void _timer_Tick(DispatcherQueueTimer sender, object args)
}



private void Grid_ActionButtonOverlay_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (sender is Grid grid)
{
grid.Opacity = 1;
}
}



private void Grid_ActionButtonOverlay_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (sender is Grid grid)
{
grid.Opacity = 0;
}
}


}
2 changes: 1 addition & 1 deletion src/Starward/Controls/InstallGameDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private async Task StartInstallationAsync()
try
{
_installGameService.Initialize(CurrentGameBiz, InstallationPath);
await _installGameService.StartRepairGameAsync();
await _installGameService.StartInstallGameAsync();
InstallGameManager.Instance.AddInstallService(_installGameService);
this.Hide();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Starward/Services/Download/GenshinInstallGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override async Task StartRepairGameAsync(CancellationToken cancellationTo
await PrepareBilibiliChannelSDKAsync(InstallGameItemType.Verify);
}
await MoveAudioAssetsFromPersistentToStreamAssetsAsync();
_installTask = InstallGameTask.Repair;
InstallTask = InstallGameTask.Repair;
StartTask(InstallGameState.Verify);
}

Expand All @@ -69,7 +69,7 @@ public override async Task StartUpdateGameAsync(CancellationToken cancellationTo
await PrepareBilibiliChannelSDKAsync(InstallGameItemType.Download);
}
await MoveAudioAssetsFromPersistentToStreamAssetsAsync();
_installTask = InstallGameTask.Update;
InstallTask = InstallGameTask.Update;
StartTask(InstallGameState.Download);
}

Expand Down
21 changes: 17 additions & 4 deletions src/Starward/Services/Download/InstallGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ public void AddInstallService(InstallGameService service)
model.InstallFinished += Model_InstallFinished;
model.InstallFailed -= Model_InstallFailed;
model.InstallFailed += Model_InstallFailed;
model.InstallCanceled -= Model_InstallCanceled;
model.InstallCanceled += Model_InstallCanceled;
InstallTaskAdded?.Invoke(this, model);
}







private void Model_InstallFinished(object? sender, EventArgs e)
{
if (sender is InstallGameStateModel model)
Expand All @@ -85,6 +83,7 @@ private void Model_InstallFinished(object? sender, EventArgs e)
_services.TryRemove(model.GameBiz, out _);
model.InstallFinished -= Model_InstallFinished;
model.InstallFailed -= Model_InstallFailed;
model.InstallCanceled -= Model_InstallCanceled;
InstallTaskRemoved?.Invoke(this, model);
}
}
Expand All @@ -100,6 +99,20 @@ private void Model_InstallFailed(object? sender, EventArgs e)
}


private void Model_InstallCanceled(object? sender, EventArgs e)
{
if (sender is InstallGameStateModel model)
{
model.Service.Pause();
model.Service.ClearState();
_services.TryRemove(model.GameBiz, out _);
model.InstallFinished -= Model_InstallFinished;
model.InstallFailed -= Model_InstallFailed;
model.InstallCanceled -= Model_InstallCanceled;
InstallTaskRemoved?.Invoke(this, model);
}
}



}
21 changes: 10 additions & 11 deletions src/Starward/Services/Download/InstallGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public static InstallGameService FromGameBiz(GameBiz gameBiz)
public GameBiz CurrentGameBiz { get; protected set; }


public InstallGameTask InstallTask { get; protected set; }


private InstallGameState _state;
public InstallGameState State
{
Expand Down Expand Up @@ -112,9 +115,6 @@ protected void OnInstallFailed(Exception ex)
protected string _installPath;


protected InstallGameTask _installTask;


protected InstallGameState _pausedState;


Expand Down Expand Up @@ -249,7 +249,7 @@ public virtual async Task StartInstallGameAsync(CancellationToken cancellationTo
{
await PrepareBilibiliChannelSDKAsync(InstallGameItemType.Download);
}
_installTask = InstallGameTask.Install;
InstallTask = InstallGameTask.Install;
StartTask(InstallGameState.Download);
}

Expand All @@ -273,7 +273,7 @@ public virtual async Task StartRepairGameAsync(CancellationToken cancellationTok
{
await PrepareBilibiliChannelSDKAsync(InstallGameItemType.Verify);
}
_installTask = InstallGameTask.Repair;
InstallTask = InstallGameTask.Repair;
StartTask(InstallGameState.Verify);
}

Expand All @@ -298,7 +298,7 @@ public virtual async Task StartPredownloadAsync(CancellationToken cancellationTo
resource = _gamePackage.PreDownload.Major!;
}
await PrepareDownloadGamePackageResourceAsync(resource);
_installTask = InstallGameTask.Predownload;
InstallTask = InstallGameTask.Predownload;
StartTask(InstallGameState.Download);
}

Expand All @@ -323,7 +323,7 @@ public virtual async Task StartUpdateGameAsync(CancellationToken cancellationTok
{
await PrepareBilibiliChannelSDKAsync(InstallGameItemType.Download);
}
_installTask = InstallGameTask.Update;
InstallTask = InstallGameTask.Update;
StartTask(InstallGameState.Download);
}

Expand Down Expand Up @@ -673,15 +673,15 @@ private void CurrentTaskFinished()
{
try
{
if (_installTask is InstallGameTask.Install or InstallGameTask.Update)
if (InstallTask is InstallGameTask.Install or InstallGameTask.Update)
{
OnInstallOrUpdateTaskFinished();
}
else if (_installTask is InstallGameTask.Repair)
else if (InstallTask is InstallGameTask.Repair)
{
OnRepairTaskFinished();
}
else if (_installTask is InstallGameTask.Predownload)
else if (InstallTask is InstallGameTask.Predownload)
{
OnPredownloadTaskFinished();
}
Expand Down Expand Up @@ -928,7 +928,6 @@ protected void Finish()




#region Execute Item (Download, Verify, Decompress, Patch)


Expand Down
Loading

0 comments on commit 603f2d5

Please sign in to comment.