|
1 | 1 | using System.Globalization;
|
2 | 2 | using System.Net;
|
| 3 | +using System.Reflection; |
3 | 4 | using System.Text;
|
4 | 5 | using System.Text.RegularExpressions;
|
5 | 6 | using Microsoft.Management.Deployment;
|
@@ -117,40 +118,32 @@ internal static class WinGetIconsHelper
|
117 | 118 | return null;
|
118 | 119 | }
|
119 | 120 |
|
120 |
| - public static CacheableIcon? GetAPPXPackageIcon(IPackage package) |
| 121 | + public static CacheableIcon? GetAppxPackageIcon(IPackage package) |
121 | 122 | {
|
122 | 123 | string appxId = package.Id.Replace("MSIX\\", "");
|
| 124 | + string globalPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps", appxId); |
123 | 125 |
|
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); |
139 | 128 |
|
140 | 129 | if (!Directory.Exists(globalPath))
|
141 | 130 | return null;
|
142 | 131 |
|
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 | + } |
150 | 139 |
|
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 | + } |
154 | 147 |
|
155 | 148 | return null;
|
156 | 149 | }
|
|
0 commit comments