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.
31 using System.Runtime.CompilerServices;
32 using System.Security;
33 using System.Security.Permissions;
36 namespace System.Diagnostics {
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
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;
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;
73 private FileVersionInfo ()
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
103 productprivatepart=0;
107 public string Comments {
113 public string CompanyName {
119 public int FileBuildPart {
121 return(filebuildpart);
125 public string FileDescription {
127 return(filedescription);
131 public int FileMajorPart {
133 return(filemajorpart);
137 public int FileMinorPart {
139 return(fileminorpart);
143 public string FileName {
145 if (SecurityManager.SecurityEnabled) {
146 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, filename).Demand ();
152 public int FilePrivatePart {
154 return(fileprivatepart);
158 public string FileVersion {
164 public string InternalName {
166 return(internalname);
170 public bool IsDebug {
176 public bool IsPatched {
182 public bool IsPreRelease {
184 return(isprerelease);
188 public bool IsPrivateBuild {
190 return(isprivatebuild);
194 public bool IsSpecialBuild {
196 return(isspecialbuild);
200 public string Language {
206 public string LegalCopyright {
208 return(legalcopyright);
212 public string LegalTrademarks {
214 return(legaltrademarks);
218 public string OriginalFilename {
220 return(originalfilename);
224 public string PrivateBuild {
226 return(privatebuild);
230 public int ProductBuildPart {
232 return(productbuildpart);
236 public int ProductMajorPart {
238 return(productmajorpart);
242 public int ProductMinorPart {
244 return(productminorpart);
248 public string ProductName {
254 public int ProductPrivatePart {
256 return(productprivatepart);
260 public string ProductVersion {
262 return(productversion);
266 public string SpecialBuild {
268 return(specialbuild);
272 [MethodImplAttribute(MethodImplOptions.InternalCall)]
273 private extern void GetVersionInfo_internal(string fileName);
275 public static FileVersionInfo GetVersionInfo (string fileName)
277 if (SecurityManager.SecurityEnabled) {
278 new FileIOPermission (FileIOPermissionAccess.Read, fileName).Demand ();
281 FileVersionInfo fvi = new FileVersionInfo ();
282 fvi.GetVersionInfo_internal (fileName);
286 public override string ToString ()
288 StringBuilder sb = new StringBuilder ();
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);
306 return sb.ToString ();