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); } }
private void Form2_FormClosing(object sender, FormClosingEventArgs e) { FileDetailsMgmt.saveDrive(drives); e.Cancel = true; Hide(); notifyIcon1.BalloonTipText = "You can open SmartSync from the here."; notifyIcon1.BalloonTipClicked += (s, a) => { Show(); }; notifyIcon1.ShowBalloonTip(5000); }
/// <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; } }
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); } }
/// <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); } }
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); }
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); } }
/// <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); } }
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); }
/// <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); } }
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; } }
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); } }
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; }; }