OSDN Git Service

na-get-lib,複数ソフトインストールかつハッシュ検証失敗したとき、ハッシュ検証成功したソフトの状態がおかしくなる不具合を修正
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.cs
index fd5b492..a66d9a6 100644 (file)
@@ -1,4 +1,4 @@
-using System;\r
+using System;\r
 using System.Drawing;\r
 using System.Windows.Forms;\r
 using NaGet.Packages;\r
@@ -6,6 +6,8 @@ using NaGet.Packages.Install;
 using System.IO;\r
 using System.Collections.Generic;\r
 \r
+using AppliStation.PackageInfo;\r
+\r
 namespace AppliStation\r
 {\r
        /// <summary>\r
@@ -13,7 +15,7 @@ namespace AppliStation
        /// </summary>\r
        public partial class PackageListViewForm : Form\r
        {\r
-               protected PackageListsManager pkgListsMan = null;\r
+               private PackageListsManager pkgListsMan = null;\r
                \r
                public PackageListViewForm()\r
                {\r
@@ -26,161 +28,152 @@ namespace AppliStation
                        uninstallToolStripMenuItem.Font = new Font(uninstallToolStripMenuItem.Font, FontStyle.Bold);\r
                        \r
                        pkgListsMan = new PackageListsManager();\r
+                       packageListView.Data = pkgListsMan;\r
                        \r
                        this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
+                       AppliStation.Util.NativeMethods.ListView_EnableVistaExplorerTheme(packageListView);\r
+                       AppliStation.Util.NativeMethods.ListView_SetDoubleBuffer(packageListView, true);\r
                }\r
                \r
-               void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
+               private void ShowInfoToDetailBoxFor(Package pkg)\r
                {\r
-                       bool installBtnEnabled = false;\r
-                       bool uninstallBtnEnabled = false;\r
-                       \r
                        detailBox.Clear();\r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               Package pkg = (Package) item.Tag;\r
-                               \r
-                               bool isInstalledPackage = pkg is InstalledPackage;\r
-                               uninstallBtnEnabled = isInstalledPackage;\r
-                               installBtnEnabled = ! isInstalledPackage;\r
-                               \r
-                               detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
-                               detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
-                               if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
-                                       detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
-                                       detailBox.SelectedText += string.Format("\83^\83O: {0}\r\n", pkg.Tags);\r
+                       \r
+                       detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
+                       detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
+                       if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
+                               detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
+                               detailBox.SelectedText += "タグ:";\r
+                               foreach (string tag in pkg.Tags.Split(' ')) {\r
+                                       detailBox.AppendText(" ");\r
+                                       AppliStation.Util.NativeMethods.RichTextBox_AddTextLink(detailBox, tag);\r
                                }\r
-                               if (isInstalledPackage) {\r
-                                       InstalledPackage iPkg = (InstalledPackage) pkg;\r
-                                       System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
-                                       if (iPkg.UninstallInfo.InstallDate != null) {\r
-                                               sb.AppendFormat("\83C\83\93\83X\83g\81[\83\8b\82µ\82½\93ú: {0:d}  ", iPkg.UninstallInfo.InstallDate.Value);\r
-                                       }\r
-                                       if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
-                                               sb.AppendFormat("\83T\83C\83Y: {0}  ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
-                                       }\r
-                                       \r
-                                       if (sb.Length > 0) {\r
-                                               detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
-                                               detailBox.SelectedText += sb.ToString();\r
-                                               detailBox.SelectedText += "\r\n";\r
-                                       }\r
+                               detailBox.AppendText("\r\n");\r
+                       }\r
+                       \r
+                       // インストール済みパッケージの場合\r
+                       InstalledPackage iPkg = pkg as InstalledPackage;\r
+                       if (iPkg != null) {\r
+                               System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
+                               if (iPkg.UninstallInfo.InstallDate != null) {\r
+                                       sb.AppendFormat("インストールした日: {0:d}  ", iPkg.UninstallInfo.InstallDate.Value);\r
                                }\r
-                               detailBox.SelectionFont = detailBox.Font;\r
-                               if (pkg.Url != null && pkg.Url.Href != null) {\r
-                                       detailBox.SelectedText += "\8cö\8e®\83T\83C\83g: " + pkg.Url.Href + "\r\n";\r
+                               if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
+                                       sb.AppendFormat("サイズ: {0}  ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
                                }\r
-                               detailBox.SelectedText += pkg.Summary;\r
                                \r
-                               break;\r
+                               if (sb.Length > 0) {\r
+                                       detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
+                                       detailBox.SelectedText += sb.ToString();\r
+                                       detailBox.SelectedText += "\r\n";\r
+                               }\r
+                       }\r
+                       detailBox.SelectionFont = detailBox.Font;\r
+                       if (pkg.Url != null && pkg.Url.Href != null) {\r
+                               detailBox.SelectedText += "公式サイト: ";\r
+                               AppliStation.Util.NativeMethods.RichTextBox_AddTextLink(detailBox, pkg.Url.Href);\r
+                               detailBox.SelectedText += "\r\n";\r
+                       }\r
+                       detailBox.SelectedText += pkg.Summary;\r
+               }\r
+               \r
+               void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
+               {\r
+                       updateSelectedPackages();\r
+               }\r
+               \r
+               private void updateSelectedPackages()\r
+               {\r
+                       uint installPkgCount = 0;\r
+                       uint uninstallPkgCount = 0;\r
+                       bool installBtnEnabled, uninstallBtnEnabled;\r
+                       \r
+                       foreach (Package pkg in packageListView.SelectedPackages) {\r
+                               if (pkg is InstalledPackage) {\r
+                                       uninstallPkgCount ++;\r
+                               } else {\r
+                                       installPkgCount ++;\r
+                               }\r
                        }\r
                        \r
+                       uint pkgCount = installPkgCount + uninstallPkgCount;\r
+                       installBtnEnabled = (installPkgCount > 0) && (uninstallPkgCount == 0);\r
+                       uninstallBtnEnabled = (uninstallPkgCount == 1) && (installPkgCount == 0);\r
+                       \r
+                       // ToolStrip\r
+                       informationToolStripDropDownButton.Visible = (pkgCount == 1);\r
                        uninstallToolStripButton.Visible = uninstallBtnEnabled;\r
                        installToolStripButton.Visible = installBtnEnabled;\r
+                       // MenuStrip\r
+                       webResourceToolStripMenuItem.Visible = (pkgCount == 1);\r
+                       uninstallToolStripMenuItem.Visible = uninstallBtnEnabled;\r
+                       installToolStripMenuItem.Visible = installBtnEnabled;\r
+                       downloadToolStripMenuItem.Visible = (pkgCount > 0);\r
                        \r
-                       if (packageListView.SelectedItems.Count <= 0) {\r
-                               detailBox.SelectionFont = detailBox.Font;\r
-                               int count = packageListView.Items.Count;\r
-                               detailBox.Text = (count > 0) ? string.Format("{0}\8cÂ\82Ì\83\\83t\83g\82ª\82 \82è\82Ü\82·\81B", count)\r
-                                       : "\8aY\93\96\82·\82é\83\\83t\83g\82ª\82 \82è\82Ü\82¹\82ñ\81B";\r
+                       // detailBoxのメッセージ設定\r
+                       switch (pkgCount) {\r
+                               case 0:\r
+                                       int count = packageListView.Items.Count;\r
+                                       detailBox.Clear();\r
+                                       detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count)\r
+                                               : "該当するソフトがありません。";\r
+                                       break;\r
+                               case 1:\r
+                                       ShowInfoToDetailBoxFor(packageListView.SelectedPackage);\r
+                                       break;\r
+                               default: // case 2 and over:\r
+                                       detailBox.Clear();\r
+                                       detailBox.Text = (installBtnEnabled)? string.Format("{0}個のソフトが選択されています。", installPkgCount) :\r
+                                               (uninstallBtnEnabled)? string.Format("{0}個のインストール済みのソフトが選択されています。", uninstallPkgCount) :\r
+                                               string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", pkgCount, uninstallPkgCount, installPkgCount);\r
+                                       break;\r
                        }\r
                        \r
-                       detailBox.SelectionStart = 0;\r
-                       detailBox.ScrollToCaret();\r
+                       try {\r
+                               detailBox.Select(0, 0);\r
+                               detailBox.ScrollToCaret();\r
+                       } catch (System.Runtime.InteropServices.COMException) {\r
+                               // ScrollToCaretでこけることがある\r
+                       }\r
                }\r
 \r
                void PackageListViewItemActivate(object sender, EventArgs e)\r
                {\r
-                       if (packageListView.SelectedItems.Count <= 0) {\r
-                               return; // exit \r
-                       }\r
+                       Package pkg = packageListView.SelectedPackage;\r
                        \r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               Package pkg = (Package) item.Tag;\r
-                               \r
+                       if (pkg != null) {\r
                                if (pkg is InstalledPackage) {\r
                                        UninstallToolStripButtonClick(sender, e);\r
                                } else {\r
                                        InstallToolStripButtonClick(sender, e);\r
                                }\r
-                               \r
-                               break;\r
-                       }\r
-               }\r
-               \r
-               AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer;\r
-\r
-               void PackageListViewColumnClick(object sender, ColumnClickEventArgs e)\r
-               {\r
-                       SortOrder order = SortOrder.None;\r
-                       \r
-                       if (packageListViewSortComparer == null) {\r
-                               order = SortOrder.Ascending;\r
-                               packageListViewSortComparer = new AppliStation.Util.ListViewItemSortComparer(e.Column, order);\r
-                               packageListView.ListViewItemSorter = packageListViewSortComparer;\r
-                       } else {\r
-                               if (packageListViewSortComparer.Column == e.Column) {\r
-                                       order = (packageListViewSortComparer.Order == SortOrder.Ascending)? SortOrder.Descending : SortOrder.Ascending;\r
-                                       \r
-                                       packageListViewSortComparer.Order = order;\r
-                               } else {\r
-                                       order = packageListViewSortComparer.Order;\r
-                                       packageListViewSortComparer.Column = e.Column;\r
-                               }\r
-                               \r
-                               packageListView.Sort();\r
-                       }\r
-                       AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, e.Column, order);\r
-                       \r
-                       // \83\\81[\83g\91Î\8fÛ\97ñ\82Ì\90F\95t\82¯\r
-                       try {\r
-                               // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
-                               AppliStation.Util.NativeMethods.SendMessage(packageListView.Handle, 0x1000+140, (uint) e.Column, 0);\r
-                       } catch (Exception) {   \r
                        }\r
                }\r
                \r
                void Form_OnLoad(object sender, EventArgs e)\r
                {\r
-                       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PackageListViewForm));\r
-                       ImageList imageList = new ImageList();\r
-                       imageList.Images.Add("installed", this.Icon);\r
-                       imageList.Images.Add("sys", (Icon)(resources.GetObject("sysinstalled.Icon")));\r
-                       packageListView.SmallImageList = imageList;\r
+                       packageListViewImageList.Images.Add("installed", Icon.ExtractAssociatedIcon(Application.ExecutablePath));\r
                        \r
                        updatePackageFilterToolStripMenuItemCheckState();\r
-                       installedASPackageFilterToolStripMenuItem.Image = this.Icon.ToBitmap();\r
-                       installedSysPackageFilterToolStripMenuItem.Image = ((Icon)(resources.GetObject("sysinstalled.Icon"))).ToBitmap();\r
-               }\r
-               \r
-               #region PackageFilter\8aÖ\98A\r
-               \r
-               private enum PackageFilterIndex : int\r
-               {\r
-                       All = 0,\r
-                       NotInstalled = 1,\r
-                       InstalledAS = 2,\r
-                       InstalledSys = 3,\r
+                       notInstalledPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["available-new"];\r
+                       installedASPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["installed"];\r
+                       installedSysPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["sys"];\r
+                       \r
+                       packageListView.UpdateItems();\r
+                       updateSelectedPackages();\r
                }\r
                \r
