Implement mono_gc_alloc_fixed on Boehm to be uncollectable. This matches SGen behavio...
[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.IO;
32 using System.Runtime.CompilerServices;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Text;
36
37 namespace System.Diagnostics {
38
39         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
40         public sealed class FileVersionInfo {
41                 /* There is no public constructor for this class, it
42                  * is initialised by the runtime.  All the private
43                  * variables here are looked up by name, so dont
44                  * change them without also changing the runtime
45                  */
46                 private string comments;
47                 private string companyname;
48                 private string filedescription;
49                 private string filename;
50                 private string fileversion;
51                 private string internalname;
52                 private string language;
53                 private string legalcopyright;
54                 private string legaltrademarks;
55                 private string originalfilename;
56                 private string privatebuild;
57                 private string productname;
58                 private string productversion;
59                 private string specialbuild;
60                 private bool isdebug;
61                 private bool ispatched;
62                 private bool isprerelease;
63                 private bool isprivatebuild;
64                 private bool isspecialbuild;
65                 private int filemajorpart;
66                 private int fileminorpart;
67                 private int filebuildpart;
68                 private int fileprivatepart;
69                 private int productmajorpart;
70                 private int productminorpart;
71                 private int productbuildpart;
72                 private int productprivatepart;
73
74                 private FileVersionInfo ()
75                 {
76                         // no nulls (for unavailable items)
77                         comments = null;
78                         companyname = null;
79                         filedescription = null;
80                         filename = null;
81                         fileversion = null;
82                         internalname = null;
83                         language = null;
84                         legalcopyright = null;
85                         legaltrademarks = null;
86                         originalfilename = null;
87                         privatebuild = null;
88                         productname = null;
89                         productversion = null;
90                         specialbuild = null;
91
92                         // This is here just to shut the compiler up
93                         isdebug=false;
94                         ispatched=false;
95                         isprerelease=false;
96                         isprivatebuild=false;
97                         isspecialbuild=false;
98                         filemajorpart=0;
99                         fileminorpart=0;
100                         filebuildpart=0;
101                         fileprivatepart=0;
102                         productmajorpart=0;
103                         productminorpart=0;
104                         productbuildpart=0;
105                         productprivatepart=0;
106                 }
107                 
108                 
109                 public string Comments {
110                         get {
111                                 return(comments);
112                         }
113                 }
114
115                 public string CompanyName {
116                         get {
117                                 return(companyname);
118                         }
119                 }
120
121                 public int FileBuildPart {
122                         get {
123                                 return(filebuildpart);
124                         }
125                 }
126
127                 public string FileDescription {
128                         get {
129                                 return(filedescription);
130                         }
131                 }
132
133                 public int FileMajorPart {
134                         get {
135                                 return(filemajorpart);
136                         }
137                 }
138                 
139                 public int FileMinorPart {
140                         get {
141                                 return(fileminorpart);
142                         }
143                 }
144
145                 public string FileName {
146                         get {
147 #if FEATURE_MONO_CAS
148                                 if (SecurityManager.SecurityEnabled) {
149                                         new FileIOPermission (FileIOPermissionAccess.PathDiscovery, filename).Demand ();
150                                 }
151 #endif
152                                 return filename;
153                         }
154                 }
155
156                 public int FilePrivatePart {
157                         get {
158                                 return(fileprivatepart);
159                         }
160                 }
161
162                 public string FileVersion {
163                         get {
164                                 return(fileversion);
165                         }
166                 }
167
168                 public string InternalName {
169                         get {
170                                 return(internalname);
171                         }
172                 }
173
174                 public bool IsDebug {
175                         get {
176                                 return(isdebug);
177                         }
178                 }
179
180                 public bool IsPatched {
181                         get {
182                                 return(ispatched);
183                         }
184                 }
185
186                 public bool IsPreRelease {
187                         get {
188                                 return(isprerelease);
189                         }
190                 }
191                 
192                 public bool IsPrivateBuild {
193                         get {
194                                 return(isprivatebuild);
195                         }
196                 }
197
198                 public bool IsSpecialBuild {
199                         get {
200                                 return(isspecialbuild);
201                         }
202                 }
203
204                 public string Language {
205                         get {
206                                 return(language);
207                         }
208                 }
209
210                 public string LegalCopyright {
211                         get {
212                                 return(legalcopyright);
213                         }
214                 }
215
216                 public string LegalTrademarks {
217                         get {
218                                 return(legaltrademarks);
219                         }
220                 }
221
222                 public string OriginalFilename {
223                         get {
224                                 return(originalfilename);
225                         }
226                 }
227
228                 public string PrivateBuild {
229                         get {
230                                 return(privatebuild);
231                         }
232                 }
233
234                 public int ProductBuildPart {
235                         get {
236                                 return(productbuildpart);
237                         }
238                 }
239
240                 public int ProductMajorPart {
241                         get {
242                                 return(productmajorpart);
243                         }
244                 }
245
246                 public int ProductMinorPart {
247                         get {
248                                 return(productminorpart);
249                         }
250                 }
251
252                 public string ProductName {
253                         get {
254                                 return(productname);
255                         }
256                 }
257
258                 public int ProductPrivatePart {
259                         get {
260                                 return(productprivatepart);
261                         }
262                 }
263
264                 public string ProductVersion {
265                         get {
266                                 return(productversion);
267                         }
268                 }
269
270                 public string SpecialBuild {
271                         get {
272                                 return(specialbuild);
273                         }
274                 }
275
276                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
277                 private extern void GetVersionInfo_internal(string fileName);
278                 
279                 public static FileVersionInfo GetVersionInfo (string fileName)
280                 {
281 #if FEATURE_MONO_CAS
282                         if (SecurityManager.SecurityEnabled) {
283                                 new FileIOPermission (FileIOPermissionAccess.Read, fileName).Demand ();
284                         }
285 #endif
286
287                         string absolute = Path.GetFullPath (fileName);
288                         if (!File.Exists (absolute))
289                                 throw new FileNotFoundException (fileName);
290
291                         FileVersionInfo fvi = new FileVersionInfo ();
292                         fvi.GetVersionInfo_internal (fileName);
293                         return fvi;
294                 }
295
296                 // use our own AppendFormat because MOBILE have only this overload
297                 static void AppendFormat (StringBuilder sb, string format, params object [] args)
298                 {
299                         sb.AppendFormat (format, args);
300                 }
301
302                 public override string ToString ()
303                 {
304                         StringBuilder sb = new StringBuilder ();
305
306                         // we use the FileName property so we don't skip the security check
307                         AppendFormat (sb, "File:             {0}{1}", FileName, Environment.NewLine);
308                         // the other informations aren't protected so we can use the members directly
309                         AppendFormat (sb, "InternalName:     {0}{1}", internalname, Environment.NewLine);
310                         AppendFormat (sb, "OriginalFilename: {0}{1}", originalfilename, Environment.NewLine);
311                         AppendFormat (sb, "FileVersion:      {0}{1}", fileversion, Environment.NewLine);
312                         AppendFormat (sb, "FileDescription:  {0}{1}", filedescription, Environment.NewLine);
313                         AppendFormat (sb, "Product:          {0}{1}", productname, Environment.NewLine);
314                         AppendFormat (sb, "ProductVersion:   {0}{1}", productversion, Environment.NewLine);
315                         AppendFormat (sb, "Debug:            {0}{1}", isdebug, Environment.NewLine);
316                         AppendFormat (sb, "Patched:          {0}{1}", ispatched, Environment.NewLine);
317                         AppendFormat (sb, "PreRelease:       {0}{1}", isprerelease, Environment.NewLine);
318                         AppendFormat (sb, "PrivateBuild:     {0}{1}", isprivatebuild, Environment.NewLine);
319                         AppendFormat (sb, "SpecialBuild:     {0}{1}", isspecialbuild, Environment.NewLine);
320                         AppendFormat (sb, "Language          {0}{1}", language, Environment.NewLine);
321
322                         return sb.ToString ();
323                 }
324         }
325 }