OSDN Git Service

AppliStation-GUI,インスコ・アンインスコ時かつ「管理者として実行時」に親フレームの表示がフリーズする問題を修正
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.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 using System.IO;\r
7 using System.Collections.Generic;\r
8 \r
9 namespace AppliStation\r
10 {\r
11         /// <summary>\r
12         /// Description of PackageListViewForm.\r
13         /// </summary>\r
14         public partial class PackageListViewForm : Form\r
15         {\r
16                 protected PackageListsManager pkgListsMan = null;\r
17                 \r
18                 public PackageListViewForm()\r
19                 {\r
20                         //\r
21                         // The InitializeComponent() call is required for Windows Forms designer support.\r
22                         //\r
23                         InitializeComponent();\r
24                         \r
25                         installToolStripMenuItem.Font = new Font(installToolStripMenuItem.Font, FontStyle.Bold);\r
26                         uninstallToolStripMenuItem.Font = new Font(uninstallToolStripMenuItem.Font, FontStyle.Bold);\r
27                         \r
28                         pkgListsMan = new PackageListsManager();\r
29                         \r
30                         this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
31                 }\r
32                 \r
33                 void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
34                 {\r
35                         bool installBtnEnabled = false;\r
36                         bool uninstallBtnEnabled = false;\r
37                         \r
38                         detailBox.Clear();\r
39                         foreach (ListViewItem item in packageListView.SelectedItems) {\r
40                                 Package pkg = (Package) item.Tag;\r
41                                 \r
42                                 bool isInstalledPackage = pkg is InstalledPackage;\r
43                                 uninstallBtnEnabled = isInstalledPackage;\r
44                                 installBtnEnabled = ! isInstalledPackage;\r
45                                 \r
46                                 detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
47                                 detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
48                                 if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
49                                         detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
50                                         detailBox.SelectedText += string.Format("\83^\83O: {0}\r\n", pkg.Tags);\r
51                                 }\r
52                                 if (isInstalledPackage) {\r
53                                         InstalledPackage iPkg = (InstalledPackage) pkg;\r
54                                         System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
55                                         if (iPkg.UninstallInfo.InstallDate != null) {\r
56                                                 sb.AppendFormat("\83C\83\93\83X\83g\81[\83\8b\82µ\82½\93ú: {0:d}  ", iPkg.UninstallInfo.InstallDate.Value);\r
57                                         }\r
58                                         if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
59                                                 sb.AppendFormat("\83T\83C\83Y: {0}  ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
60                                         }\r
61                                         \r
62                                         if (sb.Length > 0) {\r
63                                                 detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
64                                                 detailBox.SelectedText += sb.ToString();\r
65                                                 detailBox.SelectedText += "\r\n";\r
66                                         }\r
67                                 }\r
68                                 detailBox.SelectionFont = detailBox.Font;\r
69                                 if (pkg.Url != null && pkg.Url.Href != null) {\r
70                                         detailBox.SelectedText += "\8cö\8e®\83T\83C\83g: " + pkg.Url.Href + "\r\n";\r
71                                 }\r
72                                 detailBox.SelectedText += pkg.Summary;\r
73                                 \r
74                                 break;\r
75                         }\r
76                         \r
77                         uninstallToolStripButton.Visible = uninstallBtnEnabled;\r
78                         installToolStripButton.Visible = installBtnEnabled;\r
79                         packageCommandsToolStripSeparator.Visible = uninstallBtnEnabled || installBtnEnabled;\r
80                         \r
81                         if (packageListView.SelectedItems.Count <= 0) {\r
82                                 detailBox.SelectionFont = detailBox.Font;\r
83                                 int count = packageListView.Items.Count;\r
84                                 detailBox.Text = (count > 0) ? string.Format("{0}\8cÂ\82Ì\83\\83t\83g\82ª\82 \82è\82Ü\82·\81B", count)\r
85                                         : "\8aY\93\96\82·\82é\83\\83t\83g\82ª\82 \82è\82Ü\82¹\82ñ\81B";\r
86                         }\r
87                         \r
88                         detailBox.SelectionStart = 0;\r
89                         detailBox.ScrollToCaret();\r
90                 }\r
91 \r
92                 void PackageListViewItemActivate(object sender, EventArgs e)\r
93                 {\r
94                         if (packageListView.SelectedItems.Count <= 0) {\r
95                                 return; // exit \r
96                         }\r
97                         \r
98                         foreach (ListViewItem item in packageListView.SelectedItems) {\r
99                                 Package pkg = (Package) item.Tag;\r
100                                 \r
101                                 if (pkg is InstalledPackage) {\r
102                                         UninstallToolStripButtonClick(sender, e);\r
103                                 } else {\r
104                                         InstallToolStripButtonClick(sender, e);\r
105                                 }\r
106                                 \r
107                                 break;\r
108                         }\r
109                 }\r
110                 \r
111                 AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer;\r
112 \r
113                 void PackageListViewColumnClick(object sender, ColumnClickEventArgs e)\r
114                 {\r
115                         SortOrder order = SortOrder.None;\r
116                         \r
117                         if (packageListViewSortComparer == null) {\r
118                                 order = SortOrder.Ascending;\r
119                                 packageListViewSortComparer = new AppliStation.Util.ListViewItemSortComparer(e.Column, order);\r
120                                 packageListView.ListViewItemSorter = packageListViewSortComparer;\r
121                         } else {\r
122                                 if (packageListViewSortComparer.Column == e.Column) {\r
123                                         order = (packageListViewSortComparer.Order == SortOrder.Ascending)? SortOrder.Descending : SortOrder.Ascending;\r
124                                         \r
125                                         packageListViewSortComparer.Order = order;\r
126                                 } else {\r
127                                         order = packageListViewSortComparer.Order;\r
128                                         packageListViewSortComparer.Column = e.Column;\r
129                                 }\r
130                                 \r
131                                 packageListView.Sort();\r
132                         }\r
133                         AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, e.Column, order);\r
134                         \r
135                         // \83\\81[\83g\91Î\8fÛ\97ñ\82Ì\90F\95t\82¯\r
136                         try {\r
137                                 // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
138                                 AppliStation.Util.NativeMethods.SendMessage(packageListView.Handle, 0x1000+140, (uint) e.Column, 0);\r
139                         } catch (Exception) {   \r
140                         }\r
141                 }\r
142                 \r
143                 void Form_OnLoad(object sender, EventArgs e)\r
144                 {\r
145                         System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackageListViewForm));\r
146                         ImageList imageList = new ImageList();\r
147                         imageList.Images.Add("installed", this.Icon);\r
148                         imageList.Images.Add("sys", (Icon)(resources.GetObject("sysinstalled.Icon")));\r
149                         packageListView.SmallImageList = imageList;\r
150                         \r
151                         updatePackageFilterToolStripMenuItemCheckState();\r
152                         installedASPackageFilterToolStripMenuItem.Image = this.Icon.ToBitmap();\r
153                         installedSysPackageFilterToolStripMenuItem.Image = ((Icon)(resources.GetObject("sysinstalled.Icon"))).ToBitmap();\r
154                 }\r
155                 \r
156                 #region PackageFilter\8aÖ\98A\r
157                 \r
158                 private enum PackageFilterIndex : int\r
159                 {\r
160                         All = 0,\r
161                         NotInstalled = 1,\r
162                         InstalledAS = 2,\r
163                         InstalledSys = 3,\r
164                 }\r
165                 \r
166                 private PackageFilterIndex currentPackageFilter = PackageFilterIndex.All;\r
167                 \r
168                 private PackageFilterIndex CurrentPackageFilter {\r
169                         get {\r
170                                 return currentPackageFilter;\r
171                         }\r
172                         set {\r
173                                 currentPackageFilter = value;\r
174                                 \r
175                                 updatePackageFilterToolStripMenuItemCheckState();\r
176                         }\r
177                 }\r
178                 \r
179                 private void updatePackageFilterToolStripMenuItemCheckState()\r
180                 {\r
181                         ToolStripMenuItem selected = getCheckedPackageFilterToolStripItem();\r
182                         \r
183                         foreach (ToolStripMenuItem item in packageFilterToolStripDropDownButton.DropDown.Items) {\r
184                                 item.Checked = selected == item;\r
185                         }\r
186                         \r
187                         packageFilterToolStripDropDownButton.Text = selected.Text;\r
188                         packageFilterToolStripDropDownButton.Image = selected.Image;\r
189                         packageFilterToolStripDropDownButton.ToolTipText = selected.ToolTipText;\r
190                 }\r
191                 \r
192                 private ToolStripMenuItem getCheckedPackageFilterToolStripItem()\r
193                 {\r
194                         switch (currentPackageFilter) {\r
195                                 case PackageFilterIndex.NotInstalled:\r
196                                         return notInstalledPackageFilterToolStripMenuItem;\r
197                                 case PackageFilterIndex.InstalledAS:\r
198                                         return installedASPackageFilterToolStripMenuItem;\r
199                                 case PackageFilterIndex.InstalledSys:\r
200                                         return installedSysPackageFilterToolStripMenuItem;\r
201                                 default:\r
202                                         return allPackageFilterToolStripMenuItem;\r
203                         }\r
204                 }\r
205                 \r
206                 void AnyPackageFilterToolStripMenuItemClicked(object sender, EventArgs e)\r
207                 {\r
208                         if (sender == notInstalledPackageFilterToolStripMenuItem) {\r
209                                 currentPackageFilter = PackageFilterIndex.NotInstalled;\r
210                         } else if (sender == installedASPackageFilterToolStripMenuItem) {\r
211                                 currentPackageFilter = PackageFilterIndex.InstalledAS;\r
212                         } else if (sender == installedSysPackageFilterToolStripMenuItem) {\r
213                                 currentPackageFilter = PackageFilterIndex.InstalledSys;\r
214                         } else {\r
215                                 currentPackageFilter = PackageFilterIndex.All;\r
216                         }\r
217                         \r
218                         updatePackageFilterToolStripMenuItemCheckState();\r
219                         searchTextBox.FireTextChangedTrigger();\r
220                         PackageListViewUpdate();\r
221                 }\r
222                 \r
223                 #endregion\r
224                 \r
225                 void PackageListViewUpdate()\r
226                 {\r
227                         this.packageListView.Items.Clear();\r
228                         \r
229                         if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
230                                 foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) {\r
231                                         if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // \83C\83\93\83X\83g\81[\83\8b\89Â\94\\r
232                                                 if (currentPackageFilter == PackageFilterIndex.NotInstalled &&\r
233                                                     (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) != null||\r
234                                                      pkgListsMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) != null) ) {\r
235                                                         continue; // \83C\83\93\83X\83g\81[\83\8b\8dÏ\82Ý\82Í\8e\9f\82Ì\83\8b\81[\83v\82Ö(\96¢\83C\83\93\83X\83g\81[\83\8b\83\\83t\83g\92\8a\8fo\8e\9e)\r
236                                                 }\r
237                                                 \r
238                                                 ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
239                                                 item.Tag = pkg;\r
240                                                 item.ToolTipText = pkg.Summary;\r
241                 \r
242                                                 this.packageListView.Items.Add(item);\r
243                                         }\r
244                                 }\r
245                         }\r
246                         \r
247                         if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledAS) {\r
248                                 foreach (Package pkg in pkgListsMan.InstalledPkgList.Search(searchTextBox.Text)) {\r
249                                         ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
250                                         item.Tag = pkg;\r
251                                         item.ToolTipText = pkg.Summary;\r
252                                         item.ImageKey = "installed";\r
253         \r
254                                         this.packageListView.Items.Add(item);\r
255                                 }\r
256                         }\r
257                         \r
258                         if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledSys) {\r
259                                 foreach (Package pkg in pkgListsMan.SystemInstalledPkgList.Search(searchTextBox.Text)) {\r
260                                         ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
261                                         item.Tag = pkg;\r
262                                         item.ToolTipText = pkg.Summary;\r
263                                         item.ImageKey = "sys";\r
264         \r
265                                         this.packageListView.Items.Add(item);\r
266                                 }\r
267                         }\r
268                         \r
269                         PackageListViewSelectedIndexChanged(packageListView, null);\r
270                         detailBox.Refresh();\r
271                         \r
272                         //this.packageListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);\r
273                 }\r
274                 \r
275                 void PackageDetailBoxLinkClicked(object sender, LinkClickedEventArgs e)\r
276                 {\r
277                         System.Diagnostics.Process.Start(e.LinkText);\r
278                 }\r
279                 \r
280                 internal void updateActionInvoke(bool downloadPackageListsFlag)\r
281                 {\r
282                         AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
283                         prog.Shown += delegate(object sender2, EventArgs e2) {\r
284                                 NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListsMan, downloadPackageListsFlag);\r
285                                 tasks.Downloader = prog.Downloader;\r
286                                 prog.SetTaskSet(tasks);\r
287                                 prog.Refresh();\r
288                                 prog.StartTaskSet();\r
289                         };\r
290                         prog.Text = "\83\8a\83X\83g\82Ì\8dX\90V";\r
291                         prog.ShowDialog(this);\r
292                 }\r
293                         \r
294                 void UpdateToolStripButtonClick(object sender, EventArgs e)\r
295                 {\r
296                         updateActionInvoke(true);\r
297                         \r
298                         UpdatePackageList();\r
299                 }\r
300                 \r
301                 void LocalupdateToolStripMenuItemClick(object sender, EventArgs e)\r
302                 {\r
303                         updateActionInvoke(false);\r
304                         \r
305                         UpdatePackageList();\r
306                 }\r
307                 \r
308                 #region searchTextBox\82Ü\82í\82è\r
309                 \r
310                 void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e)\r
311                 {\r
312                         switch (e.KeyChar) {\r
313                                 case (char)Keys.Enter:\r
314                                         searchTextBox.FireTextChangedTrigger();\r
315                                         break;\r
316                                 case (char)Keys.Escape:\r
317                                         searchTextBox.Text = string.Empty;\r
318                                         break;\r
319                         }\r
320                 }\r
321                 \r
322                 void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e)\r
323                 {\r
324                         PackageListViewUpdate();\r
325                 }\r
326                 \r
327                 #endregion\r
328                 \r
329                 internal void installActionInvoke(Package[] pkgs)\r
330                 {\r
331                         AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
332                         prog.Shown += delegate(object sender2, EventArgs e2) {\r
333                                 NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListsMan, pkgs);\r
334                                 tasks.Downloader = prog.Downloader;\r
335                                 prog.SetTaskSet(tasks);\r
336                                 prog.Refresh();\r
337                                 prog.StartTaskSet();\r
338                         };\r
339                         prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83C\83\93\83X\83g\81[\83\8b");\r
340                         prog.ShowDialog(this);\r
341                 }\r
342                 \r
343                 void InstallToolStripButtonClick(object sender, EventArgs e)\r
344                 {\r
345                         PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
346                         confirm.PkgListsManager = pkgListsMan;\r
347                         confirm.Packages = SelectedPackages<Package>();\r
348                         confirm.UseRunas = confirm.GetShouldUseRunas();\r
349                         DialogResult result = confirm.ShowDialog(this);\r
350                         \r
351                         if (result == DialogResult.OK) {\r
352                                 Package[] instPkgs = confirm.CheckedPackages;\r
353                                 \r
354                                 if (confirm.UseRunas) {\r
355                                         installRunasActionInvoke(instPkgs);\r
356                                 } else {\r
357                                         installActionInvoke(instPkgs);\r
358                                 }\r
359                                 \r
360                                 UpdatePackageList();\r
361                         }\r
362                 }\r
363                 \r
364                 public void installRunasActionInvoke(Package[] pkgs)\r
365                 {\r
366                         this.Enabled = false;\r
367                         \r
368                         string tmpfileName = System.IO.Path.GetTempFileName();\r
369                         try {\r
370                                 NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
371                                 \r
372                                 System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();\r
373                                 procInfo.FileName = Application.ExecutablePath;\r
374                                 procInfo.Arguments = string.Format("--noupdate --cmd=install \"--pkgsref={0}\"", tmpfileName);\r
375                                 procInfo.Verb = "runas";\r
376                                 procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
377                                 \r
378                                 System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
379                                 hProc.EnableRaisingEvents = true;\r
380                                 hProc.SynchronizingObject = this;\r
381                                 hProc.Exited += delegate(object sender, EventArgs e) {\r
382                                         pkgListsMan.LoadPackageLists();\r
383                                         \r
384                                         this.Enabled = true;\r
385                                         this.BringToFront();\r
386                                         \r
387                                         if (File.Exists(tmpfileName)) {\r
388                                                 File.Delete(tmpfileName);\r
389                                         }\r
390                                 };\r
391                         } catch (System.ComponentModel.Win32Exception ex) {\r
392                                 MessageBox.Show(ex.Message, "\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
393                                 \r
394                                 if (File.Exists(tmpfileName)) {\r
395                                         File.Delete(tmpfileName);\r
396                                 }\r
397                                 this.Enabled = true;\r
398                         }\r
399                 }\r
400                 \r
401                 internal void uninstallActionInvoke(InstalledPackage[] pkgs)\r
402                 {\r
403                         AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
404                         prog.Shown += delegate(object sender2, EventArgs e2) {\r
405                                 NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListsMan, pkgs);\r
406                                 prog.SetTaskSet(tasks);\r
407                                 prog.Refresh();\r
408                                 prog.StartTaskSet();\r
409                         };\r
410                         prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83A\83\93\83C\83\93\83X\83g\81[\83\8b");\r
411                         prog.ShowDialog(this);\r
412                 }\r
413                 \r
414                 internal void uninstallRunasActionInvoke(InstalledPackage[] pkgs)\r
415                 {\r
416                         this.Enabled = false;\r
417                         \r
418                         string tmpfileName = System.IO.Path.GetTempFileName();\r
419                         try {\r
420                                 NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
421                                 \r
422                                 System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();\r
423                                 procInfo.FileName = Application.ExecutablePath;\r
424                                 procInfo.Arguments = string.Format("--noupdate --cmd=uninstall \"--pkgsref={0}\"", tmpfileName);\r
425                                 procInfo.Verb = "runas";\r
426                                 procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
427                                 \r
428                                 System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
429                                 hProc.EnableRaisingEvents = true;\r
430                                 hProc.SynchronizingObject = this;\r
431                                 hProc.Exited += delegate(object sender, EventArgs e) {\r
432                                         pkgListsMan.LoadPackageLists();\r
433                                         \r
434                                         this.Enabled = true;\r
435                                         this.BringToFront();\r
436                                         \r
437                                         if (File.Exists(tmpfileName)) {\r
438                                                 File.Delete(tmpfileName);\r
439                                         }\r
440                                 };\r
441                         } catch (System.ComponentModel.Win32Exception ex) {\r
442                                 MessageBox.Show(ex.Message, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
443                                 \r
444                                 if (File.Exists(tmpfileName)) {\r
445                                         File.Delete(tmpfileName);\r
446                                 }\r
447                                 this.Enabled = true;\r
448                         }\r
449                 }\r
450                 \r
451                 void UninstallToolStripButtonClick(object sender, EventArgs e)\r
452                 {\r
453                         PackageUninstallConfirmForm confirm = new PackageUninstallConfirmForm();\r
454                         foreach (InstalledPackage pkg in SelectedPackages<InstalledPackage>()) {\r
455                                 confirm.UninstallPackage = pkg;\r
456                                 break;\r
457                         }\r
458                         confirm.UseRunas = confirm.GetShouldUseRunas();\r
459                         DialogResult result = confirm.ShowDialog(this);\r
460                         \r
461                         if (result == DialogResult.OK) {\r
462                                 InstalledPackage[] instPkgs = new InstalledPackage[]{confirm.UninstallPackage};\r
463                                 \r
464                                 if (confirm.UseRunas) {\r
465                                         this.Enabled = false;\r
466                                         uninstallRunasActionInvoke(instPkgs);\r
467                                         this.Enabled = true;\r
468                                         this.Focus();\r
469                                 } else {\r
470                                         uninstallActionInvoke(instPkgs);\r
471                                 }\r
472                                 \r
473                                 UpdatePackageList();\r
474                         }\r
475                 }\r
476                 \r
477                 \r
478                 void WebOfficialToolStripMenuItemClick(object sender, EventArgs e)\r
479                 {\r
480                         foreach (Package pkg in SelectedPackages<Package>()) {\r
481                                 string linkURL = pkg.Url.Href;\r
482                                 \r
483                                 if (! (pkg == null || string.IsNullOrEmpty(linkURL))) {\r
484                                         System.Diagnostics.Process.Start(linkURL);\r
485                                 }\r
486                                 break;\r
487                         }\r
488                 }\r
489                 \r
490                 void WebGoogleSearchToolStripMenuItemClick(object sender, EventArgs e)\r
491                 {\r
492                         foreach (Package pkg in SelectedPackages<Package>()) {\r
493                                 string q = System.Web.HttpUtility.UrlEncode(pkg.Name, System.Text.Encoding.UTF8);\r
494                                 string googleURL = @"http://www.google.co.jp/search?q="+q;\r
495                                 \r
496                                 System.Diagnostics.Process.Start(googleURL);\r
497 \r
498                                 break;\r
499                         }\r
500                 }\r
501                 \r
502                 void OpenInstalledDirectoryStripMenuItemClick(object sender, EventArgs e)\r
503                 {\r
504                         foreach (InstalledPackage pkg in SelectedPackages<InstalledPackage>()) {\r
505                                 if (pkg.Type == InstallerType.ARCHIVE) {\r
506                                         System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name));\r
507                                 } else if (Directory.Exists(pkg.UninstallInfo.InstallLocation)) {\r
508                                         System.Diagnostics.Process.Start(pkg.UninstallInfo.InstallLocation);\r
509                                 }\r
510 \r
511                                 break;\r
512                         }\r
513                 }\r
514                 \r
515                 \r
516                 void PropertiesToolStripMenuItemClick(object sender, EventArgs e)\r
517                 {\r
518                         foreach (Package pkg in SelectedPackages<Package>()) {\r
519                                 PackageInfoForm form = new PackageInfoForm();\r
520                                 form.SelectedObject = pkg;\r
521                                 form.Text = pkg.ToString() + "\82Ì\83v\83\8d\83p\83e\83B";\r
522                                 \r
523                                 form.ShowDialog(this);\r
524 \r
525                                 break;\r
526                         }\r
527                 }\r
528                 \r
529                 void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
530                 {\r
531                         // \91I\91ð\82³\82ê\82Ä\82¢\82È\82¢\82È\82ç\8aJ\82©\82È\82¢\r
532                         if (packageListView.SelectedItems.Count <= 0) {\r
533                                 e.Cancel = true;\r
534                                 return;\r
535                         }\r
536                         \r
537                         foreach (Package pkg in SelectedPackages<Package>()) {\r
538                                 bool isInstalledPackage = pkg is InstalledPackage;\r
539                                 \r
540                                 installToolStripMenuItem.Visible = ! isInstalledPackage;\r
541                                 uninstallToolStripMenuItem.Visible = isInstalledPackage;\r
542                                 \r
543                                 webResourcesToolStripMenuItem.Text = string.Format(webResourcesToolStripMenuItem.Tag.ToString(), pkg.Name);\r
544                                 webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
545                                 // webGoogleSearchToolStripMenuItem always active.\r
546                                 \r
547                                 openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage &&\r
548                                         ( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) );\r
549 \r
550                                 break;\r
551                         }\r
552                 }\r
553                 \r
554                 private IEnumerable<Package> getUpdatedPackages(PackageList<InstalledPackage> installedPkgList, PackageList<Package> avaiablePkgList, IComparer<string> verComp)\r
555                 {\r
556                         foreach (InstalledPackage pkg in installedPkgList.Packages) {\r
557                                 Package avaiablePkg = avaiablePkgList.GetPackageForName(pkg.Name);\r
558                                 \r
559                                 if (avaiablePkgList != null) {\r
560                                         if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
561                                             installedPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
562                                                 \r
563                                                 yield return avaiablePkg;\r
564                                         }\r
565                                 }\r
566                         }\r
567                 }\r
568                 \r
569                 void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
570                 {\r
571                         List<Package> pkgs = new List<Package>();\r
572                         VersionComparetor verComp = new VersionComparetor();\r
573                         PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
574                         \r
575                         pkgs.AddRange(getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp));\r
576                         pkgs.AddRange(getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp));\r
577                         \r
578                         if (pkgs.Count <= 0) {\r
579                                 MessageBox.Show(this, "\8dX\90V\82³\82ê\82½\83\\83t\83g\82Í\82 \82è\82Ü\82¹\82ñ", "\83\\83t\83g\82Ì\8dX\90V");\r
580                                 return;\r
581                         }\r
582                         \r
583                         PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
584                         confirm.PkgListsManager = pkgListsMan;\r
585                         confirm.Packages = pkgs.ToArray();\r
586                         DialogResult result = confirm.ShowDialog(this);\r
587                         \r
588                         if (result == DialogResult.OK) {\r
589                                 Package[] instPkgs = confirm.CheckedPackages;\r
590                                 \r
591                                 if (confirm.UseRunas) {\r
592                                         this.Enabled = false;\r
593                                         installRunasActionInvoke(instPkgs);\r
594                                         this.Enabled = true;\r
595                                 } else {\r
596                                         installActionInvoke(instPkgs);\r
597                                 }\r
598                                 \r
599                                 UpdatePackageList();\r
600                         }\r
601                 }\r
602                 \r
603                 public void UpdatePackageList()\r
604                 {\r
605                         pkgListsMan.LoadPackageLists();\r
606                         this.PackageListViewUpdate();\r
607                 }\r
608                 \r
609                 /// <summary>\r
610                 /// \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
611                 /// </summary>\r
612                 public TPackage[] SelectedPackages<TPackage>() where TPackage : Package\r
613                 {\r
614                                 List<TPackage> pkgs = new List<TPackage>();\r
615                                 foreach (ListViewItem item in packageListView.SelectedItems) {\r
616                                         pkgs.Add((TPackage) item.Tag);\r
617                                 }\r
618                                 \r
619                                 return pkgs.ToArray();\r
620                 }\r
621         }\r
622 \r
623 }\r