From ac8b1dc63f9f6f478e4f0ff0b37b7ee5c9c98be9 Mon Sep 17 00:00:00 2001 From: Brian Lima Date: Wed, 12 Oct 2016 17:38:15 -0300 Subject: [PATCH] Version 2.2.0 Added a special mode for Steam in-home Streaming, it fools Steam into streaming the whole desktop then it brings the launched app to the foreground. Now, UWPHook will export the app icon to Steam when exporting new games, it automatically decides on the biggest jpg to be used as icon. --- UWPHook/App.config | 3 ++ UWPHook/AppEntry.cs | 14 +++--- UWPHook/AppManager.cs | 42 ++++++++++++++++++ UWPHook/GamesWindow.xaml.cs | 57 ++++++++++++++++++------- UWPHook/Properties/AssemblyInfo.cs | 4 +- UWPHook/Properties/Settings.Designer.cs | 12 ++++++ UWPHook/Properties/Settings.settings | 3 ++ UWPHook/SettingsWindow.xaml | 15 ++++--- UWPHook/SettingsWindow.xaml.cs | 2 + 9 files changed, 121 insertions(+), 31 deletions(-) diff --git a/UWPHook/App.config b/UWPHook/App.config index e2344c9..744efc7 100644 --- a/UWPHook/App.config +++ b/UWPHook/App.config @@ -19,6 +19,9 @@ 5 + + False + \ No newline at end of file diff --git a/UWPHook/AppEntry.cs b/UWPHook/AppEntry.cs index 675706a..9f41808 100644 --- a/UWPHook/AppEntry.cs +++ b/UWPHook/AppEntry.cs @@ -44,12 +44,12 @@ namespace UWPHook set { _aumid = value; } } - private string _icon; + private string _icon_path; - public string Icon + public string IconPath { - get { return _icon; } - set { _icon = value; } + get { return _icon_path; } + set { _icon_path = value; } } public string widestSquareIcon() @@ -58,9 +58,8 @@ namespace UWPHook Size size = new Size(0, 0); List images = new List(); - //Get every file on the directory - images.AddRange( Directory.GetFiles(_icon, "*.jpg", SearchOption.AllDirectories)); - images.AddRange(Directory.GetFiles(_icon, "*.png", SearchOption.AllDirectories)); + //Get every png in this directory, Steam only allows for .png's + images.AddRange(Directory.GetFiles(_icon_path, "*.png")); //Decide which is the largest foreach (string image in images) @@ -77,7 +76,6 @@ namespace UWPHook return result; } - public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/UWPHook/AppManager.cs b/UWPHook/AppManager.cs index 18ca929..2914c72 100644 --- a/UWPHook/AppManager.cs +++ b/UWPHook/AppManager.cs @@ -28,6 +28,8 @@ namespace UWPHook try { mgr.ActivateApplication(aumid, null, ActivateOptions.None, out processId); + //Bring the launched app to the foreground, this fixes in-home streaming + BringProcess(); } catch (Exception e) { @@ -88,6 +90,46 @@ namespace UWPHook return result; } + + [DllImport("user32.dll")] + private static extern + bool SetForegroundWindow(IntPtr hWnd); + [DllImport("user32.dll")] + private static extern + bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); + [DllImport("user32.dll")] + private static extern + bool IsIconic(IntPtr hWnd); + + public static void BringProcess() + { + /* +         const int SW_HIDE = 0; +         const int SW_SHOWNORMAL = 1; +         const int SW_SHOWMINIMIZED = 2; +         const int SW_SHOWMAXIMIZED = 3; +         const int SW_SHOWNOACTIVATE = 4; +         const int SW_RESTORE = 9; +         const int SW_SHOWDEFAULT = 10; +         */ + + var me = Process.GetCurrentProcess(); + var arrProcesses = Process.GetProcessById(id); + + // get the window handle + IntPtr hWnd = arrProcesses.MainWindowHandle; + + // if iconic, we need to restore the window + if (IsIconic(hWnd)) + { + ShowWindowAsync(hWnd, 9); + } + + // bring it to the foreground + SetForegroundWindow(hWnd); + + } + } public enum ActivateOptions diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 30065e3..7a2bb94 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -18,13 +18,12 @@ namespace UWPHook public partial class GamesWindow : Window { AppEntryModel Apps; - BackgroundWorker bwr; + BackgroundWorker bwrLoad, bwrSave; public GamesWindow() { InitializeComponent(); Apps = new AppEntryModel(); - listGames.ItemsSource = Apps.Entries; //If null or 1, the app was launched normally if (Environment.GetCommandLineArgs() != null) @@ -39,6 +38,14 @@ namespace UWPHook private void Launcher() { + if (Properties.Settings.Default.StreamMode) + { + this.Show(); + this.WindowStyle = WindowStyle.None; + this.WindowState = WindowState.Maximized; + Thread.Sleep(1000); + } + this.Title = "UWPHook: Playing a game"; //Hide the window so the app is launched seamless making UWPHook run in the background without bothering the user this.Hide(); @@ -80,6 +87,24 @@ namespace UWPHook } private void ExportButton_Click(object sender, RoutedEventArgs e) + { + bwrSave = new BackgroundWorker(); + bwrSave.DoWork += BwrSave_DoWork; + bwrSave.RunWorkerCompleted += BwrSave_RunWorkerCompleted; + grid.IsEnabled = false; + progressBar.Visibility = Visibility.Visible; + + bwrSave.RunWorkerAsync(); + } + + private void BwrSave_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + grid.IsEnabled = true; + progressBar.Visibility = Visibility.Collapsed; + MessageBox.Show("Your apps were successfuly exported, please restart Steam in order to see your apps in it.", "UWPHook", MessageBoxButton.OK, MessageBoxImage.Information); + } + + private void BwrSave_DoWork(object sender, DoWorkEventArgs e) { string steam_folder = SteamManager.GetSteamFolder(); if (!String.IsNullOrEmpty(steam_folder)) @@ -145,26 +170,29 @@ namespace UWPHook } } - - MessageBox.Show("Your apps were successfuly exported, please restart Steam in order to see your apps in it.", "UWPHook", MessageBoxButton.OK, MessageBoxImage.Information); } private void LoadButton_Click(object sender, RoutedEventArgs e) { - bwr = new BackgroundWorker(); - bwr.DoWork += Bwr_DoWork; - bwr.RunWorkerCompleted += Bwr_RunWorkerCompleted; + bwrLoad = new BackgroundWorker(); + bwrLoad.DoWork += Bwr_DoWork; + bwrLoad.RunWorkerCompleted += Bwr_RunWorkerCompleted; grid.IsEnabled = false; progressBar.Visibility = Visibility.Visible; - bwr.RunWorkerAsync(); + Apps.Entries = new System.Collections.ObjectModel.ObservableCollection(); + + bwrLoad.RunWorkerAsync(); } private void Bwr_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { - grid.IsEnabled = true; - listGames.Columns[1].IsReadOnly = true; + listGames.ItemsSource = Apps.Entries; + listGames.Columns[2].IsReadOnly = true; + listGames.Columns[3].IsReadOnly = true; + + grid.IsEnabled = true; progressBar.Visibility = Visibility.Collapsed; label.Content = "Installed Apps"; } @@ -174,19 +202,19 @@ namespace UWPHook try { //Get all installed apps on the system excluding frameworks - List installedApps = AppManager.GetInstalledApps(); + List installedApps = AppManager.GetInstalledApps(); //Alfabetic sort installedApps.Sort(); //Split every app that we couldn't resolve the app name - var x = (from s in installedApps where s.Contains("double click") select s).ToList(); + var nameNotFound = (from s in installedApps where s.Contains("double click") select s).ToList(); //Remove them from the original list installedApps.RemoveAll(item => item.Contains("double click")); //Rejoin them in the original list, but putting them into last - installedApps = installedApps.Union(x).ToList(); + installedApps = installedApps.Union(nameNotFound).ToList(); foreach (var app in installedApps) { @@ -199,11 +227,10 @@ namespace UWPHook string logosPath = Path.GetDirectoryName(valor[1]); Application.Current.Dispatcher.BeginInvoke((Action)delegate () { - Apps.Entries.Add(new AppEntry() { Name = valor[0], Icon = logosPath, Aumid = valor[2], Selected = false}); + Apps.Entries.Add(new AppEntry() { Name = valor[0], IconPath = logosPath, Aumid = valor[2], Selected = false }); }); } } - } catch (Exception ex) { diff --git a/UWPHook/Properties/AssemblyInfo.cs b/UWPHook/Properties/AssemblyInfo.cs index 897a6a0..4c37232 100644 --- a/UWPHook/Properties/AssemblyInfo.cs +++ b/UWPHook/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.4.0")] -[assembly: AssemblyFileVersion("2.1.4.0")] +[assembly: AssemblyVersion("2.2.0.0")] +[assembly: AssemblyFileVersion("2.2.0.0")] diff --git a/UWPHook/Properties/Settings.Designer.cs b/UWPHook/Properties/Settings.Designer.cs index 8eeae83..8072de2 100644 --- a/UWPHook/Properties/Settings.Designer.cs +++ b/UWPHook/Properties/Settings.Designer.cs @@ -58,5 +58,17 @@ namespace UWPHook.Properties { this["Seconds"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool StreamMode { + get { + return ((bool)(this["StreamMode"])); + } + set { + this["StreamMode"] = value; + } + } } } diff --git a/UWPHook/Properties/Settings.settings b/UWPHook/Properties/Settings.settings index 16477b8..6aed1ad 100644 --- a/UWPHook/Properties/Settings.settings +++ b/UWPHook/Properties/Settings.settings @@ -11,5 +11,8 @@ 5 + + False + \ No newline at end of file diff --git a/UWPHook/SettingsWindow.xaml b/UWPHook/SettingsWindow.xaml index 1d315dc..27c1377 100644 --- a/UWPHook/SettingsWindow.xaml +++ b/UWPHook/SettingsWindow.xaml @@ -25,8 +25,9 @@ - - + + + @@ -40,11 +41,13 @@