static void HandleDeviceArrived(string driveLetter) { MultiProgress progress = new MultiProgress(new IProgress[] {}); List <IUsbDriveInfo> foundDrives = GetFoundDrives(); var drive = foundDrives.FirstOrDefault(d => d.RootDirectory.ToString() == driveLetter); if (drive == null || !drive.IsReady) { return; } try { if (!IsAKnownBackupDrive(drive)) { if (DialogResult.Yes == new NewDrivePopup().ShowDialog()) { Directory.CreateDirectory(BackupControl.GetDestinationFolderPath(drive.RootDirectory.ToString())); } } //based on that popup, it might now pass this test: if (IsAKnownBackupDrive(drive)) { LaunchBackup(progress, GetFileLogProgress(progress), drive); } } catch (Exception error) { SIL.Reporting.ErrorReport.NotifyUserOfProblem(error, "Sorry, something went wrong."); } }
private static bool IsAKnownBackupDrive(IUsbDriveInfo drive) { //though I could not reproduce it D Rowe had found that removing the drive before the popup closed gave and exception here try { return(Directory.Exists(BackupControl.GetDestinationFolderPath(drive.RootDirectory.ToString()))); } catch { return(false); } }
static void HandleDeviceArrived(string driveLetter) { MultiProgress progress = new MultiProgress(new IProgress[] {}); List <UsbDriveInfo> foundDrives = GetFoundDrives(); var drive = foundDrives.FirstOrDefault(d => d.RootDirectory.ToString() == driveLetter); if (drive == null || !drive.IsReady) { return; } try { if (!IsAKnownBackupDrive(drive)) { if (DialogResult.Yes == new NewDrivePopup().ShowDialog()) { Directory.CreateDirectory(BackupControl.GetDestinationFolderPath(drive.RootDirectory.ToString())); } } //based on that popup, it might now pass this test: if (IsAKnownBackupDrive(drive)) { long totalSpaceInKilobytes = (long)(drive.TotalSize / 1024); long freeSpaceInKilobytes = (long)(drive.AvailableFreeSpace / 1024); string destinationDeviceRoot = drive.RootDirectory.ToString(); var backupControl = new BackupControl(destinationDeviceRoot, freeSpaceInKilobytes, totalSpaceInKilobytes, progress); using (var form = new MainWindow(backupControl, progress)) { form.ShowDialog(); } } } catch (Exception error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Sorry, something went wrong."); } }
private static bool IsAKnownBackupDrive(UsbDriveInfo drive) { return(Directory.Exists(BackupControl.GetDestinationFolderPath(drive.RootDirectory.ToString()))); }