Version 1.1

Launching apps via background process.
Invoking apps via COM.
Check if app is running every 5 seconds in order to close this app.
UWPTest
Brian Lima 8 years ago
parent 7d25822c4b
commit 4245ef9769

@ -7,5 +7,6 @@ namespace UWPHook
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,91 @@
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
{
}
}

@ -5,11 +5,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UWPHook"
mc:Ignorable="d"
Title="UWPHook" Height="350" Width="525" Loaded="Window_Loaded" Icon="1_cJz_icon.ico">
Title="UWPHook" Height="600" Width="800" Loaded="Window_Loaded" Icon="1_cJz_icon.ico">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="9*"/>
<RowDefinition Height="147*"/>
<RowDefinition Height="44*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
@ -20,7 +20,11 @@
<ListView x:Name="listView" RenderTransformOrigin="0.496,0.409">
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove" Click="MenuItem_Click"/>
<MenuItem Header="Remove" Click="MenuItem_Click">
<MenuItem.Icon>
<Image Source="{Binding Resources/delete.ico}" Stretch="Fill"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ListView.ContextMenu>
<ListView.View>
@ -32,18 +36,17 @@
</ListView>
</Grid>
<Grid Grid.Column="1" Margin="2,0,9,17" Grid.ColumnSpan="2" Grid.Row="1" Height="68" VerticalAlignment="Bottom">
<Grid Grid.Column="1" Margin="2,0,9,17" Grid.ColumnSpan="2" Grid.Row="1" Height="105" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="185*"/>
<ColumnDefinition Width="220*"/>
<ColumnDefinition Width="91*"/>
<ColumnDefinition Width="307*"/>
<ColumnDefinition Width="70*"/>
</Grid.ColumnDefinitions>
<Button x:Name="addButton" Content="Add Game" Margin="8,10,8,0" VerticalAlignment="Top" Grid.Column="2" Height="20" Click="addButton_Click"/>
<TextBox x:Name="alias_textBox" Height="23" Margin="10,36,10,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="label" Content="Alias" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="26" Width="35"/>
<TextBox x:Name="path_textBox" Height="23" Margin="10,36,10,0" TextWrapping="Wrap" VerticalAlignment="Top" Grid.Column="1"/>
<Label x:Name="label_Copy" Content="Path" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Grid.Column="1" Height="26" Width="33"/>
<Button x:Name="helpButton" Content="Help" Grid.Column="2" Margin="8,35,8,0" VerticalAlignment="Top" Height="20" Click="helpButton_Click"/>
<Button x:Name="addButton" Content="Add Game" Margin="6,33,10,0" VerticalAlignment="Top" Grid.Column="1" Height="20" Click="addButton_Click"/>
<TextBox x:Name="alias_textBox" Height="23" Margin="50,36,10,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="label" Content="Alias" HorizontalAlignment="Left" Margin="10,33,0,0" VerticalAlignment="Top" Height="26" Width="35"/>
<Button x:Name="helpButton" Content="Help" Grid.Column="1" Margin="6,69,10,0" VerticalAlignment="Top" Height="20" Click="helpButton_Click"/>
<TextBox x:Name="path_textBox" Height="23" Margin="50,69,10,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
<Label x:Name="label_Copy" Content="Path" HorizontalAlignment="Left" Margin="12,66,0,0" VerticalAlignment="Top" Height="26" Width="33"/>
</Grid>
</Grid>
</Window>

@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows;
namespace UWPHook
@ -10,33 +12,61 @@ namespace UWPHook
public partial class MainWindow : Window
{
GameModel gamesView;
AppManager manager;
public MainWindow()
{
InitializeComponent();
gamesView = new GameModel();
if (Environment.GetCommandLineArgs() != null)
{
if (Environment.GetCommandLineArgs().Length > 1)
{
manager = new AppManager();
try
{
this.Hide();
Launch_Game(String.Join(" ", Environment.GetCommandLineArgs()));
while (manager.IsRunning())
{
Thread.Sleep(5000);
}
this.Close();
}
catch (Exception e)
{
this.Show();
MessageBox.Show(e.Message);
}
}
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
gamesView = new GameModel();
listView.ItemsSource = gamesView.games;
}
var argument = Environment.GetCommandLineArgs();
string argumentGame = "";
for (int i = 1; i < argument.Length; i++)
{
argumentGame += argument[i] + " ";
}
if (argument != null)
private void Launch_Game(string game_name)
{
//Remove startup path from parameters to get the game name sent from startup options from Steam
game_name = game_name.Remove(0, (System.Reflection.Assembly.GetExecutingAssembly().Location + " ").Length);
foreach (Game game in gamesView.games)
{
foreach (Game game in gamesView.games)
if (game.game_alias.ToLower() == game_name.ToLower())
{
if (game.game_alias.ToLower() == argumentGame.ToLower().Trim())
try
{
manager.LaunchUWPApp(game.game_path);
}
catch (Exception ex)
{
Process.Start(@"shell:AppsFolder\" + game.game_path);
this.Title = "UWPHook - Now Playing :" + game.game_alias;
break;
throw new Exception("Error while trying to launch your game" + Environment.NewLine + ex.Message);
}
break;
}
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UWPHook
{
class ProccessManager
{
}
}

@ -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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

@ -8,10 +8,10 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace UWPHook.Properties
{
namespace UWPHook.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@ -22,48 +22,40 @@ namespace UWPHook.Properties
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UWPHook.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}

@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -109,9 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

@ -14,6 +14,21 @@
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -35,7 +50,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>1_cJz_icon.ico</ApplicationIcon>
<ApplicationIcon>hook_icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject>UWPHook.App</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@ -44,6 +62,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -70,6 +89,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="AppManager.cs" />
<Compile Include="GameModel.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
@ -93,6 +113,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="games.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -108,7 +129,22 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="1_cJz_icon.ico" />
<Resource Include="hook_icon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\delete.png" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Loading…
Cancel
Save