Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add setting to hide non downloaded DLSS versions in selector #224

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 50 additions & 62 deletions src/Pages/GameGridPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -39,21 +20,19 @@ namespace DLSS_Swapper.Pages
/// </summary>
public sealed partial class GameGridPage : Page
{
public List<IGameLibrary> GameLibraries { get; } = new List<IGameLibrary>();
public List<IGameLibrary> GameLibraries { get; } = [];

bool _loadingGamesAndDlls = false;
private bool _loadingGamesAndDlls = false;

public bool RunsAsAdmin { get; } = Environment.IsPrivilegedProcess;

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)
Expand All @@ -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()
Expand Down Expand Up @@ -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",
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -165,7 +142,6 @@ void FilterGames()

if (Settings.Instance.GroupGameLibrariesTogether)
{

var collectionViewSource = new CollectionViewSource()
{
IsSourceGrouped = true,
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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",
Expand All @@ -253,44 +243,45 @@ 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",
DefaultButton = ContentDialogButton.Primary,
Content = didUpdate.Message,
};


if (didUpdate.PromptToRelaunchAsAdmin is true)
{
dialog.SecondaryButtonText = "Relaunch as Administrator";
Expand All @@ -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)
{
Expand All @@ -332,9 +323,7 @@ async void MainGridView_SelectionChanged(object sender, SelectionChangedEventArg
}
}



async Task LoadGamesAndDlls()
private async Task LoadGamesAndDlls()
{
if (_loadingGamesAndDlls)
return;
Expand All @@ -347,7 +336,6 @@ async Task LoadGamesAndDlls()
var tasks = new List<Task>();
tasks.Add(LoadGamesAsync());


await Task.WhenAll(tasks);

DispatcherQueue.TryEnqueue(() =>
Expand All @@ -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();

Expand All @@ -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();
Expand Down
21 changes: 13 additions & 8 deletions src/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<RadioButton x:Name="DefaultThemeRadioButton" GroupName="ThemeGroup" Tag="Default" Checked="ThemeRadioButton_Checked" Content="Use system setting" />
</StackPanel>


<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="0,40,0,0"
Expand All @@ -74,7 +73,6 @@
</TextBlock>
</StackPanel>


<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="0,40,0,0"
Expand All @@ -86,6 +84,16 @@
</TextBlock>
</StackPanel>

<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="0,40,0,0"
Text="Hide Not Downloaded DLSS Versions" />
<StackPanel Margin="0,10,0,0">
<ToggleSwitch x:Name="HideNotDownloadedToggleSwitch" Toggled="HideNotDownloaded_Toggled" OffContent="No" OnContent="Yes" Margin="0,0,0,4"/>
<TextBlock Style="{ThemeResource CaptionTextBlockStyle}" FontStyle="Italic" Margin="0,8,0,0">
This setting will hide not downloaded DLSS versions in the selector.
</TextBlock>
</StackPanel>

<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Expand All @@ -98,7 +106,6 @@
</TextBlock>
</StackPanel>


<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="0,40,0,0"
Expand Down Expand Up @@ -126,19 +133,17 @@
</TextBlock>
<Button Content="Check for updates" Margin="0,12,0,0" Command="{Binding CheckForUpdatesCommand}" />


<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="0,40,0,0"
Text="Give Feedback" />
<RichTextBlock Margin="0,12,0,0">
<Paragraph>
You can suggest a feature or report a problem or on the DLSS Swapper
<Hyperlink NavigateUri="https://github.com/beeradmoore/dlss-swapper/issues">GitHub repository</Hyperlink>.
<Hyperlink NavigateUri="https://github.com/beeradmoore/dlss-swapper/issues">GitHub repository</Hyperlink> .
</Paragraph>
</RichTextBlock>


<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Margin="0,40,0,0"
Expand All @@ -149,10 +154,10 @@
<Hyperlink NavigateUri="https://github.com/beeradmoore/dlss-swapper/graphs/contributors">contributors</Hyperlink>
and the people who have filed
<Hyperlink NavigateUri="https://github.com/beeradmoore/dlss-swapper/issues">feedback</Hyperlink> to help improve the product.
<LineBreak />(also NVIDIA for DLSS 😊)
<LineBreak /> (also NVIDIA for DLSS 😊)
</Paragraph>
</RichTextBlock>

</StackPanel>
</ScrollViewer>
</Grid>
Expand Down
Loading