diff --git a/src/Chorus/UI/UsbDriveLocator.cs b/src/Chorus/UI/UsbDriveLocator.cs index 6a5515208..7befe2709 100644 --- a/src/Chorus/UI/UsbDriveLocator.cs +++ b/src/Chorus/UI/UsbDriveLocator.cs @@ -1,10 +1,11 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.ComponentModel; using System.IO; using System.Threading; using System.Windows.Forms; +using SIL.Reporting; namespace Chorus.UI { @@ -58,24 +59,35 @@ public bool CanExtend(object extendee) private void ScanForUsbDrives() { - while (_keepRunning) + // https://github.com/sillsdev/chorus/issues/261 + // some users have problems with their USB drive (hardware?) such that GetDrives throws + // an exception, which if not caught, results in a fatal exception for Chorus + try { - var usbRoots = new SIL.UsbDrive.RetrieveUsbDriveInfo().GetDrives() - .Select(u => u.RootDirectory.FullName); - // In Balsa, the boot device (SD Card or USB Stick) shows up as one of the - // drives and it shouldn't be used for S/R. Balsa will be changed to - // include a .chorus-hidden file in the root paritions that should not be - // used for S/R. A user can include this file in USB attached drive that - // they don't want Chorus to use. - var usbDrives = System.IO.DriveInfo.GetDrives() - .Where(d => usbRoots.Contains(d.RootDirectory.FullName) && - d.RootDirectory.GetFiles(".chorus-hidden").Count() == 0); - lock (_usbDrives) + while (_keepRunning) { - _usbDrives.Clear(); - _usbDrives.AddRange(usbDrives); + var usbRoots = new SIL.UsbDrive.RetrieveUsbDriveInfo().GetDrives() + .Select(u => u.RootDirectory.FullName); + // In Balsa, the boot device (SD Card or USB Stick) shows up as one of the + // drives and it shouldn't be used for S/R. Balsa will be changed to + // include a .chorus-hidden file in the root paritions that should not be + // used for S/R. A user can include this file in USB attached drive that + // they don't want Chorus to use. + var usbDrives = System.IO.DriveInfo.GetDrives() + .Where(d => usbRoots.Contains(d.RootDirectory.FullName) && + d.RootDirectory.GetFiles(".chorus-hidden").Count() == 0); + lock (_usbDrives) + { + _usbDrives.Clear(); + _usbDrives.AddRange(usbDrives); + } + + Thread.Sleep(3000); // check again after 3 second } - Thread.Sleep(3000); // check again after 1 second + } + catch (Exception ex) + { + ErrorReport.ReportNonFatalException(ex); } }