-               private PackageFilterIndex currentPackageFilter = PackageFilterIndex.All;\r
-               \r
-               private PackageFilterIndex CurrentPackageFilter {\r
-                       get {\r
-                               return currentPackageFilter;\r
-                       }\r
-                       set {\r
-                               currentPackageFilter = value;\r
-                               \r
-                               updatePackageFilterToolStripMenuItemCheckState();\r
-                       }\r
-               }\r
+               #region PackageFilter関連\r
                \r
+               /// <summary>\r
+               /// packgageFilterToolStripのリストを更新する。\r
+               /// </summary>\r
                private void updatePackageFilterToolStripMenuItemCheckState()\r
                {\r
                        ToolStripMenuItem selected = getCheckedPackageFilterToolStripItem();\r
                        \r
                        foreach (ToolStripMenuItem item in packageFilterToolStripDropDownButton.DropDown.Items) {\r
-                               item.Checked = selected == item;\r
+                               item.Checked = (selected == item);\r
                        }\r
                        \r
                        packageFilterToolStripDropDownButton.Text = selected.Text;\r
@@ -190,12 +183,12 @@ namespace AppliStation
                \r
                private ToolStripMenuItem getCheckedPackageFilterToolStripItem()\r
                {\r
-                       switch (currentPackageFilter) {\r
-                               case PackageFilterIndex.NotInstalled:\r
+                       switch (packageListView.FilteringType) {\r
+                               case PackageListViewPkgTypeFilter.NotInstalled:\r
                                        return notInstalledPackageFilterToolStripMenuItem;\r
-                               case PackageFilterIndex.InstalledAS:\r
+                               case PackageListViewPkgTypeFilter.InstalledAS:\r
                                        return installedASPackageFilterToolStripMenuItem;\r
-                               case PackageFilterIndex.InstalledSys:\r
+                               case PackageListViewPkgTypeFilter.InstalledSys:\r
                                        return installedSysPackageFilterToolStripMenuItem;\r
                                default:\r
                                        return allPackageFilterToolStripMenuItem;\r
@@ -205,91 +198,50 @@ namespace AppliStation
                void AnyPackageFilterToolStripMenuItemClicked(object sender, EventArgs e)\r
                {\r
                        if (sender == notInstalledPackageFilterToolStripMenuItem) {\r
-                               currentPackageFilter = PackageFilterIndex.NotInstalled;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.NotInstalled;\r
                        } else if (sender == installedASPackageFilterToolStripMenuItem) {\r
-                               currentPackageFilter = PackageFilterIndex.InstalledAS;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.InstalledAS;\r
                        } else if (sender == installedSysPackageFilterToolStripMenuItem) {\r
-                               currentPackageFilter = PackageFilterIndex.InstalledSys;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.InstalledSys;\r
                        } else {\r
-                               currentPackageFilter = PackageFilterIndex.All;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.All;\r
                        }\r
                        \r
                        updatePackageFilterToolStripMenuItemCheckState();\r
-                       searchTextBoxUpdate(false);\r
+                       searchTextBox.FireTextChangedTrigger();\r
                }\r
                \r
                #endregion\r
                \r
-               void PackageListViewUpdate()\r
+               void DetailBoxLinkClicked(object sender, LinkClickedEventArgs e)\r
                {\r
-                       this.packageListView.Items.Clear();\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
-                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(this.SearchKeyword)) {\r
-                                       if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // \83C\83\93\83X\83g\81[\83\8b\89Â\94\\r
-                                               if (currentPackageFilter == PackageFilterIndex.NotInstalled &&\r
-                                                   (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) != null||\r
-                                                    pkgListsMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) != null) ) {\r
-                                                       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
-                                               }\r
-                                               \r
-                                               ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
-                                               item.Tag = pkg;\r
-                                               item.ToolTipText = pkg.Summary;\r
-               \r
-                                               this.packageListView.Items.Add(item);\r
-                                       }\r
-                               }\r
-                       }\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledAS) {\r
-                               foreach (Package pkg in pkgListsMan.InstalledPkgList.Search(this.SearchKeyword)) {\r
-                                       ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
-                                       item.Tag = pkg;\r
-                                       item.ToolTipText = pkg.Summary;\r
-                                       item.ImageKey = "installed";\r
-       \r
-                                       this.packageListView.Items.Add(item);\r
-                               }\r
-                       }\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledSys) {\r
-                               foreach (Package pkg in pkgListsMan.SystemInstalledPkgList.Search(this.SearchKeyword)) {\r
-                                       ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
-                                       item.Tag = pkg;\r
-                                       item.ToolTipText = pkg.Summary;\r
-                                       item.ImageKey = "sys";\r
-       \r
-                                       this.packageListView.Items.Add(item);\r
+                       if (System.Text.RegularExpressions.Regex.IsMatch(e.LinkText, "^https?://")){\r
+                               /* URLの場合はブラウザ起動 */\r
+                               try {\r
+                                       System.Diagnostics.Process.Start(e.LinkText);\r
+                               } catch (System.ComponentModel.Win32Exception) {\r
+                                       MessageBox.Show(string.Format("{0}を開くのに失敗しました。", e.LinkText), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                                }\r
+                       } else {\r
+                               /* それ以外はタグとみなして検索 */\r
+                               searchTextBox.Text = e.LinkText;\r
                        }\r
-                       \r
-                       PackageListViewSelectedIndexChanged(packageListView, null);\r
-                       detailBox.Refresh();\r
-                       \r
-                       //this.packageListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);\r
-               }\r
-               \r
-               void PackageDetailBoxLinkClicked(object sender, LinkClickedEventArgs e)\r
-               {\r
-                       System.Diagnostics.Process.Start(e.LinkText);\r
                }\r
                \r
                internal void updateActionInvoke(bool downloadPackageListsFlag)\r
                {\r
                        AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
                        prog.Shown += delegate(object sender2, EventArgs e2) {\r
-                               NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListsMan, downloadPackageListsFlag);\r
-                               tasks.Downloader = prog.Downloader;\r
+                               NaGet.SubCommands.NaGetUpdate2 tasks = new NaGet.SubCommands.NaGetUpdate2(pkgListsMan, downloadPackageListsFlag);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
                        };\r
-                       prog.Text = "\83\8a\83X\83g\82Ì\8dX\90V";\r
+                       prog.Text = "リストの更新";\r
                        prog.ShowDialog(this);\r
                }\r
                        \r
-               void UpdateToolStripButtonClick(object sender, EventArgs e)\r
+               void UpdateToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
                        updateActionInvoke(true);\r
                        \r
@@ -303,140 +255,230 @@ namespace AppliStation
                        UpdatePackageList();\r
                }\r
                \r
