Skip to content

Commit 03a735f

Browse files
committed
#124 Added change_resolution options and clean up SettingsWindow
1 parent 656482e commit 03a735f

File tree

6 files changed

+127
-33
lines changed

6 files changed

+127
-33
lines changed

UWPHook/App.config

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<value>False</value>
1515
</setting>
1616
<setting name="TargetLanguage" serializeAs="String">
17-
<value/>
17+
<value />
1818
</setting>
1919
<setting name="Seconds" serializeAs="String">
2020
<value>5</value>
@@ -23,7 +23,7 @@
2323
<value>False</value>
2424
</setting>
2525
<setting name="SteamGridDbApiKey" serializeAs="String">
26-
<value/>
26+
<value />
2727
</setting>
2828
<setting name="SelectedSteamGridDB_Style" serializeAs="String">
2929
<value>0</value>
@@ -43,6 +43,9 @@
4343
<setting name="Tags" serializeAs="String">
4444
<value>READY TO PLAY,XBOX</value>
4545
</setting>
46+
<setting name="SelectedLogLevel" serializeAs="String">
47+
<value>0</value>
48+
</setting>
4649
<setting name="SteamGridDB_Style" serializeAs="Xml">
4750
<value>
4851
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@@ -91,8 +94,11 @@
9194
</ArrayOfString>
9295
</value>
9396
</setting>
94-
<setting name="SelectedLogLevel" serializeAs="String">
95-
<value>0</value>
97+
<setting name="ChangeResolution" serializeAs="String">
98+
<value>False</value>
99+
</setting>
100+
<setting name="TargetResolution" serializeAs="String">
101+
<value />
96102
</setting>
97103
</UWPHook.Properties.Settings>
98104
</userSettings>

UWPHook/GamesWindow.xaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ private async Task LauncherAsync(string[] args)
113113
ScriptManager.RunScript("Set-WinUILanguageOverride " + Properties.Settings.Default.TargetLanguage);
114114
}
115115

116+
if (Settings.Default.ChangeResolution && !String.IsNullOrEmpty(Settings.Default.TargetResolution))
117+
{
118+
var targetResolution = ExtractDimensions(Settings.Default.TargetResolution);
119+
ScriptManager.RunScript("Set-DisplayResolution -Width " + targetResolution.Width + " - Height " + targetResolution.Height + " -Force");
120+
}
121+
116122
//The only other parameter Steam will send is the app AUMID
117123
AppManager.LaunchUWPApp(args);
118124

@@ -139,6 +145,19 @@ private async Task LauncherAsync(string[] args)
139145
}
140146
}
141147

148+
static (int Width, int Height) ExtractDimensions(string resolution)
149+
{
150+
var parts = resolution.Split('x');
151+
if (parts.Length == 2)
152+
{
153+
if (int.TryParse(parts[0].Trim(), out int width) && int.TryParse(parts[1].Trim(), out int height))
154+
{
155+
return (width, height);
156+
}
157+
}
158+
throw new FormatException("Invalid resolution format.");
159+
}
160+
142161
/// <summary>
143162
/// Generates a CRC32 hash expected by Steam to link an image with a game in the library
144163
/// See https://blog.yo1.dog/calculate-id-for-non-steam-games-js/ for an example

UWPHook/Properties/Settings.Designer.cs

Lines changed: 33 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWPHook/Properties/Settings.settings

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<Setting Name="Tags" Type="System.String" Scope="User">
3636
<Value Profile="(Default)">READY TO PLAY,XBOX</Value>
3737
</Setting>
38+
<Setting Name="SelectedLogLevel" Type="System.String" Scope="User">
39+
<Value Profile="(Default)">0</Value>
40+
</Setting>
3841
<Setting Name="SteamGridDB_Style" Type="System.Collections.Specialized.StringCollection" Scope="User">
3942
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
4043
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
@@ -78,8 +81,11 @@
7881
&lt;string&gt;TRACE&lt;/string&gt;
7982
&lt;/ArrayOfString&gt;</Value>
8083
</Setting>
81-
<Setting Name="SelectedLogLevel" Type="System.String" Scope="User">
82-
<Value Profile="(Default)">0</Value>
84+
<Setting Name="ChangeResolution" Type="System.Boolean" Scope="User">
85+
<Value Profile="(Default)">False</Value>
86+
</Setting>
87+
<Setting Name="TargetResolution" Type="System.String" Scope="User">
88+
<Value Profile="(Default)" />
8389
</Setting>
8490
</Settings>
8591
</SettingsFile>

