Example #1
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            foreach (var VARIABLE in listView1.SelectedItems)
            {
                listView1.Items.Remove((ListViewItem)VARIABLE);
            }
            Drive drive = drives.Find(i => (i.serial) == label3.Text);

            if (drive != null)
            {
                drives.Remove(drive);
                drive.autosync = true;

                if (drive.source != null)
                {
                    drive.source.Clear();
                }
                else
                {
                    drive.source = new List <string[]>();
                }
                foreach (ListViewItem txt in listView1.Items)
                {
                    drive.source.Add(new string[] { txt.SubItems[0].Text, txt.SubItems[1].Text.Substring(1, txt.SubItems[1].Text.Length - 1) });
                }


                drives.Add(drive);
                FileDetailsMgmt.saveDrive(drives);
                drives = FileDetailsMgmt.getRegisteredDrives();
                // MessageBox.Show("Operation Completed", "SmartSync", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
 /// <summary>
 /// Change the synchronization settings of the selected drive
 /// </summary>
 /// <param name="syncType">The type of synchronization that is selected</param>
 private void updateSyncType(SyncType syncType)
 {
     try
     {
         if (selectedDrive == null)
         {
             return;
         }
         drives.Remove(selectedDrive);
         selectedDrive.syncType = syncType;
         drives.Add(selectedDrive);
         FileDetailsMgmt.saveDrive(drives);
         drives           = FileDetailsMgmt.getRegisteredDrives();
         lblSyncType.Text = syncType.ToString();
     }
     catch (Exception e) { Helper.WriteLog(e); }
 }
Example #3
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem item = listView1.SelectedItems[0];

            item.Remove();

            Drive drive = drives.Find(i => (i.serial) == label3.Text);


            if (drive != null)
            {
                string[] s = new string[] { item.SubItems[0].Text, item.SubItems[1].Text };
                drives.Remove(drive);
                //drive.autosync = true;
                drive.source.Remove(s);

                drives.Add(drive);
                FileDetailsMgmt.saveDrive(drives);
                drives = FileDetailsMgmt.getRegisteredDrives();
                // MessageBox.Show("Operation Completed", "SmartSync", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #4
0
        /// <summary>
        /// Register a usb device to the program
        /// </summary>
        /// <param name="o">The device to be registered</param>
        private void RegisterDevice(object o)
        {
            try
            {
                string sl    = o as string;
                Drive  drive = new Drive();
                drives         = FileDetailsMgmt.getRegisteredDrives();
                drive.autosync = true;
                drive.serial   = sl;
                Drive drv = null;
                //check if the drive has already been registered
                foreach (var d in drives)
                {
                    if (d.serial == serial)
                    {
                        drv = d;
                    }
                }

                if (drv != null)
                {
                    return;
                }
                else
                {
                    List <string[]> sources     = new List <string[]>();
                    List <string[]> syncdetails = new List <string[]>();
                    drive.source      = sources;
                    drive.syncType    = SyncType.TwoWay;
                    drive.syncDetails = syncdetails;
                    drives.Add(drive);
                    FileDetailsMgmt.saveDrive(drives);
                    drives = FileDetailsMgmt.getRegisteredDrives();
                    UnloadDevice(letter + ":\\");
                    loadDevice(letter);
                }
            }
            catch (Exception e) { Helper.WriteLog(e); }
        }
Example #5
0
        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                //check if the device is registered already and if not, register it
                string[] dirs = new string[2];
                dirs[0] = (string)e.Data.GetData(typeof(string));
                if (!Directory.Exists(dirs[0]))
                {
                    return;
                }

                DriveInformation.sdrv_folder = (string)e.Data.GetData(typeof(string));

                if (selectedDrive != null)
                {
                    DriveInformation.sdrv = letter;
                }
                else
                {
                    DriveInformation.sdrv = "";
                }

                //load the dialog form to select the drive you want to synchronize and the folder you want to do that with
                driveBrowser browser = new driveBrowser(this);
                if (browser.ShowDialog().ToString() == "Cancel")
                {
                    return;
                }

                //progressbar.Visible = true;

                //retrieve the values set from the dialog
                string value = DriveInformation.sdrv_folder;
                //check if the device has been registered else register it
                RegisterDevice(DriveInformation.sdrv_serial);
                Drive drive = drives.Find(i => (i.serial) == DriveInformation.sdrv_serial);
                if (drive == null)
                {
                    return;
                }
                //progressbar.PerformStep();
                if (drive.source.Count > 0)
                {
                    //check if the folder has originally been synchronized
                    foreach (string[] s in drive.source)
                    {
                        if (s[0] == dirs[0])
                        {
                            dirs[1] = DriveInformation.sdrv_folder;

                            drives.Remove(drive);
                            drive.source.Remove(s);

                            if (drive.source != null)
                            {
                                drive.source.Add(dirs);
                            }
                            else
                            {
                                drive.source = new List <string[]>();
                                drive.source.Add(dirs);
                            }
                            drives.Add(drive);
                            FileDetailsMgmt.saveDrive(drives);
                            drives           = FileDetailsMgmt.getRegisteredDrives();
                            statuslabel.Text = "Folder added successfully";
                        }
                    }
                }
                else
                {
                    dirs[1] = DriveInformation.sdrv_folder;
                    drives.Remove(drive);
                    drive.autosync = true;
                    if (drive.source != null)
                    {
                        drive.source.Add(dirs);
                    }
                    else
                    {
                        drive.source = new List <string[]>();
                        drive.source.Add(dirs);
                    }
                    drives.Add(drive);
                    FileDetailsMgmt.saveDrive(drives);
                    drives           = FileDetailsMgmt.getRegisteredDrives();
                    statuslabel.Text = "Folder added successfully";
                }
            }
            catch (Exception ex) { Helper.WriteLog(ex); }
            finally
            {
                //progressbar.Visible = false;
            }
        }
