diff --git a/UWPHook/App.config b/UWPHook/App.config index c4f65a2..843156f 100644 --- a/UWPHook/App.config +++ b/UWPHook/App.config @@ -14,7 +14,7 @@ False - + 5 @@ -23,7 +23,7 @@ False - + 0 @@ -43,6 +43,9 @@ READY TO PLAY,XBOX + + 0 + @@ -91,8 +94,11 @@ - - 0 + + False + + + diff --git a/UWPHook/AppManager.cs b/UWPHook/AppManager.cs index 23afe60..4e2129f 100644 --- a/UWPHook/AppManager.cs +++ b/UWPHook/AppManager.cs @@ -187,7 +187,7 @@ public static List GetInstalledApps() /// Whether this is a known app 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>(appsJson); foreach (var kvp in apps) @@ -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); diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 1c3c9af..2d8e3e6 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -1,7 +1,6 @@ using Force.Crc32; using Serilog; using Serilog.Core; -using SharpSteam; using System; using System.Collections.Generic; using System.ComponentModel; @@ -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); @@ -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."); + } + /// /// 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 @@ -385,8 +403,9 @@ private async Task 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 gridImagesDownloadTasks = new List(); bool downloadGridImages = !String.IsNullOrEmpty(Properties.Settings.Default.SteamGridDbApiKey); @@ -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 installedApps = AppManager.GetInstalledApps(); diff --git a/UWPHook/ProcessManager.cs b/UWPHook/ProcessManager.cs deleted file mode 100644 index 4e23f85..0000000 --- a/UWPHook/ProcessManager.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace UWPHook -{ - class AppManager - { - private int id; - - public void LaunchUWPApp(string uri) - { - var mgr = new ApplicationActivationManager(); - uint processId; - mgr.ActivateApplication(uri, null, ActivateOptions.None, out processId); - - id = (int)processId; - } - - public Boolean IsRunning() - { - if (id == 0) - { - return false; - } - - try - { - Process.GetProcessById(id); - } - catch (Exception) - { - return false; - } - - return true; - } - } - - public enum ActivateOptions - { - None = 0x00000000, // No flags set - DesignMode = 0x00000001, // The application is being activated for design mode, and thus will not be able to - // to create an immersive window. Window creation must be done by design tools which - // load the necessary components by communicating with a designer-specified service on - // the site chain established on the activation manager. The splash screen normally - // shown when an application is activated will also not appear. Most activations - // will not use this flag. - NoErrorUI = 0x00000002, // Do not show an error dialog if the app fails to activate. - NoSplashScreen = 0x00000004, // Do not show the splash screen when activating the app. - } - - [ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - interface IApplicationActivationManager - { - // Activates the specified immersive application for the "Launch" contract, passing the provided arguments - // string into the application. Callers can obtain the process Id of the application instance fulfilling this contract. - IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId); - IntPtr ActivateForFile([In] String appUserModelId, [In] [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] /*IShellItemArray* */ IShellItemArray itemArray, [In] String verb, [Out] out UInt32 processId); - IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId); - } - - [ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]//Application Activation Manager - class ApplicationActivationManager : IApplicationActivationManager - { - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/] - public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] - public extern IntPtr ActivateForFile([In] String appUserModelId, [In] [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] /*IShellItemArray* */ IShellItemArray itemArray, [In] String verb, [Out] out UInt32 processId); - [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] - public extern IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId); - } - - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")] - interface IShellItem - { - } - - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [Guid("b63ea76d-1f85-456f-a19c-48159efa858b")] - interface IShellItemArray - { - } -} \ No newline at end of file diff --git a/UWPHook/Properties/Settings.Designer.cs b/UWPHook/Properties/Settings.Designer.cs index 24c2a03..d465e0d 100644 --- a/UWPHook/Properties/Settings.Designer.cs +++ b/UWPHook/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace UWPHook.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.8.0.0")] public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -155,6 +155,18 @@ public string Tags { } } + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public string SelectedLogLevel { + get { + return ((string)(this["SelectedLogLevel"])); + } + set { + this["SelectedLogLevel"] = value; + } + } + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute(@" @@ -237,13 +249,25 @@ public string Tags { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0")] - public string SelectedLogLevel { + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ChangeResolution { get { - return ((string)(this["SelectedLogLevel"])); + return ((bool)(this["ChangeResolution"])); } set { - this["SelectedLogLevel"] = value; + this["ChangeResolution"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string TargetResolution { + get { + return ((string)(this["TargetResolution"])); + } + set { + this["TargetResolution"] = value; } } } diff --git a/UWPHook/Properties/Settings.settings b/UWPHook/Properties/Settings.settings index 75865b4..90d4705 100644 --- a/UWPHook/Properties/Settings.settings +++ b/UWPHook/Properties/Settings.settings @@ -35,6 +35,9 @@ READY TO PLAY,XBOX + + 0 + <?xml version="1.0" encoding="utf-16"?> <ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> @@ -78,8 +81,11 @@ <string>TRACE</string> </ArrayOfString> - - 0 + + False + + + \ No newline at end of file diff --git a/UWPHook/SettingsWindow.xaml b/UWPHook/SettingsWindow.xaml index c52e02d..46e138e 100644 --- a/UWPHook/SettingsWindow.xaml +++ b/UWPHook/SettingsWindow.xaml @@ -12,6 +12,15 @@ TextElement.FontSize="14" FontFamily="Segoe UI Light" Title="Settings" Height="750" Width="800" Icon="Resources/hook2.ico"> + + + @@ -52,14 +61,14 @@ - +