2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System / System.Diagnostics / FileVersionInfo.cs
blob8a292f9cf6498095ae0172f26f3b430c708ee66f
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)
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.
31 using System.IO;
32 using System.Runtime.CompilerServices;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Text;
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;
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;
74 private FileVersionInfo ()
76 #if NET_2_0
77 // no nulls (for unavailable items)
78 comments = null;
79 companyname = null;
80 filedescription = null;
81 filename = null;
82 fileversion = null;
83 internalname = null;
84 language = null;
85 legalcopyright = null;
86 legaltrademarks = null;
87 originalfilename = null;
88 privatebuild = null;
89 productname = null;
90 productversion = null;
91 specialbuild = null;
92 #else
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;
108 #endif
109 // This is here just to shut the compiler up
110 isdebug=false;
111 ispatched=false;
112 isprerelease=false;
113 isprivatebuild=false;
114 isspecialbuild=false;
115 filemajorpart=0;
116 fileminorpart=0;
117 filebuildpart=0;
118 fileprivatepart=0;
119 productmajorpart=0;
120 productminorpart=0;
121 productbuildpart=0;
122 productprivatepart=0;
126 public string Comments {
127 get {
128 return(comments);
132 public string CompanyName {
133 get {
134 return(companyname);
138 public int FileBuildPart {
139 get {
140 return(filebuildpart);
144 public string FileDescription {
145 get {
146 return(filedescription);
150 public int FileMajorPart {
151 get {
152 return(filemajorpart);
156 public int FileMinorPart {
157 get {
158 return(fileminorpart);
162 public string FileName {
163 get {
164 #if !NET_2_1
165 if (SecurityManager.SecurityEnabled) {
166 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, filename).Demand ();
168 #endif
169 return filename;
173 public int FilePrivatePart {
174 get {
175 return(fileprivatepart);
179 public string FileVersion {
180 get {
181 return(fileversion);
185 public string InternalName {
186 get {
187 return(internalname);
191 public bool IsDebug {
192 get {
193 return(isdebug);
197 public bool IsPatched {
198 get {
199 return(ispatched);
203 public bool IsPreRelease {
204 get {
205 return(isprerelease);
209 public bool IsPrivateBuild {
210 get {
211 return(isprivatebuild);
215 public bool IsSpecialBuild {
216 get {
217 return(isspecialbuild);
221 public string Language {
222 get {
223 return(language);
227 public string LegalCopyright {
228 get {
229 return(legalcopyright);
233 public string LegalTrademarks {
234 get {
235 return(legaltrademarks);
239 public string OriginalFilename {
240 get {
241 return(originalfilename);
245 public string PrivateBuild {
246 get {
247 return(privatebuild);
251 public int ProductBuildPart {
252 get {
253 return(productbuildpart);
257 public int ProductMajorPart {
258 get {
259 return(productmajorpart);
263 public int ProductMinorPart {
264 get {
265 return(productminorpart);
269 public string ProductName {
270 get {
271 return(productname);
275 public int ProductPrivatePart {
276 get {
277 return(productprivatepart);
281 public string ProductVersion {
282 get {
283 return(productversion);
287 public string SpecialBuild {
288 get {
289 return(specialbuild);
293 [MethodImplAttribute(MethodImplOptions.InternalCall)]
294 private extern void GetVersionInfo_internal(string fileName);
296 public static FileVersionInfo GetVersionInfo (string fileName)
298 #if !NET_2_1
299 if (SecurityManager.SecurityEnabled) {
300 new FileIOPermission (FileIOPermissionAccess.Read, fileName).Demand ();
302 #endif
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);
310 return fvi;
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 ();