2 using System.Collections.Generic;
\r
3 using System.Drawing;
\r
4 using System.Windows.Forms;
\r
5 using NaGet.Packages;
\r
6 using NaGet.Packages.Install;
\r
8 namespace AppliStation
\r
11 /// Description of PackagesInstallConfirmForm.
\r
13 public partial class InstallationConfirmForm : Form
\r
15 private Installation[] requiredInstallations = null;
\r
17 private Installation[] selectedInstallations = null;
\r
19 private PackageListsManager pkgListMan;
\r
21 public IEnumerable<Installation> Installations {
\r
23 return NaGet.Utils.MeargeEnumerable<Installation>(requiredInstallations, selectedInstallations);
\r
26 requiredInstallations = null;
\r
27 selectedInstallations = NaGet.Utils.IEnumerable2Array<Installation>(value);
\r
29 updateInstsListView();
\r
33 public PackageListsManager PkgListsManager {
\r
34 get { return pkgListMan; }
\r
38 updateInstsListView();
\r
42 public InstallationConfirmForm()
\r
45 // The InitializeComponent() call is required for Windows Forms designer support.
\r
47 InitializeComponent();
\r
49 // 管理者権限で動いているならばrunasが必要にはならないので表示しない
\r
50 if (NaGet.Utils.IsAdministrators()) {
\r
51 runasCheckBox.Checked = false;
\r
52 runasCheckBox.Visible = false;
\r
56 AppliStation.Util.NativeMethods.ListView_EnableVistaExplorerTheme(instsListView);
\r
57 AppliStation.Util.NativeMethods.ListView_SetDoubleBuffer(instsListView, true);
\r
60 #region インストールリスト表示処理部
\r
62 #region インストールリストの反映
\r
65 /// インストールリストを更新したなどで、リストの表示を更新する
\r
67 private void updateInstsListView()
\r
69 instsListView.Items.Clear();
\r
71 addInstsListItemPerGroup(requiredInstallations, instsListView.Groups["requires"], true);
\r
72 addInstsListItemPerGroup(selectedInstallations, instsListView.Groups["install"], false);
\r
74 InstsListViewItemChecked(instsListView, null);
\r
75 instsListView.Refresh();
\r
79 /// 指定したグループのリストの表示を更新する。
\r
81 /// <param name="insts">インストールリスト</param>
\r
82 /// <param name="group">対象のグループ</param>
\r
83 /// <param name="firstAppend">先頭に追加するか</param>
\r
84 private void addInstsListItemPerGroup(IEnumerable<Installation> insts, ListViewGroup group, bool firstAppend)
\r
86 // まず所属グループのアイテムをすべて削除する
\r
87 if (insts == null) return;
\r
89 List<ListViewItem> itemsToAdd = new List<ListViewItem>();
\r
90 foreach (Installation inst in insts) {
\r
91 Package pkg = inst.InstalledPackage;
\r
93 string[] itemData = new string[instsListView.Columns.Count];
\r
94 itemData[nameColumnHeader.Index] = pkg.Name;
\r
96 inst.Silent = true; // silent install as possible!
\r
98 Package curPkg = null;
\r
99 if (pkgListMan != null) {
\r
100 curPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) ??
\r
101 pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);
\r
103 itemData[versionColumnHeader.Index] = pkg.Version;
\r
104 itemData[currentVersionColumnHeader.Index] = (curPkg != null)? curPkg.Version : "-";
\r
105 // itemData[silentInstColumnHeader.Index] の設定は instViewUpdateSilentInstallView で
\r
107 ListViewItem item = new ListViewItem(itemData);
\r
109 item.ToolTipText = pkg.Summary;
\r
110 item.Checked = true;
\r
111 item.Group = group;
\r
112 instViewUpdateSilentInstallView(item);
\r
114 itemsToAdd.Add(item);
\r
118 for (int i = 0; i < itemsToAdd.Count; i++) {
\r
119 instsListView.Items.Insert(i, itemsToAdd[i]);
\r
122 instsListView.Items.AddRange(itemsToAdd.ToArray());
\r
129 /// アイテムのサイレントインストール部分の表示の更新を行う。
\r
131 /// <param name="item">対象のインストーラのリストアイテム</param>
\r
132 private void instViewUpdateSilentInstallView(ListViewItem item)
\r
134 Installation inst = (Installation) item.Tag;
\r
135 item.SubItems[silentInstColumnHeader.Index].Text =
\r
136 (inst.SupportsSilentOnly)? "サイレントインストールのみサポート" :
\r
137 (inst.Silent)? "サイレントインストール" :
\r
138 (inst.IsSupportsSilent)? "手動でインストール" :
\r
139 "サイレントインストールできませんので、手動でインストールします";
\r
142 #region instsListViewのオーナードドロー関連
\r
144 void InstsListViewDrawSubItem(object sender, DrawListViewSubItemEventArgs e)
\r
146 if (e.Header == silentInstColumnHeader) {
\r
147 Installation inst = ((Installation) e.Item.Tag);
\r
149 //e.DrawBackground();
\r
150 e.Graphics.Clip.Intersect(e.Bounds);
\r
153 AppliStation.Util.GUIUtils.Graphics_DrawCenterImage(
\r
155 instListViewSilentInstallImageList.Images[0],
\r
157 } else if (inst.IsSupportsSilent) {
\r
158 AppliStation.Util.GUIUtils.Graphics_DrawCenterImage(
\r
160 instListViewSilentInstallImageList.Images[0],
\r
162 AppliStation.Util.GUIUtils.GetImageAttributeToGrayOut(0.5f));
\r
165 e.DrawDefault = true;
\r
169 void InstsListViewDrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
\r
171 if (e.Header == silentInstColumnHeader) {
\r
172 e.DrawBackground();
\r
173 e.Graphics.Clip.Intersect(e.Bounds);
\r
174 AppliStation.Util.GUIUtils.Graphics_DrawCenterImage(
\r
176 instListViewSilentInstallImageList.Images[0],
\r
179 e.DrawDefault = true;
\r
187 void InstsListViewItemChecked(object sender, ItemCheckedEventArgs e)
\r
189 System.Windows.Forms.ListView.CheckedListViewItemCollection checkeds = instsListView.CheckedItems;
\r
191 okButton.Enabled = (checkeds != null) && (checkeds.Count > 0);
\r
194 void InstsListViewContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)
\r
196 System.Windows.Forms.ListView.CheckedIndexCollection chkIdxes = instsListView.CheckedIndices;
\r
197 System.Windows.Forms.ListView.SelectedIndexCollection selIdxes = instsListView.SelectedIndices;
\r
199 silentInstallStripMenuItem.Visible = selIdxes.Count > 0;
\r
200 if (selIdxes.Count > 0) {
\r
201 Installation inst0th = ((Installation) instsListView.Items[selIdxes[0]].Tag);
\r
202 bool bChecked = inst0th.Silent;
\r
203 bool bEnabled = (inst0th.IsSupportsSilent && (!inst0th.SupportsSilentOnly));
\r
204 silentInstallStripMenuItem.Checked = bChecked;
\r
205 silentInstallStripMenuItem.Enabled = bEnabled;
\r
207 for (int i = 1; i < selIdxes.Count; i++) {
\r
208 Installation inst = ((Installation) instsListView.Items[selIdxes[i]].Tag);
\r
210 if ( (bChecked != inst.Silent) ||
\r
211 (bEnabled != (inst.IsSupportsSilent && (!inst.SupportsSilentOnly))) ) {
\r
212 silentInstallStripMenuItem.CheckState = CheckState.Indeterminate;
\r
213 silentInstallStripMenuItem.Enabled = false;
\r
218 instListToolStripSeparator.Visible = selIdxes.Count > 0;
\r
221 selectAllInstsStripMenuItem.Enabled = chkIdxes.Count < instsListView.Items.Count;
\r
222 unselectAllInstsStripMenuItem.Enabled = chkIdxes.Count > 0;
\r
225 void SilentInstallStripMenuItemClick(object sender, EventArgs e)
\r
227 bool silent = ! silentInstallStripMenuItem.Checked;
\r
228 foreach (ListViewItem item in instsListView.SelectedItems) {
\r
229 ((Installation) item.Tag).Silent = silent;
\r
230 instViewUpdateSilentInstallView(item);
\r
234 void SelectAllInstsStripMenuItemClick(object sender, EventArgs e)
\r
236 foreach (ListViewItem item in instsListView.Items) {
\r
237 item.Checked = true;
\r
239 instsListView.Refresh();
\r
242 void UnselectAllInstsStripMenuItemClick(object sender, EventArgs e)
\r
244 foreach (ListViewItem item in instsListView.CheckedItems) {
\r
245 item.Checked = false;
\r
247 instsListView.Refresh();
\r
250 void InstallationConfirmFormShown(object sender, EventArgs e)
\r
252 System.Threading.Thread thread = new System.Threading.Thread(
\r
253 new System.Threading.ThreadStart(resolveDependecies));
\r
260 private void resolveDependecies()
\r
262 if (requiredInstallations == null) {
\r
263 Installation[] resolved, dependencies;
\r
265 DependeciesResolver.ResolveInstallations(
\r
266 selectedInstallations,
\r
271 requiredInstallations = dependencies;
\r
273 updateInstsListView();
\r
278 /// インストールするよう選択されたパッケージの配列
\r
280 public Installation[] CheckedInstallations {
\r
282 List<Installation> insts = new List<Installation>();
\r
283 foreach (ListViewItem item in instsListView.CheckedItems) {
\r
284 insts.Add((Installation) item.Tag);
\r
286 return insts.ToArray();
\r
295 public bool UseRunas {
\r
297 runasCheckBox.Checked = (! NaGet.Utils.IsAdministrators()) && value;
\r
302 return runasCheckBox.Checked;
\r
307 /// 選択されたパッケージを調査して、Runasを使うべきかいなかを返す
\r
309 public bool GetShouldUseRunas()
\r
311 if (NaGet.Utils.IsAdministrators()) {
\r
312 // 管理者権限で動いている場合は不要
\r
314 } else if (NaGet.Utils.IsUACEnabled()) {
\r
315 // UACが適用されている場合は標準では不要とする
\r
319 // ひとつでもPCターゲットなインストーラがあれば必要とする
\r
320 foreach (Installation inst in CheckedInstallations) {
\r
321 if (inst.TargetPC) return true;
\r
327 void RunasCheckBoxCheckedChanged(object sender, EventArgs e)
\r
332 private void updateUseRunas()
\r
335 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InstallationConfirmForm));
\r
336 okButton.Image = ((System.Drawing.Bitmap)(resources.GetObject("okButton.Image")));
\r
338 okButton.Image = null;
\r