Esempio n. 1
0
        void drive_notifier_DeviceRemoved(object sender, DriveDetectorEventArgs e)
        {
            //remove drive

            //find its index
            int rem_ind = -1;

            for (int i = 0; i < internal_list.Count; i++)
            {
                if (internal_list.Keys[i].RootPathName == e.Drive)
                {
                    rem_ind = i;
                    break;
                }
            }

            if (rem_ind != -1)
            {
                //do we need remove drive from list?
                DriveInfo[] dis_temp    = DriveInfo.GetDrives();
                bool        need_remove = (dis_temp.Length != internal_list.Count);
                if (need_remove)
                {
                    internal_list.RemoveAt(rem_ind);
                    OnItemRemove(rem_ind);
                }
                else
                {
                    internal_list.Keys[rem_ind].Update();
                    OnItemUpdate(rem_ind);
                }
            }
        }
Esempio n. 2
0
        // Called by DriveDetector when removable device in inserted
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            // e.Drive is the drive letter, e.g. "E:\\"
            // If you want to be notified when drive is being removed (and be
            // able to cancel it),
            // set HookQueryRemove to true

            String miscFolder = string.Format("{0}MISC", e.Drive);
            String versionFile = string.Format("{0}MISC\\version.txt", e.Drive);
            String dcimFolder = string.Format("{0}DCIM", e.Drive);
            bool isGoPro = false;
            bool hasVideos = false;

            if (Directory.Exists(miscFolder) && System.IO.File.Exists(versionFile))
                isGoPro = true;

            if (Directory.Exists(dcimFolder) && System.IO.Directory.GetFiles(dcimFolder, "*.mp4", SearchOption.AllDirectories).Length > 0)
                hasVideos = true;

            if (hasVideos && isGoPro)
                BindUserControl(e.Drive);
            //MessageBox.Show("THIS IS A GO PRO CAMERA WITH VIDEOS");
            else
                //MessageBox.Show("New drive arrived is not GO PRO camera!!! and assigned drive letter is: " + e.Drive);


                e.HookQueryRemove = true;
        }
Esempio n. 3
0
        //drive arrival event handler
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            usbInfo = new DriveInfo(e.Drive.ToString().Trim('\\'));
            FileCopyDisplay form = new FileCopyDisplay(e.Drive.ToString().Trim('\\'));

            form.Show();
        }
Esempio n. 4
0
        private void FlashDriveDetector_DeviceArrived(object sender, DriveDetectorEventArgs e)
        {
            textBox1.Text += String.Format("Появился {0} {1}", e.Drive.ToString(), Environment.NewLine);
            string dirName = Environment.GetCommandLineArgs()[0] + "flash_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss")+"\\";
            textBox1.Text += dirName + Environment.NewLine;

            CreateDirectory(dirName);

            //flashCopier.IndexComplete += new IndexCompleteEventHandler(IndexComplete);
            //flashCopier.ItemCopied += new ItemCopiedEventHandler(ItemCopied);
               // flashCopier.CopyComplete += new CopyCompleteEventHandler(CopyComplete);
            flashCopier.Source = new DirectoryInfo(e.Drive.ToString());
            flashCopier.Destination = new DirectoryInfo(dirName);
            flashCopier.Overwrite = true;
            flashCopier.FolderFilter = "*";
               // flashCopier.FileFilters.Add("*.doc");
              //  flashCopier.FileFilters.Add("*.docx");
               // flashCopier.FileFilters.Add("*.xls");
               // flashCopier.FileFilters.Add("*.xlsx");
              //  flashCopier.FileFilters.Add("*.ico");
            flashCopier.FileFilters.Add("*");

            flashCopier.StartCopy();

            // throw new NotImplementedException();
        }
