Esempio n. 1
0
 public Form1()
 {
     InitializeComponent();
     driveDetector = new DriveDetector();
     driveDetector.DeviceArrived += new DriveDetectorEventHandler(OnDriveArrived);
     driveDetector.DeviceRemoved += new DriveDetectorEventHandler(OnDriveRemoved);
     //   usbDeviceNotifier.OnDeviceNotify +=new EventHandler<DeviceNotifyEventArgs>(usbDeviceNotifier_OnDeviceNotify);
 }
Esempio n. 2
0
 /// <summary>
 /// Set up the hidden form.
 /// </summary>
 /// <param name="detector">DriveDetector object which will receive notification about USB drives, see WndProc</param>
 public DetectorForm(DriveDetector detector)
 {
     mDetector            = detector;
     this.MinimizeBox     = false;
     this.MaximizeBox     = false;
     this.ShowInTaskbar   = false;
     this.ShowIcon        = false;
     this.FormBorderStyle = FormBorderStyle.None;
     this.Load           += new System.EventHandler(this.Load_Form);
     this.Activated      += new EventHandler(this.Form_Activated);
 }
Esempio n. 3
0
        public Form2()
        {
            InitializeComponent();

            //create event handler for the detection of the usb devices
            driveDetector = new DriveDetector();
            driveDetector.DeviceArrived += new DriveDetectorEventHandler(OnDriveArrived);
            driveDetector.DeviceRemoved += new DriveDetectorEventHandler(OnDriveRemoved);
            selectedDrive      = null;
            toolStrip1.Visible = false;
            this.Load         += (s, a) => {
                //Load the settings file of the project
                if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SmartSync")))
                {
                    Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SmartSync"));
                }
                listView1.AllowDrop = true;

                //Load the system directories in a treeview

                treeView1.Nodes.Clear();
                DriveInfo[] ds = DriveInfo.GetDrives();

                foreach (DriveInfo d in ds)
                {
                    USB.USBDevice device = USB.FindDriveLetter(d.Name.Substring(0, 2));
                    if (device == null)
                    {
                        if (d.IsReady && d.TotalSize > 0 && IsNotReadOnly(d.ToString()))
                        {
                            //populate the list view with the directories in the drives of the system

                            TreeNode parentNode = new TreeNode();
                            parentNode.ImageIndex         = 0;
                            parentNode.SelectedImageIndex = 0;
                            parentNode.Text = d.RootDirectory.ToString();
                            //string[] dir = getDirectories(di.RootDirectory.ToString());
                            treeView1.Nodes.Add(parentNode);

                            foreach (var si in d.RootDirectory.GetDirectories())
                            {
                                if ((si.Attributes & FileAttributes.System) == FileAttributes.System)
                                {
                                    continue;
                                }
                                TreeNode child = new TreeNode();
                                child.ImageIndex         = 0;
                                child.Name               = si.FullName.ToString();
                                child.SelectedImageIndex = 0;

                                child.Text = si.Name;
                                parentNode.Nodes.Add(child);
                            }
                            parentNode.Expand();
                        }
                    }
                }

                //listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);

                drives = FileDetailsMgmt.getRegisteredDrives();


                statuslabel.Text = "Loading Application settings...";
                Application.DoEvents();

                statuslabel.Text = "Loading USB drives...";

                //Load the usb devices that are connected to the system
                LoadConnectedDevices();

                MenuItem item = new MenuItem();
                item.Text   = "Open";
                item.Click += (b, y) => { Show(); };

                MenuItem item1 = new MenuItem();
                item1.Text   = "Exit";
                item1.Click += (t, y) => { Application.ExitThread(); };
                ContextMenu contextMenu = new ContextMenu();
                contextMenu.MenuItems.AddRange(new MenuItem[] { item, item1 });
                notifyIcon1.ContextMenu = contextMenu;
            };
        }