OSDN Git Service

na-get-lib,パフォーマンスチューニングなど(動作変更なし)
[applistation/AppliStation.git] / AppliStation / InstallationConfirmForm.cs
index 63aa10a..3b7ed56 100644 (file)
@@ -12,19 +12,35 @@ namespace AppliStation
        /// </summary>\r
        public partial class InstallationConfirmForm : Form\r
        {\r
-               private Installation[] requiredInstallations = null;\r
-               \r
                private Installation[] selectedInstallations = null;\r
                \r
+               private Installation[] updateInstallations = null;\r
+               \r
+               private Installation[] requiredInstallations = null;\r
+               \r
                private PackageListsManager pkgListMan;\r
 \r
                public IEnumerable<Installation> Installations {\r
                        get {\r
-                               return NaGet.Utils.MeargeEnumerable<Installation>(requiredInstallations, selectedInstallations);\r
+                               return NaGet.Utils.MergeEnumerable<Installation>(requiredInstallations, selectedInstallations);\r
                        }\r
                        set {\r
+                               List<Installation> selectedInstList = new List<Installation>();\r
+                               List<Installation> updateInstList = new List<Installation>();\r
+                               \r
                                requiredInstallations = null;\r
-                               selectedInstallations = NaGet.Utils.IEnumerable2Array<Installation>(value);\r
+                               foreach (Installation inst in value) {\r
+                                       Package instPkg = pkgListMan.InstalledPkgList.GetPackageForName(inst.InstalledPackage.Name) ??\r
+                                               pkgListMan.SystemInstalledPkgList.GetPackageForName(inst.InstalledPackage.Name);\r
+                                       \r
+                                       if (instPkg != null) {\r
+                                               updateInstList.Add(inst);\r
+                                       } else {\r
+                                               selectedInstList.Add(inst);\r
+                                       }\r
+                               }\r
+                               selectedInstallations = selectedInstList.ToArray();\r
+                               updateInstallations = updateInstList.ToArray();\r
                                \r
                                updateInstsListView();\r
                        }\r
@@ -57,15 +73,22 @@ namespace AppliStation
                        AppliStation.Util.NativeMethods.ListView_SetDoubleBuffer(instsListView, true);\r
                }\r
                \r
+               #region インストールリスト表示処理部\r
+               \r
+               #region インストールリストの反映\r
+               \r
                /// <summary>\r
                /// インストールリストを更新したなどで、リストの表示を更新する\r
                /// </summary>\r
                private void updateInstsListView()\r
                {\r
-                       instsListView.Items.Clear();\r
-\r
-                       updateInstsListViewPerGroup(requiredInstallations, instsListView.Groups["requires"], true);\r
-                       updateInstsListViewPerGroup(selectedInstallations, instsListView.Groups["install"], false);\r
+                       if (instsListView.Items.Count > 0) {\r
+                               instsListView.Items.Clear();\r
+                       }\r
+                       \r
+                       addInstsListItemPerGroup(requiredInstallations, instsListView.Groups["requires"], true);\r
+                       addInstsListItemPerGroup(selectedInstallations, instsListView.Groups["install"], false);\r
+                       addInstsListItemPerGroup(updateInstallations, instsListView.Groups["update"], false);\r
                        \r
                        InstsListViewItemChecked(instsListView, null);\r
                        instsListView.Refresh();\r
@@ -77,11 +100,9 @@ namespace AppliStation
                /// <param name="insts">インストールリスト</param>\r
                /// <param name="group">対象のグループ</param>\r
                /// <param name="firstAppend">先頭に追加するか</param>\r
-               private void updateInstsListViewPerGroup(IEnumerable<Installation> insts, ListViewGroup group, bool firstAppend)\r
+               private void addInstsListItemPerGroup(IEnumerable<Installation> insts, ListViewGroup group, bool firstAppend)\r
                {\r
                        // まず所属グループのアイテムをすべて削除する\r
-                       group.Items.Clear();\r
-                       \r
                        if (insts == null) return;\r
                        \r
                        List<ListViewItem> itemsToAdd = new List<ListViewItem>();\r
@@ -91,6 +112,8 @@ namespace AppliStation
                                string[] itemData = new string[instsListView.Columns.Count];\r
                                itemData[nameColumnHeader.Index] = pkg.Name;\r
                                \r
+                               inst.Silent = true; // silent install as possible!\r
+                               \r
                                Package curPkg = null;\r
                                if (pkgListMan != null) {       \r
                                        curPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) ??\r
@@ -99,6 +122,7 @@ namespace AppliStation
                                itemData[versionColumnHeader.Index]        = pkg.Version;\r
                                itemData[currentVersionColumnHeader.Index] = (curPkg != null)? curPkg.Version : "-";\r
                                // itemData[silentInstColumnHeader.Index] の設定は instViewUpdateSilentInstallView で\r
+                               itemData[pkgListNameColumnHeader.Index]    = pkg.PackageListName;\r
                                \r
                                ListViewItem item = new ListViewItem(itemData);\r
                                item.Tag = inst;\r
@@ -118,6 +142,8 @@ namespace AppliStation
                                instsListView.Items.AddRange(itemsToAdd.ToArray());\r
                        }\r
                }\r
+\r
+               #endregion\r
                \r
                /// <summary>\r
                /// アイテムのサイレントインストール部分の表示の更新を行う。\r
@@ -176,11 +202,18 @@ namespace AppliStation
                \r
                #endregion\r
                \r
+               #endregion\r
+               \r
                void InstsListViewItemChecked(object sender, ItemCheckedEventArgs e)\r
                {\r
                        System.Windows.Forms.ListView.CheckedListViewItemCollection checkeds = instsListView.CheckedItems;\r
                        \r
-                       okButton.Enabled = checkeds != null && checkeds.Count > 0;\r
+                       runasCheckBox.Checked = GetShouldUseRunas();\r
+                       updateUseRunas();\r
+                                               \r
+                       okButton.Enabled = (checkeds != null) && (checkeds.Count > 0);\r
+                       \r
+                       checkUnselectedDependencies();\r
                }\r
                                \r
                void InstsListViewContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
@@ -238,6 +271,69 @@ namespace AppliStation
                        }\r
                        instsListView.Refresh();\r
                }\r