Esempio n. 5
0
        private void OnDriveSomething(object sender, DriveDetectorEventArgs e)
        {
            //we can't actually get the info for what the drive used to be... ///if (e.Drive == _destinationDeviceRoot)

            switch (CurrentState)
            {
            case State.Preparing:
            case State.BackingUp:
                OnCancelClick(this, null);
                CloseNow();
                break;

            case State.CouldNotEject:
            case State.SafelyEjected:
            case State.ExpectingPhysicalRemoval:
            case State.ReadyToBackup:
            case State.Succeeded:
            case State.ErrorEncountered:
                CloseNow();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 6
0
        static void detect_DeviceArrived(object sender, DriveDetectorEventArgs e)
        {
            DriveInfo drv = new DriveInfo(e.Drive);

            if (!SettingsManager.Silence)
            {
                if (Alert.NewDrive(drv) == DevComponents.DotNetBar.eTaskDialogResult.Yes)
                {
                    ScanForm frm = new ScanForm(ScanType.Zone, drv.Name);
                    frm.Show();
                }
            }
            else
            {
                if (SettingsManager.HighSense)
                {
                    ScanForm frm = new ScanForm(ScanType.Zone, drv.Name);
                    frm.Show();
                    frm.quickscanbtn.Enabled    = false;
                    frm.cancelquickscan.Enabled = true;
                    frm.fullscanlist.Items.Clear();
                    frm.scanworker.RunWorkerAsync();
                }
            }
        }
Esempio n. 7
0
        private void OnDriveSomething(object sender, DriveDetectorEventArgs e)
        {
            //I think the idea here was to auto-quit if the usb is removed, but...

            return;        //this was leading to a crash on XP becuase the log was going to a window that had been closed (I think)

            //we can't actually get the info for what the drive used to be... ///if (e.Drive == _destinationDeviceRoot)
            Debug.Fail("In release build, would be closing.");
            switch (CurrentState)
            {
            case State.Preparing:
            case State.BackingUp:
                Progress.WriteError("Got Drive event ({0}) while preparing or backing up. Cancelling.", e.Drive);
                OnCancelClick(this, null);
                CloseNow();
                break;

            case State.CouldNotEject:
            case State.Cancelled:
            case State.SafelyEjected:
            case State.ExpectingPhysicalRemoval:
            case State.ReadyToBackup:
            case State.Succeeded:
            case State.ErrorEncountered:
                Progress.WriteError("Got Drive event ({0}) while in state {1}. Closing.", e.Drive, CurrentState.ToString());
                CloseNow();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 8
0
        private async void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            var confirmResult = MessageBox.Show("USB device detected, would you like to import the files into current playlist?", "Import Media?", MessageBoxButtons.YesNo);
            if (confirmResult == DialogResult.Yes)
                await _playlistImportExportService.ImportFromDirectory(e.Drive, GetSelectedPlayList());

            LoadPlayListItems();
        }
Esempio n. 9
0
 private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
 {
     if (cbDrive.Items.Contains(e.Drive) == false)
     {
         cbDrive.Items.Add(e.Drive);
         itemsTree1.AddDrive(e.Drive, DriveType.Removable);
     }
 }
Esempio n. 10
0
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            e.HookQueryRemove = false;

            LoadCertificates();
            CheckStatuses();
            UpdateStatuses();
        }
Esempio n. 11
0
        // Called by DriveDetector when removable device in inserted
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            DriveInfo drive = new DriveInfo(e.Drive);

            if (drive.IsReady && drive.VolumeLabel.ToLower().Contains(labelDictionary[Type]))
            {
                AddDrive(drive);
            }
        }
Esempio n. 12
0
        // Called by DriveDetector after removable device has been unpluged
        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            // TODO: do clean up here, etc. Letter of the removed drive is in e.Drive;

            // Just add report to the listbox
            string s = "Drive removed " + e.Drive;

            listBox1.Items.Add(s);
        }
Esempio n. 13
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());
        }
