Skip to content

Commit 649936b

Browse files
committed
Smarter way of reading MSIX apps icons
1 parent c0837f1 commit 649936b

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/WinGetIconsHelper.cs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Globalization;
22
using System.Net;
3+
using System.Reflection;
34
using System.Text;
45
using System.Text.RegularExpressions;
56
using Microsoft.Management.Deployment;
@@ -117,40 +118,32 @@ internal static class WinGetIconsHelper
117118
return null;
118119
}
119120

120-
public static CacheableIcon? GetAPPXPackageIcon(IPackage package)
121+
public static CacheableIcon? GetAppxPackageIcon(IPackage package)
121122
{
122123
string appxId = package.Id.Replace("MSIX\\", "");
124+
string globalPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps", appxId);
123125

124-
string globalPath;
125-
var progsPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps", appxId);
126-
if (Directory.Exists(progsPath))
127-
{
128-
globalPath = Path.Join(progsPath, "Assets");
129-
if (!Directory.Exists(globalPath)) globalPath = Path.Join(progsPath, "Images");
130-
if (!Directory.Exists(globalPath)) globalPath = progsPath;
131-
}
132-
else
133-
{
134-
progsPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SystemApps", appxId);
135-
globalPath = Path.Join(progsPath, "Assets");
136-
if (!Directory.Exists(globalPath)) globalPath = Path.Join(progsPath, "Images");
137-
if (!Directory.Exists(globalPath)) globalPath = progsPath;
138-
}
126+
if (!Directory.Exists(globalPath))
127+
globalPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SystemApps", appxId);
139128

140129
if (!Directory.Exists(globalPath))
141130
return null;
142131

143-
string[] logoFiles = Directory.GetFiles(globalPath, "*StoreLogo*.png", SearchOption.TopDirectoryOnly);
144-
if (logoFiles.Length > 0)
145-
return new CacheableIcon(logoFiles[^1]);
146-
147-
logoFiles = Directory.GetFiles(globalPath, "*Splash*.png", SearchOption.TopDirectoryOnly);
148-
if (logoFiles.Length > 0)
149-
return new CacheableIcon(logoFiles[^1]);
132+
string content = File.ReadAllText(Path.Join(globalPath, "AppxManifest.xml"));
133+
Match? match = Regex.Match(content, "Square44x44Logo\\s*=\\s*[\"']([^\"']+)[\"']");
134+
if (!match.Success)
135+
{
136+
// There is no icon on the manifest
137+
return null;
138+
}
150139

151-
logoFiles = Directory.GetFiles(globalPath, "*.png", SearchOption.TopDirectoryOnly);
152-
if (logoFiles.Length > 0)
153-
return new CacheableIcon(logoFiles[^1]);
140+
string path = string.Join('.', Path.Join(globalPath, match.Groups[1].ToString()).Split('.')[..^1]);
141+
foreach (string ending in new[] { ".png", ".scale-100.png", ".scale-125.png", ".scale-150.png",
142+
".scale-175.png", ".scale-200.png" })
143+
if (Path.Exists(path + ending))
144+
{
145+
return new CacheableIcon(path + ending);
146+
}
154147

155148
return null;
156149
}

src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgDetailsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
2828
if (package.Source is LocalWinGetSource localSource)
2929
{
3030
if(localSource.Type is LocalWinGetSource.Type_t.MicrosftStore)
31-
return WinGetIconsHelper.GetAPPXPackageIcon(package);
31+
return WinGetIconsHelper.GetAppxPackageIcon(package);
3232

3333
else if (localSource.Type is LocalWinGetSource.Type_t.LocalPC)
3434
return WinGetIconsHelper.GetARPPackageIcon(package);

0 commit comments

Comments
 (0)