2 // System.Diagnostics.FileVersionInfo.cs
5 // Dick Porter (dick@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2002 Ximian, Inc.
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System
.Runtime
.CompilerServices
;
33 using System
.Security
;
34 using System
.Security
.Permissions
;
37 namespace System
.Diagnostics
{
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
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
;
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
;
74 private FileVersionInfo ()
77 // no nulls (for unavailable items)
80 filedescription
= null;
85 legalcopyright
= null;
86 legaltrademarks
= null;
87 originalfilename
= null;
90 productversion
= null;
93 // no nulls (for unavailable items)
94 comments
= String
.Empty
;
95 companyname
= String
.Empty
;
96 filedescription
= String
.Empty
;
97 filename
= String
.Empty
;
98 fileversion
= String
.Empty
;
99 internalname
= String
.Empty
;
100 language
= String
.Empty
;
101 legalcopyright
= String
.Empty
;
102 legaltrademarks
= String
.Empty
;
103 originalfilename
= String
.Empty
;
104 privatebuild
= String
.Empty
;
105 productname
= String
.Empty
;
106 productversion
= String
.Empty
;
107 specialbuild
= String
.Empty
;
109 // This is here just to shut the compiler up
113 isprivatebuild
=false;
114 isspecialbuild
=false;
122 productprivatepart
=0;
126 public string Comments
{
132 public string CompanyName
{
138 public int FileBuildPart
{
140 return(filebuildpart
);
144 public string FileDescription
{
146 return(filedescription
);
150 public int FileMajorPart
{
152 return(filemajorpart
);
156 public int FileMinorPart
{
158 return(fileminorpart
);
162 public string FileName
{
165 if (SecurityManager
.SecurityEnabled
) {
166 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, filename
).Demand ();
173 public int FilePrivatePart
{
175 return(fileprivatepart
);
179 public string FileVersion
{
185 public string InternalName
{
187 return(internalname
);
191 public bool IsDebug
{
197 public bool IsPatched
{
203 public bool IsPreRelease
{
205 return(isprerelease
);
209 public bool IsPrivateBuild
{
211 return(isprivatebuild
);
215 public bool IsSpecialBuild
{
217 return(isspecialbuild
);
221 public string Language
{
227 public string LegalCopyright
{
229 return(legalcopyright
);
233 public string LegalTrademarks
{
235 return(legaltrademarks
);
239 public string OriginalFilename
{
241 return(originalfilename
);
245 public string PrivateBuild
{
247 return(privatebuild
);
251 public int ProductBuildPart
{
253 return(productbuildpart
);
257 public int ProductMajorPart
{
259 return(productmajorpart
);
263 public int ProductMinorPart
{
265 return(productminorpart
);
269 public string ProductName
{
275 public int ProductPrivatePart
{
277 return(productprivatepart
);
281 public string ProductVersion
{
283 return(productversion
);
287 public string SpecialBuild
{
289 return(specialbuild
);
293 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
294 private extern void GetVersionInfo_internal(string fileName
);
296 public static FileVersionInfo
GetVersionInfo (string fileName
)
299 if (SecurityManager
.SecurityEnabled
) {
300 new FileIOPermission (FileIOPermissionAccess
.Read
, fileName
).Demand ();
304 string absolute
= Path
.GetFullPath (fileName
);
305 if (!File
.Exists (absolute
))
306 throw new FileNotFoundException (fileName
);
308 FileVersionInfo fvi
= new FileVersionInfo ();
309 fvi
.GetVersionInfo_internal (fileName
);
313 // use our own AppendFormat because NET_2_1 have only this overload
314 static void AppendFormat (StringBuilder sb
, string format
, params object [] args
)
316 sb
.AppendFormat (format
, args
);
319 public override string ToString ()
321 StringBuilder sb
= new StringBuilder ();
323 // we use the FileName property so we don't skip the security check
324 AppendFormat (sb
, "File: {0}{1}", FileName
, Environment
.NewLine
);
325 // the other informations aren't protected so we can use the members directly
326 AppendFormat (sb
, "InternalName: {0}{1}", internalname
, Environment
.NewLine
);
327 AppendFormat (sb
, "OriginalFilename: {0}{1}", originalfilename
, Environment
.NewLine
);
328 AppendFormat (sb
, "FileVersion: {0}{1}", fileversion
, Environment
.NewLine
);
329 AppendFormat (sb
, "FileDescription: {0}{1}", filedescription
, Environment
.NewLine
);
330 AppendFormat (sb
, "Product: {0}{1}", productname
, Environment
.NewLine
);
331 AppendFormat (sb
, "ProductVersion: {0}{1}", productversion
, Environment
.NewLine
);
332 AppendFormat (sb
, "Debug: {0}{1}", isdebug
, Environment
.NewLine
);
333 AppendFormat (sb
, "Patched: {0}{1}", ispatched
, Environment
.NewLine
);
334 AppendFormat (sb
, "PreRelease: {0}{1}", isprerelease
, Environment
.NewLine
);
335 AppendFormat (sb
, "PrivateBuild: {0}{1}", isprivatebuild
, Environment
.NewLine
);
336 AppendFormat (sb
, "SpecialBuild: {0}{1}", isspecialbuild
, Environment
.NewLine
);
337 AppendFormat (sb
, "Language {0}{1}", language
, Environment
.NewLine
);
339 return sb
.ToString ();