-               #region searchTextBox\82Ü\82í\82è\r
-               \r
-               private bool searchTextBoxIsEmpty = true;\r
-               \r
-               private Timer searchUpdateTimer = null;\r
-               \r
-               string SearchKeyword {\r
-                       get {\r
-                               return searchTextBoxIsEmpty? string.Empty : searchTextBox.Text;\r
-                       }\r
-               }\r
-               \r
-               void SearchTextBoxEnter(object sender, EventArgs e)\r
+               void SoftCollectionFileImportToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       if (searchTextBoxIsEmpty) {\r
-                               searchTextBox.Text = string.Empty;\r
-                               searchTextBox.ForeColor = DefaultForeColor;\r
-                               searchTextBoxIsEmpty = false;\r
+                       string pwd = Directory.GetCurrentDirectory();\r
+                       \r
+                       OpenFileDialog fd = new OpenFileDialog();\r
+                       fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt";\r
+                       fd.DefaultExt = "txt";\r
+                       fd.CheckFileExists = true;\r
+                       fd.CheckPathExists = true;\r
+                       fd.Multiselect = false;\r
+                       fd.ShowDialog();\r
+                       if (fd.FileNames.Length > 0) {\r
+                               string filepath = Path.GetFullPath(fd.FileName);\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
+                               \r
+                               IList<Package> pkgs;\r
+                               IList<string> invalid;\r
+                               \r
+                               try {\r
+                                       PackageCollectionFileData collectionData = new PackageCollectionFileData();\r
+                                       collectionData.load(filepath);\r
+                                       collectionData.generatePackages(pkgListsMan, out pkgs, out invalid);\r
+                                       \r
+                                       if (invalid.Count > 0) {\r
+                                               DialogResult result = MessageBox.Show("一部読み込みの失敗したパッケージがありますが続行しますか?", "インポート", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);\r
+                                               if (result != DialogResult.OK) {\r
+                                                       return;\r
+                                               }\r
+                                       }\r
+                               } catch (IOException) {\r
+                                       MessageBox.Show("ファイルの読み込みに失敗しました", "インポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       return;\r
+                               }\r
+                               \r
+                               {\r
+                                       InstallationConfirmForm confirm = new InstallationConfirmForm();\r
+                                       confirm.PkgListsManager = pkgListsMan;\r
+                                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(pkgs) );\r
+                                       confirm.UseRunas = confirm.GetShouldUseRunas();\r
+                                       DialogResult result = confirm.ShowDialog(this);\r
+                                       \r
+                                       if (result == DialogResult.OK) {\r
+                                               Installation[] insts = confirm.CheckedInstallations;\r
+                                               \r
+                                               if (confirm.UseRunas) {\r
+                                                       installRunasActionInvoke(insts);\r
+                                               } else {\r
+                                                       installActionInvoke(insts);\r
+                                               }\r
+                                               \r
+                                               UpdatePackageList();\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
                        }\r
                }\r
                \r
-               void SearchTextBoxLeave(object sender, EventArgs e)\r
+               void SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       if (string.IsNullOrEmpty(searchTextBox.Text)) {\r
-                               searchTextBox.Text = "\8c\9f\8dõ";\r
-                               searchTextBox.ForeColor = SystemColors.GrayText;\r
-                               searchTextBoxIsEmpty = true;\r
+                       string pwd = Directory.GetCurrentDirectory();\r
+                       string[] softtargets = new string[]{\r
+                               "PCにインストールされたソフト",\r
+                               "AppliStation内でインストールされたソフト",\r
+                               "インストールされたソフトすべて;PCとAppliStationにインストールされたソフトの両方"\r
+                       };\r
+                       int softtargetid = softtargets.Length - 1;\r
+                       \r
+                       {\r
+                               AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createCommandSelectionDialog(\r
+                                       "ソフトコレクションファイルに出力するソフトの種類を選択してください。", "エクスポート", "エクスポートするソフト",\r
+                                       System.Drawing.SystemIcons.Question,\r
+                                       softtargets, softtargets.Length-1);\r
+                               if (optdialog.ShowDialog(this) != DialogResult.OK) {\r
+                                       return; // canceled\r
+                               } else if (optdialog.UserInputValue != null) {\r
+                                       softtargetid = (int) optdialog.UserInputValue;\r
+                               }\r
+                       }\r
+                       \r
+                       SaveFileDialog fd = new SaveFileDialog();\r
+                       fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt";\r
+                       fd.DefaultExt = "txt";\r
+                       fd.CheckPathExists = true;\r
+                       fd.OverwritePrompt = true;\r
+                       fd.ShowDialog();\r
+                       if (fd.FileNames.Length > 0) {\r
+                               string filepath = Path.GetFullPath(fd.FileName);\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
+                               \r
+                               PackageCollectionFileData collectionData = new PackageCollectionFileData();\r
+                               \r
+                               switch (softtargetid) {\r
+                                       case 0: // PCにインストール\r
+                                               collectionData.loadPackages(pkgListsMan.SystemInstalledPkgList.GetEnumerator());\r
+                                               break;\r
+                                       case 1: // AppliStation内にインストール\r
+                                               collectionData.loadPackages(pkgListsMan.InstalledPkgList.GetEnumerator());\r
+                                               break;\r
+                                       case 2: // すべて\r
+                                       default:\r
+                                               collectionData.loadPackages(pkgListsMan.GetAllInstalledPackages());\r
+                                               break;\r
+                               }\r
+                               \r
+                               try {\r
+                                       collectionData.saveAs(fd.FileName);\r
+                               } catch (UnauthorizedAccessException) {\r
+                                       if ((File.GetAttributes(fd.FileName) & FileAttributes.ReadOnly) != 0) {\r
+                                               MessageBox.Show("読み取り専用属性が設定されています。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       } else {\r
+                                               MessageBox.Show("ファイルへの書き込みが許可されていません。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       }\r
+                                       return;\r
+                               } catch (IOException) {\r
+                                       MessageBox.Show("ファイルの書き込みに失敗しました", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       return;\r
+                               }\r
+                       } else {\r
+                               Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す\r
                        }\r
                }\r
                \r
-               void SearchTextBoxTextChanged(object sender, EventArgs e)\r
+               void OptionToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       if (searchTextBox.Focused) {\r
-                               searchTextBoxUpdate(false);\r
+                       UserPrefForm userPrefForm = new UserPrefForm();\r
+                       DialogResult result = userPrefForm.ShowDialog(this);\r
+                       \r
+                       if (result == DialogResult.OK) {\r
+                               if (userPrefForm.IsRepositoryListSettingChanged) {\r
+                                       updateActionInvoke(true);\r
+                                       UpdatePackageList();\r
+                               }\r
                        }\r
                }\r
                \r
+               #region searchTextBoxまわり\r
+               \r
                void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e)\r
                {\r
                        switch (e.KeyChar) {\r
                                case (char)Keys.Enter:\r
-                                       searchTextBoxUpdate(true);\r
+                                       searchTextBox.FireTextChangedTrigger();\r
                                        break;\r
                                case (char)Keys.Escape:\r
-                                       searchTextBox.Text = "";\r
+                                       searchTextBox.Text = string.Empty;\r
                                        break;\r
                        }\r
                }\r
                \r
-               private void searchTextBoxUpdate(bool force)\r
+               void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e)\r
                {\r
-                       if (! this.Created) return;\r
-                       \r
-                       if (searchUpdateTimer != null) {\r
-                               searchUpdateTimer.Stop();\r
-                       } else {\r
-                               searchUpdateTimer = new Timer();\r
-                               searchUpdateTimer.Tick += searchUpdateTimerTick;\r
-                       }\r
-                       searchUpdateTimer.Interval = (force)? 10 : 500;\r
-                       searchUpdateTimer.Start();\r
-               }\r
-               \r
-               private void searchUpdateTimerTick(object sender, EventArgs e)\r
-               {\r
-                       searchUpdateTimer.Stop();\r
-                       searchUpdateTimer = null;\r
-                       \r
-                       PackageListViewUpdate();\r
+                       packageListView.FilteringKeyword = searchTextBox.Text;\r
                }\r
                \r
                #endregion\r
                \r
-               internal void installActionInvoke(Package[] pkgs)\r
+               internal void installActionInvoke(Installation[] insts)\r
                {\r
                        AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
                        prog.Shown += delegate(object sender2, EventArgs e2) {\r
-                               NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListsMan, pkgs);\r
-                               tasks.Downloader = prog.Downloader;\r
+                               NaGet.SubCommands.NaGetInstall2 tasks = new NaGet.SubCommands.NaGetInstall2(pkgListsMan, insts);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
                        };\r
-                       prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83C\83\93\83X\83g\81[\83\8b");\r
+                       prog.Text = string.Format("ソフトウェアのインストール");\r
                        prog.ShowDialog(this);\r
                }\r
                \r
                void InstallToolStripButtonClick(object sender, EventArgs e)\r
                {\r
-                       PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
+                       InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Packages = SelectedPackages<Package>();\r
+                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) );\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
                        if (result == DialogResult.OK) {\r
-                               Package[] instPkgs = confirm.CheckedPackages;\r
+                               Installation[] insts = confirm.CheckedInstallations;\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
-                                       installRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
-                                       this.Focus();\r
+                                       installRunasActionInvoke(insts);\r
                                } else {\r
-                                       installActionInvoke(instPkgs);\r
+                                       installActionInvoke(insts);\r
                                }\r
                                \r
                                UpdatePackageList();\r
                        }\r
                }\r
                \r
-               public void installRunasActionInvoke(Package[] pkgs)\r
+               public void installRunasActionInvoke(Installation[] insts)\r
                {\r
-                       string tmpfileName = System.IO.Path.GetTempFileName();\r
+                       this.setWindowEnabled(false);\r
+                       \r
+                       string tmpfileName = Path.GetTempFileName();\r
                        try {\r
-                               NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
+                               NaGet.Utils.PutSerializeObject(tmpfileName, insts);\r
                                \r
                                System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();\r
                                procInfo.FileName = Application.ExecutablePath;\r
-                               procInfo.Arguments = string.Format("--noupdate --cmd=install \"--pkgsref={0}\"", tmpfileName);\r
+                               procInfo.Arguments = string.Format("--noupdate --cmd=install \"--instsref={0}\"", tmpfileName);\r
                                procInfo.Verb = "runas";\r
                                procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
                                \r
-                               using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
-                                       hProc.WaitForExit();\r
-                               }\r
-                               \r
-                               pkgListsMan.LoadPackageLists();\r
+                               System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
+                               hProc.EnableRaisingEvents = true;\r
+                               hProc.SynchronizingObject = this;\r
+                               hProc.Exited += delegate(object sender, EventArgs e) {\r
+                                       UpdatePackageList();\r
+                                       \r
+                                       this.setWindowEnabled(true);\r
+                                       this.BringToFront();\r
+                                       \r
+                                       if (File.Exists(tmpfileName)) {\r
+                                               File.Delete(tmpfileName);\r
+                                       }\r
+                               };\r
                        } catch (System.ComponentModel.Win32Exception ex) {\r
-                               MessageBox.Show(ex.Message, "\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                       } finally {\r
+                               MessageBox.Show(ex.Message, "インストール", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                               \r
                                if (File.Exists(tmpfileName)) {\r
                                        File.Delete(tmpfileName);\r
-                               }\r
+                               }                               this.setWindowEnabled(true);\r
                        }\r
                }\r
                \r
@@ -444,18 +486,20 @@ namespace AppliStation
                {\r
                        AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
                        prog.Shown += delegate(object sender2, EventArgs e2) {\r
-                               NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListsMan, pkgs);\r
+                               NaGet.SubCommands.NaGetUninstall2 tasks = new NaGet.SubCommands.NaGetUninstall2(pkgListsMan, pkgs);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
                        };\r
-                       prog.Text = string.Format("\83\\83t\83g\83E\83F\83A\82Ì\83A\83\93\83C\83\93\83X\83g\81[\83\8b");\r
+                       prog.Text = string.Format("ソフトウェアのアンインストール");\r
                        prog.ShowDialog(this);\r
                }\r
                \r
                internal void uninstallRunasActionInvoke(InstalledPackage[] pkgs)\r
