OSDN Git Service

na-get-lib,r925に伴うシリアル化可能に関する変更及び、InstalledPackageの外部からの参照をpropertyに変更
[applistation/AppliStation.git] / AppliStation / PackagesInstallConfirmForm.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Windows.Forms;\r
4 using NaGet.Packages;\r
5 using NaGet.Packages.Install;\r
6 \r
7 namespace AppliStation\r
8 {\r
9         /// <summary>\r
10         /// Description of PackagesInstallConfirmForm.\r
11         /// </summary>\r
12         public partial class PackagesInstallConfirmForm : Form\r
13         {\r
14                 private Installation[] installations;\r
15                 \r
16                 private PackageListsManager pkgListMan;\r
17                 \r
18                 /// <summary>\r
19                 /// \83p\83b\83P\81[\83W\83C\83\93\83X\83g\81[\83\8b\8f\88\97\9d\82Ì\8fW\8d\87\r
20                 /// </summary>\r
21                 public Installation[] Installations {\r
22                         get { return installations; }\r
23                         set {\r
24                                 installations = value;\r
25                                 \r
26                                 updatePackagesListView();\r
27                         }\r
28                 }\r
29                 \r
30                 public PackageListsManager PkgListsManager {\r
31                         get { return pkgListMan; }\r
32                         set {\r
33                                 pkgListMan = value;\r
34                                 \r
35                                 updatePackagesListView();\r
36                         }\r
37                 }\r
38                 \r
39                 public PackagesInstallConfirmForm()\r
40                 {\r
41                         //\r
42                         // The InitializeComponent() call is required for Windows Forms designer support.\r
43                         //\r
44                         InitializeComponent();\r
45                         \r
46                         // \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
47                         if (NaGet.Utils.IsAdministrators()) {\r
48                                 runasCheckBox.Checked = false;\r
49                                 runasCheckBox.Visible = false;\r
50                         }\r
51                 }\r
52                 \r
53                 private void updatePackagesListView()\r
54                 {\r
55                         packageListView.Items.Clear();\r
56                         \r
57                         if (installations != null) {\r
58                                 foreach (Installation inst in installations) {\r
59                                         Package pkg = inst.InstalledPackage;\r
60                                         \r
61                                         Package curPkg = null;\r
62                                         if (pkgListMan != null) {       \r
63                                                 curPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name);\r
64                                                 if (curPkg == null) curPkg = pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
65                                         }\r
66                                         string curVersion = (curPkg == null)? "-" : curPkg.Version;\r
67                                         \r
68                                         ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, curVersion});\r
69                                         item.Tag = inst;\r
70                                         item.ToolTipText = pkg.Summary;\r
71                                         item.Checked = true;\r
72                                         \r
73                                         packageListView.Items.Add(item);\r
74                                 }\r
75                         }\r
76                         \r
77                         PackageListViewItemChecked(packageListView, null);\r
78                         packageListView.Refresh();\r
79                 }\r
80                 \r
81                 void PackageListViewItemChecked(object sender, ItemCheckedEventArgs e)\r
82                 {\r
83                         System.Windows.Forms.ListView.CheckedListViewItemCollection checkeds = packageListView.CheckedItems;\r
84                         \r
85                         okButton.Enabled = checkeds != null && checkeds.Count > 0;\r
86                 }\r
87                 \r
88                 AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer;\r
89 \r
90                 void PackageListViewColumnClick(object sender, ColumnClickEventArgs e)\r
91                 {\r
92                         SortOrder order = SortOrder.None;\r
93                         \r
94                         if (packageListViewSortComparer == null) {\r
95                                 order = SortOrder.Ascending;\r
96                                 packageListViewSortComparer = new AppliStation.Util.ListViewItemSortComparer(e.Column, order);\r
97                                 packageListView.ListViewItemSorter = packageListViewSortComparer;\r
98                         } else {\r
99                                 if (packageListViewSortComparer.Column == e.Column) {\r
100                                         order = (packageListViewSortComparer.Order == SortOrder.Ascending)? SortOrder.Descending : SortOrder.Ascending;\r
101                                         \r
102                                         packageListViewSortComparer.Order = order;\r
103                                 } else {\r
104                                         order = packageListViewSortComparer.Order;\r
105                                         packageListViewSortComparer.Column = e.Column;\r
106                                 }\r
107                                 \r
108                                 packageListView.Sort();\r
109                         }\r
110                         AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, e.Column, order);\r
111                         \r
112                         // \83\\81[\83g\91Î\8fÛ\97ñ\82Ì\90F\95t\82¯\r
113                         try {\r
114                                 // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
115                                 AppliStation.Util.NativeMethods.SendMessage(packageListView.Handle, 0x1000+140, (uint) e.Column, 0);\r
116                         } catch (Exception) {   \r
117                         }\r
118                 }\r
119                 \r
120                                 \r
121                 void PackageListViewContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
122                 {\r
123                         System.Windows.Forms.ListView.CheckedIndexCollection coll = packageListView.CheckedIndices;\r
124                         selectAllPackagesStripMenuItem.Enabled = coll.Count < packageListView.Items.Count;\r
125                         unselectAllPackagesStripMenuItem.Enabled = coll.Count > 0;\r
126                 }\r
127                                 \r
128                 void SelectAllPackagesStripMenuItemClick(object sender, EventArgs e)\r
129                 {\r
130                         foreach (ListViewItem item in packageListView.Items) {\r
131                                 item.Checked = true;\r
132                         }\r
133                         packageListView.Refresh();\r
134                 }\r
135                 \r
136                 void UnselectAllPackagesStripMenuItemClick(object sender, EventArgs e)\r
137                 {\r
138                         foreach (ListViewItem item in packageListView.CheckedItems) {\r
139                                 item.Checked = false;\r
140                         }\r
141                         packageListView.Refresh();\r
142                 }\r
143                 \r
144                 /// <summary>\r
145                 /// \83C\83\93\83X\83g\81[\83\8b\82·\82é\82æ\82¤\91I\91ð\82³\82ê\82½\83p\83b\83P\81[\83W\82Ì\94z\97ñ\r
146                 /// </summary>\r
147                 public Installation[] CheckedInstallations {\r
148                         get {\r
149                                 System.Collections.Generic.List<Installation> insts = new System.Collections.Generic.List<Installation>();\r
150                                 foreach (ListViewItem item in packageListView.CheckedItems) {\r
151                                         insts.Add((Installation) item.Tag);\r
152                                 }\r
153                                 return insts.ToArray();\r
154                         }\r
155                 }\r
156                 \r
157                 #region runas\8aÖ\98A\r
158                 \r
159                 /// <summary>\r
160                 /// runas\82Å\8eÀ\8ds\82·\82é\82©\94Û\82©\r
161                 /// </summary>\r
162                 public bool UseRunas {\r
163                         set {\r
164                                 runasCheckBox.Checked = (! NaGet.Utils.IsAdministrators()) && value;\r
165                                 \r
166                                 updateUseRunas();\r
167                         }\r
168                         get {\r
169                                 return runasCheckBox.Checked;\r
170                         }\r
171                 }\r
172                 \r
173                 /// <summary>\r
174                 /// \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
175                 /// </summary>\r
176                 public bool GetShouldUseRunas()\r
177                 {\r
178                         if (NaGet.Utils.IsAdministrators()) {\r
179                                 // \8aÇ\97\9d\8eÒ\8c \8cÀ\82Å\93®\82¢\82Ä\82¢\82é\8fê\8d\87\82Í\95s\97v\r
180                                 return false;   \r
181                         } else if (NaGet.Utils.IsUACEnabled()) {\r
182                                 // UAC\82ª\93K\97p\82³\82ê\82Ä\82¢\82é\8fê\8d\87\82Í\95W\8f\80\82Å\82Í\95s\97v\82Æ\82·\82é\r
183                                 return false;   \r
184                         }\r
185                         \r
186                         // \82Ð\82Æ\82Â\82Å\82àPC\83^\81[\83Q\83b\83g\82È\83C\83\93\83X\83g\81[\83\89\82ª\82 \82ê\82Î\95K\97v\82Æ\82·\82é\r
187                         foreach (Installation inst in CheckedInstallations) {\r
188                                 if (inst.TargetPC) return true;\r
189                         }\r
190                         // \82»\82ê\88È\8aO\82Í\95s\97v\r
191                         return false;\r
192                 }\r
193                 \r
194                 void RunasCheckBoxCheckedChanged(object sender, EventArgs e)\r
195                 {\r
196                         updateUseRunas();\r
197                 }\r
198                 \r
199                 private void updateUseRunas()\r
200                 {\r
201                         if (UseRunas) {\r
202                                 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackagesInstallConfirmForm));\r
203                                 okButton.Image = ((System.Drawing.Bitmap)(resources.GetObject("okButton.Image")));\r
204                         } else {\r
205                                 okButton.Image = null;\r
206                         }\r
207                 }\r
208                 \r
209                 #endregion\r
210 \r
211 \r
212         }\r
213 }\r