Exemplo n.º 1
0
        private void CheckDrives(object sender, EventArgs e)
        {
            IEnumerable <char> currentDrives = GetCurrentDriveLetters();
            int removedMask = DrivesToMask(_knownDrives.Except(currentDrives));
            int addedMask   = DrivesToMask(currentDrives.Except(_knownDrives));

            removedMask |= DrivesToMask(_removedDrives);
            addedMask   |= DrivesToMask(_arrivedDrives);

            _removedDrives.Clear();
            _arrivedDrives.Clear();
            _knownDrives = currentDrives;

            if (removedMask > 0)
            {
                _monitor.TriggerEvents(false, removedMask);
            }
            if (addedMask > 0)
            {
                _monitor.TriggerEvents(true, addedMask);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// WndProc method that traps all messages sent to the Handle.
 /// </summary>
 /// <param name="msg">A Windows message.</param>
 protected override void WndProc(ref Message msg)
 {
     base.WndProc(ref msg);
     if (!_monitor.Enabled)
     {
         return;
     }
     if (msg.Msg == WM_DEVICECHANGE)
     {
         DeviceEvent evt = (DeviceEvent)msg.WParam.ToInt32();
         if (evt == DeviceEvent.Arrival || evt == DeviceEvent.RemoveComplete)
         {
             BroadcastHeader broadcastHeader = (BroadcastHeader)Marshal.PtrToStructure(msg.LParam, typeof(BroadcastHeader));
             if (broadcastHeader.Type == DeviceType.Volume)
             {
                 Volume volume = (Volume)Marshal.PtrToStructure(msg.LParam, typeof(Volume));
                 if ((volume.Flags & (int)VolumeFlags.Media) != 0)
                 {
                     _monitor.TriggerEvents(evt == DeviceEvent.Arrival, volume.Mask);
                 }
             }
         }
     }
 }