-               {\r
-                       string tmpfileName = System.IO.Path.GetTempFileName();\r
+               {                       \r
+                       this.setWindowEnabled(false);\r
+                       \r
+                       string tmpfileName = Path.GetTempFileName();\r
                        try {\r
                                NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
                                \r
@@ -465,14 +509,23 @@ namespace AppliStation
                                procInfo.Verb = "runas";\r
                                procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
                                \r
-                               using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
-                                       hProc.WaitForExit();\r
-                               }\r
-                               \r
-                               pkgListsMan.LoadPackageLists();\r
+                               System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
+                               hProc.EnableRaisingEvents = true;\r
+                               hProc.SynchronizingObject = this;\r
+                               hProc.Exited += delegate(object sender, EventArgs e) {\r
+                                       UpdatePackageList();\r
+                                       \r
+                                       this.setWindowEnabled(true);\r
+                                       this.BringToFront();\r
+                                       \r
+                                       if (File.Exists(tmpfileName)) {\r
+                                               File.Delete(tmpfileName);\r
+                                       }\r
+                               };\r
                        } catch (System.ComponentModel.Win32Exception ex) {\r
-                               MessageBox.Show(ex.Message, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                       } finally {\r
+                               MessageBox.Show(ex.Message, "アンインストール", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                               \r
+                               this.setWindowEnabled(true);\r
                                if (File.Exists(tmpfileName)) {\r
                                        File.Delete(tmpfileName);\r
                                }\r
@@ -482,10 +535,7 @@ namespace AppliStation
                void UninstallToolStripButtonClick(object sender, EventArgs e)\r
                {\r
                        PackageUninstallConfirmForm confirm = new PackageUninstallConfirmForm();\r
-                       foreach (InstalledPackage pkg in SelectedPackages<InstalledPackage>()) {\r
-                               confirm.UninstallPackage = pkg;\r
-                               break;\r
-                       }\r
+                       confirm.UninstallPackage = (InstalledPackage) packageListView.SelectedPackage;\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
@@ -493,10 +543,7 @@ namespace AppliStation
                                InstalledPackage[] instPkgs = new InstalledPackage[]{confirm.UninstallPackage};\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
                                        uninstallRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
-                                       this.Focus();\r
                                } else {\r
                                        uninstallActionInvoke(instPkgs);\r
                                }\r
@@ -505,150 +552,274 @@ namespace AppliStation
                        }\r
                }\r
                \r
+               internal void downloadActionInvoke(Installation[] pkgs)\r
+               {\r
+                       AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer();\r
+                       prog.Shown += delegate(object sender2, EventArgs e2) {\r
+                               NaGet.SubCommands.NaGetDownloadToCache2 tasks = new NaGet.SubCommands.NaGetDownloadToCache2(pkgListsMan, pkgs);\r
+                               prog.SetTaskSet(tasks);\r
+                               prog.Refresh();\r
+                               prog.StartTaskSet();\r
+                       };\r
+                       prog.Text = string.Format("キャッシュへのダウンロード");\r
+                       prog.ShowDialog(this);\r
+               }\r
                \r
-               void WebOfficialToolStripMenuItemClick(object sender, EventArgs e)\r
+               void DownloadToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in SelectedPackages<Package>()) {\r
+                       Installation[] insts = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) );\r
+                       \r
+                       downloadActionInvoke(insts);\r
+                       \r
+                       UpdatePackageList();\r
+               }\r
+               \r
+               void WebOfficialMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                string linkURL = pkg.Url.Href;\r
                                \r
