Merge pull request #73 from novemberdobby/master

pull/84/head
Brian Lima 2 years ago committed by GitHub
commit e8a1e0379d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,7 @@ Select every app you want to add to Steam, you can change the name by double cli
![](https://i.imgur.com/on46CMQ.png)
Close UWPHook, restart Steam, click play on your UWP game, and Steam will show your current game on your status as long as you are playing it!
Close UWPHook, restart Steam if prompted, click play on your UWP game, and Steam will show your current game on your status as long as you are playing it!
----------

@ -118,14 +118,11 @@ namespace UWPHook
public string isKnownApp()
{
if (_aumid.Contains("Microsoft.SeaofThieves"))
if(AppManager.IsKnownApp(_aumid, out string name))
{
return "Sea of Thieves";
}
else if (_aumid.Contains("Microsoft.DeltaPC"))
{
return "Gears of War: Ultimate Edition";
return name;
}
return "Name not found, double click here to edit";
}
@ -135,5 +132,10 @@ namespace UWPHook
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public override string ToString()
{
return $"{Name} ({Aumid})";
}
}
}

@ -101,6 +101,30 @@ namespace UWPHook
return result;
}
/// <summary>
/// Try to convert an aumid into a human-readable app name
/// </summary>
/// <param name="appName">Application user model ID (aumid)</param>
/// <param name="readableName">User-friendly app name</param>
/// <returns>Whether this is a known app</returns>
public static bool IsKnownApp(string appName, out string readableName)
{
string appsJson = File.ReadAllText(@"Resources\KnownApps.json");
var apps = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(appsJson);
foreach (var kvp in apps)
{
if (appName.StartsWith(kvp.Key + "_"))
{
readableName = kvp.Value;
return true;
}
}
readableName = null;
return false;
}
[DllImport("user32.dll")]
private static extern
bool SetForegroundWindow(IntPtr hWnd);

@ -39,7 +39,7 @@
</Grid>
<Button Content="Export selected apps to Steam" Click="ExportButton_Click" HorizontalAlignment="Right" Margin="0,0,10,10" Grid.Row="2" VerticalAlignment="Bottom" Width="227"/>
<ProgressBar Visibility="Collapsed" x:Name="progressBar" Margin="10,215,10,174" Grid.Row="1" IsIndeterminate="True" />
<Label Content="Filter AUMIDs:" HorizontalAlignment="Left" Margin="5,16,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="25" Margin="104,17,0,0" Grid.Row="2" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="217" TextChanged="textBox_TextChanged"/>
<Label Content="Filter:" HorizontalAlignment="Left" Margin="5,16,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="25" Margin="50,17,0,0" Grid.Row="2" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="271" TextChanged="textBox_TextChanged"/>
</Grid>
</Window>

