Skip to content

Commit 655f148

Browse files
committed
2 parents 009cce7 + d0b7297 commit 655f148

File tree

5 files changed

+165
-54
lines changed

5 files changed

+165
-54
lines changed

main/Classes/handleWindowsApp.cs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
using System.Linq;
55
using System.Xml;
66
using System.Collections.Generic;
7-
using System.Management.Automation;
8-
using System.Collections.ObjectModel;
7+
using Windows.Management.Deployment;
98

109
namespace client.Classes
1110
{
1211
class handleWindowsApp
1312
{
1413
public static Dictionary<string, string> fileDirectoryCache = new Dictionary<string, string>();
1514

15+
private static PackageManager pkgManger = new PackageManager();
1616
public static Image getWindowsAppIcon(String file, bool alreadyAppID = false)
1717
{
1818
// Get the app's ID from its shortcut target file (Ex. 4DF9E0F8.Netflix_mcm4njqhnhss8!Netflix.app)
1919
String microsoftAppName = (!alreadyAppID) ? GetLnkTarget(file) : file;
2020

2121
// Split the string to get the app name from the beginning (Ex. 4DF9E0F8.Netflix)
22-
String subAppName = microsoftAppName.Split('_')[0];
22+
String subAppName = microsoftAppName.Split('!')[0];
2323

2424
// Loop through each of the folders with the app name to find the one with the manifest + logos
2525
String appPath = findWindowsAppsFolder(subAppName);
@@ -33,14 +33,14 @@ public static Image getWindowsAppIcon(String file, bool alreadyAppID = false)
3333

3434
String logoLocation = (appManifest.SelectSingleNode("/sm:Package/sm:Properties/sm:Logo", appManifestNamespace).InnerText).Replace("\\", @"\");
3535

36+
37+
3638
if (logoLocation != null)
3739
{
3840
// Get the last instance or usage of \ to cut out the path of the logo just to have the path leading to the general logo folder
3941
logoLocation = logoLocation.Substring(0, logoLocation.LastIndexOf(@"\"));
4042
String logoLocationFullPath = Path.GetFullPath(appPath + "\\" + logoLocation);
4143

42-
String logoPath = "";
43-
4444
// Search for all files with 150x150 in its name and use the first result
4545
DirectoryInfo logoDirectory = new DirectoryInfo(logoLocationFullPath);
4646
FileInfo[] filesInDir = getLogoFolder("StoreLogo", logoDirectory);
@@ -106,27 +106,12 @@ public static string findWindowsAppsFolder(string subAppName)
106106
{
107107
try
108108
{
109+
IEnumerable<Windows.ApplicationModel.Package> packages = pkgManger.FindPackagesForUser("", subAppName);
109110

110-
using (PowerShell powerShell = PowerShell.Create())
111-
{
112-
powerShell.AddScript($"Get-AppxPackage -name {subAppName}");
113-
114-
Collection<PSObject> PSOutput = powerShell.Invoke();
115111

116-
117-
if (PSOutput[0] != null)
118-
{
119-
String finalPath = Environment.ExpandEnvironmentVariables("%ProgramW6432%") + $@"\WindowsApps\" + PSOutput[0] + @"\";
120-
fileDirectoryCache[subAppName] = finalPath;
121-
return finalPath;
122-
}
123-
}
124-
125-
/*
126-
foreach (string folder in Directory.GetDirectories(Environment.ExpandEnvironmentVariables("%ProgramW6432%") + $@"\WindowsApps\"))
127-
{
128-
appDirecList.Add(folder);
129-
}*/
112+
String finalPath = Environment.ExpandEnvironmentVariables("%ProgramW6432%") + $@"\WindowsApps\" + packages.First().InstalledLocation.DisplayName + @"\";
113+
fileDirectoryCache[subAppName] = finalPath;
114+
return finalPath;
130115
}
131116
catch (UnauthorizedAccessException) { };
132117
return "";
@@ -139,7 +124,7 @@ public static string findWindowsAppsFolder(string subAppName)
139124

140125
public static string findWindowsAppsName(string AppName)
141126
{
142-
String subAppName = AppName.Split('_')[0];
127+
String subAppName = AppName.Split('!')[0];
143128
String appPath = findWindowsAppsFolder(subAppName);
144129

145130

main/Forms/frmClient.Designer.cs

Lines changed: 121 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main/Forms/frmClient.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
using client.Classes;
22
using client.User_controls;
33
using System;
4-
using System.Collections.Generic;
5-
using System.ComponentModel;
64
using System.Drawing;
75
using System.IO;
8-
using System.Linq;
9-
using System.Text;
106
using System.Threading.Tasks;
117
using System.Windows.Forms;
8+
using Windows.Data.Json;
9+
using System.Net.Http;
1210

1311
namespace client.Forms
1412
{
1513
public partial class frmClient : Form
1614
{
15+
private static readonly HttpClient client = new HttpClient();
1716
public frmClient()
1817
{
1918
System.Runtime.ProfileOptimization.StartProfile("frmClient.Profile");
2019
InitializeComponent();
2120
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
2221
Reload();
22+
23+
currentVersion.Text = "v" + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
24+
25+
githubVersion.Text = Task.Run(() => getVersionData()).Result;
2326
}
2427
public void Reload()
2528
{
@@ -96,5 +99,26 @@ public void LeaveControl(object sender, EventArgs e, Control control)
9699
control.BackColor = Color.FromArgb(3, 3, 3);
97100
}
98101

102+
private static async Task<String> getVersionData()
103+
{
104+
try
105+
{
106+
HttpClient client = new HttpClient();
107+
client.DefaultRequestHeaders.Add("User-Agent", "taskbar-groups");
108+
var res = await client.GetAsync("https://api.github.com/repos/tjackenpacken/taskbar-groups/releases");
109+
res.EnsureSuccessStatusCode();
110+
string responseBody = await res.Content.ReadAsStringAsync();
111+
112+
JsonArray responseJSON = JsonArray.Parse(responseBody);
113+
JsonObject jsonObjectData = responseJSON[0].GetObject();
114+
115+
return jsonObjectData["tag_name"].GetString();
116+
} catch {return "Not found";}
117+
}
118+
119+
private void githubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
120+
{
121+
System.Diagnostics.Process.Start("https://github.com/tjackenpacken/taskbar-groups/releases");
122+
}
99123
}
100124
}

0 commit comments

Comments
 (0)