OSDN Git Service

AppliStation-GUI,パッケージリストの列で「ライセンス」と「インストールした日」を追加(デフォルト非表示)。
[applistation/AppliStation.git] / AppliStation / AppliStation.PackageInfo / PackageInfoForm.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Windows.Forms;\r
4 using System.Text;\r
5 using System.Text.RegularExpressions;\r
6 using System.IO;\r
7 using NaGet.Packages.Install;\r
8 using NaGet.Packages;\r
9 \r
10 namespace AppliStation.PackageInfo\r
11 {\r
12         /// <summary>\r
13         /// Description of PackageInfoForm.\r
14         /// </summary>\r
15         public partial class PackageInfoForm : Form\r
16         {\r
17                 private Package pkg;\r
18                 \r
19                 public PackageInfoForm()\r
20                 {\r
21                         InitializeComponent();\r
22                 }\r
23                 \r
24                 /// <summary>\r
25                 /// 現在選択中(=表示中)のパッケージ\r
26                 /// </summary>\r
27                 public Package SelectedObject {\r
28                         get { return pkg; }\r
29                         set {\r
30                                 pkg = value;\r
31                                 updateSelectedObject();\r
32                         }\r
33                 }\r
34                 \r
35                 private void updateSelectedObject()\r
36                 {\r
37                         bool isInstalledPackage = pkg is InstalledPackage;\r
38                         \r
39                         iconLabel.Image = null;\r
40                         iconLabel.Size = Size.Empty;\r
41                         if (isInstalledPackage) {\r
42                                 Icon icon = AppliStation.Util.GUIUtils.GetIconForPackage((InstalledPackage) pkg);\r
43                                 if (icon != null) {\r
44                                         iconLabel.Image = icon.ToBitmap();\r
45                                         iconLabel.Size = icon.Size;\r
46                                 }\r
47                         }\r
48                         nameLabel.Text = string.Format("{0} ({1})", pkg.Name, pkg.Version);\r
49                         nameLabel.Font = new Font(SystemFonts.CaptionFont.FontFamily, SystemFonts.CaptionFont.Size*1.25f);\r
50                         \r
51                         summaryTextBox.Text = pkg.Summary;\r
52                         \r
53                         if (isInstalledPackage) {\r
54                                 UninstallInformation uninstInfo = ((InstalledPackage) pkg).UninstallInfo;\r
55                                 \r
56                                 string instPath = null;\r
57                                 if ((pkg.Type == InstallerType.ARCHIVE)\r
58                                     ||(pkg.Type == InstallerType.ITSELF)) {\r
59                                         instPath = Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name);\r
60                                 } else if (Directory.Exists(uninstInfo.InstallLocation)) {\r
61                                         instPath = uninstInfo.InstallLocation;\r
62                                 }\r
63                                 \r
64                                 statusLinkLabel.Links.Clear();\r
65                                 if (string.IsNullOrEmpty(instPath)) {\r
66                                         statusLinkLabel.Text = "情報が提供されていません";\r
67                                         statusLinkLabel.Enabled = false;\r
68                                 } else {\r
69                                         statusLinkLabel.Text = instPath;\r
70                                         statusLinkLabel.Enabled = true;\r
71                                         statusLinkLabel.Links.Add(0, instPath.Length, instPath);\r
72                                 }\r
73                         }\r
74                         urlLinkLabel.Links.Clear();\r
75                         if (pkg.Url != null) {\r
76                                 urlLinkLabel.Text = pkg.Url.Href;\r
77                                 urlLinkLabel.Links.Add(0, pkg.Url.Href.Length, pkg.Url.Href);\r
78                                 urlLinkLabel.Enabled = true;\r
79                                 urlLabel.Enabled = true;\r
80                         } else {\r
81                                 urlLinkLabel.Text = string.Empty;\r
82                                 urlLinkLabel.Enabled = false;\r
83                                 urlLabel.Enabled = false;\r
84                         }\r
85                         tagsTextBox.Text = pkg.Tags;\r
86                         setLinkLabelFromLicense(licenseLinkLabel, pkg);\r
87                         typeValueLabel.Text = PackageDescripter.GetInstallerTypeLabel(pkg.Type);\r
88                         if (! string.IsNullOrEmpty(pkg.PackageListName)) {\r
89                                 packageListNameValueLabel.Text = pkg.PackageListName;\r
90                                 packageListNameValueLabel.Enabled = true;\r
91                         } else {\r
92                                 packageListNameValueLabel.Enabled = false;\r
93                         }\r
94                         \r
95                         tabControl1.TabPages.Clear();\r
96                         if (pkg is InstalledPackage && string.IsNullOrEmpty(pkg.Version)) {\r
97                                 tabControl1.Visible = false;\r
98                         } else {\r
99                                 tabControl1.Visible = true;\r
100                                 foreach (Installer inst in pkg.Installer) {\r
101                                         TabPage page = new TabPage(string.Format("インストーラー その{0}", tabControl1.TabCount+1));\r
102                                         page.Dock = DockStyle.Fill;\r
103                                         \r
104                                         InstallerInfoForm instForm = new InstallerInfoForm();\r
105                                         instForm.SelectedObject = inst;\r
106                                         instForm.Dock = DockStyle.Fill;\r
107                                         page.Controls.Add(instForm);\r
108                                         \r
109                                         tabControl1.TabPages.Add(page);\r
110                                 }\r
111                         }\r
112                         \r
113                         this.Size = new Size(this.Size.Width, (tabControl1.TabCount>0)? 380 : 250);\r
114                 }\r
115                 \r
116                 /// <summary>\r
117                 /// インストーラーの種類についてラベルにテキストを設定する\r
118                 /// </summary>\r
119                 /// <param name="typeValueLabel">設定先のラベル</param>\r
120                 /// <param name="instType">インストーラーの種類</param>\r
121                 private static void setLinkLabelFromLicense(LinkLabel linklabel, Package pkg)\r
122                 {\r
123                         linklabel.Enabled = true;\r
124                         \r
125                         string text;\r
126                         LinkLabel.Link[] links;\r
127                         PackageDescripter.GetLicenseValueLabel(pkg, out text, out links);\r
128                         \r
129                         linklabel.Text = text;\r
130                         linklabel.Links.Clear();\r
131                         foreach (LinkLabel.Link link in links) {\r
132                                 linklabel.Links.Add(link);\r
133                         }\r
134                 }\r
135                 \r
136                 private void linkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
137                 {\r
138                         string linkData = e.Link.LinkData.ToString();\r
139                         \r
140                         if (Directory.Exists(linkData)) {\r
141                                 e.Link.Visited = true;\r
142                                 System.Diagnostics.Process.Start(e.Link.LinkData.ToString());\r
143                         } else if (System.Text.RegularExpressions.Regex.IsMatch(linkData, @"^(https?|file)://")) {\r
144                                 e.Link.Visited = true;\r
145                                 try {\r
146                                         System.Diagnostics.Process.Start(e.Link.LinkData.ToString());\r
147                                 } catch (System.ComponentModel.Win32Exception) {\r
148                                         MessageBox.Show(string.Format("{0}を開くのに失敗しました。", e.Link.LinkData), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
149                                 }\r
150                         }\r
151                 }\r
152                 \r
153                 void CloseButtonClick(object sender, EventArgs e)\r
154                 {\r
155                         if (! this.Modal) {\r
156                                 this.DialogResult = DialogResult.OK;\r
157                                 this.Close();\r
158                         }\r
159                 }\r
160                 \r
161                 void PackageInfoFormFormClosed(object sender, FormClosedEventArgs e)\r
162                 {\r
163                         this.Dispose(true);\r
164                 }\r
165         }\r
166 }\r