FileVersionInfo.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. // System.Diagnostics.FileVersionInfo.cs
  3. //
  4. // Authors:
  5. // Dick Porter ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Runtime.CompilerServices;
  31. namespace System.Diagnostics {
  32. public sealed class FileVersionInfo {
  33. /* There is no public constructor for this class, it
  34. * is initialised by the runtime. All the private
  35. * variables here are looked up by name, so dont
  36. * change them without also changing the runtime
  37. */
  38. private string comments;
  39. private string companyname;
  40. private string filedescription;
  41. private string filename;
  42. private string fileversion;
  43. private string internalname;
  44. private string language;
  45. private string legalcopyright;
  46. private string legaltrademarks;
  47. private string originalfilename;
  48. private string privatebuild;
  49. private string productname;
  50. private string productversion;
  51. private string specialbuild;
  52. private bool isdebug;
  53. private bool ispatched;
  54. private bool isprerelease;
  55. private bool isprivatebuild;
  56. private bool isspecialbuild;
  57. private int filemajorpart;
  58. private int fileminorpart;
  59. private int filebuildpart;
  60. private int fileprivatepart;
  61. private int productmajorpart;
  62. private int productminorpart;
  63. private int productbuildpart;
  64. private int productprivatepart;
  65. private FileVersionInfo() {
  66. /* This is here just to shut the compiler up */
  67. comments=null;
  68. companyname=null;
  69. filedescription=null;
  70. filename=null;
  71. fileversion=null;
  72. internalname=null;
  73. language=null;
  74. legalcopyright=null;
  75. legaltrademarks=null;
  76. originalfilename=null;
  77. privatebuild=null;
  78. productname=null;
  79. productversion=null;
  80. specialbuild=null;
  81. isdebug=false;
  82. ispatched=false;
  83. isprerelease=false;
  84. isprivatebuild=false;
  85. isspecialbuild=false;
  86. filemajorpart=0;
  87. fileminorpart=0;
  88. filebuildpart=0;
  89. fileprivatepart=0;
  90. productmajorpart=0;
  91. productminorpart=0;
  92. productbuildpart=0;
  93. productprivatepart=0;
  94. }
  95. public string Comments {
  96. get {
  97. return(comments);
  98. }
  99. }
  100. public string CompanyName {
  101. get {
  102. return(companyname);
  103. }
  104. }
  105. public int FileBuildPart {
  106. get {
  107. return(filebuildpart);
  108. }
  109. }
  110. public string FileDescription {
  111. get {
  112. return(filedescription);
  113. }
  114. }
  115. public int FileMajorPart {
  116. get {
  117. return(filemajorpart);
  118. }
  119. }
  120. public int FileMinorPart {
  121. get {
  122. return(fileminorpart);
  123. }
  124. }
  125. public string FileName {
  126. get {
  127. return(filename);
  128. }
  129. }
  130. public int FilePrivatePart {
  131. get {
  132. return(fileprivatepart);
  133. }
  134. }
  135. public string FileVersion {
  136. get {
  137. return(fileversion);
  138. }
  139. }
  140. public string InternalName {
  141. get {
  142. return(internalname);
  143. }
  144. }
  145. public bool IsDebug {
  146. get {
  147. return(isdebug);
  148. }
  149. }
  150. public bool IsPatched {
  151. get {
  152. return(ispatched);
  153. }
  154. }
  155. public bool IsPreRelease {
  156. get {
  157. return(isprerelease);
  158. }
  159. }
  160. public bool IsPrivateBuild {
  161. get {
  162. return(isprivatebuild);
  163. }
  164. }
  165. public bool IsSpecialBuild {
  166. get {
  167. return(isspecialbuild);
  168. }
  169. }
  170. public string Language {
  171. get {
  172. return(language);
  173. }
  174. }
  175. public string LegalCopyright {
  176. get {
  177. return(legalcopyright);
  178. }
  179. }
  180. public string LegalTrademarks {
  181. get {
  182. return(legaltrademarks);
  183. }
  184. }
  185. public string OriginalFilename {
  186. get {
  187. return(originalfilename);
  188. }
  189. }
  190. public string PrivateBuild {
  191. get {
  192. return(privatebuild);
  193. }
  194. }
  195. public int ProductBuildPart {
  196. get {
  197. return(productbuildpart);
  198. }
  199. }
  200. public int ProductMajorPart {
  201. get {
  202. return(productmajorpart);
  203. }
  204. }
  205. public int ProductMinorPart {
  206. get {
  207. return(productminorpart);
  208. }
  209. }
  210. public string ProductName {
  211. get {
  212. return(productname);
  213. }
  214. }
  215. public int ProductPrivatePart {
  216. get {
  217. return(productprivatepart);
  218. }
  219. }
  220. public string ProductVersion {
  221. get {
  222. return(productversion);
  223. }
  224. }
  225. public string SpecialBuild {
  226. get {
  227. return(specialbuild);
  228. }
  229. }
  230. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  231. private extern void GetVersionInfo_internal(string fileName);
  232. public static FileVersionInfo GetVersionInfo(string fileName) {
  233. FileVersionInfo fvi=new FileVersionInfo();
  234. fvi.GetVersionInfo_internal(fileName);
  235. return(fvi);
  236. }
  237. public override string ToString() {
  238. string str;
  239. str="File: " + filename + "\n";
  240. str+="InternalName: " + internalname + "\n";
  241. str+="OriginalFilename: " + originalfilename + "\n";
  242. str+="FileVersion: " + fileversion + "\n";
  243. str+="FileDescription: " + filedescription + "\n";
  244. str+="Product: " + productname + "\n";
  245. str+="ProductVersion: " + productversion + "\n";
  246. str+="Debug: " + isdebug + "\n";
  247. str+="Patched: " + ispatched + "\n";
  248. str+="PreRelease: " + isprerelease + "\n";
  249. str+="PrivateBuild: " + isprivatebuild + "\n";
  250. str+="SpecialBuild: " + isspecialbuild + "\n";
  251. str+="Language " + language + "\n";
  252. return(str);
  253. }
  254. }
  255. }