public void Dispose() { Debug.WriteLine("Dispose"); if (_threadCancel != null) _threadCancel.Cancel(); if (_pauseEvent != null) _pauseEvent.Set(); try { Dokan.RemoveMountPoint(String.Format("{0}:\\", Letter)); if (_filesystem != null) { _filesystem.Dispose(); _filesystem = null; } } catch { Status = DriveStatus.Unmounted; } finally { _filesystem = null; } if (_mountCancel != null) {_mountCancel.Dispose();} if (_threadCancel != null) {_threadCancel.Dispose();} if (_pauseEvent != null) {_pauseEvent.Dispose();} }
private void MountLoop() { while (true) { Debug.WriteLine("Thread:Pause"); _pauseEvent.WaitOne(-1); if (_threadCancel.IsCancellationRequested) { Debug.WriteLine("Thread:Cancel"); break; } Debug.WriteLine("Thread:Mount"); try { _filesystem.Mount(String.Format("{0}:\\", Letter), DokanOptions.NetworkDrive | DokanOptions.KeepAlive); } catch (Exception e) { _lastExeption = e; _exeptionThrown = true; _mountCancel.Cancel(); } Status = DriveStatus.Unmounted; if (!_exeptionThrown) { OnStatusChanged(EventArgs.Empty); } } }
public void Unmount() { if (this._threadCancel != null) { this._threadCancel.Cancel(); } if (this._pauseEvent != null) { this._pauseEvent.Set(); } Debug.WriteLine("Unmount"); Status = DriveStatus.Unmounting; try { Dokan.RemoveMountPoint(String.Format("{0}:\\", mountedLetter)); } catch { //Status = DriveStatus.Unmounted; // OnStatusChanged(EventArgs.Empty); } finally { _filesystem = null; } }
public void Unmount() { Debug.WriteLine("Unmount"); Status = DriveStatus.Unmounting; try { // Dokan.Unmount(Letter); Dokan.RemoveMountPoint(String.Format("{0}:\\", Letter)); if (_filesystem != null) { _filesystem.Dispose(); } } catch { //Status = DriveStatus.Unmounted; // OnStatusChanged(EventArgs.Empty); } finally { _filesystem = null; } }
/// <summary>Triggers the event when change on device occured.</summary> /// <param name="sender"></param> /// <param name="e"></param> private void MediaEventArrived(object sender, EventArrivedEventArgs e) { // Get the Event object and display it var pd = e.NewEvent.Properties["TargetInstance"]; DriveStatus driveStatus = _mDriveStatus; var usbDriveInfo = new USBDriveInfo(); { var mbo = pd.Value as ManagementBaseObject; if (mbo != null) { var info = new System.IO.DriveInfo((string)mbo.Properties["DeviceID"].Value); driveStatus = info.IsReady ? DriveStatus.Inserted : DriveStatus.Ejected; usbDriveInfo.DriveName = (string)mbo.Properties["DeviceID"].Value; } usbDriveInfo.DriveStatus = driveStatus; } if (driveStatus != _mDriveStatus) { _mDriveStatus = driveStatus; if (null != MediaWatcher) { MediaWatcher(sender, usbDriveInfo); } } }
public static DriveStatus ToStorApiDriveStatus(PhysicalDisk pd) { DriveStatus driveStatus = DriveStatus.DRIVE_UNKNOWN; switch (pd.HealthStatus) { case HealthStatusEnum.Healthy: driveStatus = DriveStatus.DRIVE_GOOD; goto IL_27; case HealthStatusEnum.Unhealthy: driveStatus = DriveStatus.DRIVE_FAILED; goto IL_27; } driveStatus = DriveStatus.DRIVE_UNKNOWN; IL_27: if (driveStatus != DriveStatus.DRIVE_FAILED) { foreach (OperationalStatusEnum operationalStatusEnum in pd.OperationalStatus) { if (operationalStatusEnum == OperationalStatusEnum.PredictiveFailure) { driveStatus = DriveStatus.DRIVE_IMMINENT_FAILURE; break; } if (operationalStatusEnum == OperationalStatusEnum.Error || operationalStatusEnum == OperationalStatusEnum.NonRecoverableError || operationalStatusEnum == OperationalStatusEnum.LostCommunication || operationalStatusEnum == OperationalStatusEnum.NoContact) { driveStatus = DriveStatus.DRIVE_FAILED; break; } } } return(driveStatus); }
/// <summary> /// Refreshes the list of availalable drives. /// </summary> /// <returns>The status of the drives.</returns> public DriveStatus RefreshDrives() { if (this.driveService == null) { throw new InvalidOperationException("Media type must be selected first."); } // Initialize the drives DriveStatus result = this.driveService.Initialize(); this.logging.Write("Devices initialized", result.ToString()); // Display the next screen switch (this.mediaType) { case MediaType.Usb: this.PopulateUsbDrives(); this.view.DisplayUsbScreen(); this.view.ScreenTitle = Properties.Resources.TitleUsb; break; case MediaType.Dvd: this.view.DisplayDvdScreen(); this.view.ScreenTitle = Properties.Resources.TitleDvd; break; default: throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Invalid media type {0}.", this.mediaType)); } this.view.DriveStatus = result; return(result); }
public void Mount() { Debug.WriteLine("Mount"); if (Directory.GetLogicalDrives().Any(drive=>drive[0]==Letter)) { throw new Exception("Drive with the same letter exists"); } Status = DriveStatus.Mounting; try { SetupFilesystem(); } catch { Status = DriveStatus.Unmounted; throw; } SetupMountThread(); var mountEvent = Task.Factory.StartNew(() => { while (!_mountCancel.IsCancellationRequested && Directory.GetLogicalDrives().All( drive => drive[0] != Letter)) { Thread.Sleep(1000); } }, _mountCancel.Token); _pauseEvent.Set(); mountEvent.Wait(); if (_exeptionThrown) { _exeptionThrown = false; throw _lastExeption; } if(Settings.Default.UseNetworkDrive) Utilities.SetNetworkDriveName(_connection, Name); Status= DriveStatus.Mounted; OnStatusChanged(EventArgs.Empty); }
/// <summary> /// Begins the backup process. /// </summary> /// <param name="drivePath">The path to the selected drive.</param> public void BeginBackup(string drivePath) { // Re-initilize the drive service to get the lastest status before begining. DriveStatus status = this.RefreshDrives(); if (status == DriveStatus.Ready && this.mediaType == MediaType.Usb) { // Don't continue for empty drive path. Happens if the user clicks continue without selecting a drive. if (String.IsNullOrEmpty(drivePath)) { return; } status = this.driveService.SetActiveDrive(drivePath); this.logging.Write("Drive selected", drivePath, status.ToString()); } string driveLabel = GetDriveLabel(this.driveService.ActiveDrive); this.view.SelectedDriveLabel = driveLabel; // Display appropriate prompts for erasing the drive before allowing to continue backup. bool ready = status == DriveStatus.Ready || (status == DriveStatus.DeviceNotBlank && DialogResult.OK == this.view.DisplayMessage( String.Format(CultureInfo.InvariantCulture, Properties.Resources.UsbEraseMessage, driveLabel), Properties.Resources.UsbFreeSpaceCaption, Properties.Resources.UsbFreeSpaceErase, Properties.Resources.UsbFreeSpaceCancel) && DialogResult.Yes == MessageBox.Show( String.Format(CultureInfo.InvariantCulture, Properties.Resources.UsbEraseConfirm, driveLabel), Properties.Resources.UsbFreeSpaceCaption, MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button2, 0)); // Begin burning if ready. if (ready) { this.view.DisableStandby = true; // Disable standby during backup. this.canceling = false; this.driveService.BeginBackup(); this.view.DisplayProgressScreen(); this.view.ScreenTitle = this.mediaType == MediaType.Usb ? Properties.Resources.TitleUsbProgress : Properties.Resources.TitleDvdProgress; this.logging.Write("Backup started"); } else { this.view.DriveStatus = status; } }
private void MountLoop() { while (true) { Debug.WriteLine("Thread:Pause"); _pauseEvent.WaitOne(-1); if (_threadCancel.IsCancellationRequested) { Debug.WriteLine("Thread:Cancel"); break; } Debug.WriteLine("Thread:Mount"); try { _filesystem = new VirtualFilesystem("WinSshFS spool"); foreach (SftpDrive drive in _drives) { if (drive.MountPoint != "") { _filesystem.AddSubFS(drive); } } mountedLetter = Letter; int threadCount = 8; #if DEBUG threadCount = 1; #endif _filesystem.Mount(String.Format("{0}:\\", mountedLetter), Settings.Default.UseNetworkDrive ? DokanOptions.NetworkDrive : DokanOptions.RemovableDrive, threadCount); } catch (Exception e) { _lastExeption = e; _exeptionThrown = true; _mountCancel.Cancel(); } Status = DriveStatus.Unmounted; this._mountThread = null; if (!_exeptionThrown) { OnStatusChanged(EventArgs.Empty); } } }
public void Dispose() { Debug.WriteLine("Dispose"); try { Dokan.RemoveMountPoint(String.Format("{0}:\\", Letter)); } catch { Status = DriveStatus.Unmounted; } finally { _filesystem = null; } }
public void Set(FolderModel F) { use_global_login = F.use_global_login; ID = F.ID; Name = F.Name; Note = F.Note; Folder = F.Folder; Letter = F.Letter; Username = F.Username; Password = F.Password; Passphrase = F.Passphrase; PrivateKey = F.PrivateKey; Status = F.Status; Type = F.Type; VirtualDriveFolder = F.VirtualDriveFolder; use_virtual_drive = F.use_virtual_drive; Automount = F.Automount; }
/// <summary>Triggers the event when change on device occured.</summary> /// <param name="sender"></param> /// <param name="e"></param> private void MediaEventArrived(object sender, EventArrivedEventArgs e) { // Get the Event object and display it PropertyData pd = e.NewEvent.Properties["TargetInstance"]; DriveStatus driveStatus = this.m_driveStatus; if (pd != null) { ManagementBaseObject mbo = pd.Value as ManagementBaseObject; System.IO.DriveInfo info = new System.IO.DriveInfo((string)mbo.Properties["DeviceID"].Value); driveStatus = info.IsReady ? DriveStatus.Inserted : DriveStatus.Ejected; } if (driveStatus != this.m_driveStatus) { this.m_driveStatus = driveStatus; if (null != MediaWatcher) { MediaWatcher(sender, driveStatus); } } }
public void Unmount() { _threadCancel?.Cancel(); _pauseEvent?.Set(); Debug.WriteLine("Unmount"); Status = DriveStatus.Unmounting; try { Dokan.RemoveMountPoint($"{mountedLetter}:\\"); } catch { //Status = DriveStatus.Unmounted; // OnStatusChanged(EventArgs.Empty); } finally { _filesystem = null; } }
public List <DriveStatus> GetDriveStatuses() { using (SqlConnection con = new SqlConnection(ConnectionString)) { var driveStatuses = new List <DriveStatus>(); using (SqlCommand cmd = new SqlCommand("GetDriveStatuses", con)) { cmd.CommandType = CommandType.StoredProcedure; con.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var driveStatus = new DriveStatus() { Id = Guid.Parse(reader["Id"].ToString()), Status = reader["Status"].ToString() }; driveStatuses.Add(driveStatus); } con.Close(); } return(driveStatuses); } }
private void GetDriveStatus(object sender, EventArrivedEventArgs e) { // Get the Event object and display it PropertyData pd = e.NewEvent.Properties["TargetInstance"]; DriveStatus driveStatus = m_driveStatus; if (pd != null) { var mbo = pd.Value as ManagementBaseObject; var info = new DriveInfo((string) mbo.Properties["DeviceID"].Value); driveStatus = info.IsReady ? DriveStatus.Inserted : DriveStatus.Ejected; } if (driveStatus != m_driveStatus) { m_driveStatus = driveStatus; if (null != MediaWatcher) { MediaWatcher(sender, driveStatus); } } }
public void Mount() { Debug.WriteLine("Mount"); if (Directory.GetLogicalDrives().Any(drive=>drive[0]==Letter)) { throw new Exception("Drive with the same letter exists"); } Status = DriveStatus.Mounting; try { SetupFilesystem(); } catch { Status = DriveStatus.Unmounted; throw; } SetupMountThread(); var mountEvent = Task.Factory.StartNew(() => { while (!_mountCancel.IsCancellationRequested && Directory.GetLogicalDrives().All( drive => drive[0] != Letter)) { Thread.Sleep(1000); } }, _mountCancel.Token); _pauseEvent.Set(); mountEvent.Wait(); if (_exeptionThrown) { _exeptionThrown = false; throw _lastExeption; } Utilities.SetNetworkDriveName(_connection, Name); Status= DriveStatus.Mounted; OnStatusChanged(EventArgs.Empty); }
public void Unmount() { Debug.WriteLine("Unmount"); Status = DriveStatus.Unmounting; try { // Dokan.Unmount(Letter); Dokan.RemoveMountPoint(String.Format("{0}:\\", Letter)); if (_filesystem != null) { _filesystem.Dispose(); } } catch { Status = DriveStatus.Unmounted; OnStatusChanged(EventArgs.Empty); } finally { _filesystem = null; } }
private void MountLoop() { while (true) { Debug.WriteLine("Thread:Pause"); _pauseEvent.WaitOne(-1); if (_threadCancel.IsCancellationRequested) { Debug.WriteLine("Thread:Cancel"); break; } Debug.WriteLine("Thread:Mount"); try { _filesystem.Mount(String.Format("{0}:\\", Letter), DokanOptions.NetworkDrive |DokanOptions.KeepAlive); } catch (Exception e) { _lastExeption = e; _exeptionThrown = true; _mountCancel.Cancel(); } Status = DriveStatus.Unmounted; if (!_exeptionThrown) { OnStatusChanged(EventArgs.Empty); } } }
/// <summary> /// Updates the current drive status. /// </summary> /// <param name="status">The new status.</param> protected void UpdateStatus(DriveStatus status) { this.StatusUpdateArgs.Status = status; this.WorkerThread.ReportProgress(this.StatusUpdateArgs.Progress); }
private void MountLoop() { while (true) { Debug.WriteLine("Thread:Pause"); _pauseEvent.WaitOne(-1); if (_threadCancel.IsCancellationRequested) { Debug.WriteLine("Thread:Cancel"); break; } Debug.WriteLine("Thread:Mount"); try { _filesystem = new VirtualFilesystem("WinSshFS spool"); foreach (SftpDrive drive in _drives) { _filesystem.AddSubFS(drive); } _filesystem.Mount(String.Format("{0}:\\", Letter), Settings.Default.UseNetworkDrive ? DokanOptions.NetworkDrive | DokanOptions.KeepAlive : DokanOptions.RemovableDrive | DokanOptions.KeepAlive); } catch (Exception e) { _lastExeption = e; _exeptionThrown = true; _mountCancel.Cancel(); } Status = DriveStatus.Unmounted; if (!_exeptionThrown) { OnStatusChanged(EventArgs.Empty); } } }
/// <summary> /// Initializes the drive. Detects available DVD drives and the media inserted in each drive. /// </summary> /// <returns>The result of the detection.</returns> public override DriveStatus Initialize() { DriveStatus result = DriveStatus.NoDrive; try { MsftDiscMaster2 discMaster = new MsftDiscMaster2(); if (!discMaster.IsSupportedEnvironment || discMaster.Count <= 0) { result = DriveStatus.NoDrive; } else { bool possibleDriveFound = false; foreach (string recorderID in discMaster) { try { MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(recorderID); // Check that the drive is supported bool supportsBurn = false; foreach (IMAPI_FEATURE_PAGE_TYPE type in discRecorder2.SupportedFeaturePages) { switch (type) { case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_RANDOMLY_WRITABLE: case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_INCREMENTAL_STREAMING_WRITABLE: case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_WRITE_ONCE: case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_DVD_DASH_WRITE: case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_LAYER_JUMP_RECORDING: case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_BD_WRITE: case IMAPI_FEATURE_PAGE_TYPE.IMAPI_FEATURE_PAGE_TYPE_HD_DVD_WRITE: supportsBurn = true; break; } if (supportsBurn) { break; } } // This device does not support buring, skip it. if (!supportsBurn) { continue; } MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data(); if (!String.IsNullOrEmpty(discRecorder2.ExclusiveAccessOwner)) { result = DriveStatus.DriveNotReady; } else if (discFormatData.IsCurrentMediaSupported(discRecorder2)) { discFormatData.Recorder = discRecorder2; // Detect the media if (!discFormatData.MediaHeuristicallyBlank) { result = DriveStatus.MediaNotBlank; } else if (2048L * discFormatData.TotalSectorsOnMedia < this.ImageReader.ImageFile.Length) { if (!possibleDriveFound) { result = DriveStatus.MediaTooSmall; } } else { // Valid media found, use this drive. result = this.SetActiveDrive(recorderID); // Set the write speed SetWriteSpeed(discFormatData); break; } } else if (!possibleDriveFound) { // Check if the media has files on it since IsCurrentMediaSupported returns false when the media is not recordable. DriveInfo info = new DriveInfo((string)discRecorder2.VolumePathNames[0]); if (!info.IsReady) { result = DriveStatus.NoMedia; } else if (info.RootDirectory.GetFiles().Length > 0 || info.RootDirectory.GetDirectories().Length > 0) { result = DriveStatus.MediaNotBlank; } } // If we found a drive with media, save that as a possible drive, but keep // looking in case there is a drive with valid media. possibleDriveFound = result != DriveStatus.NoDrive && result != DriveStatus.NoMedia; } catch (COMException ex) { switch ((uint)ex.ErrorCode) { case 0xC0AA0205: // E_IMAPI_RECORDER_MEDIA_BECOMING_READY case 0xC0AA0206: // E_IMAPI_RECORDER_MEDIA_FORMAT_IN_PROGRESS case 0xC0AA0207: // E_IMAPI_RECORDER_MEDIA_BUSY case 0xC0AA020D: // E_IMAPI_RECORDER_COMMAND_TIMEOUT case 0xC0AA0210: // E_IMAPI_RECORDER_LOCKED result = DriveStatus.DriveNotReady; break; default: result = DriveStatus.InvalidMedia; this.Logging.WriteException("Error trying to read media.", ex); break; } } } } } catch (COMException ex) { result = DriveStatus.NoDrive; this.Logging.WriteException("Error trying to read drives.", ex); } return(result); }