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                 public Package SelectedObject {\r
23                         get { return pkg; }\r
24                         set {\r
25                                 pkg = value;\r
26                                 updateSelectedObject();\r
27                         }\r
28                 }\r
29                 \r
30                 private void updateSelectedObject()\r
31                 {\r
32                         bool isInstalledPackage = pkg is InstalledPackage;\r
33                         \r
34                         iconLabel.Image = null;\r
35                         iconLabel.Size = Size.Empty;\r
36                         if (isInstalledPackage) {\r
37                                 Icon icon = AppliStation.Util.PackageUtils.GetIconForPackage((InstalledPackage) pkg);\r
38                                 if (icon != null) {\r
39                                         iconLabel.Image = icon.ToBitmap();\r
40                                         iconLabel.Size = icon.Size;\r
41                                 }\r
42                         }\r
43                         nameLabel.Text = string.Format("{0} ({1})", pkg.Name, pkg.Version);\r
44                         nameLabel.Font = new Font(SystemFonts.DefaultFont.FontFamily, SystemFonts.DefaultFont.Size*1.5f);\r
45                         \r
46                         summaryTextBox.Text = pkg.Summary;\r
47                         \r
48                         if (isInstalledPackage) {\r
49                                 UninstallInformation uninstInfo = ((InstalledPackage) pkg).UninstallInfo;\r
50                                 \r
51                                 string instPath = null;\r
52                                 if (pkg.Type == InstallerType.ARCHIVE) {\r
53                                         instPath = System.IO.Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name);\r
54                                 } else if (System.IO.Directory.Exists(uninstInfo.InstallLocation)) {\r
55                                         instPath = uninstInfo.InstallLocation;\r
56                                 }\r
57                                 \r
58                                 statusLinkLabel.Links.Clear();\r
59                                 if (string.IsNullOrEmpty(instPath)) {\r
60                                         statusLinkLabel.Text = "\8fî\95ñ\82ª\92ñ\8b\9f\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ";\r
61                                         statusLinkLabel.Enabled = false;\r
62                                 } else {\r
63                                         statusLinkLabel.Text = instPath;\r
64                                         statusLinkLabel.Enabled = true;\r
65                                         \r
66                                         addLinkToLinkLabel(statusLinkLabel, uninstInfo.InstallLocation, uninstInfo.InstallLocation);\r
67                                 }\r
68                         }\r
69                         urlLinkLabel.Links.Clear();\r
70                         if (pkg.Url != null) {\r
71                                 urlLinkLabel.Text = pkg.Url.Href;\r
72                                 urlLinkLabel.Links.Add(0, pkg.Url.Href.Length, pkg.Url.Href);\r
73                         } else {\r
74                                 urlLinkLabel.Text = string.Empty;\r
75                                 urlLinkLabel.Enabled = false;\r
76                                 urlLabel.Enabled = false;\r
77                         }\r
78                         tagsTextBox.Text = pkg.Tags;\r
79                         setLinkLabelFromLicense(licenseLinkLabel, pkg.License);\r
80                         typeValueLabel.Text = pkg.Type.ToString();\r
81                         \r
82                         tabControl1.TabPages.Clear();\r
83                         foreach (Installer inst in pkg.Installer) {\r
84                                 TabPage page = new TabPage(string.Format("\83C\83\93\83X\83g\81[\83\89 \82»\82Ì{0}", tabControl1.TabCount+1));\r
85                                 page.Dock = DockStyle.Fill;\r
86                                 \r
87                                 InstallerInfoForm instForm = new InstallerInfoForm();\r
88                                 instForm.SelectedObject = inst;\r
89                                 instForm.Dock = DockStyle.Fill;\r
90                                 page.Controls.Add(instForm);\r
91                                 \r
92                                 tabControl1.TabPages.Add(page);\r
93                         }\r
94                 }\r
95                 \r
96                 private static void setLinkLabelFromLicense(LinkLabel linklabel, string license)\r
97                 {\r
98                         linklabel.Enabled = true;\r
99                         switch (license ?? string.Empty) {\r
100                                 case "":\r
101                                         linklabel.Text = "\83t\83\8a\81[\83\\83t\83g\83E\83F\83A (\96³\8f\9e)";\r
102                                         linklabel.Enabled = false;\r
103                                         break;\r
104                                 case "GPL":\r
105                                         linklabel.Text = "GPL (\83I\81[\83v\83\93\83\\81[\83X)";\r
106                                         addLinkToLinkLabel(linklabel, "GPL", @"http://www.gnu.org/licenses/gpl.ja.html");\r
107                                         addLinkToLinkLabel(linklabel, "\83I\81[\83v\83\93\83\\81[\83X", @"http://creativecommons.org/licenses/GPL/2.0/deed.ja");\r
108                                         break;\r
109                                 case "GPLv2":\r
110                                         linklabel.Text = "GPLv2 (\83I\81[\83v\83\93\83\\81[\83X)";\r
111                                         addLinkToLinkLabel(linklabel, "GPLv2", @"http://www.gnu.org/licenses/gpl-2.0.html");\r
112                                         break;\r
113                                 case "GPLv3":\r
114                                         linklabel.Text = "GPLv3 (\83I\81[\83v\83\93\83\\81[\83X)";\r
115                                         addLinkToLinkLabel(linklabel, "GPLv3", @"http://www.gnu.org/licenses/gpl-3.0.html");\r
116                                         break;\r
117                                 case "LGPL":\r
118                                         linklabel.Text = "LGPL (\83I\81[\83v\83\93\83\\81[\83X)";\r
119                                         addLinkToLinkLabel(linklabel, "LGPL", @"http://www.gnu.org/licenses/lgpl.ja.html");\r
120                                         addLinkToLinkLabel(linklabel, "\83I\81[\83v\83\93\83\\81[\83X", @"http://creativecommons.org/licenses/LGPL/2.1/deed.ja");\r
121                                         break;\r
122                                 case "LGPLv2":\r
123                                         linklabel.Text = "LGPLv2 (\83I\81[\83v\83\93\83\\81[\83X)";\r
124                                         addLinkToLinkLabel(linklabel, "LGPLv2", @"http://www.gnu.org/licenses/lgpl-2.1.html");\r
125                                         break;\r
126                                 case "LGPLv3":\r
127                                         linklabel.Text = "LGPLv3 (\83I\81[\83v\83\93\83\\81[\83X)";\r
128                                         addLinkToLinkLabel(linklabel, "LGPLv3", @"http://www.gnu.org/licenses/lgpl-3.0.html");\r
129                                         break;\r
130                                 case "MPL":\r
131                                         linklabel.Text = "MPL (\83I\81[\83v\83\93\83\\81[\83X)";\r
132                                         addLinkToLinkLabel(linklabel, "MPL", @"http://www.mozilla.org/MPL/MPL-1.1.html");\r
133                                         break;\r
134                                 case "CPL":\r
135                                         linklabel.Text = "CPL (\83I\81[\83v\83\93\83\\81[\83X)";\r
136                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://sourceforge.jp/projects/opensource/wiki/licenses%2FCommon_Public_License");\r
137                                         break;\r
138                                 case "MIT":\r
139                                         linklabel.Text = "MIT\83\89\83C\83Z\83\93\83X (\83I\81[\83v\83\93\83\\81[\83X)";\r
140                                         addLinkToLinkLabel(linklabel, "MIT\83\89\83C\83Z\83\93\83X", @"http://www.opensource.org/licenses/mit-license.php");\r
141                                         break;\r
142                                 case "BSD":\r
143                                         linklabel.Text = "\8fC\90³\8dÏBSD\83\89\83C\83Z\83\93\83X (\83I\81[\83v\83\93\83\\81[\83X)";\r
144                                         addLinkToLinkLabel(linklabel, "BSD\83\89\83C\83Z\83\93\83X", @"http://www.opensource.org/licenses/bsd-license.php");\r
145                                         break;\r
146                                 case "NYSL":\r
147                                         linklabel.Text = "\8eÏ\82é\82È\82è\8fÄ\82­\82È\82è\8dD\82«\82É\82µ\82ë\83\89\83C\83Z\83\93\83X";\r
148                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://www.kmonos.net/nysl/");\r
149                                         break;\r
150                                 case "Public Domain":\r
151                                         linklabel.Text = "\83p\83u\83\8a\83b\83N\83h\83\81\83C\83\93 (\92\98\8dì\8c \94ñ\93K\97p)";\r
152                                         linklabel.Links.Add(0, linklabel.Text.Length, @"http://e-words.jp/w/E38391E38396E383AAE38383E382AFE38389E383A1E382A4E383B3.html");\r
153                                         break;\r
154                                 default:\r
155                                         if (license.StartsWith("http://")) {\r
156                                                 linklabel.Text = license;\r
157                                                 linklabel.Links.Add(0, license.Length, license);\r
158                                         } else {\r
159                                                 linklabel.Text = license;\r
160                                                 linklabel.Links.Add(0, 0, string.Empty);\r
161                                         }\r
162                                         break;\r
163                         }\r
164                         \r
165                 }\r
166                 \r
167                 /// <summary>\r
168                 /// \83\8a\83\93\83N\83\89\83x\83\8b\82Ì\83\8a\83\93\83N\91}\93ü\95Ö\97\98\83\81\83\\83b\83h\r
169                 /// </summary>\r
170                 /// <param name="linkLabel">\91Î\8fÛ\83\8a\83\93\83N\83\89\83x\83\8b</param>\r
171                 /// <param name="word">\83\8a\83\93\83N\91Î\8fÛ\95\8e\9a\97ñ</param>\r
172                 /// <param name="link">\83\8a\83\93\83N\83I\83u\83W\83F\83N\83g</param>\r
173                 private static void addLinkToLinkLabel(LinkLabel linkLabel, string word, string link)\r
174                 {\r
175                         int pos = linkLabel.Text.IndexOf(word, 0);\r
176                         if (pos >= 0) {\r
177                                 linkLabel.Links.Add(pos, word.Length, link);\r
178                         } else throw new ArgumentException(string.Format("label text \"{0}\" does not contain \"{1}\"!", linkLabel.Text, word));\r
179                 }\r
180                 \r
181                 private void linkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
182                 {\r
183                         string linkData = e.Link.LinkData.ToString();\r
184                         \r
185                         if (System.IO.Directory.Exists(linkData)) {\r
186                                 e.Link.Visited = true;\r
187                                 System.Diagnostics.Process.Start(e.Link.LinkData.ToString());\r
188                         } else if (System.Text.RegularExpressions.Regex.IsMatch(linkData, @"(https?|file)://")) {\r
189                                 e.Link.Visited = true;\r
190                                 System.Diagnostics.Process.Start(linkData);\r
191                         }\r
192                 }\r
193         }\r
194 }\r