OSDN Git Service

AppliStation-GUI,インストール処理中のキャンセルでウィンドウが閉じてしまう不具合(1.0リリース以後のいつ混入したんだろう)の修正
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / PackageUtils.cs
1 using System;\r
2 using System.IO;\r
3 using System.Drawing;\r
4 using NaGet.Packages;\r
5 using NaGet.Packages.Install;\r
6 \r
7 namespace AppliStation.Util\r
8 {\r
9         public sealed class PackageUtils\r
10         {\r
11                 \r
12                 public static Icon GetIconForPackage(InstalledPackage pkg)\r
13                 {\r
14                         string iconPath = pkg.UninstallInfo.IconPath;\r
15                         if (! string.IsNullOrEmpty(iconPath)) {\r
16                                 if (iconPath.EndsWith(",0") || iconPath.EndsWith(",-0")) {\r
17                                         iconPath = iconPath.Substring(0, iconPath.LastIndexOf(','));\r
18                                 }\r
19                                 if (File.Exists(iconPath)) {\r
20                                         return Icon.ExtractAssociatedIcon(iconPath);\r
21                                 }\r
22                         } else if (pkg.Type == InstallerType.ARCHIVE) {\r
23                                 string progGrp = Path.Combine(NaGet.Env.ArchiveProgramGroup, pkg.Name);\r
24                                 if (Directory.Exists(progGrp)) {\r
25                                         string[] lnkFiles = Directory.GetFiles(progGrp, "*.lnk");\r
26                                         \r
27                                         if (lnkFiles.Length >= 1) {\r
28                                                 using (NaGet.InteropServices.ShellLink link = new NaGet.InteropServices.ShellLink(lnkFiles[0])) {\r
29                                                         if (File.Exists(link.GetPath(0))) {\r
30                                                                 return Icon.ExtractAssociatedIcon(link.GetPath(0));\r
31                                                         }\r
32                                                 }\r
33                                         }\r
34                                 }\r
35                         }\r
36                         return null;\r
37                 }\r
38                 \r
39         }\r
40 }\r