Example #6
0
        void device_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
                    foreach (string f in file)
                    {
                        string[] dirs = new string[2];
                        dirs[0] = f;
                        if (!Directory.Exists(dirs[0]))
                        {
                            return;
                        }
                        DriveInformation.sdrv_folder = f;
                        usbDevice dv = (usbDevice)sender;
                        DriveInformation.sdrv = dv.letter.Substring(0, 1);

                        //load the dialog form to select the drive you want to synchronize and the folder you want to do that with
                        driveBrowser browser = new driveBrowser(this);
                        if (browser.ShowDialog().ToString() == "Cancel")
                        {
                            return;
                        }

                        //retrieve the values set from the dialog
                        //check if the device has been registered else register it
                        RegisterDevice(DriveInformation.sdrv_serial);
                        Drive drive = drives.Find(i => (i.serial) == DriveInformation.sdrv_serial);
                        if (drive == null)
                        {
                            return;
                        }
                        if (drive.source.Count > 0)
                        {
                            //check if the folder has originally been synchronized
                            foreach (string[] s in drive.source)
                            {
                                if (s[0] == dirs[0])
                                {
                                    dirs[1] = DriveInformation.sdrv_folder;

                                    drives.Remove(drive);
                                    drive.source.Remove(s);

                                    if (drive.source != null)
                                    {
                                        drive.source.Add(dirs);
                                    }
                                    else
                                    {
                                        drive.source = new List <string[]>();
                                        drive.source.Add(dirs);
                                    }
                                    drives.Add(drive);
                                    FileDetailsMgmt.saveDrive(drives);
                                    drives           = FileDetailsMgmt.getRegisteredDrives();
                                    statuslabel.Text = "Folder added successfully";
                                }
                            }
                        }
                        else
                        {
                            dirs[1] = DriveInformation.sdrv + ":\\" + DriveInformation.sdrv_folder;
                            drives.Remove(drive);
                            drive.autosync = true;
                            if (drive.source != null)
                            {
                                drive.source.Add(dirs);
                            }
                            else
                            {
                                drive.source = new List <string[]>();
                                drive.source.Add(dirs);
                            }
                            drives.Add(drive);
                            FileDetailsMgmt.saveDrive(drives);
                            drives           = FileDetailsMgmt.getRegisteredDrives();
                            statuslabel.Text = "Folder added successfully";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Helper.WriteLog(ex);
            }
        }
Example #7
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;
            };
        }