PismoMount.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Model.Logging;
  3. using System;
  4. namespace MediaBrowser.IsoMounter
  5. {
  6. /// <summary>
  7. /// Class IsoMount
  8. /// </summary>
  9. internal class PismoMount : IIsoMount
  10. {
  11. /// <summary>
  12. /// Gets or sets the iso path.
  13. /// </summary>
  14. /// <value>The iso path.</value>
  15. public string IsoPath { get; internal set; }
  16. /// <summary>
  17. /// Gets the mounted path.
  18. /// </summary>
  19. /// <value>The mounted path.</value>
  20. public string MountedPath { get; internal set; }
  21. /// <summary>
  22. /// The PFM file mount
  23. /// </summary>
  24. private PfmFileMount _pfmFileMount;
  25. /// <summary>
  26. /// The _iso manager
  27. /// </summary>
  28. private readonly PismoIsoManager _isoManager;
  29. /// <summary>
  30. /// Gets or sets the logger.
  31. /// </summary>
  32. /// <value>The logger.</value>
  33. private ILogger Logger { get; set; }
  34. /// <summary>
  35. /// Prevents a default instance of the <see cref="PismoMount" /> class from being created.
  36. /// </summary>
  37. /// <param name="mount">The mount.</param>
  38. /// <param name="isoPath">The iso path.</param>
  39. /// <param name="isoManager">The iso manager.</param>
  40. /// <param name="logger">The logger.</param>
  41. internal PismoMount(PfmFileMount mount, string isoPath, PismoIsoManager isoManager, ILogger logger)
  42. {
  43. _pfmFileMount = mount;
  44. IsoPath = isoPath;
  45. _isoManager = isoManager;
  46. Logger = logger;
  47. MountedPath = mount.GetMount().GetUncName();
  48. }
  49. /// <summary>
  50. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  51. /// </summary>
  52. public void Dispose()
  53. {
  54. Dispose(true);
  55. GC.SuppressFinalize(this);
  56. }
  57. /// <summary>
  58. /// Releases unmanaged and - optionally - managed resources.
  59. /// </summary>
  60. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  61. protected virtual void Dispose(bool dispose)
  62. {
  63. UnMount();
  64. }
  65. /// <summary>
  66. /// Uns the mount.
  67. /// </summary>
  68. private void UnMount()
  69. {
  70. if (_pfmFileMount != null)
  71. {
  72. Logger.Info("Unmounting {0}", IsoPath);
  73. _pfmFileMount.Cancel();
  74. _pfmFileMount.Detach();
  75. _isoManager.OnUnmount(this);
  76. _pfmFileMount.Dispose();
  77. _pfmFileMount = null;
  78. }
  79. }
  80. }
  81. }