ComHelper.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // ComHelper.cs
  2. // ------------------------------------------------------------------
  3. //
  4. // Copyright (c) 2009 Dino Chiesa.
  5. // All rights reserved.
  6. //
  7. // This code module is part of DotNetZip, a zipfile class library.
  8. //
  9. // ------------------------------------------------------------------
  10. //
  11. // This code is licensed under the Microsoft Public License.
  12. // See the file License.txt for the license details.
  13. // More info on: http://dotnetzip.codeplex.com
  14. //
  15. // ------------------------------------------------------------------
  16. //
  17. // last saved (in emacs):
  18. // Time-stamp: <2011-June-13 17:04:06>
  19. //
  20. // ------------------------------------------------------------------
  21. //
  22. // This module defines a COM Helper class.
  23. //
  24. // Created: Tue, 08 Sep 2009 22:03
  25. //
  26. using Interop=System.Runtime.InteropServices;
  27. namespace Ionic.Zip
  28. {
  29. /// <summary>
  30. /// This class exposes a set of COM-accessible wrappers for static
  31. /// methods available on the ZipFile class. You don't need this
  32. /// class unless you are using DotNetZip from a COM environment.
  33. /// </summary>
  34. [System.Runtime.InteropServices.GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000F")]
  35. [System.Runtime.InteropServices.ComVisible(true)]
  36. #if !NETCF
  37. [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
  38. #endif
  39. public class ComHelper
  40. {
  41. /// <summary>
  42. /// A wrapper for <see cref="ZipFile.IsZipFile(string)">ZipFile.IsZipFile(string)</see>
  43. /// </summary>
  44. /// <param name="filename">The filename to of the zip file to check.</param>
  45. /// <returns>true if the file contains a valid zip file.</returns>
  46. public bool IsZipFile(string filename)
  47. {
  48. return ZipFile.IsZipFile(filename);
  49. }
  50. /// <summary>
  51. /// A wrapper for <see cref="ZipFile.IsZipFile(string, bool)">ZipFile.IsZipFile(string, bool)</see>
  52. /// </summary>
  53. /// <remarks>
  54. /// We cannot use "overloaded" Method names in COM interop.
  55. /// So, here, we use a unique name.
  56. /// </remarks>
  57. /// <param name="filename">The filename to of the zip file to check.</param>
  58. /// <returns>true if the file contains a valid zip file.</returns>
  59. public bool IsZipFileWithExtract(string filename)
  60. {
  61. return ZipFile.IsZipFile(filename, true);
  62. }
  63. #if !NETCF
  64. /// <summary>
  65. /// A wrapper for <see cref="ZipFile.CheckZip(string)">ZipFile.CheckZip(string)</see>
  66. /// </summary>
  67. /// <param name="filename">The filename to of the zip file to check.</param>
  68. ///
  69. /// <returns>true if the named zip file checks OK. Otherwise, false. </returns>
  70. public bool CheckZip(string filename)
  71. {
  72. return ZipFile.CheckZip(filename);
  73. }
  74. /// <summary>
  75. /// A COM-friendly wrapper for the static method <see cref="ZipFile.CheckZipPassword(string,string)"/>.
  76. /// </summary>
  77. ///
  78. /// <param name="filename">The filename to of the zip file to check.</param>
  79. ///
  80. /// <param name="password">The password to check.</param>
  81. ///
  82. /// <returns>true if the named zip file checks OK. Otherwise, false. </returns>
  83. public bool CheckZipPassword(string filename, string password)
  84. {
  85. return ZipFile.CheckZipPassword(filename, password);
  86. }
  87. /// <summary>
  88. /// A wrapper for <see cref="ZipFile.FixZipDirectory(string)">ZipFile.FixZipDirectory(string)</see>
  89. /// </summary>
  90. /// <param name="filename">The filename to of the zip file to fix.</param>
  91. public void FixZipDirectory(string filename)
  92. {
  93. ZipFile.FixZipDirectory(filename);
  94. }
  95. #endif
  96. /// <summary>
  97. /// A wrapper for <see cref="ZipFile.LibraryVersion">ZipFile.LibraryVersion</see>
  98. /// </summary>
  99. /// <returns>
  100. /// the version number on the DotNetZip assembly, formatted as a string.
  101. /// </returns>
  102. public string GetZipLibraryVersion()
  103. {
  104. return ZipFile.LibraryVersion.ToString();
  105. }
  106. }
  107. }