Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions UWPHook/AppEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ public bool Selected
}


private string _name;
private string? _name;
/// <summary>
/// Gets or sets the name of the application
/// </summary>
public string Name
public string? Name
{
get { return _name; }
set { _name = value; }
}

private string _executable;
private string? _executable;
/// <summary>
/// Gets or sets the executable of the application
/// </summary>
public string Executable
public string? Executable
{
get { return _executable; }
set { _executable = value; }
}

private string _aumid;
private string? _aumid;
/// <summary>
/// Gets or sets the aumid of the application
/// </summary>
public string Aumid
public string? Aumid
{
get { return _aumid; }
set { _aumid = value; }
Expand All @@ -58,9 +58,9 @@ public string Aumid
/// <summary>
/// Gets or sets the icon for the app
/// </summary>
private string _icon;
private string? _icon;

public string Icon
public string? Icon
{
get { return _icon; }
set { _icon = value; }
Expand All @@ -70,9 +70,9 @@ public string Icon
/// <summary>
/// Sets the path where icons for the app is
/// </summary>
private string _icon_path;
private string? _icon_path;

public string IconPath
public string? IconPath
{
get { return _icon_path; }
set { _icon_path = value; }
Expand All @@ -84,6 +84,8 @@ public string widestSquareIcon()
Size size = new Size(0, 0);
List<string> images = new List<string>();

if (_icon_path == null)
return string.Empty;

try
{
Expand All @@ -101,7 +103,7 @@ public string widestSquareIcon()
//Decide which is the largest
foreach (string image in images)
{
Image icon = null;
Image? icon = null;

//Try to load the image, if it's a invalid file, skip it
try
Expand Down Expand Up @@ -130,17 +132,17 @@ public string widestSquareIcon()

public string isKnownApp()
{
if(AppManager.IsKnownApp(_aumid, out string name))
if(_aumid != null && AppManager.IsKnownApp(_aumid, out string? name) && name != null)
{
return name;
}

return "Name not found, double click here to edit";
}

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Expand Down
55 changes: 38 additions & 17 deletions UWPHook/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static class AppManager
{
private static int runningProcessId;
private static bool isLauncherProcess;
private static string executablePath;
private static string executablePath = "";

/// <summary>
/// Launch a UWP App using a ApplicationActivationManager and sets a internal id to launched proccess id
Expand Down Expand Up @@ -136,11 +136,12 @@ public static Boolean IsRunning()
{
foreach (var process in searcher.Get())
{
string processName = Convert.ToString(process.Properties["Name"].Value);
string? processName = Convert.ToString(process.Properties["Name"].Value);
int processId = Convert.ToInt32(process.Properties["processid"].Value);
string processPath = Convert.ToString(process.Properties["ExecutablePath"].Value);
string? processPath = Convert.ToString(process.Properties["ExecutablePath"].Value);

if (String.IsNullOrWhiteSpace(processName) || result.ContainsKey(processName)) continue;
if (String.IsNullOrWhiteSpace(processName) || String.IsNullOrWhiteSpace(processPath)
|| result.ContainsKey(processName)) continue;

result.Add(processName, (processPath, processId));
}
Expand All @@ -155,14 +156,17 @@ public static Boolean IsRunning()
/// <returns>List of installed UWP Apps</returns>
public static List<String> GetInstalledApps()
{
List<String> result = null;
List<String>? result = null;
var assembly = Assembly.GetExecutingAssembly();
//Load the powershell script to get installed apps
var resourceName = "UWPHook.Resources.GetAUMIDScript.ps1";
try
{
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (Stream? stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
throw new Exception("Assembly::GetManifestResourceStream error, resourceName: " + resourceName);

using (StreamReader reader = new StreamReader(stream))
{
//Every entry is listed separated by ;
Expand All @@ -185,32 +189,49 @@ public static List<String> GetInstalledApps()
/// <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)
public static bool IsKnownApp(string? appName, out string? readableName)
{
string appsJson = GetEmbeddedResource("KnownApps.json");
var apps = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(appsJson);
if (appName == null)
{
readableName = null;
return false;
}

string? appsJson = GetEmbeddedResource("KnownApps.json");

Dictionary<string, string>? apps = null;
if (appsJson != null)
apps = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(appsJson);

foreach (var kvp in apps)
if (apps != null)
{
if (appName.StartsWith(kvp.Key + "_"))
foreach (var kvp in apps)
{
readableName = kvp.Value;
return true;
if (appName.StartsWith(kvp.Key + "_"))
{
readableName = kvp.Value;
return true;
}
}
}

readableName = null;
return false;
}

static string GetEmbeddedResource(string resourceName)
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))
using (Stream? stream = assembly.GetManifestResourceStream(resourceName))
{
return reader.ReadToEnd();
if (stream == null)
return null;

using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}

Expand Down
Loading