OSDN Git Service

AppliStation-GUI,インストールダイアログでの表示処理等の整理
authorttp <ttp@users.sourceforge.jp>
Sat, 13 Sep 2008 03:39:37 +0000 (03:39 +0000)
committerttp <ttp@users.sourceforge.jp>
Sat, 13 Sep 2008 03:39:37 +0000 (03:39 +0000)
 * 依存用のインストールリストを入れる配列を作っておいた。

git-svn-id: http://localhost/svn/AppliStation/trunk@973 34ed2c89-c49f-4a4b-abdb-c318350108cf

AppliStation/InstallationConfirmForm.cs
AppliStation/PackageListViewForm.cs
na-get-lib/NaGet.Packages/PackageListsManager.cs
na-get-lib/NaGet/Utils.cs

index 8414b9b..6cac28b 100644 (file)
@@ -1,4 +1,5 @@
 using System;\r
 using System;\r
+using System.Collections.Generic;\r
 using System.Drawing;\r
 using System.Windows.Forms;\r
 using NaGet.Packages;\r
 using System.Drawing;\r
 using System.Windows.Forms;\r
 using NaGet.Packages;\r
@@ -11,22 +12,19 @@ namespace AppliStation
        /// </summary>\r
        public partial class InstallationConfirmForm : Form\r
        {\r
        /// </summary>\r
        public partial class InstallationConfirmForm : Form\r
        {\r
-               private Installation[] installations;\r
+               private Installation[] requiredInstallations = null;\r
                \r
                \r
-               private PackageListsManager pkgListMan;\r
+               private Installation[] selectedInstallations = null;\r
                \r
                \r
-               /// <summary>\r
-               /// パッケージインストール処理の集合\r
-               /// </summary>\r
-               public Installation[] Installations {\r
-                       get { return installations; }\r
+               private PackageListsManager pkgListMan;\r
+\r
+               public IEnumerable<Installation> Installations {\r
+                       get {\r
+                               return NaGet.Utils.MeargeEnumerable<Installation>(requiredInstallations, selectedInstallations);\r
+                       }\r
                        set {\r
                        set {\r
-                               installations = value;\r
-                               \r
-                               // 基本はサイレントインストールを行うこととする\r
-                               foreach (Installation inst in installations) {\r
-                                       inst.Silent = inst.IsSupportsSilent;\r
-                               }\r
+                               requiredInstallations = null;\r
+                               selectedInstallations = NaGet.Utils.IEnumerable2Array<Installation>(value);\r
                                \r
                                updateInstsListView();\r
                        }\r
                                \r
                                updateInstsListView();\r
                        }\r
@@ -66,36 +64,74 @@ namespace AppliStation
                {\r
                        instsListView.Items.Clear();\r
                        \r
                {\r
                        instsListView.Items.Clear();\r
                        \r
-                       if (installations != null) {\r
-                               foreach (Installation inst in installations) {\r
-                                       Package pkg = inst.InstalledPackage;\r
-                                       \r
-                                       string[] itemData = new string[instsListView.Columns.Count];\r
-                                       itemData[nameColumnHeader.Index] = pkg.Name;\r
-                                       \r
-                                       Package curPkg = null;\r
-                                       if (pkgListMan != null) {       \r
-                                               curPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) ??\r
-                                                       pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
-                                       }\r
-                                       itemData[versionColumnHeader.Index]        = pkg.Version;\r
-                                       itemData[currentVersionColumnHeader.Index] = (curPkg != null)? curPkg.Version : "-";\r
-                                       // itemData[silentInstColumnHeader.Index] の設定は instViewUpdateSilentInstallView で\r
-                                       \r
-                                       ListViewItem item = new ListViewItem(itemData);\r
-                                       item.Tag = inst;\r
-                                       item.ToolTipText = pkg.Summary;\r
-                                       item.Checked = true;\r
-                                       item.Group = instsListView.Groups["install"];\r
-                                       instViewUpdateSilentInstallView(item);\r
-                                       \r
-                                       instsListView.Items.Add(item);\r
-                               }\r
-                       }\r
+                       updateInstsListViewPerGroup(selectedInstallations, instsListView.Groups["install"]);\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
                        \r
                        InstsListViewItemChecked(instsListView, null);\r
                        instsListView.Refresh();\r
                }\r
                        \r
                        InstsListViewItemChecked(instsListView, null);\r
                        instsListView.Refresh();\r
                }\r
+\r
+               /// <summary>\r
+               /// 指定したグループのリストの表示を更新する。\r
+               /// </summary>\r
+               /// <param name="insts">インストールリスト</param>\r
+               /// <param name="group">対象のグループ</param>\r
+               private void updateInstsListViewPerGroup(IEnumerable<Installation> insts, ListViewGroup group)\r
+               {\r
+                       // まず所属グループのアイテムをすべて削除する\r
+                       group.Items.Clear();\r
+                       \r
+                       if (insts == null) return;\r
+                       \r
+                       foreach (Installation inst in insts) {\r
+                               Package pkg = inst.InstalledPackage;\r
+                               \r
+                               string[] itemData = new string[instsListView.Columns.Count];\r
+                               itemData[nameColumnHeader.Index] = pkg.Name;\r
+                               \r
+                               Package curPkg = null;\r
+                               if (pkgListMan != null) {       \r
+                                       curPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) ??\r
+                                               pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
+                               }\r
+                               itemData[versionColumnHeader.Index]        = pkg.Version;\r
+                               itemData[currentVersionColumnHeader.Index] = (curPkg != null)? curPkg.Version : "-";\r
+                               // itemData[silentInstColumnHeader.Index] の設定は instViewUpdateSilentInstallView で\r
+                               \r
+                               ListViewItem item = new ListViewItem(itemData);\r
+                               item.Tag = inst;\r
+                               item.ToolTipText = pkg.Summary;\r
+                               item.Checked = true;\r
+                               item.Group = group;\r
+                               instViewUpdateSilentInstallView(item);\r
+                               \r
+                               instsListView.Items.Add(item);\r
+                       }\r
+               }\r
                \r
                /// <summary>\r
                /// アイテムのサイレントインストール部分の表示の更新を行う。\r
                \r
                /// <summary>\r
                /// アイテムのサイレントインストール部分の表示の更新を行う。\r
@@ -222,7 +258,7 @@ namespace AppliStation
                /// </summary>\r
                public Installation[] CheckedInstallations {\r
                        get {\r
                /// </summary>\r
                public Installation[] CheckedInstallations {\r
                        get {\r
-                               System.Collections.Generic.List<Installation> insts = new System.Collections.Generic.List<Installation>();\r
+                               List<Installation> insts = new List<Installation>();\r
                                foreach (ListViewItem item in instsListView.CheckedItems) {\r
                                        insts.Add((Installation) item.Tag);\r
                                }\r
                                foreach (ListViewItem item in instsListView.CheckedItems) {\r
                                        insts.Add((Installation) item.Tag);\r
                                }\r
index 13f03da..7468b75 100644 (file)
@@ -71,7 +71,7 @@ namespace AppliStation
                        uint uninstallPkgCount = 0;\r
                        bool installBtnEnabled, uninstallBtnEnabled;\r
                        \r
                        uint uninstallPkgCount = 0;\r
                        bool installBtnEnabled, uninstallBtnEnabled;\r
                        \r
-                       Package[] selectedPkgs = SelectedPackages<Package>();\r
+                       Package[] selectedPkgs = NaGet.Utils.IEnumerable2Array<Package>(SelectedPackages<Package>());\r
                        foreach (Package pkg in selectedPkgs) {\r
                                if (pkg is InstalledPackage) {\r
                                        uninstallPkgCount ++;\r
                        foreach (Package pkg in selectedPkgs) {\r
                                if (pkg is InstalledPackage) {\r
                                        uninstallPkgCount ++;\r
@@ -367,7 +367,7 @@ namespace AppliStation
                {\r
                        InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
                {\r
                        InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Installations = Installation.ConvertInstallations(SelectedPackages<Package>());\r
+                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(SelectedPackages<Package>()) );\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
@@ -603,12 +603,14 @@ namespace AppliStation
                \r
                void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
                {\r
                \r
                void UpgradeToolStripButtonClick(object sender, EventArgs e)\r
                {\r
-                       List<Package> pkgs = new List<Package>();\r
+                       List<Package> pkgs;\r
                        VersionComparetor verComp = new VersionComparetor();\r
                        PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
                        \r
                        VersionComparetor verComp = new VersionComparetor();\r
                        PackageList<Package> avaiablePackageList = pkgListsMan.AvailablePkgList;\r
                        \r
-                       pkgs.AddRange(getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp));\r
-                       pkgs.AddRange(getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp));\r
+                       pkgs = NaGet.Utils.MeargeList(\r
+                               getUpdatedPackages(pkgListsMan.InstalledPkgList, avaiablePackageList, verComp),\r
+                               getUpdatedPackages(pkgListsMan.SystemInstalledPkgList, avaiablePackageList, verComp)\r
+                       );\r
                        \r
                        if (pkgs.Count <= 0) {\r
                                MessageBox.Show(this, "更新されたソフトはありません", "ソフトの更新");\r
                        \r
                        if (pkgs.Count <= 0) {\r
                                MessageBox.Show(this, "更新されたソフトはありません", "ソフトの更新");\r
@@ -642,14 +644,14 @@ namespace AppliStation
                /// <summary>\r
                /// インストールするよう選択されたパッケージの配列\r
                /// </summary>\r
                /// <summary>\r
                /// インストールするよう選択されたパッケージの配列\r
                /// </summary>\r
-               public TPackage[] SelectedPackages<TPackage>() where TPackage : Package\r
+               public IEnumerable<TPackage> SelectedPackages<TPackage>() where TPackage : Package\r
                {\r
                        List<TPackage> pkgs = new List<TPackage>();\r
                        foreach (ListViewItem item in packageListView.SelectedItems) {\r
                                pkgs.Add((TPackage) item.Tag);\r
                        }\r
                        \r
                {\r
                        List<TPackage> pkgs = new List<TPackage>();\r
                        foreach (ListViewItem item in packageListView.SelectedItems) {\r
                                pkgs.Add((TPackage) item.Tag);\r
                        }\r
                        \r
-                       return pkgs.ToArray();\r
+                       return pkgs;\r
                }\r
                \r
                /// <summary>\r
                }\r
                \r
                /// <summary>\r
index 4136544..af10c01 100644 (file)
@@ -199,12 +199,10 @@ namespace NaGet.Packages
                /// <returns>全てのインストールされたパッケージのイテレータ</returns>\r
                public IEnumerable<InstalledPackage> GetAllInstalledPackages()\r
                {\r
                /// <returns>全てのインストールされたパッケージのイテレータ</returns>\r
                public IEnumerable<InstalledPackage> GetAllInstalledPackages()\r
                {\r
-                       foreach (InstalledPackage pkg in installedPkgList) {\r
-                               yield return pkg;\r
-                       }\r
-                       foreach (InstalledPackage pkg in systemInstalledPkgList) {\r
-                               yield return pkg;\r
-                       }\r
+                       return NaGet.Utils.MeargeEnumerable<InstalledPackage>(\r
+                               installedPkgList.GetEnumerator(),\r
+                               systemInstalledPkgList.GetEnumerator()\r
+                       );\r
                }\r
                \r
                /// <summary>\r
                }\r
                \r
                /// <summary>\r
@@ -213,12 +211,10 @@ namespace NaGet.Packages
                /// <returns>パッケージのイテレータ</returns>\r
                public IEnumerable<Package> GetAllPackages()\r
                {\r
                /// <returns>パッケージのイテレータ</returns>\r
                public IEnumerable<Package> GetAllPackages()\r
                {\r
-                       foreach (Package pkg in availablePkgList) {\r
-                               yield return pkg;\r
-                       }\r
-                       foreach (Package pkg in GetAllInstalledPackages()) {\r
-                               yield return pkg;\r
-                       }\r
+                       return NaGet.Utils.MeargeEnumerable<Package>(\r
+                               availablePkgList.GetEnumerator(),\r
+                               (IEnumerator<Package>) GetAllInstalledPackages().GetEnumerator()\r
+                       );\r
                }\r
                \r
                /// <summary>\r
                }\r
                \r
                /// <summary>\r
index 819d741..1bb3eb5 100644 (file)
@@ -1,4 +1,5 @@
 using System;\r
 using System;\r
+using System.Collections.Generic;\r
 using System.IO;\r
 using System.Text;\r
 using System.Globalization;\r
 using System.IO;\r
 using System.Text;\r
 using System.Globalization;\r
@@ -22,6 +23,8 @@ namespace NaGet
                {\r
                }\r
                \r
                {\r
                }\r
                \r
+               #region 汎用的なオブジェクト操作メソッド\r
+               \r
                /// <summary>\r
                /// オブジェクトのフィールドをコピーしてクローン化する\r
                /// </summary>\r
                /// <summary>\r
                /// オブジェクトのフィールドをコピーしてクローン化する\r
                /// </summary>\r
@@ -37,6 +40,75 @@ namespace NaGet
                }\r
                \r
                /// <summary>\r
                }\r
                \r
                /// <summary>\r
+               /// イテレータを結合して、返す\r
+               /// </summary>\r
+               /// <param name="enus">元となる複数のイテレータ</param>\r
+               /// <returns>結合されたイテレータ</returns>\r
+               public static IEnumerable<T> MeargeEnumerable<T>(params IEnumerable<T>[] enus)\r
+               {\r
+                       foreach (IEnumerable<T> enu in enus) {\r
+                               if (enu == null) continue;\r
+                               \r
+                               foreach (T elem in enu) {\r
+                                       yield return elem;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// イテレータを結合して、返す\r
+               /// </summary>\r
+               /// <param name="enus">元となる複数のイテレータ</param>\r
+               /// <returns>結合されたイテレータ</returns>\r
+               public static IEnumerable<T> MeargeEnumerable<T>(params IEnumerator<T>[] enus)\r
+               {\r
+                       foreach (IEnumerator<T> enu in enus) {\r
+                               if (enu == null) continue;\r
+                               \r
+                               try {\r
+                                       while (enu.MoveNext()) {\r
+                                               yield return enu.Current;\r
+                                       }\r
+                               } finally {\r
+                                       enu.Dispose();\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// イテレータを結合して、Listとして返す\r
+               /// </summary>\r
+               /// <param name="enus">元となる複数のイテレータ</param>\r
+               /// <returns>結合されたイテレータ</returns>\r
+               public static List<T> MeargeList<T>(params IEnumerable<T>[] enus)\r
+               {\r
+                       List<T> list = new List<T>();\r
+                       \r
+                       foreach (IEnumerable<T> enu in enus) {\r
+                               if (enu == null) continue;\r
+                       \r
+                               list.AddRange(enu);\r
+                       }\r
+                       return list;\r
+               }\r
+               \r
+               /// <summary>\r
+               /// イテレータを配列に効率的に変換する\r
+               /// </summary>\r
+               /// <remarks>与えられる型が具体的にわかっているならば、それに特化した手続きをとる方が好ましい</remarks>\r
+               /// <param name="enu">元となるイテレータ</param>\r
+               /// <returns>変換された配列</returns>\r
+               public static T[] IEnumerable2Array<T>(IEnumerable<T> enu) {\r
+                       if (enu is T[]) {\r
+                               return (T[]) enu;\r
+                       } else {\r
+                               return ((enu is List<T>)? ((List<T>)enu):new List<T>(enu)).ToArray();\r
+                       }\r
+               }\r
+               \r
+               #endregion\r
+               \r
+               /// <summary>\r
                /// パス変数に指定のフォルダを追加する\r
                /// </summary>\r
                /// <param name="dir">追加するフォルダ</param>\r
                /// パス変数に指定のフォルダを追加する\r
                /// </summary>\r
                /// <param name="dir">追加するフォルダ</param>\r
@@ -240,7 +312,7 @@ namespace NaGet
                        }\r
 \r
                        string[] pathArray = pattern.Split(Path.DirectorySeparatorChar);\r
                        }\r
 \r
                        string[] pathArray = pattern.Split(Path.DirectorySeparatorChar);\r
-                       System.Collections.Generic.List<string> extended = new System.Collections.Generic.List<string>();\r
+                       List<string> extended = new List<string>();\r
                        try {\r
                                if (pathArray.Length == 1) {\r
                                        extended.AddRange(Directory.GetFiles(baseDir, pathArray[0], SearchOption.TopDirectoryOnly));\r
                        try {\r
                                if (pathArray.Length == 1) {\r
                                        extended.AddRange(Directory.GetFiles(baseDir, pathArray[0], SearchOption.TopDirectoryOnly));\r
@@ -319,7 +391,7 @@ namespace NaGet
                public static string GetDotsRemovedPath(string aPath)\r
                {\r
                        string[] folders = splitPath(aPath);\r
                public static string GetDotsRemovedPath(string aPath)\r
                {\r
                        string[] folders = splitPath(aPath);\r
-                       System.Collections.Generic.List<string> newFolders = new System.Collections.Generic.List<string>();\r
+                       List<string> newFolders = new List<string>();\r
                        \r
                        foreach (string fol in folders) {\r
                                if (fol == ".") {\r
                        \r
                        foreach (string fol in folders) {\r
                                if (fol == ".") {\r