Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jul 27, 2024
1 parent 1dccec2 commit 06fde35
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 26 deletions.
15 changes: 15 additions & 0 deletions src/Starward/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,21 @@ public static bool IsGameBizSelectorPinned
}


public static string? DefaultGameInstallationPath
{
get => GetValue<string>();
set => SetValue(value);
}


public static int SpeedLimitKBPerSecond
{
get => GetValue(0);
set => SetValue(value);
}




#endregion

Expand Down
33 changes: 14 additions & 19 deletions src/Starward/Controls/InstallGameDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,20 @@


<!-- No Permission -->
<StackPanel x:Name="StackPanel_NoPermission"
Grid.Row="2"
Margin="0,8,0,0"
Orientation="Horizontal"
Visibility="Collapsed">
<TextBlock FontSize="14"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsTextScaleFactorEnabled="False"
Text="No write permission, please restart as administrator." />
<TextBlock Margin="6,0,0,0"
FontSize="14"
IsTextScaleFactorEnabled="False">
<Hyperlink x:Name="Hyperlink_Restart"
Click="Hyperlink_Restart_Click"
UnderlineStyle="None">
<Run Foreground="{ThemeResource SystemFillColorCriticalBrush}" Text="Restart" />
</Hyperlink>
</TextBlock>
</StackPanel>
<TextBlock x:Name="TextBlock_NoPermission"
Grid.Row="2"
Margin="0,8,0,0"
FontSize="14"
IsTextScaleFactorEnabled="False"
Visibility="Collapsed">
<Run Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="No write permission, please restart as administrator." />
<Run Text="" />
<Hyperlink x:Name="Hyperlink_Restart"
Click="Hyperlink_Restart_Click"
UnderlineStyle="None">
<Run Foreground="{ThemeResource SystemFillColorCriticalBrush}" Text="Click to Restart" />
</Hyperlink>
</TextBlock>



Expand Down
49 changes: 43 additions & 6 deletions src/Starward/Controls/InstallGameDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,30 @@ private async void ContentDialog_Loaded(object sender, RoutedEventArgs e)
try
{
_installGameService = InstallGameService.FromGameBiz(CurrentGameBiz);
UnzipSpaceBytes = await _installGameService.GetGamePackageDecompressedSizeAsync(CurrentGameBiz);
string? path = AppConfig.DefaultGameInstallationPath;
if (Directory.Exists(path))
{
string folder = Path.Combine(path, CurrentGameBiz.ToString());
InstallationPath = folder;
if (CanCreateDirectory(folder))
{
await ChangeInstallationPathInternalAsync(folder);
}
else
{
Button_Installation.IsEnabled = false;
StackPanel_FreeSpace.Visibility = Visibility.Collapsed;
TextBlock_NoPermission.Visibility = Visibility.Visible;
}
}
else
{
UnzipSpaceBytes = await _installGameService.GetGamePackageDecompressedSizeAsync(CurrentGameBiz);
}
}
catch (Exception ex)
{

_logger.LogError(ex, "Initialize install game dialog {biz}.", CurrentGameBiz);
}
}

Expand All @@ -88,6 +107,21 @@ private void ContentDialog_Unloaded(object sender, RoutedEventArgs e)



