Skip to content

Commit

Permalink
get KnownApps.json from embedded resource to enable single file release
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Ostermann committed Dec 1, 2024
1 parent a03cdcc commit cf10c01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion UWPHook/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static List<String> GetInstalledApps()
/// <returns>Whether this is a known app</returns>
public static bool IsKnownApp(string appName, out string readableName)
{
string appsJson = File.ReadAllText(@"Resources\KnownApps.json");
string appsJson = GetEmbeddedResource("KnownApps.json");
var apps = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(appsJson);

foreach (var kvp in apps)
Expand All @@ -203,6 +203,17 @@ public static bool IsKnownApp(string appName, out string readableName)
return false;
}

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))
{
return reader.ReadToEnd();
}
}

[DllImport("user32.dll")]
private static extern
bool SetForegroundWindow(IntPtr hWnd);
Expand Down
3 changes: 3 additions & 0 deletions UWPHook/UWPHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<UseWPF>true</UseWPF>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ApplicationIcon>Resources\hook2.ico</ApplicationIcon>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit cf10c01

Please sign in to comment.