-                               if (! (pkg == null || string.IsNullOrEmpty(linkURL))) {\r
-                                       System.Diagnostics.Process.Start(linkURL);\r
+                               if (! string.IsNullOrEmpty(linkURL)) {\r
+                                       try {\r
+                                               System.Diagnostics.Process.Start(linkURL);\r
+                                       } catch (System.ComponentModel.Win32Exception) {\r
+                                               MessageBox.Show(string.Format("{0}を開くのに失敗しました。", linkURL), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                                       }\r
                                }\r
-                               break;\r
                        }\r
                }\r
                \r
-               void WebGoogleSearchToolStripMenuItemClick(object sender, EventArgs e)\r
+               void WebGoogleSearchMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in SelectedPackages<Package>()) {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                string q = System.Web.HttpUtility.UrlEncode(pkg.Name, System.Text.Encoding.UTF8);\r
                                string googleURL = @"http://www.google.co.jp/search?q="+q;\r
                                \r
-                               System.Diagnostics.Process.Start(googleURL);\r
-\r
-                               break;\r
+                               try {\r
+                                       System.Diagnostics.Process.Start(googleURL);\r
+                               } catch (System.ComponentModel.Win32Exception) {\r
+                                       MessageBox.Show("Googleを開くのに失敗しました。", "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                               }\r
                        }\r
                }\r
                \r
                void OpenInstalledDirectoryStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (InstalledPackage pkg in SelectedPackages<InstalledPackage>()) {\r
-                               if (pkg.Type == InstallerType.ARCHIVE) {\r
+                       InstalledPackage pkg = (InstalledPackage) packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
+                               if (pkg.Type == InstallerType.ARCHIVE || pkg.Type == InstallerType.ITSELF) {\r
                                        System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name));\r
-                               } else if (Directory.Exists(pkg.UninstallInfo.InstallLocation)) {\r
-                                       System.Diagnostics.Process.Start(pkg.UninstallInfo.InstallLocation);\r
+                               } else if (Directory.Exists(pkg.DiscoverInstalledLocation())) {\r
+                                       System.Diagnostics.Process.Start(pkg.DiscoverInstalledLocation());\r
                                }\r
-\r
-                               break;\r
                        }\r
                }\r
                \r
                \r