UWPHook/SettingsWindow.xaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
TextElement.FontSize="14"
1313
FontFamily="Segoe UI Light"
1414
Title="Settings" Height="750" Width="800" Icon="Resources/hook2.ico">
15+
<Window.Resources>
16+
<Style TargetType="ToggleButton" BasedOn="{StaticResource MaterialDesignSwitchToggleButton}">
17+
<Setter Property="LayoutTransform">
18+
<Setter.Value>
19+
<ScaleTransform ScaleX="0.7" ScaleY="0.7" />
20+
</Setter.Value>
21+
</Setter>
22+
</Style>
23+
</Window.Resources>
1524
<Grid>
1625
<Grid.ColumnDefinitions>
1726
<ColumnDefinition Width="27*"/>
@@ -52,14 +61,14 @@
5261
<materialDesign:ColorZone Padding="16" Mode="PrimaryMid" VerticalAlignment="Top" Height="30" Grid.ColumnSpan="4" Grid.Row="0">
5362
<Label Content="Settings" HorizontalAlignment="Left" Margin="-10,-15,0,-17" VerticalAlignment="Top" FontFamily="Segoe UI Semibold" FontSize="14" Height="32" Foreground="#DDFFFFFF"/>
5463
</materialDesign:ColorZone>
55-
<ToggleButton x:Name="language_toggle" Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" RenderTransformOrigin="0.304,0.444" Grid.Row="1" Margin="5,3,6,4" />
64+
<ToggleButton x:Name="language_toggle" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" RenderTransformOrigin="0.304,0.444" Grid.Row="1" Margin="5,3,6,4" />
5665
<Label ToolTip="Some apps use the system language to choose what language to display, this setting will store your current language, change it so you can play in another language and then revert your system back to your default display language." x:Name="label_cultures" Content="Set system language when launching an app*" VerticalAlignment="Center" Height="29" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>
5766
<ComboBox ToolTip="Some apps use the system language to choose what language to display, this setting will store your current language, change it so you can play in another language and then revert your system back to your default display language." x:Name="cultures_comboBox" Margin="0,0,10,0" VerticalAlignment="Center" Height="32" Grid.Column="3" HorizontalAlignment="Right" Width="92" Grid.Row="1"/>
5867
<Label x:Name="label_seconds" ToolTip="If 0, UWPHook will not run in the background and will not update the in-game status" Content="Check if the launched app is running every" VerticalAlignment="Center" Height="29" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2"/>
5968
<ComboBox x:Name="seconds_comboBox" Margin="0,0,10,0" VerticalAlignment="Center" Height="32" Grid.Column="3" HorizontalAlignment="Right" Width="92" Grid.Row="2"/>
60-
<ToggleButton x:Name="streaming_toggle" Style="{DynamicResource MaterialDesignSwitchToggleButton}" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" Grid.Row="3" Margin="6,3,5,4" />
69+
<ToggleButton x:Name="streaming_toggle" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" Grid.Row="3" Margin="6,3,5,4" />
6170
<Label ToolTip="This fixes Steam in-home Streaming, set this in the host computer." x:Name="label_streaming" Content="Enable streaming mode" VerticalAlignment="Center" Height="29" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="3"/>
62-
<ToggleButton x:Name="change_resolution_toggle" Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Change host resolution on streaming mode" IsChecked="False" Grid.Row="4" Width="NaN" Margin="5,3,6,3" />
71+
<ToggleButton x:Name="change_resolution_toggle" ToolTip="Change host resolution on streaming mode" IsChecked="False" Grid.Row="4" Margin="5,3,6,3" />
6372
<Label ToolTip="Change the host computer resolution on launch, return to previous after." x:Name="label_resolution" Content="Change host resolution to:" VerticalAlignment="Center" Height="29" Grid.Column="1" Grid.Row="4"/>
6473
<ComboBox x:Name="resolution_comboBox" Margin="0,0,10,0" VerticalAlignment="Center" Height="32" Grid.Column="2" Width="220" Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Right"/>
6574
<Label ToolTip="Add these tags to exported games, use comma separated values" x:Name="label_tags" Content="Export with these tags:" Margin="0,0,8,0" VerticalAlignment="Center" Height="29" Grid.Column="1" Grid.Row="5"/>

UWPHook/SettingsWindow.xaml.cs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Diagnostics;
33
using System.Globalization;
4+
using System.Management;
45
using System.Security.Policy;
56
using System.Windows;
7+
using UWPHook.Properties;
68
using static System.Net.WebRequestMethods;
79

