private void CloseVolumes() { while (_volumeHandles.Count > 0) { var volumeHandle = _volumeHandles.Pop(); DiskUtils.UnlockVolume(volumeHandle); volumeHandle.Dispose(); } }
private void OpenVolumes() { if (!Utils.IsNullOrEmpty(_diskInfo.Drives)) { foreach (var drive in _diskInfo.Drives) { try { var volumeHandle = DiskUtils.GetVolumeHandle(drive.Name); if (volumeHandle == null) { throw new Exception($"Could not open volume: {drive.Name}"); } if (!DiskUtils.LockVolume(volumeHandle)) { volumeHandle.Close(); throw new Exception($"Could not lock volume: {drive.Name}"); } if (!DiskUtils.UnmountVolume(volumeHandle)) { DiskUtils.UnlockVolume(volumeHandle); volumeHandle.Close(); throw new Exception($"Could not unmount volume: {drive.Name}"); } _volumeHandles.Push(volumeHandle); } catch { CloseVolumes(); throw; } } } }