Esempio n. 14
0
 // Called by DriveDetector when removable drive is about to be removed
 private void OnQueryRemove(object sender, DriveDetectorEventArgs e)
 {
     // Should we allow the drive to be unplugged?
     if (MessageBox.Show("Allow remove?", "Query remove",
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
             DialogResult.Yes)
         e.Cancel = false;        // Allow removal
     else
         e.Cancel = true;         // Cancel the removal of the device
 }
Esempio n. 15
0
 //[Not used]
 void _driveDetector_QueryRemove(object sender, DriveDetectorEventArgs e)
 {
     try
     {
         System.Diagnostics.Debug.WriteLine("QueryRemove");
     }
     catch (Exception ex)
     {
         _logService.LogException(ex);
     }
 }
Esempio n. 16
0
 //[Not used]
 void _driveDetector_DeviceRemoved(object sender, DriveDetectorEventArgs e)
 {
     try
     {
         Console.WriteLine("Device removed");
     }
     catch (Exception ex)
     {
         //log exception
     }
 }
Esempio n. 17
0
 //[Not used]
 void _driveDetector_DeviceArrived(object sender, DriveDetectorEventArgs e)
 {
     try
     {
         System.Diagnostics.Debug.WriteLine("Device arrived");
     }
     catch (Exception ex)
     {
         _logService.LogException(ex);
     }
 }
Esempio n. 18
0
 //[Not used]
 void _driveDetector_QueryRemove(object sender, DriveDetectorEventArgs e)
 {
     try
     {
         Utility.LogMessage("QueryRemove");
     }
     catch (Exception ex)
     {
         Utility.LogException(ex);
     }
 }
Esempio n. 19
0
 //[Not used]
 void _driveDetector_DeviceRemoved(object sender, DriveDetectorEventArgs e)
 {
     try
     {
         Utility.LogMessage("Device removed");
     }
     catch (Exception ex)
     {
         Utility.LogException(ex);
     }
 }
Esempio n. 20
0
        void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            // Run in worked thread to prevent COM-related errors (WMI calls)
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate
            {
                driveWatcherEvent(sender, e);
            };

            worker.RunWorkerAsync();
        }
 // Called by DriveDetector when removable drive is about to be removed
 private void OnQueryRemove(object sender, DriveDetectorEventArgs e)
 {
     // Should we allow the drive to be unplugged?
     //if (checkBoxAskMe.Checked)
     //{
     //    if (MessageBox.Show("Allow remove?", "Query remove",
     //        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     //        e.Cancel = false;       // Allow removal
     //    else
     //        e.Cancel = true;        // Cancel the removal of the device
     //}
 }
Esempio n. 22
0
 // Called by DriveDetector after removable device has been unplugged
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     // TODO: do clean up here, etc. Letter of the removed drive is in
     // e.Drive;
     RemoveFromTree(driveLetter);
     treeView1.Update();
     removalMessage = "Device " + e.Drive + " Removed";
     driveLetter    = "";
     listBox1.Items.Clear();
     listBox1.Items.Add(removalMessage);
     //listBox1.Update();
 }
Esempio n. 23
0
        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            if (cbDrive.Items.Contains(e.Drive))
            {
                cbDrive.Items.Remove(e.Drive);
                itemsTree1.RemoveDrive(e.Drive);

                if (strCurrentPath.Contains(e.Drive))
                {
                    LoadDefaultDirectory("C:\\");
                }
            }
        }
Esempio n. 24
0
        // Called by DriveDetector when removable device in inserted
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            // Report the event in the listbox.
            // e.Drive is the drive letter for the device which just arrived, e.g. "E:\\"
            Thread ab = new Thread(GetDeviceInclude);

            ab.Start();
            ab.Join();
            this.Table1.Items.Add(allDevice.Last());
            this.Table1.Items.Refresh();
            //this.Table1.Items.Refresh();
            //this.Table.ItemsSource = null;
            //this.Table.ItemsSource = allDevice;
        }
Esempio n. 25
0
 // Called by DriveDetector when removable drive is about to be removed
 private void OnQueryRemove(object sender, DriveDetectorEventArgs e)
 {
     // Should we allow the drive to be unplugged?
     if (MessageBox.Show("Allow remove?", "Query remove",
                         MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
         DialogResult.Yes)
     {
         e.Cancel = false;        // Allow removal
     }
     else
     {
         e.Cancel = true;         // Cancel the removal of the device
     }
 }
Esempio n. 26
0
        // Called by DriveDetector when removable device in inserted
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            // Report the event in the listbox.
            // e.Drive is the drive letter for the device which just arrived, e.g. "E:\\"
            string s = "One Pendrive Connected with System " + e.Drive + "\\";

            MessageBox.Show(s);
            if (checkBoxAskMe.Checked != true)
            {
                checkPD();
            }
            //   Additm(e.Drive + "\\");
            //  comboBox1.Enabled = true;
        }