@ -1,4 +1,4 @@
using Force.Crc32;
using Force.Crc32;
using SharpSteam;
using System;
using System.Collections.Generic;
@ -18,7 +18,6 @@ using UWPHook.Properties;
using UWPHook.SteamGridDb;
using VDFParser;
using VDFParser.Models;
using System.Diagnostics;
namespace UWPHook
{
@ -38,13 +37,15 @@ namespace UWPHook
var args = Environment.GetCommandLineArgs();
//If null or 1, the app was launched normally
if (args != null)
if (args?.Length > 1)
{
//When length is 1, the only argument is the path where the app is installed
if (Environment.GetCommandLineArgs().Length > 1)
{
_ = LauncherAsync(args);
}
_ = LauncherAsync(args);
}
else
{
//auto refresh on load
LoadButton_Click(null, null);
}
}
@ -129,11 +130,23 @@ namespace UWPHook
grid.IsEnabled = false;
progressBar.Visibility = Visibility.Visible;
await ExportGames();
bool restartSteam = true;
var result = await ExportGames(restartSteam);
grid.IsEnabled = true;
progressBar.Visibility = Visibility.Collapsed;
MessageBox.Show("Your apps were successfuly exported, please restart Steam in order to see your apps.", "UWPHook", MessageBoxButton.OK, MessageBoxImage.Information);
string msg = "Your apps were successfuly exported!";
if(!restartSteam)
{
msg += " Please restart Steam in order to see them.";
}
else if(result)
{
msg += " Steam has been restarted.";
}
MessageBox.Show(msg, "UWPHook", MessageBoxButton.OK, MessageBoxImage.Information);
}
private async Task SaveImage(string imageUrl, string destinationFilename, ImageFormat format)
@ -264,7 +277,7 @@ namespace UWPHook
}
}
private async Task ExportGames()
private async Task<bool> ExportGames(bool restartSteam)
{
string[] tags = Settings.Default.Tags.Split(',');
string steam_folder = SteamManager.GetSteamFolder();
@ -391,6 +404,52 @@ namespace UWPHook
});
}
}
if(restartSteam)
{
Func<Process> getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault();
Process steam = getSteam();
if (steam != null)
{
string steamExe = steam.MainModule.FileName;
//we always ask politely
Debug.WriteLine("Requesting Steam shutdown");
Process.Start(steamExe, "-exitsteam");
bool restarted = false;
Stopwatch watch = new Stopwatch();
watch.Start();
//give it N seconds to sort itself out
int waitSeconds = 8;
while (watch.Elapsed.TotalSeconds < waitSeconds)
{
Thread.Sleep(TimeSpan.FromSeconds(0.5f));
if (getSteam() == null)
{
Debug.WriteLine("Restarting Steam");
Process.Start(steamExe);
restarted = true;
break;
}
}
if (!restarted)
{
Debug.WriteLine("Steam instance not restarted");
MessageBox.Show("Failed to restart Steam, please launch it manually", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
}
else
{
Debug.WriteLine("Steam instance not found to be restarted");
}
}
return true;
}
public static void ClearAllShortcuts()
@ -427,7 +486,7 @@ namespace UWPHook
}
catch (Exception ex)
{
MessageBox.Show("Error: Program failed while trying to clear your Steam shurtcuts:" + Environment.NewLine + ex.Message + ex.StackTrace);
MessageBox.Show("Error: Program failed while trying to clear your Steam shortcuts:" + Environment.NewLine + ex.Message + ex.StackTrace);
}
}
MessageBox.Show("All non-Steam shortcuts has been cleared.");
@ -483,6 +542,12 @@ namespace UWPHook
//Remove end lines from the String and split both values, I split the appname and the AUMID using |
//I hope no apps have that in their name. Ever.
var values = app.Replace("\r\n", "").Split('|');
if (values.Length >= 3 && AppManager.IsKnownApp(values[2], out string readableName))
{
values[0] = readableName;
}
if (!String.IsNullOrWhiteSpace(values[0]))
{
//We get the default square tile to find where the app stores it's icons, then we resolve which one is the widest
@ -492,17 +557,6 @@ namespace UWPHook
Apps.Entries.Add(new AppEntry() { Name = values[0], IconPath = logosPath, Aumid = values[2], Selected = false });
});
}
if (values.Length > 2)
{
if (values[2].Contains("Microsoft.SeaofThieves"))
{
values[0] = "Sea of Thieves";
}
else if (values[2].Contains("Microsoft.DeltaPC"))
{
values[0] = "Gears of War: Ultimate Edition";
}
}
}
}
catch (Exception ex)
@ -529,7 +583,7 @@ namespace UWPHook
public bool Contains(object o)
{
AppEntry appEntry = o as AppEntry;
return (appEntry.Aumid.ToLower().Contains(textBox.Text.ToLower()));
return (appEntry.Aumid.ToLower().Contains(textBox.Text.ToLower()) || appEntry.Name.ToLower().Contains(textBox.Text.ToLower()));
}
private void SettingsButton_Click(object sender, RoutedEventArgs e)

@ -0,0 +1,4 @@
{
"Microsoft.SeaofThieves": "Sea of Thieves",
"Microsoft.DeltaPC": "Gears of War: Ultimate Edition"
}

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@ -162,6 +162,9 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<None Include="Resources\KnownApps.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

Loading…
Cancel
Save