void driverWatcher_DriverChanged(List <string> drivers, bool isAdd)
        {
            if (drivers.IsNullOrEmpty())
            {
                return;
            }

            RunOnUIThreadAsync(() =>
            {
                if (isAdd)
                {
                    foreach (var item in drivers)
                    {
                        LocalDriver newDriver = new LocalDriver(item, this);
                        var firstDriver       = this.Folders.FirstOrDefault(f => f.Name.CompareTo(newDriver.Name) > 0);
                        if (!firstDriver.IsNull())
                        {
                            this.Folders.Insert(this.Folders.IndexOf(firstDriver), newDriver);
                        }
                        else
                        {
                            this.Folders.Add(newDriver);
                        }

                        this.Items.Add(newDriver);
                    }
                }
                else
                {
                    foreach (var item in drivers)
                    {
                        var driver = this.Folders.FirstOrDefault(d => d.Name.EqualIgnoreCase(item));
                        if (!driver.IsNull())
                        {
                            driver.Dispose();
                            this.Folders.Remove(driver);
                            this.Items.Remove(driver);
                        }
                    }
                }

                if (!DriverChanged.IsNull())
                {
                    DriverChanged(drivers, isAdd);
                }
            });
        }
Esempio n. 2
0
        void Scan()
        {
            while (!isStopped)
            {
                var newDrivers = GetDriverNames();

                var addedDrive = newDrivers.Except(oldDrivers);

                if (!addedDrive.IsNullOrEmpty() && !DriverChanged.IsNull())
                {
                    DriverChanged(addedDrive.ToList(), true);
                }

                var removeDrive = oldDrivers.Except(newDrivers);
                if (!removeDrive.IsNullOrEmpty() && !DriverChanged.IsNull())
                {
                    DriverChanged(removeDrive.ToList(), false);
                }

                oldDrivers = newDrivers;
                Thread.Sleep(interval);
            }
        }