Skip to content

Commit

Permalink
#261: Ignore USB GetDrives crash (#272)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bobeaton authored Nov 1, 2021
1 parent ce80374 commit 62e91ca
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/Chorus/UI/UsbDriveLocator.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 62e91ca

Please sign in to comment.