OSDN Git Service

AppliAppliStation-GUI,検索バーの更新(Deleteキーとか押した時など)がうまくいかないバグ対策
[applistation/AppliStation.git] / AppliStation / PackageUninstallConfirmForm.cs
1 using System;\r
2 using System.IO;\r
3 using System.Drawing;\r
4 using System.Windows.Forms;\r
5 using NaGet.Packages;\r
6 using NaGet.Packages.Install;\r
7 \r
8 namespace AppliStation\r
9 {\r
10         /// <summary>\r
11         /// Description of PackageUninstallConfirmForm.\r
12         /// </summary>\r
13         public partial class PackageUninstallConfirmForm : Form\r
14         {\r
15                 private InstalledPackage uninstallPackage;\r
16                 \r
17                 public InstalledPackage UninstallPackage {\r
18                         get { return uninstallPackage; }\r
19                         set {\r
20                                 uninstallPackage = value;\r
21                                 \r
22                                 label2.Text = string.Format("{0}({1})", uninstallPackage.Name, uninstallPackage.Version);\r
23                                 label2.Font = new Font(SystemFonts.DefaultFont.FontFamily, SystemFonts.DefaultFont.Size*1.5f);\r
24                                 \r
25                                 Icon icon = getIconForPackage(uninstallPackage);\r
26                                 if (icon != null) {\r
27                                         iconLabel.Image = icon.ToBitmap();\r
28                                         iconLabel.Size = icon.Size;\r
29                                 }\r
30                         }\r
31                 }\r
32                 \r
33                 private static Icon getIconForPackage(InstalledPackage pkg)\r
34                 {\r
35                         string iconPath = pkg.UninstallInfo.IconPath;\r
36                         if (! string.IsNullOrEmpty(iconPath)) {\r
37                                 if (iconPath.EndsWith(",0") || iconPath.EndsWith(",-0")) {\r
38                                         iconPath = iconPath.Substring(0, iconPath.LastIndexOf(','));\r
39                                 }\r
40                                 if (File.Exists(iconPath)) {\r
41                                         return Icon.ExtractAssociatedIcon(iconPath);\r
42                                 }\r
43                         } else if (pkg.Type == InstallerType.ARCHIVE) {\r
44                                 string progGrp = Path.Combine(NaGet.Env.ArchiveProgramGroup, pkg.Name);\r
45                                 if (Directory.Exists(progGrp)) {\r
46                                         string[] lnkFiles = Directory.GetFiles(progGrp, "*.lnk");\r
47                                         \r
48                                         if (lnkFiles.Length >= 1) {\r
49                                                 using (NaGet.InteropServices.ShellLink link = new NaGet.InteropServices.ShellLink(lnkFiles[0])) {\r
50                                                         if (File.Exists(link.GetPath(0))) {\r
51                                                                 return Icon.ExtractAssociatedIcon(link.GetPath(0));\r
52                                                         }\r
53                                                 }\r
54                                         }\r
55                                 }\r
56                         }\r
57                         return null;\r
58                 }\r
59                 \r
60                 public PackageUninstallConfirmForm()\r
61                 {\r
62                         //\r
63                         // The InitializeComponent() call is required for Windows Forms designer support.\r
64                         //\r
65                         InitializeComponent();\r
66                         \r
67                         // \8aÇ\97\9d\8eÒ\8c \8cÀ\82Å\93®\82¢\82Ä\82¢\82é\82È\82ç\82Îrunas\82ª\95K\97v\82É\82Í\82È\82ç\82È\82¢\82Ì\82Å\95\\8e¦\82µ\82È\82¢\r
68                         if (NaGet.Utils.IsAdministrators()) {\r
69                                 runasCheckBox.Checked = false;\r
70                                 runasCheckBox.Visible = false;\r
71                         }\r
72                 }\r
73                 \r
74                 #region runas\8aÖ\98A\r
75                 \r
76                 /// <summary>\r
77                 /// runas\82Å\8eÀ\8ds\82·\82é\82©\94Û\82©\r
78                 /// </summary>\r
79                 public bool UseRunas {\r
80                         set {\r
81                                 runasCheckBox.Checked = (! NaGet.Utils.IsAdministrators()) && value;\r
82                                 \r
83                                 updateUseRunas();\r
84                         }\r
85                         get {\r
86                                 return runasCheckBox.Checked;\r
87                         }\r
88                 }\r
89                 \r
90                 /// <summary>\r
91                 /// \91I\91ð\82³\82ê\82½\83p\83b\83P\81[\83W\82ð\92²\8d¸\82µ\82Ä\81ARunas\82ð\8eg\82¤\82×\82«\82©\82¢\82È\82©\82ð\95Ô\82·\r
92                 /// </summary>\r
93                 public bool GetShouldUseRunas()\r
94                 {\r
95                         if (NaGet.Utils.IsAdministrators()) {\r
96                                 // \8aÇ\97\9d\8eÒ\8c \8cÀ\82Å\93®\82¢\82Ä\82¢\82é\8fê\8d\87\82Í\95s\97v\r
97                                 return false;   \r
98                         }\r
99                         \r
100                         return (uninstallPackage.Type != InstallerType.ARCHIVE);\r
101                 }\r
102                 \r
103                 void RunasCheckBoxCheckedChanged(object sender, EventArgs e)\r
104                 {\r
105                         updateUseRunas();\r
106                 }\r
107                 \r
108                 private void updateUseRunas()\r
109                 {\r
110                         if (UseRunas) {\r
111                                 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackagesInstallConfirmForm));\r
112                                 okButton.Image = ((System.Drawing.Bitmap)(resources.GetObject("okButton.Image")));\r
113                         } else {\r
114                                 okButton.Image = null;\r
115                         }\r
116                 }\r
117                 \r
118                 #endregion\r
119 \r
120         }\r
121 }\r