OSDN Git Service

AppliStation-GUI,ライセンスにまつわる記述周辺の修正
[applistation/AppliStation.git] / AppliStation / PackageInfoForm.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Windows.Forms;\r
4 using NaGet.Packages.Install;\r
5 using NaGet.Packages;\r
6 using System.Text;\r
7 \r
8 namespace AppliStation\r
9 {\r
10         /// <summary>\r
11         /// Description of PackageInfoForm.\r
12         /// </summary>\r
13         public partial class PackageInfoForm : Form\r
14         {\r
15                 private Package pkg;\r
16                 \r
17                 public PackageInfoForm()\r
18                 {\r
19                         InitializeComponent();\r
20                 }\r
21                 \r
22                 /// <summary>\r
23                 /// 現在選択中(=表示中)のパッケージ\r
24                 /// </summary>\r
25                 public Package SelectedObject {\r
26                         get { return pkg; }\r
27                         set {\r
28                                 pkg = value;\r
29                                 updateSelectedObject();\r
30                         }\r
31                 }\r
32                 \r
33                 private void updateSelectedObject()\r
34                 {\r
35                         bool isInstalledPackage = pkg is InstalledPackage;\r
36                         \r
37                         iconLabel.Image = null;\r
38                         iconLabel.Size = Size.Empty;\r
39                         if (isInstalledPackage) {\r
40                                 Icon icon = AppliStation.Util.GUIUtils.GetIconForPackage((InstalledPackage) pkg);\r
41                                 if (icon != null) {\r
42                                         iconLabel.Image = icon.ToBitmap();\r
43                                         iconLabel.Size = icon.Size;\r
44                                 }\r
45                         }\r
46                         nameLabel.Text = string.Format("{0} ({1})", pkg.Name, pkg.Version);\r
47                         nameLabel.Font = new Font(SystemFonts.DefaultFont.FontFamily, SystemFonts.DefaultFont.Size*1.5f);\r
48                         \r
49                         summaryTextBox.Text = pkg.Summary;\r
50                         \r
51                         if (isInstalledPackage) {\r
52                                 UninstallInformation uninstInfo = ((InstalledPackage) pkg).UninstallInfo;\r
53                                 \r
54                                 string instPath = null;\r
55                                 if (pkg.Type == InstallerType.ARCHIVE) {\r
56                                         instPath = System.IO.Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name);\r
57                                 } else if (System.IO.Directory.Exists(uninstInfo.InstallLocation)) {\r
58                                         instPath = uninstInfo.InstallLocation;\r
59                                 }\r
60                                 \r
61                                 statusLinkLabel.Links.Clear();\r
62                                 if (string.IsNullOrEmpty(instPath)) {\r
63                                         statusLinkLabel.Text = "情報が提供されていません";\r
64                                         statusLinkLabel.Enabled = false;\r
65                                 } else {\r
66                                         statusLinkLabel.Text = instPath;\r
67                                         statusLinkLabel.Enabled = true;\r
68                                         \r
69                                         addLinkToLinkLabel(statusLinkLabel, uninstInfo.InstallLocation, uninstInfo.InstallLocation);\r
70                                 }\r
71                         }\r
72                         urlLinkLabel.Links.Clear();\r
73                         if (pkg.Url != null) {\r
74                                 urlLinkLabel.Text = pkg.Url.Href;\r
75                                 urlLinkLabel.Links.Add(0, pkg.Url.Href.Length, pkg.Url.Href);\r
76                         } else {\r
77                                 urlLinkLabel.Text = string.Empty;\r
78                                 urlLinkLabel.Enabled = false;\r
79                                 urlLabel.Enabled = false;\r
80                         }\r
81                         tagsTextBox.Text = pkg.Tags;\r
82                         setLinkLabelFromLicense(licenseLinkLabel, pkg.License, pkg.Url.Href);\r
83                         setTypeValueLabel(typeValueLabel, pkg.Type);\r
84                         \r
85                         tabControl1.TabPages.Clear();\r
86                         if (pkg is InstalledPackage && string.IsNullOrEmpty(pkg.Version)) {\r
87                                 tabControl1.Visible = false;\r
88                         } else {\r
89                                 tabControl1.Visible = true;\r
90                                 foreach (Installer inst in pkg.Installer) {\r
91                                         TabPage page = new TabPage(string.Format("インストーラ その{0}", tabControl1.TabCount+1));\r
92                                         page.Dock = DockStyle.Fill;\r
93                                         \r
94                                         InstallerInfoForm instForm = new InstallerInfoForm();\r
95                                         instForm.SelectedObject = inst;\r
96                                         instForm.Dock = DockStyle.Fill;\r
97                                         page.Controls.Add(instForm);\r
98                                         \r
99                                         tabControl1.TabPages.Add(page);\r
100                                 }\r
101                         }\r
102                         \r
103                         this.Size = new Size(this.Size.Width, (tabControl1.TabCount>0)? 380 : 250);\r
104                 }\r
105                 \r
106                 /// <summary>\r
107                 /// インストーラの種類についてラベルにテキストを設定する\r
108                 /// </summary>\r
109                 /// <param name="typeValueLabel">設定先のラベル</param>\r
110                 /// <param name="instType">インストーラの種類</param>\r
111                 private static void setLinkLabelFromLicense(LinkLabel linklabel, string license, string publicSiteUrl)\r
112                 {\r
113                         linklabel.Enabled = true;\r
114                         switch (license ?? string.Empty) {\r
115                                 case "":\r
116                                         if (string.IsNullOrEmpty(publicSiteUrl)) {\r
117                                                 linklabel.Text = "フリーソフトウェア (無償)";\r
118                                                 linklabel.Enabled = false;\r
119                                         } else {\r
120                                                 linklabel.Text = "フリーソフトウェア (詳細は公式サイトなどで確認してください)";\r
121                                                 addLinkToLinkLabel(linklabel, "公式サイト", publicSiteUrl);\r
122                                         }\r
123                                         break;\r
124                                 #region オープンソースかつコピーレフト\r
125                                 case "GPL":\r
126                                         linklabel.Text = "GPL (オープンソース)";\r
127                                         addLinkToLinkLabel(linklabel, "GPL", @"http://www.gnu.org/licenses/gpl.ja.html");\r
128                                         addLinkToLinkLabel(linklabel, "オープンソース", @"http://creativecommons.org/licenses/GPL/2.0/deed.ja");\r
129                                         break;\r
130                                 case "GPLv2":\r
131                                 case "GPLv2+":\r
132                                         linklabel.Text = "GPLv2 (オープンソース)";\r
133                                         addLinkToLinkLabel(linklabel, "GPLv2", @"http://www.gnu.org/licenses/gpl-2.0.txt");\r
134                                         break;\r
135                                 case "GPLv3":\r
136                                 case "GPLv3+":\r
137                                         linklabel.Text = "GPLv3 (オープンソース)";\r
138                                         addLinkToLinkLabel(linklabel, "GPLv3", @"http://www.gnu.org/licenses/gpl-3.0.txt");\r
139                                         break;\r
140                                 case "LGPL":\r
141                                         linklabel.Text = "LGPL (オープンソース)";\r
142                                         addLinkToLinkLabel(linklabel, "LGPL", @"http://www.gnu.org/licenses/lgpl.ja.html");\r
143                                         addLinkToLinkLabel(linklabel, "オープンソース", @"http://creativecommons.org/licenses/LGPL/2.1/deed.ja");\r
144                                         break;\r
145                                 case "LGPLv2":\r
146                                 case "LGPLv2+":\r
147                                         linklabel.Text = "LGPLv2 (オープンソース)";\r
148                                         addLinkToLinkLabel(linklabel, "LGPLv2", @"http://www.gnu.org/licenses/lgpl-2.1.txt");\r
149                                         break;\r
150                                 case "LGPLv3":\r
151                                 case "LGPLv3+":\r
152                                         linklabel.Text = "LGPLv3 (オープンソース)";\r
153                                         addLinkToLinkLabel(linklabel, "LGPLv3", @"http://www.gnu.org/licenses/lgpl-3.0.txt");\r
154                                         break;\r
155                                 case "AGPLv3":\r
156                                 case "AGPLv3+":\r
157                                         linklabel.Text = "AGPLv3 (オープンソース)";\r
158                                         addLinkToLinkLabel(linklabel, "AGPLv3", @"http://www.gnu.org/licenses/agpl-3.0.txt");\r
159                                         break;\r
160                                 case "MPL":\r
161                                         linklabel.Text = "MPL (オープンソース)";\r
162                                         addLinkToLinkLabel(linklabel, "MPL", @"http://www.mozilla.org/MPL/MPL-1.1.html");\r
163                                         break;\r
164                                 case "CPL":\r
165                                         linklabel.Text = "CPL (オープンソース)";\r
166                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://sourceforge.jp/projects/opensource/wiki/licenses%2FCommon_Public_License");\r
167                                         break;\r
168                                 case "Artistic":\r
169                                         linklabel.Text = "Artisticライセンス (オープンソース)";\r
170                                         addLinkToLinkLabel(linklabel, "Artisticライセンス", @"http://www.perlfoundation.org/artistic_license_2_0");\r
171                                         break;\r
172                                 #endregion\r
173                                 #region オープンソースだが、コピーレフトでない著名なライセンス\r
174                                 case "MIT":\r
175                                         linklabel.Text = "MITライセンス (オープンソース)";\r
176                                         addLinkToLinkLabel(linklabel, "MITライセンス", @"http://www.opensource.org/licenses/mit-license.php");\r
177                                         break;\r
178                                 case "BSD":\r
179                                         linklabel.Text = "修正済BSDライセンス (オープンソース)";\r
180                                         addLinkToLinkLabel(linklabel, "BSDライセンス", @"http://www.opensource.org/licenses/bsd-license.php");\r
181                                         break;\r
182                                 case "Apache":\r
183                                 case "ASLv2":\r
184                                 case "ASLv2+":\r
185                                         linklabel.Text = "Apacheライセンス (オープンソース)";\r
186                                         addLinkToLinkLabel(linklabel, "Apacheライセンス", @"http://www.apache.org/licenses/LICENSE-2.0.txt");\r
187                                         break;\r
188                                 case "zlib":\r
189                                         linklabel.Text = "zlibライセンス";\r
190                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://opentechpress.jp/docs/licenses/zlib-license.shtml");\r
191                                         break;\r
192                                 #endregion\r
193                                 case "NYSL":\r
194                                         linklabel.Text = "煮るなり焼くなり好きにしろライセンス";\r
195                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://www.kmonos.net/nysl/NYSL_withfaq.TXT");\r
196                                         break;\r
197                                 case "Public Domain":\r
198                                         linklabel.Text = "パブリックドメイン (著作権帰属なし)";\r
199                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://e-words.jp/w/E38391E38396E383AAE38383E382AFE38389E383A1E382A4E383B3.html");\r
200                                         break;\r
201                                 default:\r
202                                         if (license.StartsWith("http://")) {\r
203                                                 linklabel.Text = license;\r
204                                                 linklabel.Links.Add(0, license.Length, license);\r
205                                         } else {\r
206                                                 linklabel.Text = license;\r
207                                                 linklabel.Links.Add(0, 0, string.Empty);\r
208                                         }\r
209                                         break;\r
210                         }\r
211                         \r
212                 }\r
213                 \r
214                 /// <summary>\r
215                 /// インストーラの種類についてラベルにテキストを設定する\r
216                 /// </summary>\r
217                 /// <param name="typeValueLabel">設定先のラベル</param>\r
218                 /// <param name="instType">インストーラの種類</param>\r
219                 private static void setTypeValueLabel(Label typeValueLabel, InstallerType instType)\r
220                 {\r
221                         switch (instType) {\r
222                                 case InstallerType.ARCHIVE:\r
223                                         typeValueLabel.Text = "自己解凍書庫または書庫";\r
224                                         break;\r
225                                 case InstallerType.EXEC_INSTALLER:\r
226                                         typeValueLabel.Text = "インストーラ形式";\r
227                                         break;\r
228                                 case InstallerType.MSI_PACKAGE:\r
229                                         typeValueLabel.Text = "MSIファイル形式";\r
230                                         break;\r
231                                 default:\r
232                                         typeValueLabel.Text = "不明なインストール形式(インストール不能)";\r
233                                         break;\r
234                         }\r
235                 }\r
236                 \r
237                 /// <summary>\r
238                 /// リンクラベルのリンク挿入便利メソッド\r
239                 /// </summary>\r
240                 /// <param name="linkLabel">対象リンクラベル</param>\r
241                 /// <param name="word">リンク対象文字列</param>\r
242                 /// <param name="link">リンクオブジェクト</param>\r
243                 private static void addLinkToLinkLabel(LinkLabel linkLabel, string word, string link)\r
244                 {\r
245                         int pos = linkLabel.Text.IndexOf(word, 0);\r
246                         if (pos >= 0) {\r
247                                 linkLabel.Links.Add(pos, word.Length, link);\r
248                         } else throw new ArgumentException(string.Format("label text \"{0}\" does not contain \"{1}\"!", linkLabel.Text, word));\r
249                 }\r
250                 \r
251                 private void linkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
252                 {\r
253                         string linkData = e.Link.LinkData.ToString();\r
254                         \r
255                         if (System.IO.Directory.Exists(linkData)) {\r
256                                 e.Link.Visited = true;\r
257                                 System.Diagnostics.Process.Start(e.Link.LinkData.ToString());\r
258                         } else if (System.Text.RegularExpressions.Regex.IsMatch(linkData, @"(https?|file)://")) {\r
259                                 e.Link.Visited = true;\r
260                                 System.Diagnostics.Process.Start(linkData);\r
261                         }\r
262                 }\r
263         }\r
264 }\r