Skip to content

Commit

Permalink
Merge pull request #153 from dos-ise/master
Browse files Browse the repository at this point in the history
.NET8 Migration
  • Loading branch information
BrianLima authored Dec 8, 2024
2 parents a6e7eda + 03a735f commit 109b9b5
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 340 deletions.
14 changes: 10 additions & 4 deletions UWPHook/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<value>False</value>
</setting>
<setting name="TargetLanguage" serializeAs="String">
<value/>
<value />
</setting>
<setting name="Seconds" serializeAs="String">
<value>5</value>
Expand All @@ -23,7 +23,7 @@
<value>False</value>
</setting>
<setting name="SteamGridDbApiKey" serializeAs="String">
<value/>
<value />
</setting>
<setting name="SelectedSteamGridDB_Style" serializeAs="String">
<value>0</value>
Expand All @@ -43,6 +43,9 @@
<setting name="Tags" serializeAs="String">
<value>READY TO PLAY,XBOX</value>
</setting>
<setting name="SelectedLogLevel" serializeAs="String">
<value>0</value>
</setting>
<setting name="SteamGridDB_Style" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Expand Down Expand Up @@ -91,8 +94,11 @@
</ArrayOfString>
</value>
</setting>
<setting name="SelectedLogLevel" serializeAs="String">
<value>0</value>
<setting name="ChangeResolution" serializeAs="String">
<value>False</value>
</setting>
<setting name="TargetResolution" serializeAs="String">
<value />
</setting>
</UWPHook.Properties.Settings>
</userSettings>
Expand Down
13 changes: 12 additions & 1 deletion UWPHook/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static List<String> GetInstalledApps()
/// <returns>Whether this is a known app</returns>
public static bool IsKnownApp(string appName, out string readableName)
{
string appsJson = File.ReadAllText(@"Resources\KnownApps.json");
string appsJson = GetEmbeddedResource("KnownApps.json");
var apps = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(appsJson);

foreach (var kvp in apps)
Expand All @@ -203,6 +203,17 @@ public static bool IsKnownApp(string appName, out string readableName)
return false;
}

static string GetEmbeddedResource(string resourceName)
{
var assembly = Assembly.GetExecutingAssembly();
resourceName = assembly.GetManifestResourceNames().First(r => r.Contains(resourceName));
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}

[DllImport("user32.dll")]
private static extern
bool SetForegroundWindow(IntPtr hWnd);
Expand Down
28 changes: 25 additions & 3 deletions UWPHook/GamesWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Force.Crc32;
using Serilog;
using Serilog.Core;
using SharpSteam;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -114,6 +113,12 @@ private async Task LauncherAsync(string[] args)
ScriptManager.RunScript("Set-WinUILanguageOverride " + Properties.Settings.Default.TargetLanguage);
}

if (Settings.Default.ChangeResolution && !String.IsNullOrEmpty(Settings.Default.TargetResolution))
{
var targetResolution = ExtractDimensions(Settings.Default.TargetResolution);
ScriptManager.RunScript("Set-DisplayResolution -Width " + targetResolution.Width + " - Height " + targetResolution.Height + " -Force");
}

//The only other parameter Steam will send is the app AUMID
AppManager.LaunchUWPApp(args);

Expand All @@ -140,6 +145,19 @@ private async Task LauncherAsync(string[] args)
}
}

static (int Width, int Height) ExtractDimensions(string resolution)
{
var parts = resolution.Split('x');
if (parts.Length == 2)
{
if (int.TryParse(parts[0].Trim(), out int width) && int.TryParse(parts[1].Trim(), out int height))
{
return (width, height);
}
}
throw new FormatException("Invalid resolution format.");
}

/// <summary>
/// Generates a CRC32 hash expected by Steam to link an image with a game in the library
/// See https://blog.yo1.dog/calculate-id-for-non-steam-games-js/ for an example
Expand Down Expand Up @@ -385,8 +403,9 @@ private async Task<bool> ExportGames()
{
var users = SteamManager.GetUsers(steam_folder);
var selected_apps = Apps.Entries.Where(app => app.Selected);
var exePath = @"""" + System.Reflection.Assembly.GetExecutingAssembly().Location + @"""";
var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var processModule = Process.GetCurrentProcess().MainModule;
var exePath = processModule?.FileName;
var exeDir = Path.GetDirectoryName(exePath);

List<Task> gridImagesDownloadTasks = new List<Task>();
bool downloadGridImages = !String.IsNullOrEmpty(Properties.Settings.Default.SteamGridDbApiKey);
Expand Down Expand Up @@ -745,6 +764,9 @@ private void Bwr_DoWork(object sender, DoWorkEventArgs e)
{
try
{
//For some reason I need to enforce Set-ExecutionPolicy none
ScriptManager.RunScript("Set-ExecutionPolicy RemoteSigned -Scope Process -Force");

//Get all installed apps on the system excluding frameworks
List<String> installedApps = AppManager.GetInstalledApps();

Expand Down
92 changes: 0 additions & 92 deletions UWPHook/ProcessManager.cs

This file was deleted.

34 changes: 29 additions & 5 deletions UWPHook/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions UWPHook/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<Setting Name="Tags" Type="System.String" Scope="User">
<Value Profile="(Default)">READY TO PLAY,XBOX</Value>
</Setting>
<Setting Name="SelectedLogLevel" Type="System.String" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SteamGridDB_Style" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
Expand Down Expand Up @@ -78,8 +81,11 @@
&lt;string&gt;TRACE&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="SelectedLogLevel" Type="System.String" Scope="User">
<Value Profile="(Default)">0</Value>
<Setting Name="ChangeResolution" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="TargetResolution" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
15 changes: 12 additions & 3 deletions UWPHook/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
TextElement.FontSize="14"
FontFamily="Segoe UI Light"
Title="Settings" Height="750" Width="800" Icon="Resources/hook2.ico">
<Window.Resources>
<Style TargetType="ToggleButton" BasedOn="{StaticResource MaterialDesignSwitchToggleButton}">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.7" ScaleY="0.7" />
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="27*"/>
Expand Down Expand Up @@ -52,14 +61,14 @@
<materialDesign:ColorZone Padding="16" Mode="PrimaryMid" VerticalAlignment="Top" Height="30" Grid.ColumnSpan="4" Grid.Row="0">
<Label Content="Settings" HorizontalAlignment="Left" Margin="-10,-15,0,-17" VerticalAlignment="Top" FontFamily="Segoe UI Semibold" FontSize="14" Height="32" Foreground="#DDFFFFFF"/>
</materialDesign:ColorZone>
<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" />
<ToggleButton x:Name="language_toggle" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" RenderTransformOrigin="0.304,0.444" Grid.Row="1" Margin="5,3,6,4" />
<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"/>
<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"/>
<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"/>
<ComboBox x:Name="seconds_comboBox" Margin="0,0,10,0" VerticalAlignment="Center" Height="32" Grid.Column="3" HorizontalAlignment="Right" Width="92" Grid.Row="2"/>
<ToggleButton x:Name="streaming_toggle" Style="{DynamicResource MaterialDesignSwitchToggleButton}" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" Grid.Row="3" Margin="6,3,5,4" />
<ToggleButton x:Name="streaming_toggle" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="False" Grid.Row="3" Margin="6,3,5,4" />
<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"/>
<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" />
<ToggleButton x:Name="change_resolution_toggle" ToolTip="Change host resolution on streaming mode" IsChecked="False" Grid.Row="4" Margin="5,3,6,3" />
<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"/>
<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"/>
<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"/>
Expand Down
Loading

0 comments on commit 109b9b5

Please sign in to comment.