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                                         this.Enabled = false;\r
356                                         installRunasActionInvoke(instPkgs);\r
357                                         this.Enabled = true;\r
358                                         this.Focus();\r
359                                 } else {\r
360                                         installActionInvoke(instPkgs);\r
361                                 }\r
362                                 \r
363                                 UpdatePackageList();\r
364                         }\r
365                 }\r
366                 \r
367                 public void installRunasActionInvoke(Package[] pkgs)\r
368                 {\r
369                         string tmpfileName = System.IO.Path.GetTempFileName();\r
370                         try {\r
371                                 NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
372                                 \r
373                                 System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();\r
374                                 procInfo.FileName = Application.ExecutablePath;\r
375                                 procInfo.Arguments = string.Format("--noupdate --cmd=install \"--pkgsref={0}\"", tmpfileName);\r
376                                 procInfo.Verb = "runas";\r
377                                 procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
378                                 \r
379                                 using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
380                                         hProc.WaitForExit();\r
381                                 }\r
382                                 \r
383                                 pkgListsMan.LoadPackageLists();\r
384                         } catch (System.ComponentModel.Win32Exception ex) {\r
385                                 MessageBox.Show(ex.Message, "\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
386                         } finally {\r
387                                 if (File.Exists(tmpfileName)) {\r
388                                         File.Delete(tmpfileName);\r
389                                 }\r
390                         }\r
391                 }\r
392                 \r
393                 internal void uninstallActionInvoke(InstalledPackage[] pkgs)\r
394                 {\r
395                         AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
396                         prog.Shown += delegate(object sender2, EventArgs e2) {\r
397                                 NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListsMan, pkgs);\r
398                                 prog.SetTaskSet(tasks);\r
399                                 prog.Refresh();\r
400                                 prog.StartTaskSet();\r
401                         };\r
402                         prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83A\83\93\83C\83\93\83X\83g\81[\83\8b");\r
403                         prog.ShowDialog(this);\r
404                 }\r
405                 \r
406                 internal void uninstallRunasActionInvoke(InstalledPackage[] pkgs)\r
407                 {\r
408                         string tmpfileName = System.IO.Path.GetTempFileName();\r
409                         try {\r
410                                 NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
411                                 \r
412                                 System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();\r
413                                 procInfo.FileName = Application.ExecutablePath;\r
414                                 procInfo.Arguments = string.Format("--noupdate --cmd=uninstall \"--pkgsref={0}\"", tmpfileName);\r
415                                 procInfo.Verb = "runas";\r
416                                 procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
417                                 \r
418                                 using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
419                                         hProc.WaitForExit();\r
420                                 }\r
421                                 \r
422                                 pkgListsMan.LoadPackageLists();\r
423                         } catch (System.ComponentModel.Win32Exception ex) {\r
424                                 MessageBox.Show(ex.Message, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
425                         } finally {\r
426                                 if (File.Exists(tmpfileName)) {\r
427                                         File.Delete(tmpfileName);\r
428                                 }\r
429                         }\r
430                 }\r
431                 \r
432                 void UninstallToolStripButtonClick(object sender, EventArgs e)\r
433                 {\r
434                         PackageUninstallConfirmForm confirm = new PackageUninstallConfirmForm();\r
435                         foreach (InstalledPackage pkg in SelectedPackages<InstalledPackage>()) {\r
436                                 confirm.UninstallPackage = pkg;\r
437                                 break;\r
438                         }\r
439                         confirm.UseRunas = confirm.GetShouldUseRunas();\r
440                         DialogResult result = confirm.ShowDialog(this);\r
441                         \r
442                         if (result == DialogResult.OK) {\r
443                                 InstalledPackage[] instPkgs = new InstalledPackage[]{confirm.UninstallPackage};\r
444                                 \r
445                                 if (confirm.UseRunas) {\r
446                                         this.Enabled = false;\r
447                                         uninstallRunasActionInvoke(instPkgs);\r
448                                         this.Enabled = true;\r
449                                         this.Focus();\r
450                                 } else {\r
451                                         uninstallActionInvoke(instPkgs);\r
452                                 }\r
453                                 \r
454                                 UpdatePackageList();\r
455                         }\r
456                 }\r
457                 \r
458                 \r
459                 void WebOfficialToolStripMenuItemClick(object sender, EventArgs e)\r
460                 {\r
461                         foreach (Package pkg in SelectedPackages<Package>()) {\r
462                                 string linkURL = pkg.Url.Href;\r
463                                 \r
464                                 if (! (pkg == null || string.IsNullOrEmpty(linkURL))) {\r
465                                         System.Diagnostics.Process.Start(linkURL);\r
466                                 }\r
467                                 break;\r
468                         }\r
469                 }\r
470                 \r
471                 void WebGoogleSearchToolStripMenuItemClick(object sender, EventArgs e)\r
472                 {\r
473                         foreach (Package pkg in SelectedPackages<Package>()) {\r
474                                 string q = System.Web.HttpUtility.UrlEncode(pkg.Name, System.Text.Encoding.UTF8);\r
475                                 string googleURL = @"http://www.google.co.jp/search?q="+q;\r
476                                 \r
477                                 System.Diagnostics.Process.Start(googleURL);\r
478 \r
479                                 break;\r
480                         }\r
481                 }\r
482                 \r
483                 void OpenInstalledDirectoryStripMenuItemClick(object sender, EventArgs e)\r
484                 {\r
485                         foreach (InstalledPackage pkg in SelectedPackages<InstalledPackage>()) {\r
486                                 if (pkg.Type == InstallerType.ARCHIVE) {\r
487                                         System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name));\r
488                                 } else if (Directory.Exists(pkg.UninstallInfo.InstallLocation)) {\r
489                                         System.Diagnostics.Process.Start(pkg.UninstallInfo.InstallLocation);\r
490                                 }\r
491 \r
492                                 break;\r
493                         }\r
494                 }\r
495                 \r
496                 \r
497                 void PropertiesToolStripMenuItemClick(object sender, EventArgs e)\r
498                 {\r
499                         foreach (Package pkg in SelectedPackages<Package>()) {\r
500                                 PackageInfoForm form = new PackageInfoForm();\r
501                                 form.SelectedObject = pkg;\r
502                                 form.Text = pkg.ToString() + "\82Ì\83v\83\8d\83p\83e\83B";\r
503                                 \r
504                                 form.ShowDialog(this);\r
505 \r
506                                 break;\r
507                         }\r
508                 }\r
509                 \r
510                 void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
511                 {\r
512                         // \91I\91ð\82³\82ê\82Ä\82¢\82È\82¢\82È\82ç\8aJ\82©\82È\82¢\r
513                         if (packageListView.SelectedItems.Count <= 0) {\r
514                                 e.Cancel = true;\r
515                                 return;\r
516                         }\r
517                         \r
518                         foreach (Package pkg in SelectedPackages<Package>()) {\r
519                                 bool isInstalledPackage = pkg is InstalledPackage;\r
520                                 \r
521                                 installToolStripMenuItem.Visible = ! isInstalledPackage;\r
522                                 uninstallToolStripMenuItem.Visible = isInstalledPackage;\r
523                                 \r
524                                 webResourcesToolStripMenuItem.Text = string.Format(webResourcesToolStripMenuItem.Tag.ToString(), pkg.Name);\r
525                                 webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
526                                 // webGoogleSearchToolStripMenuItem always active.\r
527                                 \r
528                                 openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage &&\r
529                                         ( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) );\r
530 \r
531                                 break;\r
532                         }\r
533                 }\r
534                 \r
535                 private IEnumerable<Package> getUpdatedPackages(PackageList<InstalledPackage> installedPkgList, PackageList<Package> avaiablePkgList, IComparer<string> verComp)\r
536                 {\r
537                         foreach (InstalledPackage pkg in installedPkgList.Packages) {\r
538                                 Package avaiablePkg = avaiablePkgList.GetPackageForName(pkg.Name);\r
539                                 \r
540                                 if (avaiablePkgList != null) {\r
541                                         if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
542                                             installedPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
543                                                 \r
544                                                 yield return avaiablePkg;\r
545                                         }\r
546                                 }\r
547                         }\r
548                 }\r
549                 \r
550                 void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
551                 {\r
552                         List<Package> pkgs = new List<Package>();\r
553                         VersionComparetor verComp = new VersionComparetor();\r
554                         PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
555                         \r
556                         pkgs.AddRange(getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp));\r
557                         pkgs.AddRange(getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp));\r
558                         \r
559                         if (pkgs.Count <= 0) {\r
560                                 MessageBox.Show(this, "\8dX\90V\82³\82ê\82½\83\\83t\83g\82Í\82 \82è\82Ü\82¹\82ñ", "\83\\83t\83g\82Ì\8dX\90V");\r
561                                 return;\r
562                         }\r
563                         \r
564                         PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
565                         confirm.PkgListsManager = pkgListsMan;\r
566                         confirm.Packages = pkgs.ToArray();\r
567                         DialogResult result = confirm.ShowDialog(this);\r
568                         \r
569                         if (result == DialogResult.OK) {\r
570                                 Package[] instPkgs = confirm.CheckedPackages;\r
571                                 \r
572                                 if (confirm.UseRunas) {\r
573                                         this.Enabled = false;\r
574                                         installRunasActionInvoke(instPkgs);\r
575                                         this.Enabled = true;\r
576                                 } else {\r
577                                         installActionInvoke(instPkgs);\r
578                                 }\r
579                                 \r
580                                 UpdatePackageList();\r
581                         }\r
582                 }\r
583                 \r
584                 public void UpdatePackageList()\r
585                 {\r
586                         pkgListsMan.LoadPackageLists();\r
587                         this.PackageListViewUpdate();\r
588                 }\r
589                 \r
590                 /// <summary>\r
591                 /// \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
592                 /// </summary>\r
593                 public TPackage[] SelectedPackages<TPackage>() where TPackage : Package\r
594                 {\r
595                                 List<TPackage> pkgs = new List<TPackage>();\r
596                                 foreach (ListViewItem item in packageListView.SelectedItems) {\r
597                                         pkgs.Add((TPackage) item.Tag);\r
598                                 }\r
599                                 \r
600                                 return pkgs.ToArray();\r
601                 }\r
602         }\r
603 \r
604 }\r