OSDN Git Service

na-get-lib,複数ソフトインストールかつハッシュ検証失敗したとき、ハッシュ検証成功したソフトの状態がおかしくなる不具合を修正
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.cs
index 3407709..a66d9a6 100644 (file)
@@ -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,6 +28,7 @@ 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
@@ -47,8 +50,10 @@ namespace AppliStation
                                }\r
                                detailBox.AppendText("\r\n");\r
                        }\r
-                       if (pkg is InstalledPackage) {\r
-                               InstalledPackage iPkg = (InstalledPackage) pkg;\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
@@ -74,40 +79,53 @@ namespace AppliStation
                \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
-                       Package[] selectedPkgs = NaGet.Utils.IEnumerable2Array<Package>(GetSelectedPackages<Package>());\r
-                       foreach (Package pkg in selectedPkgs) {\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
-                       informationToolStripDropDownButton.Visible = (selectedPkgs.Length == 1);\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
                        // detailBoxのメッセージ設定\r
-                       detailBox.Clear();\r
-                       switch (selectedPkgs.Length) {\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(selectedPkgs[0]);\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}個はインストール可能)", installPkgCount+uninstallPkgCount, uninstallPkgCount, installPkgCount);\r
+                                               string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", pkgCount, uninstallPkgCount, installPkgCount);\r
                                        break;\r
                        }\r
                        \r
@@ -121,65 +139,17 @@ namespace AppliStation
 \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
-               private void buildInstalledDirectoryMenuItemStripChildren(InstalledPackage pkg)\r
-               {\r
-                       //installedDirectoryStripMenuItem.BaseFolderPath = pkg.UninstallInfo.InstallLocation;\r
-                       installedDirectoryStripMenuItem.BaseFolderPath = pkg.discoverInstalledLocation();\r
-               }\r
-               \r
-               #region packageListViewのSort関連\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
-                       // ソート対象列の色付け\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
-               #endregion\r
-               \r
                void Form_OnLoad(object sender, EventArgs e)\r
                {\r
                        packageListViewImageList.Images.Add("installed", Icon.ExtractAssociatedIcon(Application.ExecutablePath));\r
@@ -188,37 +158,22 @@ namespace AppliStation
                        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
                #region PackageFilter関連\r
                \r
-               private enum PackageFilterIndex : int\r
-               {\r
-                       All = 0,\r
-                       NotInstalled = 1,\r
-                       InstalledAS = 2,\r
-                       InstalledSys = 3,\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
-               \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
@@ -228,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
@@ -243,73 +198,21 @@ 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
                        searchTextBox.FireTextChangedTrigger();\r
-                       PackageListViewUpdate();\r
                }\r
                \r
                #endregion\r
                \r
-               void PackageListViewUpdate()\r
-               {\r
-                       this.packageListView.Items.Clear();\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
-                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) {\r
-                                       if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // インストール可能\r
-                                               bool notinstalled = (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) == null&&\r
-                                                    pkgListsMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) == null);\r
-                                               if (currentPackageFilter == PackageFilterIndex.NotInstalled && ! notinstalled) {\r
-                                                       continue; // インストール済みは次のループへ(未インストールソフト抽出時)\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
-                                               item.ImageKey = (notinstalled)? "available-new" : "available";\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(searchTextBox.Text)) {\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(searchTextBox.Text)) {\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
-                               }\r
-                       }\r
-                       \r
-                       PackageListViewSelectedIndexChanged(packageListView, null);\r
-                       detailBox.Refresh();\r
-                       \r
-                       //this.packageListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);\r
-               }\r
-               \r
                void DetailBoxLinkClicked(object sender, LinkClickedEventArgs e)\r
                {\r
                        if (System.Text.RegularExpressions.Regex.IsMatch(e.LinkText, "^https?://")){\r
@@ -329,7 +232,7 @@ namespace AppliStation
                {\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
+                               NaGet.SubCommands.NaGetUpdate2 tasks = new NaGet.SubCommands.NaGetUpdate2(pkgListsMan, downloadPackageListsFlag);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
@@ -352,6 +255,129 @@ namespace AppliStation
                        UpdatePackageList();\r
                }\r
                \r
+               void SoftCollectionFileImportToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\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 SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\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 OptionToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
                        UserPrefForm userPrefForm = new UserPrefForm();\r
@@ -381,7 +407,7 @@ namespace AppliStation
                \r
                void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e)\r
                {\r
-                       PackageListViewUpdate();\r
+                       packageListView.FilteringKeyword = searchTextBox.Text;\r
                }\r
                \r
                #endregion\r
@@ -390,7 +416,7 @@ namespace AppliStation
                {\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, insts);\r
+                               NaGet.SubCommands.NaGetInstall2 tasks = new NaGet.SubCommands.NaGetInstall2(pkgListsMan, insts);\r
                                prog.SetTaskSet(tasks);\r
                                prog.Refresh();\r
                                prog.StartTaskSet();\r
@@ -403,7 +429,7 @@ namespace AppliStation
                {\r
                        InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(GetSelectedPackages<Package>()) );\r
+                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) );\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
@@ -460,7 +486,7 @@ 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
@@ -509,10 +535,7 @@ namespace AppliStation
                void UninstallToolStripButtonClick(object sender, EventArgs e)\r
                {\r
                        PackageUninstallConfirmForm confirm = new PackageUninstallConfirmForm();\r
-                       foreach (InstalledPackage pkg in GetSelectedPackages<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
@@ -529,26 +552,48 @@ 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 DownloadToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       Installation[] insts = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) );\r
+                       \r
+                       downloadActionInvoke(insts);\r
+                       \r
+                       UpdatePackageList();\r
+               }\r
                \r
