From: ttp Date: Wed, 27 Feb 2008 16:15:42 +0000 (+0000) Subject: AppliStation-GUI,パッケージのアイコン取得ルーチンにてZoneAlarm及びアーカイブインストーラ物がアイコンが表示されなかった対策 X-Git-Tag: v1.0.0~9 X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=commitdiff_plain;h=ca875e0831789124a42eccf8dab30b735e1be292;ds=inline AppliStation-GUI,パッケージのアイコン取得ルーチンにてZoneAlarm及びアーカイブインストーラ物がアイコンが表示されなかった対策 git-svn-id: http://localhost/svn/AppliStation/trunk@858 34ed2c89-c49f-4a4b-abdb-c318350108cf --- diff --git a/AppliStation/PackageUninstallConfirmForm.cs b/AppliStation/PackageUninstallConfirmForm.cs index b922f24..b38749b 100644 --- a/AppliStation/PackageUninstallConfirmForm.cs +++ b/AppliStation/PackageUninstallConfirmForm.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Drawing; using System.Windows.Forms; using NaGet.Packages; @@ -21,17 +22,39 @@ namespace AppliStation label2.Text = string.Format("{0}({1})", uninstallPackage.Name, uninstallPackage.Version); label2.Font = new Font(SystemFonts.DefaultFont.FontFamily, SystemFonts.DefaultFont.Size*1.5f); - string iconPath = uninstallPackage.UninstallInfo.IconPath; - if (!string.IsNullOrEmpty(iconPath)) { - if (iconPath.EndsWith(",0")) { - iconPath = iconPath.Substring(0, iconPath.Length-2); - } - if (System.IO.File.Exists(iconPath)) { - iconLabel.Image = Icon.ExtractAssociatedIcon(iconPath).ToBitmap(); - iconLabel.Size = iconLabel.Image.Size; + Icon icon = getIconForPackage(uninstallPackage); + if (icon != null) { + iconLabel.Image = icon.ToBitmap(); + iconLabel.Size = icon.Size; + } + } + } + + private static Icon getIconForPackage(InstalledPackage pkg) + { + string iconPath = pkg.UninstallInfo.IconPath; + if (! string.IsNullOrEmpty(iconPath)) { + if (iconPath.EndsWith(",0") || iconPath.EndsWith(",-0")) { + iconPath = iconPath.Substring(0, iconPath.LastIndexOf(',')); + } + if (File.Exists(iconPath)) { + return Icon.ExtractAssociatedIcon(iconPath); + } + } else if (pkg.Type == InstallerType.ARCHIVE) { + string progGrp = Path.Combine(NaGet.Env.ArchiveProgramGroup, pkg.Name); + if (Directory.Exists(progGrp)) { + string[] lnkFiles = Directory.GetFiles(progGrp, "*.lnk"); + + if (lnkFiles.Length >= 1) { + using (NaGet.InteropServices.ShellLink link = new NaGet.InteropServices.ShellLink(lnkFiles[0])) { + if (File.Exists(link.GetPath(0))) { + return Icon.ExtractAssociatedIcon(link.GetPath(0)); + } + } } } } + return null; } public PackageUninstallConfirmForm()