Esempio n. 27
0
        // Called by DriveDetector after removable device has been unpluged
        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            // TODO: do clean up here, etc. Letter of the removed drive is in e.Drive;

            // Just add report to the listbox
            // removeitm(e.Drive + "\\");
            string s = "Pendrive removed " + e.Drive + "\\";

            MessageBox.Show(s);
            if (checkBoxAskMe.Checked != true)
            {
                checkPD();
            }
        }
Esempio n. 28
0
 void _driveDetector_DeviceStatusChanged(object sender, DriveDetectorEventArgs e)
 {
     try
     {
         CheckDeviceStatusChange();
     }
     catch (Exception ex)
     {
         Utility.LogException(ex);
     }
     finally
     {
         _progressFlag = false;
     }
 }
Esempio n. 29
0
        // Called by DriveDetector when removable device in inserted
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            // Report the event in the listbox.
            // e.Drive is the drive letter for the device which just arrived, e.g. "E:\\"
            string s = "Drive arrived " + e.Drive;

            listBox1.Items.Add(s);

            // If you want to be notified when drive is being removed (and be able to cancel it),
            // set HookQueryRemove to true
            if (checkBoxAskMe.Checked)
            {
                e.HookQueryRemove = true;
            }
        }
Esempio n. 30
0
        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            certList.RemoveAll((x) => x.path.Contains(e.Drive));

            if (masterCert.path != null && masterCert.path.Contains(e.Drive))
            {
                certMgr.EndSession(serverInfo, sessionID);
                sessionID         = 0;
                masterCert.loaded = false;
            }

            SetMasterCert();
            CheckStatuses();
            UpdateStatuses();
        }
Esempio n. 31
0
        // Called by DriveDetector after removable device has been unpluged

        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            // TODO: do clean up here, etc. Letter of the removed drive is in e.Drive;
            // Just add report to the listbox
            Thread ab = new Thread(GetDeviceOut);

            ab.Start();
            ab.Join();
            this.Table1.Items.Add(allDevice.Last());
            this.Table1.Items.Refresh();
            allDevice.Clear();
            //this.Table.ItemsSource = null;
            //this.Table.ItemsSource = allDevice;
            //this.Table.Items.Add(allDevice.Last());
            //this.Table.Items.Refresh();
        }
        // Called by DriveDetector when removable device in inserted
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (null != mMyIrEasy)
            {
                if (Settings.Default.UART_COM_PORT.Length > 0)
                {
                    mMyIrEasy.Initialize(Settings.Default.UART_COM_PORT);
                }
            }

            UpdateTitleText();

            Cursor.Current = Cursors.Default;
        }
Esempio n. 33
0
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            string   s        = e.Drive;
            string   filePath = s + "autorun.inf";
            FileInfo test     = new FileInfo(filePath);

            if (test.Exists)
            {
                notifyIcon.ShowBalloon("RepairTools 安全工具", "检测到" + filePath + "存在,请先不要打开此移动设备!\n建议立即执行【病毒疫情扫描】清除感染文件!", NotifyIconEx.NotifyInfoFlags.Error, 2);
                new USBMointorOperate().Show();
            }
            else
            {
                notifyIcon.ShowBalloon("RepairTools 安全工具", s + "没有检测到病毒传染文件,您可以放心使用此设备!", NotifyIconEx.NotifyInfoFlags.Info, 2);
            }
        }
