OSDN Git Service

3cfd8e6b3da248e68d36d36ed2ca97e98d8eb88e
[applistation/AppliStation.git] / na-get-lib / NaGet.Packages / Package.cs
1 using System.Xml.Serialization;\r
2 \r
3 namespace NaGet.Packages\r
4 {\r
5         /// <summary>\r
6         /// インストーラの種類を表す。\r
7         /// </summary>\r
8         public enum InstallerType\r
9         {\r
10                 /// <summary>\r
11                 /// インストーラ\r
12                 /// </summary>\r
13                 [XmlEnum(Name="installer")]\r
14                 EXEC_INSTALLER,\r
15                 /// <summary>\r
16                 /// Microsoft Software Installer\r
17                 /// </summary>\r
18                 [XmlEnum(Name="msi")]\r
19                 MSI_PACKAGE,\r
20                 /// <summary>\r
21                 /// 自己解凍書庫を含む書庫一般\r
22                 /// </summary>\r
23                 [XmlEnum(Name="archive")]\r
24                 ARCHIVE,\r
25                 /// <summary>\r
26                 /// それ自身がプログラムそのものである\r
27                 /// </summary>\r
28                 [XmlEnum(Name="itself")]\r
29                 ITSELF,\r
30                 /// <summary>\r
31                 /// インストールできない単なるデータ(BIOSなど)\r
32                 /// </summary>\r
33                 [XmlEnum(Name="cannotinstall")]\r
34                 CANNOT_INSTALL,\r
35         }\r
36         \r
37         /// <summary>\r
38         /// パッケージ情報を格納するクラス\r
39         /// </summary>\r
40         public class Package\r
41         {\r
42                 /// <summary>\r
43                 /// パッケージ名\r
44                 /// </summary>\r
45                 public string Name;\r
46 \r
47                 /// <summary>\r
48                 /// バージョン文字列\r
49                 /// </summary>\r
50                 public string Version;\r
51 \r
52                 /// <summary>\r
53                 /// パッケージの概要\r
54                 /// </summary>\r
55                 public string Summary;\r
56                 \r
57                 /// <summary>\r
58                 /// パッケージの解説\r
59                 /// </summary>\r
60                 public string Description;\r
61 \r
62                 /// <summary>\r
63                 /// 公式サイトのURL\r
64                 /// </summary>\r
65                 public LocationEntry Url;\r
66                 \r
67                 /// <summary>\r
68                 /// 製作者の名前\r
69                 /// </summary>\r
70                 public string Author;\r
71                 \r
72                 /// <summary>\r
73                 /// インストーラのタイプ\r
74                 /// </summary>\r
75                 public InstallerType Type;\r
76                 \r
77                 /// <summary>\r
78                 /// インストーラが書庫内に入っているかのフラグ\r
79                 /// </summary>\r
80                 public bool ArchivedInstaller = false;\r
81                 \r
82                 /// <summary>\r
83                 /// アンインストーラのレジストリのキー\r
84                 /// </summary>\r
85                 public string UninstallerKey;\r
86                 \r
87                 /// <summary>\r
88                 /// サイレントインストールのための引数。\r
89                 /// インストーラ形式のみ有効で、nullもしくは空文字列の場合は\r
90                 /// サイレントインストールができないことをあらわす\r
91                 /// </summary>\r
92                 public string SilentInstallArguments;\r
93                 \r
94                 /// <summary>\r
95                 /// インストールスクリプト(MSBuildドキュメント)\r
96                 /// </summary>\r
97                 public string InstallScript;\r
98                 \r
99                 /// <summary>\r
100                 /// アーカイブインストーラのときのSystem32のコピー\r
101                 /// </summary>\r
102                 public string System32CopyFiles;\r
103                 \r
104                 /// <summary>\r
105                 /// インストーラのリソースの配列\r
106                 /// </summary>\r
107                 [XmlElement]\r
108                 public Installer[] Installer;\r
109 \r
110                 /// <summary>\r
111                 /// 必要とされるパッケージの配列\r
112                 /// </summary>\r
113                 [XmlArray(IsNullable=true),XmlArrayItem("Entry")]\r
114                 public Entry[] Requires;\r
115                 \r
116                 /// <summary>\r
117                 /// 競合するパッケージの配列\r
118                 /// </summary>\r
119                 [XmlArray(IsNullable=true),XmlArrayItem("Entry")]\r
120                 public Entry[] Conflicts;\r
121                 \r
122                 /// <summary>\r
123                 /// タグ\r
124                 /// </summary>\r
125                 public string Tags;\r
126                 \r
127                 /// <summary>\r
128                 /// ライセンス\r
129                 /// </summary>\r
130                 public string License;\r
131                 \r
132                 /// <summary>\r
133                 /// 所属するパッケージリスト名称\r
134                 /// </summary>\r
135                 public string PackageListName;\r
136         }\r
137 \r
138         /// <summary>\r
139         /// パッケージ参照を示すクラス\r
140         /// </summary>\r
141         public struct Entry\r
142         {\r
143                 /// <summary>\r
144                 /// パッケージ名\r
145                 /// </summary>\r
146                 [XmlAttribute]\r
147                 public string Name;\r
148                 /// <summary>\r
149                 /// パッケージのバージョン比較の式\r
150                 /// </summary>\r
151                 [XmlAttribute]\r
152                 public string Flags;\r
153                 /// <summary>\r
154                 /// パッケージのバージョン\r
155                 /// </summary>\r
156                 [XmlAttribute]\r
157                 public string Version;\r
158                 \r
159                 public Entry(string name, string flags, string version)\r
160                 {\r
161                         Name = name;\r
162                         Flags = flags;\r
163                         Version = version;\r
164                 }\r
165                 public bool Match(Package pkg)\r
166                 {\r
167                         System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(\r
168                                 (System.Text.RegularExpressions.Regex.IsMatch(Name, "^/.*/$"))?\r
169                                 Name.Substring(1, Name.Length-2) :\r
170                                 string.Format("^{0}$", System.Text.RegularExpressions.Regex.Escape(Name))\r
171                         , System.Text.RegularExpressions.RegexOptions.Singleline);\r
172                         \r
173                         if (regex.IsMatch(pkg.Name)) {\r
174                                 if (string.IsNullOrEmpty(Version)) {\r
175                                         return true;\r
176                                 } else {\r
177                                         // TODO Flagの内容は現在のところ無視\r
178                                         return pkg.Version == Version;\r
179                                 }\r
180                         } else {\r
181                                 return false;\r
182                         }\r
183                 }\r
184         }\r
185 \r
186         public class Installer\r
187         {\r
188                 /// <summary>\r
189                 /// コンストラクタ\r
190                 /// </summary>\r
191                 public Installer()\r
192                 {\r
193                 }\r
194                 \r
195                 public Platform Platform;\r
196                 \r
197                 /// <summary>\r
198                 /// ダウンロードリソースURLの配列\r
199                 /// </summary>\r
200                 public LocationEntry Url;\r
201                 \r
202                 /// <summary>\r
203                 /// ファイル検証用ハッシュ\r
204                 /// </summary>\r
205                 [XmlElement]\r
206                 public HashValue[] Hash;\r
207         }\r
208         \r
209         /// <summary>\r
210         /// リソースの位置を示すクラス\r
211         /// </summary>\r
212         public class LocationEntry\r
213         {\r
214                 // TODO LocationEntryは果たして必要なのかの、考察\r
215                 \r
216                 /// <summary>\r
217                 /// コンストラクタ\r
218                 /// </summary>\r
219                 public LocationEntry()\r
220                 {\r
221                 }\r
222 \r
223                 /// <summary>\r
224                 /// コンストラクタ\r
225                 /// </summary>\r
226                 /// <param name="sHref">リソースのURL</param>\r
227                 public LocationEntry(string sHref)\r
228                 {\r
229                         Href = sHref;\r
230                 }\r
231 \r
232                 /// <summary>\r
233                 /// リソースのURL\r
234                 /// </summary>\r
235                 [XmlAttribute]\r
236                 public string Href;\r
237         }\r
238 }\r