Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jul 25, 2024
1 parent e074ec2 commit 03299a8
Show file tree
Hide file tree
Showing 7 changed files with 492 additions and 208 deletions.
133 changes: 72 additions & 61 deletions src/Starward/Controls/InstallGameController.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Starward.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

<Button Padding="0"
<Button x:Name="Button_Controller"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
Visibility="Collapsed">
<Grid>
<FontIcon FontSize="16"
Glyph="&#xEBD3;"
Expand All @@ -19,77 +22,85 @@

<Button.Flyout>
<Flyout Placement="RightEdgeAlignedBottom">
<Grid Width="240" Height="200">
<Flyout.FlyoutPresenterStyle>
<Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
<!--<Setter Property="MaxHeight" Value="758" />-->
</Style>
</Flyout.FlyoutPresenterStyle>
<Grid Width="240">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid Height="44">
<Grid Width="44"
Height="44"
HorizontalAlignment="Left"
VerticalAlignment="Top"
CornerRadius="8">
<Image Width="44"
Height="44"
Source="ms-appx:///Assets/Image/icon_ys.jpg" />
<Image Width="22"
Height="22"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Source="ms-appx:///Assets/Image/gameicon_hyperion.png" />
<ItemsControl Grid.Row="1" ItemsSource="{x:Bind InstallServices}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Spacing="8" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Height="44">
<Grid Width="44"
Height="44"
HorizontalAlignment="Left"
VerticalAlignment="Top"
CornerRadius="8">
<Image Width="44"
Height="44"
Source="{Binding Icon.GameIcon}" />
<Image Width="22"
Height="22"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Source="{Binding Icon.ServerIcon}" />

</Grid>
</Grid>


<ProgressBar MinHeight="4"
Margin="56,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Value="40">
<ProgressBar.Resources>
<x:Double x:Key="ProgressBarTrackHeight">4</x:Double>
<CornerRadius x:Key="ProgressBarTrackCornerRadius">4</CornerRadius>
</ProgressBar.Resources>
</ProgressBar>
<ProgressBar MinHeight="4"
Margin="56,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
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="Downloading" />
<TextBlock Margin="56,0,0,0"
FontSize="12"
Text="{Binding StateText}" />

<TextBlock Margin="56,0,0,10"
VerticalAlignment="Bottom"
FontSize="12"
Text="21.35/43.56 GB" />
<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"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon FontSize="16"
Glyph="&#xE768;"
IsTextScaleFactorEnabled="False" />
</Button>
<Button Width="28"
Height="28"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
Visibility="Collapsed">
<FontIcon FontSize="16"
Glyph="&#xEA39;"
IsTextScaleFactorEnabled="False" />
</Button>
</StackPanel>
<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>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

</Grid>

</Grid>
</Flyout>
Expand Down
78 changes: 65 additions & 13 deletions src/Starward/Controls/InstallGameController.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Starward.Services.Download;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using System.Threading;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -30,27 +21,88 @@ public sealed partial class InstallGameController : UserControl
private readonly ILogger<InstallGameController> _logger = AppConfig.GetLogger<InstallGameController>();


private readonly InstallGameManager _installGameManager = AppConfig.GetService<InstallGameManager>();
private readonly InstallGameManager _installGameManager = InstallGameManager.Instance;


private readonly SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1);


private readonly DispatcherQueueTimer _timer;


public InstallGameController()
{
this.InitializeComponent();
_installGameManager.InstallTaskAdded += _installGameManager_InstallTaskAdded;
_installGameManager.InstallTaskRemoved += _installGameManager_InstallTaskRemoved;
_timer = DispatcherQueue.CreateTimer();
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Tick += _timer_Tick;
}



[ObservableProperty]
private ObservableCollection<InstallGameStateModel> _installServices = new();


private ObservableCollection<InstallGameStateModel> _installServices = new();

private void _installGameManager_InstallTaskAdded(object? sender, InstallGameStateModel e)
{
try
{
_semaphoreSlim.Wait();
_timer.Start();
Button_Controller.Visibility = Visibility.Visible;
if (!InstallServices.Contains(e))
{
InstallServices.Add(e);
}
}
finally
{
_semaphoreSlim.Release();
}
}



private void _installGameManager_InstallTaskRemoved(object? sender, InstallGameStateModel e)
{
try
{
_semaphoreSlim.Wait();
InstallServices.Remove(e);
if (InstallServices.Count == 0)
{
_timer.Stop();
Button_Controller.Visibility = Visibility.Collapsed;
}
}
finally
{
_semaphoreSlim.Release();
}
}




private void _timer_Tick(DispatcherQueueTimer sender, object args)
{
try
{
_semaphoreSlim.Wait();
foreach (var model in InstallServices)
{
model.UpdateState();
}
}
finally
{
_semaphoreSlim.Release();
}
}


}
4 changes: 3 additions & 1 deletion src/Starward/Controls/InstallGameDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed partial class InstallGameDialog : ContentDialog

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


private InstallGameService _installGameService;


Expand Down Expand Up @@ -149,7 +150,8 @@ private async Task StartInstallationAsync()
try
{
_installGameService.Initialize(CurrentGameBiz, InstallationPath);
await _installGameService.StartInstallGameAsync();
await _installGameService.StartRepairGameAsync();
InstallGameManager.Instance.AddInstallService(_installGameService);
this.Hide();
}
catch (Exception ex)

Check warning on line 157 in src/Starward/Controls/InstallGameDialog.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The variable 'ex' is declared but never used

Check warning on line 157 in src/Starward/Controls/InstallGameDialog.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The variable 'ex' is declared but never used

Check warning on line 157 in src/Starward/Controls/InstallGameDialog.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The variable 'ex' is declared but never used

Check warning on line 157 in src/Starward/Controls/InstallGameDialog.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The variable 'ex' is declared but never used
Expand Down
3 changes: 1 addition & 2 deletions src/Starward/Services/Download/InstallGameItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace Starward.Services.Download;

Expand Down
Loading

0 comments on commit 03299a8

Please sign in to comment.