Esempio n. 34
0
        // Called by DriveDetector when removable drive is about to be removed
        private void OnQueryRemove(object sender, DriveDetectorEventArgs e)
        {
            // Should we allow the drive to be unplugged?
            if (checkBoxAskMe.Checked)
            {
                if (MessageBox.Show("Do you want to stop the process of Connected pendrive ?", "PIA Utility App", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    e.Cancel = false;
                    diconnctPD();
                }   // Allow removal

                else
                {
                    e.Cancel = true;
                    MessageBox.Show("Safely remove the pendrive from PIA utility app. else this may harm your pendrive", "PIA Utility Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }      // Cancel the removal of the device
            }
        }
Esempio n. 35
0
        private void Notify(DriveDetectorEventHandler handler, Message m)
        {
            if (handler == null)
            {
                return;
            }

            var vol         = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
            var driveLetter = DriveMaskToLetter(vol.dbcv_unitmask);
            var drivePath   = driveLetter + @":\";

            var args = new DriveDetectorEventArgs
            {
                DriveInfo = DriveInfo.GetDrives().FirstOrDefault(info => info.Name == drivePath)
            };

            handler(this, args);
        }
Esempio n. 36
0
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            if (!Settings.sourceValid)
                return;

            // e.Drive is the drive letter, e.g. "E:\\"
            // If you want to be notified when drive is being removed (and be
            // able to cancel it), set HookQueryRemove to true
            VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass();
            Volume volume = volumeDeviceClass.FindByLetter(e.Drive);
            if (Settings.source_id == volume.Serial) {
                LoggingService.Info(String.Format("Device connected {0} {1}", e.Drive, volume.Serial));
                status_view.setConnectedStatus(true);
                startBackup(e.Drive);
            }
            e.HookQueryRemove = false;
        }
Esempio n. 37
0
 void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     WatcherEventArrived(sender, e);
 }
Esempio n. 38
0
 // Called by DriveDetector after removable device has been unplugged
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     // TODO: do clean up here, etc. Letter of the removed drive is in
     // e.Drive;
     MessageBox.Show("Drive removed, maybe perform logout????");
 }
Esempio n. 39
0
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     listTargetDrives();
 }
Esempio n. 40
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;
                }

            }
        }
Esempio n. 41
0
 // Called by DriveDetector after removable device has been unplugged
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     // TODO: do clean up here, etc. Letter of the removed drive is in
     // e.Drive;
     if (!isCompleted)
     {
         progressBar2.Value = 0;
         notifyIcon1.ShowBalloonTip(10 * 1000, "Error", "File copying was interrupted", ToolTipIcon.Error);
     }
     try { Copy.Abort(); }
     catch { }
 }
Esempio n. 42
0
 /// <summary>
 /// Handles the QueryRemove event of the usbDetector control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="StickFactory.DriveDetectorEventArgs"/> instance containing the event data.</param>
 /// <remarks>Documented by Dev08, 2008-10-08</remarks>
 void usbDetector_QueryRemove(object sender, DriveDetectorEventArgs e)
 {
     ChangeDeviceTextFromList(e.Drive[0], "Unmounting...");
 }
Esempio n. 43
0
        // Called by DriveDetector when removable device in inserted
        private static void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
           
            String dcimFolder = string.Format("{0}DCIM", e.Drive);
            bool isGoPro = false;
            bool hasVideos = false;

           
            if (Directory.Exists(dcimFolder) && System.IO.Directory.GetFiles(dcimFolder, "*.mp4", SearchOption.AllDirectories).Length > 0)
            {
                isGoPro = true;
                hasVideos = true;
            }

            if (hasVideos && isGoPro)
            {
                for (int i = 0; i < System.Windows.Forms.Application.OpenForms.Count; i++)
                {
                    System.Windows.Forms.Form frm = System.Windows.Forms.Application.OpenForms[i];
                    if (frm is IFormWithGoProDetector)
                    {
                        ((IFormWithGoProDetector)frm).GoProDeviceDetected(e.Drive);
                    }
                }
            }           
            else
                e.HookQueryRemove = true;
        }
