OSDN Git Service

チケット #38687 tar.gz 形式が 7-ZIP32.DLL がインストールされている環境下で正しく展開されない
[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                         this.SuspendLayout();\r
38                         \r
39                         InstalledPackage instPkg = pkg as InstalledPackage;\r
40                         bool isInstalledPackage = instPkg != null;\r
41                         \r
42                         iconLabel.Image = null;\r
43                         iconLabel.Size = Size.Empty;\r
44                         if (isInstalledPackage) {\r
45                                 Icon icon = AppliStation.Util.GUIUtils.GetIconForPackage(instPkg);\r
46                                 if (icon != null) {\r
47                                         iconLabel.Image = icon.ToBitmap();\r
48                                         iconLabel.Size = icon.Size;\r
49                                 }\r
50                         }\r
51                         nameLabel.Text = string.Format("{0} ({1})", pkg.Name, pkg.Version);\r
52                         nameLabel.Font = new Font(SystemFonts.CaptionFont.FontFamily, SystemFonts.CaptionFont.Size*1.25f);\r
53                         \r
54                         summaryTextBox.Text = pkg.Summary;\r
55                         \r
56                         if (isInstalledPackage) {\r
57                                 UninstallInformation uninstInfo = instPkg.UninstallInfo;\r
58                                 \r
59                                 string instPath = null;\r
60                                 if ((pkg.Type == InstallerType.ARCHIVE)\r
61                                     ||(pkg.Type == InstallerType.ITSELF)) {\r
62                                         instPath = Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name);\r
63                                 } else if (Directory.Exists(uninstInfo.InstallLocation)) {\r
64                                         instPath = uninstInfo.InstallLocation;\r
65                                 }\r
66                                 \r
67                                 statusLinkLabel.Links.Clear();\r
68                                 if (string.IsNullOrEmpty(instPath)) {\r
69                                         statusLinkLabel.Text = "情報が提供されていません";\r
70                                         statusLinkLabel.Enabled = false;\r
71                                 } else {\r
72                                         statusLinkLabel.Text = instPath;\r
73                                         statusLinkLabel.Enabled = true;\r
74                                         statusLinkLabel.Links.Add(0, instPath.Length, instPath);\r
75                                 }\r
76                         }\r
77                         urlLinkLabel.Links.Clear();\r
78                         if (pkg.Url != null) {\r
79                                 urlLinkLabel.Text = pkg.Url.Href;\r
80                                 urlLinkLabel.Links.Add(0, pkg.Url.Href.Length, pkg.Url.Href);\r
81                                 urlLinkLabel.Enabled = true;\r
82                                 urlLabel.Enabled = true;\r
83                         } else {\r
84                                 urlLinkLabel.Text = string.Empty;\r
85                                 urlLinkLabel.Enabled = false;\r
86                                 urlLabel.Enabled = false;\r
87                         }\r
88                         tagsTextBox.Text = pkg.Tags;\r
89                         setLinkLabelFromLicense(licenseLinkLabel, pkg);\r
90                         typeValueLabel.Text = PackageDescripter.GetInstallerTypeLabel(pkg.Type);\r
91                         if (! string.IsNullOrEmpty(pkg.PackageListName)) {\r
92                                 packageListNameValueLabel.Text = pkg.PackageListName;\r
93                                 packageListNameValueLabel.Enabled = true;\r
94                         } else {\r
95                                 packageListNameValueLabel.Enabled = false;\r
96                         }\r
97                         \r
98                         tabControl1.TabPages.Clear();\r
99                         if (isInstalledPackage && string.IsNullOrEmpty(pkg.Version)) {\r
100                                 tabControl1.Visible = false;\r
101                         } else {\r
102                                 tabControl1.Visible = true;\r
103                                 foreach (Installer inst in pkg.Installer) {\r
104                                         TabPage page = new TabPage(string.Format("インストーラー その{0}", tabControl1.TabCount+1));\r
105                                         page.Dock = DockStyle.Fill;\r
106                                         \r
107                                         InstallerInfoForm instForm = new InstallerInfoForm();\r
108                                         instForm.SelectedObject = inst;\r
109                                         instForm.Dock = DockStyle.Fill;\r
110                                         page.Controls.Add(instForm);\r
111                                         \r
112                                         tabControl1.TabPages.Add(page);\r
113                                 }\r
114                         }\r
115                         \r
116                         this.Validate();\r
117                         this.ResumeLayout();\r
118                 }\r
119                 \r
120                 /// <summary>\r
121                 /// インストーラーの種類についてラベルにテキストを設定する\r
122                 /// </summary>\r
123                 /// <param name="typeValueLabel">設定先のラベル</param>\r
124                 /// <param name="instType">インストーラーの種類</param>\r
125                 private static void setLinkLabelFromLicense(LinkLabel linklabel, Package pkg)\r
126                 {\r
127                         linklabel.Enabled = true;\r
128                         \r
129                         string text;\r
130                         LinkLabel.Link[] links;\r
131                         PackageDescripter.GetLicenseValueLabel(pkg, out text, out links);\r
132                         \r
133                         linklabel.Text = text;\r
134                         linklabel.Links.Clear();\r
135                         foreach (LinkLabel.Link link in links) {\r
136                                 linklabel.Links.Add(link);\r
137                         }\r
138                 }\r
139                 \r
140                 private void linkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
141                 {\r
142                         string linkData = e.Link.LinkData.ToString();\r
143                         \r
144                         if (Directory.Exists(linkData)) {\r
145                                 e.Link.Visited = true;\r
146                                 System.Diagnostics.Process.Start(e.Link.LinkData.ToString());\r
147                         } else if (System.Text.RegularExpressions.Regex.IsMatch(linkData, @"^(https?|file)://")) {\r
148                                 e.Link.Visited = true;\r
149                                 try {\r
150                                         System.Diagnostics.Process.Start(e.Link.LinkData.ToString());\r
151                                 } catch (System.ComponentModel.Win32Exception) {\r
152                                         MessageBox.Show(string.Format("{0}を開くのに失敗しました。", e.Link.LinkData), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
153                                 }\r
154                         }\r
155                 }\r
156                 \r
157                 void CloseButtonClick(object sender, EventArgs e)\r
158                 {\r
159                         if (! this.Modal) {\r
160                                 this.DialogResult = DialogResult.OK;\r
161                                 this.Close();\r
162                         }\r
163                 }\r
164                 \r
165                 void PackageInfoFormFormClosed(object sender, FormClosedEventArgs e)\r
166                 {\r
167                         this.Dispose(true);\r
168                 }\r
169         }\r
170 }\r