810
namespace UWPHook
@@ -16,28 +18,23 @@ public SettingsWindow()
1618
{
1719
InitializeComponent();
1820

19-
this.Title = "UWPHook version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
21+
Title = "UWPHook version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
2022

21-
foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
22-
{
23-
cultures_comboBox.Items.Add(culture.TextInfo.CultureName);
24-
}
23+
cultures_comboBox.ItemsSource = CultureInfo.GetCultures(CultureTypes.AllCultures).Select(c => c.TextInfo.CultureName);
24+
cultures_comboBox.SelectedItem = string.IsNullOrEmpty(Settings.Default.TargetLanguage) ? CultureInfo.CurrentCulture.TextInfo.CultureName : Properties.Settings.Default.TargetLanguage;
2525

26-
for (int i = 0; i < 10; i++)
27-
{
28-
seconds_comboBox.Items.Add(i + " seconds");
29-
if (i == Properties.Settings.Default.Seconds)
30-
{
31-
seconds_comboBox.SelectedIndex = i;
32-
}
33-
}
26+
seconds_comboBox.ItemsSource = Enumerable.Range(0, 10).Select(i => i + " seconds");
27+
seconds_comboBox.SelectedIndex = Properties.Settings.Default.Seconds;
28+
29+
resolution_comboBox.ItemsSource = GetResolutions();
30+
resolution_comboBox.SelectedItem = string.IsNullOrEmpty(Settings.Default.TargetResolution) ? GetCurrentResolution() : Properties.Settings.Default.TargetResolution;
3431

3532
int logLevel_index = 0;
3633
int.TryParse(Properties.Settings.Default.SelectedLogLevel, out logLevel_index);
3734

38-
cultures_comboBox.SelectedItem = Properties.Settings.Default.TargetLanguage;
3935
language_toggle.IsChecked = Properties.Settings.Default.ChangeLanguage;
4036
streaming_toggle.IsChecked = Properties.Settings.Default.StreamMode;
37+
change_resolution_toggle.IsChecked = Properties.Settings.Default.ChangeResolution;
4138
logLevel_comboBox.SelectedIndex = logLevel_index;
4239
steamgriddb_api_key.Text = Properties.Settings.Default.SteamGridDbApiKey;
4340
style_comboBox.SelectedIndex = Properties.Settings.Default.SelectedSteamGridDB_Style;
@@ -47,12 +44,45 @@ public SettingsWindow()
4744
tags_textBox.Text = Properties.Settings.Default.Tags;
4845
}
4946

47+
#pragma warning disable CA1416 // Validate platform compatibility
48+
private IEnumerable<string> GetResolutions()
49+
{
50+
51+
using var searcher = new ManagementObjectSearcher("SELECT * FROM CIM_VideoControllerResolution");
52+
foreach (var resolution in searcher.Get())
53+
{
54+
uint horizontalResolution = (uint)resolution["HorizontalResolution"];
55+
uint verticalResolution = (uint)resolution["VerticalResolution"];
56+
yield return horizontalResolution + " x " + verticalResolution;
57+
}
58+
59+
}
60+
61+
private string GetCurrentResolution()
62+
{
63+
using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
64+
foreach (var mo in searcher.Get())
65+
{
66+
var currentHorizontalResolution = mo["CurrentHorizontalResolution"];
67+
var currentVerticalResolution = mo["CurrentVerticalResolution"];
68+
if (currentHorizontalResolution != null && currentVerticalResolution != null)
69+
{
70+
return $"{currentHorizontalResolution} x {currentVerticalResolution}";
71+
}
72+
}
73+
74+
return string.Empty;
75+
}
76+
#pragma warning restore CA1416 // Validate platform compatibility
77+
5078
private void saveButton_Click(object sender, RoutedEventArgs e)
5179
{
5280
Properties.Settings.Default.ChangeLanguage = (bool)language_toggle.IsChecked;
5381
Properties.Settings.Default.TargetLanguage = cultures_comboBox.SelectedItem.ToString();
5482
Properties.Settings.Default.Seconds = Int32.Parse(seconds_comboBox.SelectedItem.ToString().Substring(0, 1));
5583
Properties.Settings.Default.StreamMode = (bool)streaming_toggle.IsChecked;
84+
Properties.Settings.Default.ChangeResolution = (bool)change_resolution_toggle.IsChecked;
85+
Properties.Settings.Default.TargetResolution = resolution_comboBox.SelectedItem.ToString();
5686
Properties.Settings.Default.SelectedLogLevel = logLevel_comboBox.SelectedIndex.ToString();
5787
Properties.Settings.Default.SteamGridDbApiKey = steamgriddb_api_key.Text.Trim('\r', '\n');
5888
Properties.Settings.Default.SelectedSteamGridDB_Style = style_comboBox.SelectedIndex;
@@ -102,7 +132,7 @@ private void clearAll_button_Click(object sender, RoutedEventArgs e)
102132
private void key_Button_Click(object sender, RoutedEventArgs e)
103133
{
104134
MessageBox.Show(messageBoxText: "You are being redirected to SteamGridDB website!\r\n" +
105-
"Log-in, or create your account, go to your profile preferences and click 'Generate API Key', then paste the key back on UWPHook.", "Attention!", MessageBoxButton.OK, MessageBoxImage.Information );
135+
"Log-in, or create your account, go to your profile preferences and click 'Generate API Key', then paste the key back on UWPHook.", "Attention!", MessageBoxButton.OK, MessageBoxImage.Information);
106136
OpenUrl("https://www.steamgriddb.com/profile/preferences/api");
107137
}
108138

0 commit comments

Comments
 (0)