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 ()
76 // no nulls (for unavailable items)
79 filedescription = null;
84 legalcopyright = null;
85 legaltrademarks = null;
86 originalfilename = null;
89 productversion = null;
92 // This is here just to shut the compiler up
105 productprivatepart=0;
109 public string Comments {
115 public string CompanyName {
121 public int FileBuildPart {
123 return(filebuildpart);
127 public string FileDescription {
129 return(filedescription);
133 public int FileMajorPart {
135 return(filemajorpart);
139 public int FileMinorPart {
141 return(fileminorpart);
145 public string FileName {
148 if (SecurityManager.SecurityEnabled) {
149 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, filename).Demand ();
156 public int FilePrivatePart {
158 return(fileprivatepart);
162 public string FileVersion {
168 public string InternalName {
170 return(internalname);
174 public bool IsDebug {
180 public bool IsPatched {
186 public bool IsPreRelease {
188 return(isprerelease);
192 public bool IsPrivateBuild {
194 return(isprivatebuild);
198 public bool IsSpecialBuild {
200 return(isspecialbuild);
204 public string Language {
210 public string LegalCopyright {
212 return(legalcopyright);
216 public string LegalTrademarks {
218 return(legaltrademarks);
222 public string OriginalFilename {
224 return(originalfilename);
228 public string PrivateBuild {
230 return(privatebuild);
234 public int ProductBuildPart {
236 return(productbuildpart);
240 public int ProductMajorPart {
242 return(productmajorpart);
246 public int ProductMinorPart {
248 return(productminorpart);
252 public string ProductName {
258 public int ProductPrivatePart {
260 return(productprivatepart);
264 public string ProductVersion {
266 return(productversion);
270 public string SpecialBuild {
272 return(specialbuild);
276 [MethodImplAttribute(MethodImplOptions.InternalCall)]
277 private extern void GetVersionInfo_internal(string fileName);
279 public static FileVersionInfo GetVersionInfo (string fileName)
282 if (SecurityManager.SecurityEnabled) {
283 new FileIOPermission (FileIOPermissionAccess.Read, fileName).Demand ();
287 string absolute = Path.GetFullPath (fileName);
288 if (!File.Exists (absolute))
289 throw new FileNotFoundException (fileName);
291 FileVersionInfo fvi = new FileVersionInfo ();
292 fvi.GetVersionInfo_internal (fileName);
296 // use our own AppendFormat because NET_2_1 have only this overload
297 static void AppendFormat (StringBuilder sb, string format, params object [] args)
299 sb.AppendFormat (format, args);
302 public override string ToString ()
304 StringBuilder sb = new StringBuilder ();
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);
322 return sb.ToString ();