private void LoadDriveList() { driveListView.Nodes.Clear(); Dictionary <string, TreeNode> nodes = new Dictionary <string, TreeNode>(); foreach (KeyValuePair <DriveInfo, DriveBackupData> dat in Program.driveDataList) { DriveBackupData driveDat = dat.Value; DriveInfo drive = driveDat.drive; TreeNode tmp = new TreeNode(); tmp.Text = "(" + drive.Name + ") " + drive.VolumeLabel; tmp.Tag = driveDat; if (driveDat.backupList != null && driveDat.backupList.Count > 0) { foreach (var v in driveDat.backupList) { TreeNode tmp2 = new TreeNode(); tmp2.Text = BackupUtil.ConvertRealPath(v, drive); tmp.Nodes.Add(tmp2); } } else { TreeNode tmp2 = new TreeNode(); tmp2.Text = "No synced folders found"; tmp.Nodes.Add(tmp2); } if (!nodes.ContainsKey(Program.VALID_DRIVE_TYPES[drive.DriveType])) { TreeNode driveType = new TreeNode(Program.VALID_DRIVE_TYPES[drive.DriveType]); nodes.Add(Program.VALID_DRIVE_TYPES[drive.DriveType], driveType); } TreeNode typeNode = nodes[Program.VALID_DRIVE_TYPES[drive.DriveType]]; typeNode.Nodes.Add(tmp); } foreach (TreeNode node in nodes.Values) { driveListView.Nodes.Add(node); } driveListView.ExpandAll(); UpdateUIData(); }
public async Task Start(MethodInvoker method) { Debug.WriteLine("Start"); await Task.Run(() => { try { int c = 0; foreach (string path in driveData.backupList) { if (Program.TERMINATE_BACKUP) { Program.BACKUP_STATE = "Terminated"; return; } c++; DirectoryInfo inf = new DirectoryInfo(BackupUtil.ConvertRealPath(path, driveData.drive)); if (!inf.Exists) { continue; } List <BackupData> dat = GetBackupData(inf, null); data = data.Concat(dat).ToList(); progress = ((c * 100) / driveData.backupList.Count); Program.BACKUP_PROGRESS = progress; } Debug.WriteLine("Complete" + data.Count); method(); isComplete = true; } catch (FileNotFoundException e) { Program.ThrowErrorMessage(e); return; } catch (IOException e) { Program.ThrowErrorMessage(e); return; } }); }