OSDN Git Service

AppliStation-GUI,無人インストールのGUIの可変。アイコン表示の試作。
[applistation/AppliStation.git] / AppliStation / InstallationConfirmForm.cs
index 5fc8f4b..f8a6356 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
@@ -16,7 +16,7 @@ namespace AppliStation
                private PackageListsManager pkgListMan;\r
                \r
                /// <summary>\r
-               /// \83p\83b\83P\81[\83W\83C\83\93\83X\83g\81[\83\8b\8f\88\97\9d\82Ì\8fW\8d\87\r
+               /// パッケージインストール処理の集合\r
                /// </summary>\r
                public Installation[] Installations {\r
                        get { return installations; }\r
@@ -43,7 +43,7 @@ namespace AppliStation
                        //\r
                        InitializeComponent();\r
                        \r
-                       // \8aÇ\97\9d\8eÒ\8c \8cÀ\82Å\93®\82¢\82Ä\82¢\82é\82È\82ç\82Îrunas\82ª\95K\97v\82É\82Í\82È\82ç\82È\82¢\82Ì\82Å\95\\8e¦\82µ\82È\82¢\r
+                       // 管理者権限で動いているならばrunasが必要にはならないので表示しない\r
                        if (NaGet.Utils.IsAdministrators()) {\r
                                runasCheckBox.Checked = false;\r
                                runasCheckBox.Visible = false;\r
@@ -58,14 +58,24 @@ namespace AppliStation
                                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
-                                               if (curPkg == null) curPkg = pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
+                                               curPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) ??\r
+                                                       pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
                                        }\r
-                                       string curVersion = (curPkg == null)? "-" : curPkg.Version;\r
+                                       itemData[versionColumnHeader.Index]        = pkg.Version;\r
+                                       itemData[currentVersionColumnHeader.Index] = (curPkg != null)? curPkg.Version : "-";\r
+                                       \r
+                                       itemData[silentInstColumnHeader.Index]     = \r
+                                               (inst.SupportsSilentOnly)? "無人インストールのみサポート" :\r
+                                               (inst.Silent)? "無人インストール" :\r
+                                               (inst.IsSupportsSilent)? "マニュアルでインストール" :\r
+                                               "マニュアルでしかインストールできません";\r
                                        \r
-                                       ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, curVersion});\r
+                                       ListViewItem item = new ListViewItem(itemData);\r
                                        item.Tag = inst;\r
                                        item.ToolTipText = pkg.Summary;\r
                                        item.Checked = true;\r
@@ -78,6 +88,49 @@ namespace AppliStation
                        instsListView.Refresh();\r
                }\r
                \r
+               #region instsListViewのオーナードドロー関連\r
+               \r
+               void InstsListViewDrawSubItem(object sender, DrawListViewSubItemEventArgs e)\r
+               {\r
+                       if (e.Header == silentInstColumnHeader) {\r
+                               Installation inst = ((Installation) e.Item.Tag);\r
+                               \r
+                               //e.DrawBackground();\r
+                               e.Graphics.Clip.Intersect(e.Bounds);\r
+                               \r
+                               if (inst.Silent) {\r
+                                       AppliStation.Util.GUIUtils.Graphics_DrawCenterImage(\r
+                                               e.Graphics,\r
+                                               instListViewSilentInstallImageList.Images[0],\r
+                                               e.Bounds, null);\r
+                               } else if (inst.IsSupportsSilent) {\r
+                                       AppliStation.Util.GUIUtils.Graphics_DrawCenterImage(\r
+                                               e.Graphics,\r
+                                               instListViewSilentInstallImageList.Images[0],\r
+                                               e.Bounds,\r
+                                               AppliStation.Util.GUIUtils.GetImageAttributeToGrayOut(0.5f));\r
+                               }\r
+                       } else {\r
+                               e.DrawDefault = true;\r
+                       }\r
+               }\r
+               \r
+               void InstsListViewDrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)\r
+               {\r
+                       if (e.Header == silentInstColumnHeader) {\r
+                               e.DrawBackground();\r
+                               e.Graphics.Clip.Intersect(e.Bounds);\r
+                               AppliStation.Util.GUIUtils.Graphics_DrawCenterImage(\r
+                                       e.Graphics,\r
+                                       instListViewSilentInstallImageList.Images[0],\r
+                                       e.Bounds, null);\r
+                       } else {\r
+                               e.DrawDefault = true;\r
+                       }\r
+               }\r
+               \r
+               #endregion\r
+               \r
                void InstsListViewItemChecked(object sender, ItemCheckedEventArgs e)\r
                {\r
                        System.Windows.Forms.ListView.CheckedListViewItemCollection checkeds = instsListView.CheckedItems;\r
@@ -109,7 +162,7 @@ namespace AppliStation
                        }\r
                        AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(instsListView, e.Column, order);\r
                        \r