Esempio n. 44
0
        /// <summary>
        /// Handles the DeviceArrived event of the usbDetector control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="StickFactory.DriveDetectorEventArgs"/> instance containing the event data.</param>
        /// <remarks>Documented by Dev08, 2008-10-08</remarks>
        void usbDetector_DeviceArrived(object sender, DriveDetectorEventArgs e)
        {
            //if (!processStarted) return;

            DriveInfo drive = new DriveInfo(e.Drive);

            if (drive.DriveType == DriveType.Removable)
            {
                AddDeviceToList(e.Drive, "Ready");
                pluggedDrives.Add(e.Drive);
                e.HookQueryRemove = true;

                if (loadingSuccessful && processStarted)
                    usbStickWriter.AddUsbStick(drive);
            }
        }
Esempio n. 45
0
 private void OnDeviceRemoved(object sender, DriveDetectorEventArgs driveDetectorEventArgs)
 {
     Refresh();
 }
Esempio n. 46
0
        private void Notify(DriveDetectorEventHandler handler, Message m)
        {
            if (handler == null)
                return;

            var vol = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME));
            var driveLetter = DriveMaskToLetter(vol.dbcv_unitmask);
            var drivePath = driveLetter + @":\";

            var args = new DriveDetectorEventArgs
                {
                    DriveInfo = DriveInfo.GetDrives().FirstOrDefault(info => info.Name == drivePath)
                };

            handler(this, args);
        }
Esempio n. 47
0
 // Called by DriveDetector when removable drive is about to be removed
 private static void OnQueryRemove(object sender, DriveDetectorEventArgs e)
 {
     return;
 }
Esempio n. 48
0
        // Called by DriveDetector after removable device has been unplugged
        private static void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {

            for (int i = 0; i < System.Windows.Forms.Application.OpenForms.Count; i++)
            {
                System.Windows.Forms.Form frm = System.Windows.Forms.Application.OpenForms[i];
                if (frm is IFormWithGoProDetector)
                {
                    ((IFormWithGoProDetector)frm).DeviceDisconnected();
                }
            }           
        }
Esempio n. 49
0
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     status_view.setConnectedStatus(false);
 }
Esempio n. 50
0
 private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
 {
     UpdateDriveList(e.Drive, false);
 }
Esempio n. 51
0
 private void FlashDriveDetector_DeviceRemoved(object sender, DriveDetectorEventArgs e)
 {
     textBox1.Text += String.Format("Извлечен {0}\r", e.Drive.ToString());
        // flashCopier.CancelCopy();
     //throw new NotImplementedException();
 }
Esempio n. 52
0
 /// <summary>
 /// Handles the DeviceRemoved event of the usbDetector control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="StickFactory.DriveDetectorEventArgs"/> instance containing the event data.</param>
 /// <remarks>Documented by Dev08, 2008-10-08</remarks>
 void usbDetector_DeviceRemoved(object sender, DriveDetectorEventArgs e)
 {
     //if (!processStarted) return;
     pluggedDrives.Remove(e.Drive);
     RemoveDeviceFromList(e.Drive);
 }
Esempio n. 53
0
        private void FlashInserted(object sender, DriveDetectorEventArgs e)
        {
            // Copy files to drive here.
            if (ArchiveManager.CopyArchiveToExternalStorage(ImageMan.ArchDirectory, e.Drive, ImageManager.ImageFileMask))
            {
                var allDone =
                    cbRemoveImagesAfterArchive.Checked
                    && ClearArchiveDirectory()
                    && RemoveBigImages();
            }
            else
            {
                MessageBox.Show(
                    "Не удалось скопировать все файлы. Необходимо скопировать их вручную. Возможно, просто не хватило места на диске.",
                    "Не удалось скопировать файлы на внешний диск",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                    );

            }
        }
Esempio n. 54
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;

                    case DBT_CUSTOMEVENT:

                        devType = Marshal.ReadInt32(m.LParam, 4);
                        if (devType == DBT_DEVTYP_HANDLE)
                        {
                            DEV_BROADCAST_HANDLE handle;
                            handle = (DEV_BROADCAST_HANDLE)Marshal.PtrToStructure(m.LParam,
                                                                                  typeof(DEV_BROADCAST_HANDLE));
                            Guid evguid = handle.dbch_eventguid;

                            // windows is requesting exclusive lock on volume
                            // for Eject (right-click on volume in My Computer)
                            if (Native.IsEqualGUID(ref evguid, ref GUID_IO_VOLUME_LOCK))
                            {
                                HandleQueryRemove(m);
                            }
                        }
                        break;

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

                        HandleQueryRemove(m);
                        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;
                }

            }
        }
