/// <summary> /// Load the usb devices that are already connected to the system /// </summary> private void LoadConnectedDevices() { try { DriveInfo[] driveInfos = DriveInfo.GetDrives(); foreach (var driveInfo in driveInfos) { //check if the drive is a usb drive USB.USBDevice device = USB.FindDriveLetter(driveInfo.Name.Substring(0, 2)); if (device != null) { if (driveInfo.IsReady && driveInfo.TotalSize > 0) { serial = DriveInformation.getSerial(driveInfo.Name); //USB.FindDriveLetter(driveInfo.Name.Substring(0, 2)).SerialNumber; //RegisterDevice(serial); loadDevice(driveInfo.Name); } } } statuslabel.Text = "Ready"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public usbDevice(string letter, List <Drive> drives, string serial) { InitializeComponent(); this.serial = serial; this.drives = drives; this.letter = letter; syncdetails = new List <string[]>(); // this.usbserial = usbserial; this.Load += (s, a) => { this.ContextMenuStrip = contextMenuStrip1; frm = this.FindForm(); lb = (ListView)frm.Controls.Find("listView1", true)[0]; ts = (ToolStrip)frm.Controls.Find("toolStrip1", true)[0]; lblSyncType = (ToolStripLabel)ts.Items.Find("lblSyncType", true)[0]; panel1 = (Panel)frm.Controls.Find("panel1", true)[0]; label3 = (Label)frm.Controls.Find("label3", true)[0]; label2 = (Label)frm.Controls.Find("label2", true)[0]; // regBtn = (Button)frm.Controls.Find("btnRegister", true)[0]; treeview = (TreeView)frm.Controls.Find("treeView1", true)[0]; string lt = letter.Substring(0, 1); serial = DriveInformation.getSerial(lt + ":\\"); //USB.FindDriveLetter(lt + ":").SerialNumber; //Thread secondaryThread=new Thread(new ThreadStart(getDeviceData)); //secondaryThread.Start(); LoadDevice(); }; }
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); }