+\r
+               void InstallationConfirmFormShown(object sender, EventArgs e)\r
+               {\r
+                       if (InvokeRequired) {\r
+                               Invoke(new MethodInvoker(resolveDependecies));\r
+                       } else {\r
+                               resolveDependecies();\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 依存関係を解決する\r
+               /// </summary>\r
+               private void resolveDependecies()\r
+               {\r
+                       if (requiredInstallations == null) {\r
+                               Installation[] resolved, dependencies;\r
+                               \r
+                               DependeciesResolver.ResolveInstallations(\r
+                                       selectedInstallations,\r
+                                       pkgListMan,\r
+                                       out resolved,\r
+                                       out dependencies);\r
+                               \r
+                               requiredInstallations = dependencies;\r
+                               \r
+                               addInstsListItemPerGroup(requiredInstallations, instsListView.Groups["requires"], true);\r
+                               \r
+                               InstsListViewItemChecked(instsListView, null);\r
+                               instsListView.Refresh();\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 依存関係を確認してGUIに反映させる。\r
+               /// 選択されていないが依存関係上必要なソフトを探し出す。\r
+               /// </summary>\r
+               /// <returns>選択されていないが依存関係上必要なソフトの個数(何もない場合はゼロ)</returns>\r
+               private uint checkUnselectedDependencies()\r
+               {\r
+                       uint retVal = 0;\r
+                       \r
+                       List<Package> instPkgs = new List<Package>();\r
+                       foreach (Installation inst in Installations) {\r
+                               instPkgs.Add(inst.InstalledPackage);\r
+                       }\r
+                       \r
+                       List<Package> pkg = new List<Package>();\r
+                       foreach (Installation inst in DependeciesResolver.CreateRequiresInstallations(CheckedInstallations, pkgListMan, instPkgs)) {\r
+                               pkg.Add(inst.InstalledPackage);\r
+                       }\r
+                       \r
+                       foreach (ListViewItem item in instsListView.Items) {\r
+                               if ((pkg.IndexOf(((Installation) item.Tag).InstalledPackage) >= 0) && !item.Checked) {\r
+                                       item.ForeColor = Color.Red;\r
+                                       retVal++;\r
+                               } else {\r
+                                       item.ForeColor = Color.Empty;\r
+                               }\r
+                       \r
+                       }\r
+                       return retVal;\r
+               }\r
                \r
                /// <summary>\r
                /// インストールするよう選択されたパッケージの配列\r
@@ -305,6 +401,5 @@ namespace AppliStation
                }\r
                \r
                #endregion\r
-               \r
        }\r
 }\r