private bool CanCreateDirectory(string path)
{
try
{
Directory.CreateDirectory(path);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
}



[RelayCommand]
private async Task ChangeInstallationPathAsync()
{
Expand All @@ -97,19 +131,22 @@ private async Task ChangeInstallationPathAsync()



private async Task ChangeInstallationPathInternalAsync()
private async Task ChangeInstallationPathInternalAsync(string? path = null)
{
try
{
var path = await FileDialogHelper.PickFolderAsync(MainWindow.Current.WindowHandle);
if (!Directory.Exists(path))
{
path = await FileDialogHelper.PickFolderAsync(MainWindow.Current.WindowHandle);
}
if (Directory.Exists(path))
{
TextBlock_InstallationPath.FontSize = 14;
InstallationPath = path;
if (_installGameService.CheckAccessPermission(path))
{
StackPanel_FreeSpace.Visibility = Visibility.Visible;
StackPanel_NoPermission.Visibility = Visibility.Collapsed;
TextBlock_NoPermission.Visibility = Visibility.Collapsed;

AvailableSpaceBytes = new DriveInfo(path).AvailableFreeSpace;
UnzipSpaceBytes = await _installGameService.GetGamePackageDecompressedSizeAsync(CurrentGameBiz);
Expand All @@ -130,7 +167,7 @@ private async Task ChangeInstallationPathInternalAsync()
{
Button_Installation.IsEnabled = false;
StackPanel_FreeSpace.Visibility = Visibility.Collapsed;
StackPanel_NoPermission.Visibility = Visibility.Visible;
TextBlock_NoPermission.Visibility = Visibility.Visible;
}
}
}
Expand Down
96 changes: 96 additions & 0 deletions src/Starward/Pages/Setting/DownloadSettingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8" ?>
<sp:PageBase x:Class="Starward.Pages.Setting.DownloadSettingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="using:Starward.Language"
xmlns:local="using:Starward.Pages.Setting"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sp="using:Starward.Pages"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

<ScrollViewer>
<StackPanel Margin="0,0,48,0">


<!-- default install path -->
<TextBlock FontSize="20"
FontWeight="SemiBold"
Text="Default Game Installation Path" />
<TextBlock Margin="0,12,0,0"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="The games will be installed in different subfolders, changing the default path will not move the installed game files."
TextWrapping="Wrap" />
<StackPanel Margin="0,12,0,0" Orientation="Horizontal">
<!-- locate folder -->
<Button Height="40"
Padding="16,0,16,0"
BorderThickness="0"
Command="{x:Bind ChangeDefaultInstallPathCommand}"
CornerRadius="8,20,20,8"
Style="{ThemeResource AccentButtonStyle}">
<StackPanel Orientation="Horizontal" Spacing="8">
<FontIcon Glyph="&#xE8DE;" />
<TextBlock Text="{x:Bind lang:Lang.LauncherPage_Locate}" />
</StackPanel>
</Button>
<Grid Height="40"
Margin="16,0,0,0"
Background="{ThemeResource CustomAcrylicBrush}"
CornerRadius="20"
Visibility="{x:Bind DefaultInstallPath, Converter={StaticResource ObjectToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Height="40"
Padding="16,0,8,1"
BorderThickness="0"
Command="{x:Bind OpenDefaultInstallPathCommand}"
CornerRadius="0">
<TextBlock VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind DefaultInstallPath}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap" />
</Button>
<Button Grid.Column="1"
Height="36"
BorderThickness="0"
Command="{x:Bind DeleteDefaultInstallPathCommand}"
CornerRadius="0">
<FontIcon Margin="0,2,2,0"
FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Glyph="&#xE711;" />
</Button>
</Grid>
</StackPanel>



<!-- speed limit -->
<TextBlock Margin="0,20,0,0"
FontSize="20"
FontWeight="SemiBold"
Text="Speed Limit" />
<TextBlock Margin="0,12,0,0"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="The number 0 means no speed limit."
TextWrapping="Wrap" />
<StackPanel Margin="0,12,0,0"
Orientation="Horizontal"
Spacing="12">
<NumberBox MinWidth="100"
Minimum="0"
Value="{x:Bind SpeedLimit, Mode=TwoWay}" />
<TextBlock VerticalAlignment="Center" Text="KB/s" />
</StackPanel>



</StackPanel>
</ScrollViewer>

</sp:PageBase>
127 changes: 127 additions & 0 deletions src/Starward/Pages/Setting/DownloadSettingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
using Starward.Helpers;
using Starward.Services.Download;
using System;
using System.IO;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.System;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Starward.Pages.Setting;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[INotifyPropertyChanged]
public sealed partial class DownloadSettingPage : PageBase
{


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


public DownloadSettingPage()
{
this.InitializeComponent();
InitializeDefaultInstallPath();
}




private void InitializeDefaultInstallPath()
{
try
{
string? path = AppConfig.DefaultGameInstallationPath;
if (Directory.Exists(path))
{
DefaultInstallPath = path;
}
else
{
AppConfig.DefaultGameInstallationPath = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Get default intall path");
}
}



[ObservableProperty]
private string? defaultInstallPath;
partial void OnDefaultInstallPathChanged(string? value)
{
AppConfig.DefaultGameInstallationPath = value;
}



[ObservableProperty]
private int speedLimit = AppConfig.SpeedLimitKBPerSecond;
partial void OnSpeedLimitChanged(int value)
{
InstallGameManager.SpeedLimitBytesPerSecond = value == 0 ? long.MaxValue : value * 1024;
AppConfig.SpeedLimitKBPerSecond = value;
}



[RelayCommand]
private async Task ChangeDefaultInstallPathAsync()
{
try
{
var path = await FileDialogHelper.PickFolderAsync(MainWindow.Current.WindowHandle);
if (Directory.Exists(path))
{
DefaultInstallPath = path;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to change default install path");
}
}




[RelayCommand]
private async Task OpenDefaultInstallPathAsync()
{

try
{
if (Directory.Exists(DefaultInstallPath))
{
var folder = await StorageFolder.GetFolderFromPathAsync(DefaultInstallPath);
await Launcher.LaunchFolderAsync(folder);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to open default install path");
}
}




[RelayCommand]
private void DeleteDefaultInstallPath()
{
DefaultInstallPath = null;
}



}
5 changes: 5 additions & 0 deletions src/Starward/Pages/Setting/SettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<FontIcon Glyph="&#xEC7A;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Download" Tag="DownloadSettingPage">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xEBD3;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="{x:Bind lang:Lang.SettingPage_FileManagement}" Tag="FileSettingPage">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE8F1;" />
Expand Down
1 change: 1 addition & 0 deletions src/Starward/Pages/Setting/SettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewIte
{
nameof(AboutSettingPage) => typeof(AboutSettingPage),
nameof(AppearanceSettingPage) => typeof(AppearanceSettingPage),
nameof(DownloadSettingPage) => typeof(DownloadSettingPage),
nameof(ExperienceSettingPage) => typeof(ExperienceSettingPage),
nameof(FileSettingPage) => typeof(FileSettingPage),
nameof(AdvancedSettingPage) => typeof(AdvancedSettingPage),
Expand Down
Loading

0 comments on commit 06fde35

Please sign in to comment.