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; } }
/// <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 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); } }
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); } }