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