IsoMount.cs 2.6 KB

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