public void addToKnownConnectedDrive(DriveInformation DI)
        {
            DI.LoadFromConfig();

            knownConnectedDrives.Add(DI);
            DriveChange(_knownConnectedDrives, null);
        }
        public void TickEngine()
        {
            while (EngineRunning)
            {
                try
                {
                    // Get all connected Drives
                    DriveInfo[] allDrives = DriveInfo.GetDrives();

                    // Find all New Drives
                    foreach (var drive in allDrives)
                    {
                        bool driveFound = false;
                        foreach (var knownDrive in knownConnectedDrives)
                        {
                            if (drive.Name.Equals(knownDrive.Name))
                            {
                                driveFound = true;
                                break;
                            }
                        }

                        if (!driveFound)
                        {
                            connectingDrives.Add(new DriveInformation()
                            {
                                Name = drive.Name
                            });
                        }
                    }

                    // Find all Missing Drives
                    foreach (var knownDrive in knownConnectedDrives)
                    {
                        bool driveFound = false;
                        foreach (var drive in allDrives)
                        {
                            if (knownDrive.Name.Equals(drive.Name))
                            {
                                driveFound = true;
                                break;
                            }
                        }
                        if (!driveFound)
                        {
                            disconnectingDrives.Add(new DriveInformation()
                            {
                                Name = knownDrive.Name
                            });
                        }
                    }

                    // Apply Changes
                    if (connectingDrives.Count > 0)
                    {
                        foreach (var drive in connectingDrives)
                        {
                            addToKnownConnectedDrive(drive);
                        }
                        connectingDrives = new List <DriveInformation>();
                    }

                    if (disconnectingDrives.Count > 0)
                    {
                        var removeTarget = new DriveInformation();
                        foreach (var drive in disconnectingDrives)
                        {
                            foreach (var knownDrive in knownConnectedDrives)
                            {
                                if (drive.Name.Equals(knownDrive.Name))
                                {
                                    removeTarget = knownDrive;
                                }
                            }
                        }
                        removeFromKnownConnectedDrive(removeTarget);
                        disconnectingDrives = new List <DriveInformation>();
                    }

                    //sleep
                    Thread.Sleep(100);
                }
                catch
                {
                }
            }
        }
 public void removeFromKnownConnectedDrive(DriveInformation DI)
 {
     knownConnectedDrives.Remove(DI);
     DriveChange(_knownConnectedDrives, null);
 }