Ejemplo n.º 1
0
        /// <summary>
        /// This is the method that does that synchronises the folders in the device
        ///
        /// </summary>
        public void executeSyn()
        {
            try
            {
                synchronizing = true;
                //updatedFiles.Clear();
                //drive.syncDetails.Clear();
                int number = drive.source.Count;
                int step;
                if (number != 0)
                {
                    step = 100 / number;
                }
                else
                {
                    step = 1;
                }
                progressBar1.Value = 0;
                foreach (string[] directory in drive.source)
                {
                    printMessage("Synchronizing " + directory[0] + " ...");
                    progressBar1.Value += step;
                    //check if the folder synchronises by comparing their sizes. If the sizes are the same then it skips the folder and goes on to another folder.
                    Synchronize(directory[0], letter.Substring(0, 1) + ":\\" + directory[1], drive.syncType);
                }
                progressBar1.Value = 0;

                synchronized = true;

                printMessage("Synchronization complete.");
                drive.syncDetails = syncdetails;
                Drive d = FileDetailsMgmt.thisDrive(serial, drives);

                drives.Remove(d);
                drives.Add(drive);
                FileDetailsMgmt.saveDrive(drives);
            }


            catch (IOException e)
            {
                printMessage("An error occured.");
                Helper.WriteLog(e);
            }


            finally
            {
                LoadDevice();
                loadDeviceInfo();
                synchronizing = false;
            }
        }
Ejemplo n.º 2
0
        private void LoadDevice()
        {
            try
            {
                DriveInfo drive = new DriveInfo(letter);
                this.name    = drive.VolumeLabel;
                lblname.Text = name + " " + letter;
                //printMessage("Checking drive.....");
                decimal totalSize     = Math.Round(Convert.ToDecimal(drive.TotalSize) / 1000000000, 1);
                decimal availableSize = Math.Round(Convert.ToDecimal(drive.TotalFreeSpace) / 1000000000, 1);
                lblSize.Text       = availableSize.ToString() + "GB" + "/" + totalSize.ToString() + "GB";
                progressBar1.Value = Convert.ToInt32(((totalSize - availableSize) / totalSize) * 100);
                if (availableSize < (Convert.ToDecimal(0.1) * totalSize))
                {
                    progressBar1.Color = Color.Red;
                }

                Drive drv = FileDetailsMgmt.thisDrive(serial, drives);

                if (drv == null)
                {
                    printMessage("Unregistered device");

                    pictureBox1.Image = Properties.Resources.usb_disconnected;
                }
                else
                {
                    lblSyncType.Text = drv.syncType.ToString();
                    this.drive       = drv;
                    printMessage("Device Ready");
                }

                if (drv.autosync && synchronized == false)
                {
                    if (drv.source.Count > 0)
                    {
                        if (SmartSync.Properties.Settings.Default.autosync == false)
                        {
                            return;
                        }
                        executeSyn();
                        progressBar1.Color = Color.DeepSkyBlue;
                    }
                }
            }
            catch (Exception e) { Helper.WriteLog(e); }
        }
Ejemplo n.º 3
0
        private void usbDevice_Click(object sender, EventArgs e)
        {
            if (synchronizing == true)
            {
                return;
            }
            loadDeviceInfo();
            //List<NonSyncList> list = FileDetailsMgmt.getNonSyncList();
            //NonSyncList itm = list.Find(i => (i.serial) == serial);
            Drive drv = FileDetailsMgmt.thisDrive(serial, drives);

            if (drv != null)
            {
                ts.Visible        = true;
                pictureBox1.Image = Properties.Resources.usb_connected;
            }
            else
            {
                ts.Visible        = true;
                pictureBox1.Image = Properties.Resources.usb_disconnected;
            }
            List <usbDevice> devices = new List <usbDevice>();

            foreach (Control ctrl in panel1.Controls)
            {
                devices.Add((usbDevice)ctrl);
            }

            foreach (usbDevice dv in devices)
            {
                if (dv.Name != this.Name)
                {
                    deSelectDevice(dv);
                }
            }
            label2.Text                  = this.Name.Substring(0, 1); //this.Name.Length - 1);
            this.BorderStyle             = BorderStyle.FixedSingle;
            DriveInformation.sdrv_serial = serial;
            this.FindForm().Controls.Find("label2", true)[0].Text = this.Name.Substring(0, 1);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Load the information of the drive to the parent form
        /// </summary>
        private void loadDeviceInfo()
        {
            try
            {
                DriveInfo drive = new DriveInfo(letter);


                label3.Text = serial;

                Drive drv = FileDetailsMgmt.thisDrive(serial, drives);

                if (drv == null)
                {
                    lb.Items.Clear();
                    printMessage("Unregistered device");

                    foreach (TreeNode node in treeview.Nodes)
                    {
                        foreach (TreeNode n in node.Nodes)
                        {
                            n.ImageIndex = 0;

                            n.SelectedImageIndex = 0;
                        }
                    }
                    pictureBox1.Image = Properties.Resources.usb_disconnected;
                }
                else
                {
                    this.drive = drv;
                    lb.Items.Clear();
                    lblSyncType.Text = drv.syncType.ToString();
                    //lb.Columns.Clear();

                    int i = 0;
                    if (drv.source.Count > 0)
                    {
                        foreach (string[] s in drv.source)
                        {
                            if (drv.syncDetails.Count > 0)
                            {
                                string[] s1 = new string[] { s[0], s[1], drv.syncDetails[i][0], drv.syncDetails[i][0] };
                                lb.Items.Add(new ListViewItem(s1));
                                lb.Items[0].ImageIndex = 1;
                            }
                            else
                            {
                                string[] s1 = new string[] { s[0], s[1], "Not synchronized", "Not synchronized" };
                                lb.Items.Add(new ListViewItem(s1));
                                lb.Items[0].ImageIndex = 1;
                            }
                            // lb.Items.Add(new ListViewItem(s));
                        }
                    }



                    foreach (TreeNode node in treeview.Nodes)
                    {
                        foreach (TreeNode n in node.Nodes)
                        {
                            if (drv.source != null && drv.source.Count > 0)
                            {
                                foreach (var s in drv.source[0])
                                {
                                    if (s == n.Name)
                                    {
                                        n.ImageIndex = 1;

                                        n.SelectedImageIndex = 1;
                                        break;
                                    }
                                    else
                                    {
                                        n.ImageIndex = 0;

                                        n.SelectedImageIndex = 0;
                                    }
                                }
                            }
                            else
                            {
                                n.ImageIndex = 0;

                                n.SelectedImageIndex = 0;
                            }
                        }
                    }



                    if (drv.autosync && synchronized == false)
                    {
                        if (drv.source.Count > 0)
                        {
                            printMessage("Synchronizing...");
                            //backgroundWorker1.RunWorkerAsync();
                            executeSyn();
                            progressBar1.Color = Color.DeepSkyBlue;
                            //Thread thread = new Thread(new ThreadStart(executeSync));
                            //thread.Start();
                        }
                    }

                    printMessage("Device Ready");
                }
            }
            catch (Exception e)
            {
                Helper.WriteLog(e);
            }
        }