-               void PropertiesToolStripMenuItemClick(object sender, EventArgs e)\r
+               void PropertiesCommonMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in SelectedPackages<Package>()) {\r
+                       if (packageListView.SelectedItems.Count >= 5) {\r
+                               string msg = string.Format("{0}個のプロパティダイアログを開こうとしています。\n継続しますか?", packageListView.SelectedItems.Count);\r
+                               if (MessageBox.Show(msg, "プロパティ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) {\r
+                                       return;\r
+                               }\r
+                       }\r
+                       \r
+                       foreach (Package pkg in packageListView.SelectedPackages) {\r
                                PackageInfoForm form = new PackageInfoForm();\r
                                form.SelectedObject = pkg;\r
-                               form.Text = pkg.ToString() + "\82Ì\83v\83\8d\83p\83e\83B";\r
-                               form.AutoSize = true;\r
+                               form.Text = string.Format("{0}({1})のプロパティ", pkg.Name, pkg.Version);\r
                                \r
-                               form.ShowDialog(this);\r
-\r
-                               break;\r
+                               form.Show(this);\r
                        }\r
                }\r
                \r
-               void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
+               private void updateLauncherMenuItem(AppliStation.Util.ToolStripPetitLauncherMenuItem launcherMenuItem)\r
                {\r
-                       // \91I\91ð\82³\82ê\82Ä\82¢\82È\82¢\82È\82ç\8aJ\82©\82È\82¢\r
-                       if (packageListView.SelectedItems.Count <= 0) {\r
-                               e.Cancel = true;\r
-                               return;\r
-                       }\r
+                       bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
                        \r
-                       foreach (Package pkg in SelectedPackages<Package>()) {\r
-                               bool isInstalledPackage = pkg is InstalledPackage;\r
-                               \r
-                               installToolStripMenuItem.Visible = ! isInstalledPackage;\r
-                               uninstallToolStripMenuItem.Visible = isInstalledPackage;\r
+                       if (selectionIsOnlyOne) {\r
+                               Package pkg = packageListView.SelectedPackage;\r
+                               InstalledPackage iPkg = pkg as InstalledPackage;\r
                                \r
-                               webResourcesToolStripMenuItem.Text = string.Format(webResourcesToolStripMenuItem.Tag.ToString(), pkg.Name);\r
-                               webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
-                               // webGoogleSearchToolStripMenuItem always active.\r
-                               \r
-                               openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage &&\r
-                                       ( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) );\r
-\r
-                               break;\r
+                               // インストール済みパッケージのとき\r
+                               if (iPkg != null) {\r
+                                       bool launcherMenuItemVisible = \r
+                                               (pkg.Type == InstallerType.ARCHIVE) ||\r
+                                               (pkg.Type == InstallerType.ITSELF) ||\r
+                                               Directory.Exists(iPkg.DiscoverInstalledLocation());\r
+                                       \r
+                                       launcherMenuItem.Visible = launcherMenuItemVisible;\r
+                                       if (launcherMenuItemVisible) {\r
+                                               launcherMenuItem.BaseFolderPath = iPkg.DiscoverInstalledLocation();\r
+                                       }\r
+                               } else {\r
+                                       launcherMenuItem.Visible = false;\r
+                               }\r
+                       } else {\r
+                               launcherMenuItem.Visible = false;\r
                        }\r
                }\r
                \r
-               private IEnumerable<Package> getUpdatedPackages(PackageList<InstalledPackage> installedPkgList, PackageList<Package> avaiablePkgList, IComparer<string> verComp)\r
+               void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
                {\r
-                       foreach (InstalledPackage pkg in installedPkgList.Packages) {\r
-                               Package avaiablePkg = avaiablePkgList.GetPackageForName(pkg.Name);\r
-                               \r
-                               if (avaiablePkgList != null) {\r
-                                       if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
-                                           installedPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
-                                               \r
-                                               yield return avaiablePkg;\r
-                                       }\r
+                       bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
+                       bool hasSelection = packageListView.SelectedItems.Count > 0;\r
+                       \r
+                       updateSelectedPackages();\r
+                       \r
+                       // インストール先のフォルダの設定\r
+                       updateLauncherMenuItem(installedDirectoryToolStripMenuItem);\r
+                       \r
+                       if (packageListView.View == View.Details) {\r
+                               // ヘッダ部がクリックされたとき、パッケージが選択されていないものとして扱って処理をする。\r
+                               int headerHeight = AppliStation.Util.NativeMethods.ColumnHeader_GetSize(packageListView).Height;\r
+                               if (packageListView.PointToClient(packageListContextMenuStrip.Location).Y < headerHeight) {\r
+                                       selectionIsOnlyOne = hasSelection = false;\r
+                                       installToolStripMenuItem.Visible = false;\r
+                                       uninstallToolStripMenuItem.Visible = false;\r
+                                       installedDirectoryToolStripMenuItem.Visible = false;\r
                                }\r
                        }\r
+                       \r
+                       packageListContextMenuStripSeparator.Visible = selectionIsOnlyOne;\r
+                       webResourceToolStripMenuItem.Visible = selectionIsOnlyOne;\r
+                       propertiesToolStripMenuItem.Visible = hasSelection;\r
+                       columnToolStripMenuItem.Visible = (! hasSelection) && (packageListView.View == View.Details);\r
                }\r
                \r
-               void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
+               void InformationToolStripDropDownButtonDropDownOpening(object sender, EventArgs e)\r
                {\r
-                       List<Package> pkgs = new List<Package>();\r
-                       VersionComparetor verComp = new VersionComparetor();\r
-                       PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
+                       bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
+                       bool hasSelection = packageListView.SelectedItems.Count > 0;\r
+                       \r
+                       // インストール先のフォルダの設定\r
+                       updateLauncherMenuItem(installedDirectoryMenuItem);\r
+                       \r
+                       webResourceMenuItem.Visible = selectionIsOnlyOne;\r
+                       propertiesMenuItem.Visible = hasSelection;\r
+               }\r
+               \r
+               void WebResourceCommonContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
+               {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       \r
+                       if (pkg != null && pkg.Url != null && !string.IsNullOrEmpty(pkg.Url.Href)) {\r
+                               webOfficialMenuItem.Enabled = true;\r
+                               webOfficialMenuItem.ToolTipText = pkg.Url.Href;\r
+                       } else {\r
+                               webOfficialMenuItem.Enabled = false;\r
+                               webOfficialMenuItem.ToolTipText = null;\r
+                       }\r
                        \r
-                       pkgs.AddRange(getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp));\r
-                       pkgs.AddRange(getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp));\r
+                       // webGoogleSearchMenuItem always active.\r
+               }\r
+               \r
+               void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
+               {\r
+                       List<Package> pkgs = new List<Package>(\r
+                               UpgradeFinder.GetUpgradePackages(pkgListsMan)\r
+                       );\r
                        \r
                        if (pkgs.Count <= 0) {\r
-                               MessageBox.Show(this, "\8dX\90V\82³\82ê\82½\83\\83t\83g\82Í\82 \82è\82Ü\82¹\82ñ", "\83\\83t\83g\82Ì\8dX\90V");\r
+                               MessageBox.Show(this, "更新されたソフトはありません", "ソフトの更新");\r
                                return;\r
                        }\r
                        \r
-                       PackagesInstallConfirmForm confirm = new PackagesInstallConfirmForm();\r
+                       InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Packages = pkgs.ToArray();\r
+                       confirm.Installations = Installation.ConvertInstallations(pkgs.ToArray());\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
                        if (result == DialogResult.OK) {\r
-                               Package[] instPkgs = confirm.CheckedPackages;\r
+                               Installation[] insts = confirm.CheckedInstallations;\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
-                                       installRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
+                                       installRunasActionInvoke(insts);\r
                                } else {\r
-                                       installActionInvoke(instPkgs);\r
+                                       installActionInvoke(insts);\r
                                }\r
                                \r
                                UpdatePackageList();\r
                        }\r
                }\r
                \r