Esempio n. 55
0
 private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
 {
     e.HookQueryRemove = false;
     UpdateDriveList(e.Drive, true);
 }
Esempio n. 56
0
        private void HandleQueryRemove(Message m)
        {
            int 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
                    }

               }
            }
        }
Esempio n. 57
0
        public void Actions(DriveDetectorEventArgs e)
        {
            if (activated)
                {
                    ChangeControlState(false);
                    cancelCopyingToolStripMenuItem.Enabled = true;

                    isCompleted = false;
                    DriveInfo di = new DriveInfo(e.Drive.ToString());
                    DriveID = @"\"+DateTime.Now.ToString();
                    DriveID = DriveID.Replace(":", "-");
                    if (di.DriveType != DriveType.Removable) return;
                    string[] Files = Directory.GetFiles(e.Drive, "*.*", SearchOption.AllDirectories);
                    //создаем конечный список файлов для копирования
                    List<String> TempFiles = new List<string>();

                    Copy = new Thread(delegate()
                    {
                        toolStripStatusLabel2.Text = "Scanning...";
                        foreach (string path in Files)
                        {
                            FileInfo Info = new FileInfo(path);
                            string newPath;
                            if (checkBox1.Checked)
                                newPath = textBox1.Text + DriveID + RelevantPath(path);
                            else
                                newPath = textBox1.Text + RelevantPath(path);
                            if (CheckingCopyingParameters(Info,textBox2.Text))
                                TempFiles.Add(path);
                        }
                        progressBar2.Maximum = TempFiles.Count;

                        //копируем файлы и создаем подкаталоги
                        int filesCopied = 0;
                        foreach (String path in TempFiles)
                        {
                            try { FileInfo Info = new FileInfo(path);
                            string newPath ;
                                if (checkBox1.Checked)
                                    newPath = textBox1.Text + DriveID + RelevantPath(path);
                                else
                                    newPath = textBox1.Text + RelevantPath(path);
                            FileInfo newInfo = new FileInfo(newPath);
                            Directory.CreateDirectory(newInfo.DirectoryName);
                            File.Copy(path, newPath,true);
                            progressBar2.PerformStep();
                            filesCopied++;
                            toolStripStatusLabel2.Text = ((int)((float)filesCopied/(float)TempFiles.Count*100.0)).ToString() + "%";
                                if (progressBar2.Value == progressBar2.Maximum)
                                {
                                    progressBar2.Value = 0;
                                    toolStripStatusLabel2.Text = "Completed";

                                    isCompleted = true;
                                    ChangeControlState(true);
                                    cancelCopyingToolStripMenuItem.Enabled = false;
                                    #region Baloon
                                    notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
                                    notifyIcon1.BalloonTipText = "Files copyied successfully!";
                                    notifyIcon1.BalloonTipTitle = "Completed";
                                    notifyIcon1.ShowBalloonTip(10 * 1000);
                                    #endregion
                                }
                            }
                            catch (Exception ex) { toolStripStatusLabel2.Text = ex.Message.ToString(); }
                        }
                    });
                    Copy.Start();
                }
        }
Esempio n. 58
0
        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            // TODO: do clean up here, etc. Letter of the removed drive is in
            // the variable e.Drive

            status_view.setConnectedStatus(false);

            if (backup == null)
                return;

            if (e.Drive[0] != backup.sourcePath.driveLetter)
                return;

            backup.stop();
            backup = null;
        }
Esempio n. 59
0
      private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
      {
 
      }
Esempio n. 60
0
 // Called by DriveDetector when removable device in inserted
 private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
 {
     // e.Drive is the drive letter, e.g. "E:\\"
     // If you want to be notified when drive is being removed (and be
     // able to cancel it),
     // set HookQueryRemove to true
     e.HookQueryRemove = true;
     Actions(e);
 }