diff --git a/src/Pages/GameGridPage.xaml.cs b/src/Pages/GameGridPage.xaml.cs index cadce7d..51eb3d6 100644 --- a/src/Pages/GameGridPage.xaml.cs +++ b/src/Pages/GameGridPage.xaml.cs @@ -1,33 +1,14 @@ -using DLSS_Swapper.Data; -using DLSS_Swapper.Data.EpicGamesStore; -using DLSS_Swapper.Data.GOG; -using DLSS_Swapper.Data.Steam; -using DLSS_Swapper.Data.UbisoftConnect; -using DLSS_Swapper.Data.Xbox; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using DLSS_Swapper.Data; using DLSS_Swapper.Interfaces; using DLSS_Swapper.UserControls; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Documents; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Security.Principal; -using System.Text.Json; -using System.Threading.Tasks; -using System.Windows.Input; -using Windows.Foundation; -using Windows.Foundation.Collections; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -39,9 +20,9 @@ namespace DLSS_Swapper.Pages /// public sealed partial class GameGridPage : Page { - public List GameLibraries { get; } = new List(); + public List GameLibraries { get; } = []; - bool _loadingGamesAndDlls = false; + private bool _loadingGamesAndDlls = false; public bool RunsAsAdmin { get; } = Environment.IsPrivilegedProcess; @@ -49,11 +30,9 @@ public GameGridPage() { this.InitializeComponent(); DataContext = this; - } - - async Task LoadGamesAsync() + private async Task LoadGamesAsync() { // Added this check so if we get to here and this is true we probably crashed loading games last time and we should prompt for that. if (Settings.Instance.WasLoadingGames) @@ -65,7 +44,7 @@ async Task LoadGamesAsync() }; paragraph.Inlines.Add(new Run() { - Text = "DLSS Swapper had an issue loading game libraries. Please try disabling a game library below. You can re-enable these options later in the settings.", + Text = "DLSS Swapper had an issue loading game libraries. Please try disabling a game library below. You can re-enable these options later in the settings.", }); richTextBlock.Blocks.Add(paragraph); paragraph = new Paragraph() @@ -94,24 +73,20 @@ async Task LoadGamesAsync() - var grid = new Grid() { RowSpacing = 10, }; + grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions.Add(new RowDefinition()); - Grid.SetRow(richTextBlock, 0); grid.Children.Add(richTextBlock); - var gameLibrarySelectorControl = new GameLibrarySelectorControl(); - Grid.SetRow(gameLibrarySelectorControl, 1); grid.Children.Add(gameLibrarySelectorControl); - var dialog = new EasyContentDialog(XamlRoot) { Title = "Failed to load game libraries", @@ -120,8 +95,10 @@ async Task LoadGamesAsync() DefaultButton = ContentDialogButton.Primary, Content = grid, }; + var result = await dialog.ShowAsync(); - if (result == ContentDialogResult.Primary) + + if (result is ContentDialogResult.Primary) { gameLibrarySelectorControl.Save(); } @@ -156,7 +133,7 @@ async Task LoadGamesAsync() }); } - void FilterGames() + private void FilterGames() { // TODO: Remove weird hack which otherwise causes MainGridView_SelectionChanged to fire when changing MainGridView.ItemsSource. MainGridView.SelectionChanged -= MainGridView_SelectionChanged; @@ -165,7 +142,6 @@ void FilterGames() if (Settings.Instance.GroupGameLibrariesTogether) { - var collectionViewSource = new CollectionViewSource() { IsSourceGrouped = true, @@ -191,7 +167,7 @@ void FilterGames() { foreach (var gameLibrary in GameLibraries) { - games.AddRange(gameLibrary.LoadedGames.Where(g => g.HasDLSS == true)); + games.AddRange(gameLibrary.LoadedGames.Where(g => g.HasDLSS is true)); } } else @@ -212,15 +188,14 @@ void FilterGames() MainGridView.SelectionChanged += MainGridView_SelectionChanged; } - - async void Page_Loaded(object sender, RoutedEventArgs e) + private async void Page_Loaded(object sender, RoutedEventArgs e) { await LoadGamesAndDlls(); } - async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArgs e) + private async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (e.AddedItems.Count == 0) + if (e.AddedItems.Count is 0) { return; } @@ -230,21 +205,36 @@ async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArg { EasyContentDialog dialog; - if (game.HasDLSS == false) + if (game.HasDLSS is false) { dialog = new EasyContentDialog(XamlRoot) { - //dialog.Title = "Error"; + Title = "Error", PrimaryButtonText = "Okay", DefaultButton = ContentDialogButton.Primary, Content = $"DLSS was not detected in {game.Title}.", }; + + await dialog.ShowAsync(); + return; + } + + if (Settings.Instance.HideNotDownloadedVersions && App.CurrentApp.MainWindow.CurrentDLSSRecords.Where(static r => r.LocalRecord.IsDownloaded).Count() is 0) + { + dialog = new(XamlRoot) + { + Title = "Error", + PrimaryButtonText = "Okay", + DefaultButton = ContentDialogButton.Primary, + Content = "You have not downloaded any DLSS version. Please download one from the library page.", + }; + await dialog.ShowAsync(); return; } var dlssPickerControl = new DLSSPickerControl(game); - dialog = new EasyContentDialog(XamlRoot) + dialog = new(XamlRoot) { Title = "Select DLSS Version", PrimaryButtonText = "Swap", @@ -253,37 +243,37 @@ async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArg Content = dlssPickerControl, }; - if (String.IsNullOrEmpty(game.BaseDLSSVersion) == false) + if (string.IsNullOrEmpty(game.BaseDLSSVersion) is false) { dialog.SecondaryButtonText = "Reset"; } var result = await dialog.ShowAsync(); - - if (result == ContentDialogResult.Primary) + if (result is ContentDialogResult.Primary) { var selectedDLSSRecord = dlssPickerControl.GetSelectedDLSSRecord(); - if (selectedDLSSRecord.LocalRecord.IsDownloading == true || selectedDLSSRecord.LocalRecord.IsDownloaded == false) + if (selectedDLSSRecord.LocalRecord.IsDownloading is true || selectedDLSSRecord.LocalRecord.IsDownloaded is false) { // TODO: Initiate download here. - dialog = new EasyContentDialog(XamlRoot) + dialog = new(XamlRoot) { Title = "Error", CloseButtonText = "Okay", DefaultButton = ContentDialogButton.Close, Content = "Please download the DLSS record from the downloads page first.", }; + await dialog.ShowAsync(); return; } var didUpdate = game.UpdateDll(selectedDLSSRecord); - if (didUpdate.Success == false) + if (didUpdate.Success is false) { - dialog = new EasyContentDialog(XamlRoot) + dialog = new(XamlRoot) { Title = "Error", PrimaryButtonText = "Okay", @@ -291,6 +281,7 @@ async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArg Content = didUpdate.Message, }; + if (didUpdate.PromptToRelaunchAsAdmin is true) { dialog.SecondaryButtonText = "Relaunch as Administrator"; @@ -303,11 +294,11 @@ async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArg } } } - else if (result == ContentDialogResult.Secondary) + else if (result is ContentDialogResult.Secondary) { var didReset = game.ResetDll(); - if (didReset.Success == false) + if (didReset.Success is false) { dialog = new EasyContentDialog(XamlRoot) { @@ -332,9 +323,7 @@ async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArg } } - - - async Task LoadGamesAndDlls() + private async Task LoadGamesAndDlls() { if (_loadingGamesAndDlls) return; @@ -347,7 +336,6 @@ async Task LoadGamesAndDlls() var tasks = new List(); tasks.Add(LoadGamesAsync()); - await Task.WhenAll(tasks); DispatcherQueue.TryEnqueue(() => @@ -357,12 +345,12 @@ async Task LoadGamesAndDlls() }); } - async void RefreshButton_Click(object sender, RoutedEventArgs e) + private async void RefreshButton_Click(object sender, RoutedEventArgs e) { await LoadGamesAndDlls(); } - async void FilterButton_Click(object sender, RoutedEventArgs e) + private async void FilterButton_Click(object sender, RoutedEventArgs e) { var gameFilterControl = new GameFilterControl(); @@ -376,7 +364,7 @@ async void FilterButton_Click(object sender, RoutedEventArgs e) }; var result = await dialog.ShowAsync(); - if (result == ContentDialogResult.Primary) + if (result is ContentDialogResult.Primary) { Settings.Instance.HideNonDLSSGames = gameFilterControl.IsHideNonDLSSGamesChecked(); Settings.Instance.GroupGameLibrariesTogether = gameFilterControl.IsGroupGameLibrariesTogetherChecked(); diff --git a/src/Pages/SettingsPage.xaml b/src/Pages/SettingsPage.xaml index 08818c2..72dd74d 100644 --- a/src/Pages/SettingsPage.xaml +++ b/src/Pages/SettingsPage.xaml @@ -54,7 +54,6 @@ - - + + + + + This setting will hide not downloaded DLSS versions in the selector. + + -