+               protected override bool ProcessCmdKey(ref Message msg, Keys keyData)\r
+               {\r
+                       if ((int)keyData == (int)Keys.Control + (int)Keys.E) {\r
+                               searchTextBox.SelectAll();\r
+                               searchTextBox.Focus();\r
+                               return true;\r
+                       }\r
+                       \r
+                       return base.ProcessCmdKey(ref msg, keyData);\r
+               }\r
+               \r
                public void UpdatePackageList()\r
                {\r
                        pkgListsMan.LoadPackageLists();\r
-                       this.PackageListViewUpdate();\r
+                       packageListView.UpdateItems();\r
+                       updateSelectedPackages();\r
                }\r
                \r
                /// <summary>\r
-               /// \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
+               /// 自ウィンドウの有効無効(Enabled)を(必要あればInvokeして)実行する \r
                /// </summary>\r
-               public TPackage[] SelectedPackages<TPackage>() where TPackage : Package\r
+               /// <param name="enabled">有効か否か。Enabledの値に入れられる</param>\r
+               private void setWindowEnabled(bool enabled)\r
                {\r
-                               List<TPackage> pkgs = new List<TPackage>();\r
-                               foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                                       pkgs.Add((TPackage) item.Tag);\r
+                       MethodInvoker process = (MethodInvoker) delegate() {\r
+                               this.Enabled = enabled;\r
+                       };\r
+                       \r
+                       if (InvokeRequired) {\r
+                               Invoke(process);\r
+                       } else {\r
+                               process.Invoke();\r
+                       }\r
+               }\r
+               \r
+               void ColumnCommonToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       packageListView.BeginUpdate();\r
+                       ColumnHeader sortcolumn = packageListView.SortColumn;\r
+                       \r
+                       // 列の追加と削除\r
+                       foreach (ToolStripItem item in columnToolStripMenuItem.DropDownItems) {\r
+                               ToolStripMenuItem menu = item as ToolStripMenuItem;\r
+                               if (menu != null) {\r
+                                       bool exists = false;\r
+                                       // 列が存在しているがチェックが外れていたら削除する。\r
+                                       foreach (ColumnHeader header in packageListView.Columns) {\r
+                                               if (header.Tag == menu.Tag) {\r
+                                                       exists = true;\r
+                                                       if (sortcolumn == header) {\r
+                                                               packageListView.SortColumn = sortcolumn = null;\r
+                                                       }\r
+                                                       if (menu.Checked == false) {\r
+                                                               packageListView.Columns.Remove(header);\r
+                                                       }\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       \r
+                                       // 列が存在していなく、チェックがされているなら追加する。\r
+                                       if (menu.Checked && !exists) {\r
+                                               ColumnHeader header = new ColumnHeader();\r
+                                               header.Text = menu.Text;\r
+                                               header.Tag = menu.Tag;\r
+                                               packageListView.Columns.Add(header);\r
+                                       }\r
                                }\r
-                               \r
-                               return pkgs.ToArray();\r
+                       }\r
+                       \r
+                       AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, (sortcolumn != null)? sortcolumn.Index : -1, SortOrder.None);\r
+                       \r
+                       packageListView.UpdateItems();\r
+                       \r
+                       packageListView.EndUpdate();\r
                }\r
        }\r
 \r