-               void WebOfficialToolStripMenuItemClick(object sender, EventArgs e)\r
+               void WebOfficialMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in GetSelectedPackages<Package>()) {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                string linkURL = pkg.Url.Href;\r
                                \r
-                               if (! (pkg == null || string.IsNullOrEmpty(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 GetSelectedPackages<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
@@ -557,107 +602,125 @@ namespace AppliStation
                                } catch (System.ComponentModel.Win32Exception) {\r
                                        MessageBox.Show("Googleを開くのに失敗しました。", "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                                }\r
-\r
-                               break;\r
                        }\r
                }\r
                \r
                void OpenInstalledDirectoryStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (InstalledPackage pkg in GetSelectedPackages<InstalledPackage>()) {\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.discoverInstalledLocation())) {\r
-                                       System.Diagnostics.Process.Start(pkg.discoverInstalledLocation());\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 GetSelectedPackages<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 = 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
-                       // コンテクストメニューから開かれなかった場合はインストール/アンインストールは表示しない\r
-                       bool parentIsPkgListView = (packageListContextMenuStrip.SourceControl == packageListView);\r
-                       // メニューアイテムのインストール/アンインストールの表示はツールストリップに同じ\r
-                       installToolStripMenuItem.Visible = parentIsPkgListView && installToolStripButton.Visible;\r
-                       uninstallToolStripMenuItem.Visible = parentIsPkgListView && uninstallToolStripButton.Visible;\r
-                       \r
-                       // インストールもアンインストールもできない状態ならば、メニューを表示しない\r
-                       if (! (installToolStripButton.Visible || uninstallToolStripButton.Visible)) {\r
-                               e.Cancel = true;\r
-                               return;\r
-                       }\r
-                       \r
-                       // 選択パッケージが1つのとき\r
                        bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
+                       \r
                        if (selectionIsOnlyOne) {\r
-                               Package pkg = GetSelectedPackage<Package>();\r
-                               bool isInstalledPackage = pkg is InstalledPackage;\r
-                               \r
-                               webResourcesToolStripMenuItem.Text = string.Format(\r
-                                       webResourcesToolStripMenuItem.Tag.ToString(),\r
-                                       pkg.Name.Replace("&", "&&")); // pkg.Nameに&が含まれているときはエンコード\r
-                               webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
-                               // webGoogleSearchToolStripMenuItem always active.\r
+                               Package pkg = packageListView.SelectedPackage;\r
+                               InstalledPackage iPkg = pkg as InstalledPackage;\r
                                \r
-                               if (isInstalledPackage) {\r
-                                       bool installedDirectoryStripMenuItemVisible = \r
+                               // インストール済みパッケージのとき\r
+                               if (iPkg != null) {\r
+                                       bool launcherMenuItemVisible = \r
                                                (pkg.Type == InstallerType.ARCHIVE) ||\r
                                                (pkg.Type == InstallerType.ITSELF) ||\r
-                                               Directory.Exists(((InstalledPackage) pkg).discoverInstalledLocation());\r
+                                               Directory.Exists(iPkg.DiscoverInstalledLocation());\r
                                        \r
-                                       installedDirectoryStripMenuItem.Visible = installedDirectoryStripMenuItemVisible;\r
-                                       if (installedDirectoryStripMenuItemVisible) {\r
-                                               buildInstalledDirectoryMenuItemStripChildren((InstalledPackage) pkg);\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
-                       packageListContextMenuStripSeparator.Visible = parentIsPkgListView && selectionIsOnlyOne;\r
-                       webResourcesToolStripMenuItem.Visible = selectionIsOnlyOne;\r
-                       if (! selectionIsOnlyOne) installedDirectoryStripMenuItem.Visible = false;\r
-                       propertiesToolStripMenuItem.Visible = selectionIsOnlyOne;\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) {\r
-                               Package avaiablePkg = avaiablePkgList.GetPackageForName(pkg.Name);\r
-                               \r
-                               if (avaiablePkg != 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
+                       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
-                       List<Package> pkgs;\r
-                       VersionComparetor verComp = new VersionComparetor();\r
-                       PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\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 = NaGet.Utils.MeargeList(\r
-                               getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp),\r
-                               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
@@ -697,29 +760,8 @@ namespace AppliStation
                public void UpdatePackageList()\r
                {\r
                        pkgListsMan.LoadPackageLists();\r
-                       this.PackageListViewUpdate();\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストールするよう選択されたパッケージの配列\r
-               /// </summary>\r
-               public IEnumerable<TPackage> GetSelectedPackages<TPackage>() where TPackage : Package\r
-               {\r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               yield return (TPackage) item.Tag;\r
-                       }\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストールするよう選択されたパッケージをひとつ返す。\r
-               /// </summary>\r
-               /// <returns>選択されたパッケージ(選択されていないときはnull)</returns>\r
-               public TPackage GetSelectedPackage<TPackage>() where TPackage : Package\r
-               {\r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               return (TPackage) item.Tag;\r
-                       }\r
-                       return null;\r
+                       packageListView.UpdateItems();\r
+                       updateSelectedPackages();\r
                }\r
                \r
                /// <summary>\r
@@ -738,6 +780,47 @@ namespace AppliStation
                                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
+                       \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
 }\r