New test.
[mono.git] / mcs / class / System / System.Diagnostics / FileVersionInfo.cs
1 //
2 // System.Diagnostics.FileVersionInfo.cs
3 //
4 // Authors:
5 //      Dick Porter (dick@ximian.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2002 Ximian, Inc.
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Runtime.CompilerServices;
32 using System.Security;
33 using System.Security.Permissions;
34 using System.Text;
35
36 namespace System.Diagnostics {
37
38         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
39         public sealed class FileVersionInfo {
40                 /* There is no public constructor for this class, it
41                  * is initialised by the runtime.  All the private
42                  * variables here are looked up by name, so dont
43                  * change them without also changing the runtime
44                  */
45                 private string comments;
46                 private string companyname;
47                 private string filedescription;
48                 private string filename;
49                 private string fileversion;
50                 private string internalname;
51                 private string language;
52                 private string legalcopyright;
53                 private string legaltrademarks;
54                 private string originalfilename;
55                 private string privatebuild;
56                 private string productname;
57                 private string productversion;
58                 private string specialbuild;
59                 private bool isdebug;
60                 private bool ispatched;
61                 private bool isprerelease;
62                 private bool isprivatebuild;
63                 private bool isspecialbuild;
64                 private int filemajorpart;
65                 private int fileminorpart;
66                 private int filebuildpart;
67                 private int fileprivatepart;
68                 private int productmajorpart;
69                 private int productminorpart;
70                 private int productbuildpart;
71                 private int productprivatepart;
72
73                 private FileVersionInfo ()
74                 {
75                         // no nulls (for unavailable items)
76                         comments = String.Empty;
77                         companyname = String.Empty;
78                         filedescription = String.Empty;
79                         filename = String.Empty;
80                         fileversion = String.Empty;
81                         internalname = String.Empty;
82                         language = String.Empty;
83                         legalcopyright = String.Empty;
84                         legaltrademarks = String.Empty;
85                         originalfilename = String.Empty;
86                         privatebuild = String.Empty;
87                         productname = String.Empty;
88                         productversion = String.Empty;
89                         specialbuild = String.Empty;
90                         // This is here just to shut the compiler up
91                         isdebug=false;
92                         ispatched=false;
93                         isprerelease=false;
94                         isprivatebuild=false;
95                         isspecialbuild=false;
96                         filemajorpart=0;
97                         fileminorpart=0;
98                         filebuildpart=0;
99                         fileprivatepart=0;
100                         productmajorpart=0;
101                         productminorpart=0;
102                         productbuildpart=0;
103                         productprivatepart=0;
104                 }
105                 
106                 
107                 public string Comments {
108                         get {
109                                 return(comments);
110                         }
111                 }
112
113                 public string CompanyName {
114                         get {
115                                 return(companyname);
116                         }
117                 }
118
119                 public int FileBuildPart {
120                         get {
121                                 return(filebuildpart);
122                         }
123                 }
124
125                 public string FileDescription {
126                         get {
127                                 return(filedescription);
128                         }
129                 }
130
131                 public int FileMajorPart {
132                         get {
133                                 return(filemajorpart);
134                         }
135                 }
136                 
137                 public int FileMinorPart {
138                         get {
139                                 return(fileminorpart);
140                         }
141                 }
142
143                 public string FileName {
144                         get {
145                                 if (SecurityManager.SecurityEnabled) {
146                                         new FileIOPermission (FileIOPermissionAccess.PathDiscovery, filename).Demand ();
147                                 }
148                                 return filename;
149                         }
150                 }
151
152                 public int FilePrivatePart {
153                         get {
154                                 return(fileprivatepart);
155                         }
156                 }
157
158                 public string FileVersion {
159                         get {
160                                 return(fileversion);
161                         }
162                 }
163
164                 public string InternalName {
165                         get {
166                                 return(internalname);
167                         }
168                 }
169
170                 public bool IsDebug {
171                         get {
172                                 return(isdebug);
173                         }
174                 }
175
176                 public bool IsPatched {
177                         get {
178                                 return(ispatched);
179                         }
180                 }
181
182                 public bool IsPreRelease {
183                         get {
184                                 return(isprerelease);
185                         }
186                 }
187                 
188                 public bool IsPrivateBuild {
189                         get {
190                                 return(isprivatebuild);
191                         }
192                 }
193
194                 public bool IsSpecialBuild {
195                         get {
196                                 return(isspecialbuild);
197                         }
198                 }
199
200                 public string Language {
201                         get {
202                                 return(language);
203                         }
204                 }
205
206                 public string LegalCopyright {
207                         get {
208                                 return(legalcopyright);
209                         }
210                 }
211
212                 public string LegalTrademarks {
213                         get {
214                                 return(legaltrademarks);
215                         }
216                 }
217
218                 public string OriginalFilename {
219                         get {
220                                 return(originalfilename);
221                         }
222                 }
223
224                 public string PrivateBuild {
225                         get {
226                                 return(privatebuild);
227                         }
228                 }
229
230                 public int ProductBuildPart {
231                         get {
232                                 return(productbuildpart);
233                         }
234                 }
235
236                 public int ProductMajorPart {
237                         get {
238                                 return(productmajorpart);
239                         }
240                 }
241
242                 public int ProductMinorPart {
243                         get {
244                                 return(productminorpart);
245                         }
246                 }
247
248                 public string ProductName {
249                         get {
250                                 return(productname);
251                         }
252                 }
253
254                 public int ProductPrivatePart {
255                         get {
256                                 return(productprivatepart);
257                         }
258                 }
259
260                 public string ProductVersion {
261                         get {
262                                 return(productversion);
263                         }
264                 }
265
266                 public string SpecialBuild {
267                         get {
268                                 return(specialbuild);
269                         }
270                 }
271
272                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
273                 private extern void GetVersionInfo_internal(string fileName);
274                 
275                 public static FileVersionInfo GetVersionInfo (string fileName)
276                 {
277                         if (SecurityManager.SecurityEnabled) {
278                                 new FileIOPermission (FileIOPermissionAccess.Read, fileName).Demand ();
279                         }
280
281                         FileVersionInfo fvi = new FileVersionInfo ();
282                         fvi.GetVersionInfo_internal (fileName);
283                         return fvi;
284                 }
285                 
286                 public override string ToString ()
287                 {
288                         StringBuilder sb = new StringBuilder ();
289
290                         // we use the FileName property so we don't skip the security check
291                         sb.AppendFormat ("File:             {0}{1}", FileName, Environment.NewLine);
292                         // the other informations aren't protected so we can use the members directly
293                         sb.AppendFormat ("InternalName:     {0}{1}", internalname, Environment.NewLine);
294                         sb.AppendFormat ("OriginalFilename: {0}{1}", originalfilename, Environment.NewLine);
295                         sb.AppendFormat ("FileVersion:      {0}{1}", fileversion, Environment.NewLine);
296                         sb.AppendFormat ("FileDescription:  {0}{1}", filedescription, Environment.NewLine);
297                         sb.AppendFormat ("Product:          {0}{1}", productname, Environment.NewLine);
298                         sb.AppendFormat ("ProductVersion:   {0}{1}", productversion, Environment.NewLine);
299                         sb.AppendFormat ("Debug:            {0}{1}", isdebug, Environment.NewLine);
300                         sb.AppendFormat ("Patched:          {0}{1}", ispatched, Environment.NewLine);
301                         sb.AppendFormat ("PreRelease:       {0}{1}", isprerelease, Environment.NewLine);
302                         sb.AppendFormat ("PrivateBuild:     {0}{1}", isprivatebuild, Environment.NewLine);
303                         sb.AppendFormat ("SpecialBuild:     {0}{1}", isspecialbuild, Environment.NewLine);
304                         sb.AppendFormat ("Language          {0}{1}", language, Environment.NewLine);
305
306                         return sb.ToString ();
307                 }
308         }
309 }