Beispiel #1
0
        //private  void usbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)


        //{

        //    string value = e.Volume.Letter;
        //    DriveInfo info = new DriveInfo(value);
        //   // string serial = e.Device.SerialNumber;
        //  //  string vendor = e.Device.IdVendor.ToString();
        //    MessageBox.Show(e.Device.SerialNumber);

        //    MessageBox.Show(e.DeviceType.ToString());
        //    MessageBox.Show(e.EventType.ToString());
        //   // MessageBox.Show("yes");
        //   //DriveDetectorEventArgs m = new DriveDetectorEventArgs();
        //   //OnDriveArrived(sender, m);

        //    devices dv = new devices();
        //    dv.Name = drive;
        //    loadDevice(dv);
        //    //calls up the method that will check if the device has been configured for synchronization
        //    checkDevice(e.Device.IdProduct.ToString(), e.Device.IdVendor.ToString(), e.Device.SerialNumber, drive);
        //}

        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            drive = e.Drive;

            //  DeviceNotifyEventArgs ar = (DeviceNotifyEventArgs)e;
            //  usbDeviceNotifier_OnDeviceNotify(sender, ar);

            //  MessageBox.Show(e.Drive.ToString() + " " + e.ToString());
        }
Beispiel #2
0
        void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            string name = e.Drive;

            UnloadDevice(name);
            NotifyRemoval(name.Substring(0, 1));
            if (letter == name.Substring(0, 1))
            {
                listView1.Items.Clear();
                foreach (TreeNode node in treeView1.Nodes)
                {
                    foreach (TreeNode n in node.Nodes)
                    {
                        n.ImageIndex         = 0;
                        n.SelectedImageIndex = 0;
                    }
                }
            }
        }
Beispiel #3
0
        void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            //get the information of the usb device that just arrived at the system
            DriveInfo drive = new DriveInfo(e.Drive);

            if (drive.TotalSize > 0 && IsNotReadOnly(e.Drive))
            {
                letter = e.Drive.Substring(0, 1);

                serial = DriveInformation.getSerial(e.Drive); //USB.FindDriveLetter(e.Drive.Substring(0, 2)).SerialNumber;
                //check if the drive have been registered before else prompt for the registration of the drive

                //RegisterDevice(serial);
                loadDevice(e.Drive);
                if (SmartSync.Properties.Settings.Default.notifyoniteminsert == false)
                {
                    return;
                }
                Drive drv = FileDetailsMgmt.thisDrive(serial, drives);
                if (drv == null)
                {
                    DialogResult result = MessageBox.Show("A new device is inserted into your system,\n Do you want to synchronize it?", "SmartSync", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result.ToString() == "No")
                    {
                        return;
                    }
                    else
                    {
                        RegisterDevice(serial);
                    }
                }
                NotifyDetection(e.Drive.Substring(0, 1));
            }

            //letter = e.Drive.Substring(0, 1);
        }
Beispiel #4
0
        /// <summary>
        /// Message handler which must be called from client form.
        /// Processes Windows messages and calls event handlers.
        /// </summary>
        /// <param name="m"></param>
        public void WndProc(ref Message m)
        {
            int  devType;
            char c;

            if (m.Msg == WM_DEVICECHANGE)
            {
                // WM_DEVICECHANGE can have several meanings depending on the WParam value...
                switch (m.WParam.ToInt32())
                {
                //
                // New device has just arrived
                //
                case DBT_DEVICEARRIVAL:

                    devType = Marshal.ReadInt32(m.LParam, 4);
                    if (devType == DBT_DEVTYP_VOLUME)
                    {
                        DEV_BROADCAST_VOLUME vol;
                        vol = (DEV_BROADCAST_VOLUME)
                              Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));

                        // Get the drive letter
                        c = DriveMaskToLetter(vol.dbcv_unitmask);


                        //
                        // Call the client event handler
                        //
                        // We should create copy of the event before testing it and
                        // calling the delegate - if any
                        DriveDetectorEventHandler tempDeviceArrived = DeviceArrived;
                        if (tempDeviceArrived != null)
                        {
                            DriveDetectorEventArgs e = new DriveDetectorEventArgs();
                            e.Drive = c + ":\\";
                            tempDeviceArrived(this, e);

                            // Register for query remove if requested
                            if (e.HookQueryRemove)
                            {
                                // If something is already hooked, unhook it now
                                if (mDeviceNotifyHandle != IntPtr.Zero)
                                {
                                    RegisterForDeviceChange(false, null);
                                }

                                RegisterQuery(c + ":\\");
                            }
                        }         // if  has event handler
                    }
                    break;



                //
                // Device is about to be removed
                // Any application can cancel the removal
                //
                case DBT_DEVICEQUERYREMOVE:

                    devType = Marshal.ReadInt32(m.LParam, 4);
                    if (devType == DBT_DEVTYP_HANDLE)
                    {
                        // TODO: we could get the handle for which this message is sent
                        // from vol.dbch_handle and compare it against a list of handles for
                        // which we have registered the query remove message (?)
                        //DEV_BROADCAST_HANDLE vol;
                        //vol = (DEV_BROADCAST_HANDLE)
                        //   Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HANDLE));
                        // if ( vol.dbch_handle ....


                        //
                        // Call the event handler in client
                        //
                        DriveDetectorEventHandler tempQuery = QueryRemove;
                        if (tempQuery != null)
                        {
                            DriveDetectorEventArgs e = new DriveDetectorEventArgs();
                            e.Drive = mCurrentDrive;            // drive which is hooked
                            tempQuery(this, e);

                            // If the client wants to cancel, let Windows know
                            if (e.Cancel)
                            {
                                m.Result = (IntPtr)BROADCAST_QUERY_DENY;
                            }
                            else
                            {
                                // Change 28.10.2007: Unregister the notification, this will
                                // close the handle to file or root directory also.
                                // We have to close it anyway to allow the removal so
                                // even if some other app cancels the removal we would not know about it...
                                RegisterForDeviceChange(false, null);       // will also close the mFileOnFlash
                            }
                        }
                    }
                    break;


                //
                // Device has been removed
                //
                case DBT_DEVICEREMOVECOMPLETE:

                    devType = Marshal.ReadInt32(m.LParam, 4);
                    if (devType == DBT_DEVTYP_VOLUME)
                    {
                        devType = Marshal.ReadInt32(m.LParam, 4);
                        if (devType == DBT_DEVTYP_VOLUME)
                        {
                            DEV_BROADCAST_VOLUME vol;
                            vol = (DEV_BROADCAST_VOLUME)
                                  Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
                            c = DriveMaskToLetter(vol.dbcv_unitmask);

                            //
                            // Call the client event handler
                            //
                            DriveDetectorEventHandler tempDeviceRemoved = DeviceRemoved;
                            if (tempDeviceRemoved != null)
                            {
                                DriveDetectorEventArgs e = new DriveDetectorEventArgs();
                                e.Drive = c + ":\\";
                                tempDeviceRemoved(this, e);
                            }

                            // TODO: we could unregister the notify handle here if we knew it is the
                            // right drive which has been just removed
                            //RegisterForDeviceChange(false, null);
                        }
                    }
                    break;
                }
            }
        }
Beispiel #5
0
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
 }