private void UnmountAndDetach(string vhdFileName) { FileInfo fi = new FileInfo(vhdFileName); if (!fi.Exists) { return; } Log.WriteLine("UnmountAndDetach({0})", vhdFileName); fi.IsReadOnly = false; //unlock file to enable load try { if (_virtualDisk != null) // && _virtualDisk.FileName.CompareTo(vhdFileName) != 0) { _virtualDisk.Close(); _virtualDisk = null; } if (_virtualDisk == null || !_virtualDisk.IsOpen) { _virtualDisk = new Medo.IO.VirtualDisk(vhdFileName); _virtualDisk.Open(); } string diskPath = _virtualDisk.GetAttachedPath(); if (!string.IsNullOrWhiteSpace(diskPath)) //if device is attached { DiskCryptor.DriveInfo drive = FindDriveInfo(diskPath); if (drive != null) { try { UnmountDiscryptorDrive(drive); } catch (Exception err) { Log.WriteLine("UnmountDiscryptorDrive({0}) - Error: {1}", diskPath, err); } } _virtualDisk.Detach(); } } catch (Exception err) { Log.WriteLine("UnmountAndDetach({0}): {1}", vhdFileName, err.ToString()); throw; } finally { if (_virtualDisk != null) { _virtualDisk.Close(); _virtualDisk = null; } fi.IsReadOnly = true; //lock file to improve security } }
private void m_listDrives_SelectedIndexChanged(object sender, EventArgs e) { m_lblSelected.Text = "Selected: ???"; m_btnMount.Enabled = false; m_btnUnmount.Enabled = false; if (m_listDrives.SelectedIndices.Count <= 0) { return; } DiskCryptor.DriveInfo drive = m_listDrives.SelectedItems[0].Tag as DiskCryptor.DriveInfo; m_lblSelected.Text = "Selected: " + drive.volume + ", MP: " + drive.mount_point; m_btnMount.Enabled = drive.volume.StartsWith("pt") && drive.status.StartsWith("unmounted"); m_btnUnmount.Enabled = drive.volume.StartsWith("pt") && drive.status.StartsWith("mounted"); }
private void m_btnUnmount_Click(object sender, EventArgs e) { ExecuteClickAction(() => { m_lblSelected.Text = "Selected: ???"; if (m_listDrives.SelectedIndices.Count <= 0) { return; } DiskCryptor.DriveInfo drive = m_listDrives.SelectedItems[0].Tag as DiskCryptor.DriveInfo; Unmount(drive); ReloadDriveData(); }, sender); }
private void OnDiskAddedMountDiskCryptorDisk(DiskCryptor.DriveInfo driveInfo) { if (_cachedDriveInfo == null) { return; } //find newly added drive var found = _cachedDriveInfo.FirstOrDefault(d => d.ToString() == driveInfo.ToString()); if (found == null) { _diskCryptor.OnDisksAdded -= OnDiskAddedMountDiskCryptorDisk; _cachedDriveInfo = null; Debug.WriteLine("On Disk Added: " + driveInfo.Description()); _diskCryptor.ExecuteMount(driveInfo, _selectedDriveLetterForMount, GetPasswordFunc()); ReloadDriveData(1000); } }
private void m_btnMount_Click(object sender, EventArgs e) { ExecuteClickAction(() => { m_lblSelected.Text = "Selected: ???"; if (m_listDrives.SelectedIndices.Count <= 0) { return; } if (string.IsNullOrWhiteSpace(m_txtPwd.Text)) { MessageBox.Show(this, "Password is empty"); return; } DiskCryptor.DriveInfo drive = m_listDrives.SelectedItems[0].Tag as DiskCryptor.DriveInfo; _diskCryptor.ExecuteMount(drive, m_cmbAvailableDriveLetters.SelectedItem.ToString(), m_txtPwd.Text); ReloadDriveData(); }, sender); }
private void Unmount(DiskCryptor.DriveInfo drive) { _diskCryptor.ExecuteUnMount(drive); ReloadDriveData(); }