-                       // \83\\81[\83g\91Î\8fÛ\97ñ\82Ì\90F\95t\82¯\r
+                       // ソート対象列の色付け\r
                        try {\r
                                // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
                                AppliStation.Util.NativeMethods.SendMessage(instsListView.Handle, 0x1000+140, (uint) e.Column, 0);\r
@@ -120,9 +173,42 @@ namespace AppliStation
                                \r
                void InstsListViewContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
                {\r
-                       System.Windows.Forms.ListView.CheckedIndexCollection coll = instsListView.CheckedIndices;\r
-                       selectAllPackagesStripMenuItem.Enabled = coll.Count < instsListView.Items.Count;\r
-                       unselectAllPackagesStripMenuItem.Enabled = coll.Count > 0;\r
+                       System.Windows.Forms.ListView.CheckedIndexCollection  chkIdxes = instsListView.CheckedIndices;\r
+                       System.Windows.Forms.ListView.SelectedIndexCollection selIdxes = instsListView.SelectedIndices;\r
+                       \r
+                       silentInstallStripMenuItem.Visible = selIdxes.Count > 0;\r
+                       if (selIdxes.Count > 0) {\r
+                               Installation inst0th = ((Installation) instsListView.Items[selIdxes[0]].Tag);\r
+                               bool bChecked = inst0th.Silent;\r
+                               bool bEnabled = (inst0th.IsSupportsSilent && (!inst0th.SupportsSilentOnly));\r
+                               silentInstallStripMenuItem.Checked = bChecked;\r
+                               silentInstallStripMenuItem.Enabled = bEnabled;\r
+                               \r
+                               for (int i = 1; i < selIdxes.Count; i++) {\r
+                                       Installation inst = ((Installation) instsListView.Items[selIdxes[i]].Tag);\r
+                                       \r
+                                       if ( (bChecked != inst.Silent) ||\r
+                                           (bEnabled != (inst.IsSupportsSilent && (!inst.SupportsSilentOnly))) ) {\r
+                                               silentInstallStripMenuItem.CheckState = CheckState.Indeterminate;\r
+                                               silentInstallStripMenuItem.Enabled = false;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       instListToolStripSeparator.Visible = selIdxes.Count > 0;\r
+               \r
+                       \r
+                       selectAllInstsStripMenuItem.Enabled = chkIdxes.Count < instsListView.Items.Count;\r
+                       unselectAllInstsStripMenuItem.Enabled = chkIdxes.Count > 0;\r
+               }\r
+               \r
+               void SilentInstallStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       bool silent = ! silentInstallStripMenuItem.Checked;\r
+                       foreach (ListViewItem item in instsListView.CheckedItems) {\r
+                               ((Installation) item.Tag).Silent = silent;\r
+                       }\r
+                       updateInstsListView();\r
                }\r
                                \r
                void SelectAllInstsStripMenuItemClick(object sender, EventArgs e)\r
@@ -142,7 +228,7 @@ namespace AppliStation
                }\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
+               /// インストールするよう選択されたパッケージの配列\r
                /// </summary>\r
                public Installation[] CheckedInstallations {\r
                        get {\r
@@ -154,10 +240,10 @@ namespace AppliStation
                        }\r
                }\r
                \r
-               #region runas\8aÖ\98A\r
+               #region runas関連\r
                \r
                /// <summary>\r
-               /// runas\82Å\8eÀ\8ds\82·\82é\82©\94Û\82©\r
+               /// runasで実行するか否か\r
                /// </summary>\r
                public bool UseRunas {\r
                        set {\r
@@ -171,23 +257,23 @@ namespace AppliStation
                }\r
                \r
                /// <summary>\r
-               /// \91I\91ð\82³\82ê\82½\83p\83b\83P\81[\83W\82ð\92²\8d¸\82µ\82Ä\81ARunas\82ð\8eg\82¤\82×\82«\82©\82¢\82È\82©\82ð\95Ô\82·\r
+               /// 選択されたパッケージを調査して、Runasを使うべきかいなかを返す\r
                /// </summary>\r
                public bool GetShouldUseRunas()\r
                {\r
                        if (NaGet.Utils.IsAdministrators()) {\r
-                               // \8aÇ\97\9d\8eÒ\8c \8cÀ\82Å\93®\82¢\82Ä\82¢\82é\8fê\8d\87\82Í\95s\97v\r
+                               // 管理者権限で動いている場合は不要\r
                                return false;   \r
                        } else if (NaGet.Utils.IsUACEnabled()) {\r
-                               // UAC\82ª\93K\97p\82³\82ê\82Ä\82¢\82é\8fê\8d\87\82Í\95W\8f\80\82Å\82Í\95s\97v\82Æ\82·\82é\r
+                               // UACが適用されている場合は標準では不要とする\r
                                return false;   \r
                        }\r
                        \r
-                       // \82Ð\82Æ\82Â\82Å\82àPC\83^\81[\83Q\83b\83g\82È\83C\83\93\83X\83g\81[\83\89\82ª\82 \82ê\82Î\95K\97v\82Æ\82·\82é\r
+                       // ひとつでもPCターゲットなインストーラがあれば必要とする\r
                        foreach (Installation inst in CheckedInstallations) {\r
                                if (inst.TargetPC) return true;\r
                        }\r
-                       // \82»\82ê\88È\8aO\82Í\95s\97v\r
+                       // それ以外は不要\r
                        return false;\r
                }\r
                \r
@@ -207,7 +293,6 @@ namespace AppliStation
                }\r
                \r
                #endregion\r
-\r
-\r
+               \r
        }\r
 }\r