diff --git a/UWPHook/AppManager.cs b/UWPHook/AppManager.cs index 6bdb23b..e6b8cd5 100644 --- a/UWPHook/AppManager.cs +++ b/UWPHook/AppManager.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; @@ -39,6 +41,25 @@ namespace UWPHook return true; } + + public List GetInstalledApps() + { + List result = null; + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = "UWPHook.Resources.GetAUMIDScript.txt"; + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + { + using (StreamReader reader = new StreamReader(stream)) + { + ScriptManager script = new ScriptManager(); + var r = script.RunScript(reader.ReadToEnd()).Split(';').ToList(); + + } + } + + return result; + } } public enum ActivateOptions diff --git a/UWPHook/MainWindow.xaml.cs b/UWPHook/MainWindow.xaml.cs index 241c6e9..5fadd4f 100644 --- a/UWPHook/MainWindow.xaml.cs +++ b/UWPHook/MainWindow.xaml.cs @@ -79,6 +79,7 @@ namespace UWPHook private void helpButton_Click(object sender, RoutedEventArgs e) { + manager.InstalledApps(); Process.Start("https://www.reddit.com/r/UWPHook/comments/53eaj9/welcome_to_uwphook_link_your_uwp_games_to_steam/"); } diff --git a/UWPHook/Properties/Resources.Designer.cs b/UWPHook/Properties/Resources.Designer.cs index 930a76f..0cc634a 100644 --- a/UWPHook/Properties/Resources.Designer.cs +++ b/UWPHook/Properties/Resources.Designer.cs @@ -22,7 +22,7 @@ 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 { + public class Resources { private static global::System.Resources.ResourceManager resourceMan; @@ -36,7 +36,7 @@ namespace UWPHook.Properties { /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + public 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); @@ -51,7 +51,7 @@ namespace UWPHook.Properties { /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + public static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -59,5 +59,25 @@ namespace UWPHook.Properties { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to $installedapps = get-AppxPackage + /// + ///$aumidList = @() + ///foreach ($app in $installedapps) + ///{ + ///    foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id) + ///    { + ///        $aumidList += $app.packagefamilyname + "!" + $id + ///    } + ///} + /// + ///$aumidList. + /// + public static string GetAUMIDScript { + get { + return ResourceManager.GetString("GetAUMIDScript", resourceCulture); + } + } } } diff --git a/UWPHook/Properties/Resources.resx b/UWPHook/Properties/Resources.resx index 2f96abe..32d0e44 100644 --- a/UWPHook/Properties/Resources.resx +++ b/UWPHook/Properties/Resources.resx @@ -118,4 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\GetAUMIDScript.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/UWPHook/Resources/GetAUMIDScript.txt b/UWPHook/Resources/GetAUMIDScript.txt new file mode 100644 index 0000000..3b59ac2 --- /dev/null +++ b/UWPHook/Resources/GetAUMIDScript.txt @@ -0,0 +1,12 @@ +$installedapps = get-AppxPackage + +$aumidList = @() +foreach ($app in $installedapps) +{ +    foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id) +    { +        $aumidList += $app.packagefamilyname + "!" + $id + ";" +    } +} + +$aumidList \ No newline at end of file diff --git a/UWPHook/ScriptManager.cs b/UWPHook/ScriptManager.cs new file mode 100644 index 0000000..aaeb473 --- /dev/null +++ b/UWPHook/ScriptManager.cs @@ -0,0 +1,55 @@ +using System.Collections.ObjectModel; +using System.Management.Automation; +using System.Management.Automation.Runspaces; +using System.Text; + +namespace UWPHook +{ + class ScriptManager + { + public string RunScript(string scriptText) + { + // create Powershell runspace + + Runspace runspace = RunspaceFactory.CreateRunspace(); + + // open it + + runspace.Open(); + + // create a pipeline and feed it the script text + + Pipeline pipeline = runspace.CreatePipeline(); + pipeline.Commands.AddScript(scriptText); + + // add an extra command to transform the script + // output objects into nicely formatted strings + + // remove this line to get the actual objects + // that the script returns. For example, the script + + // "Get-Process" returns a collection + // of System.Diagnostics.Process instances. + + pipeline.Commands.Add("Out-String"); + + // execute the script + + Collection results = pipeline.Invoke(); + + // close the runspace + + runspace.Close(); + + // convert the script result into a single string + + StringBuilder stringBuilder = new StringBuilder(); + foreach (PSObject obj in results) + { + stringBuilder.AppendLine(obj.ToString()); + } + + return stringBuilder.ToString(); + } + } +} diff --git a/UWPHook/UWPHook.csproj b/UWPHook/UWPHook.csproj index 3638251..b4cf211 100644 --- a/UWPHook/UWPHook.csproj +++ b/UWPHook/UWPHook.csproj @@ -63,6 +63,10 @@ + + ..\packages\System.Management.Automation.6.1.7601.17515\lib\net45\System.Management.Automation.dll + True + @@ -81,6 +85,7 @@ MSBuild:Compile Designer + MSBuild:Compile Designer @@ -111,7 +116,7 @@ True - ResXFileCodeGenerator + PublicResXFileCodeGenerator Resources.Designer.cs Designer @@ -146,6 +151,9 @@ false + + +