private void ButtonRemove_Click(object sender, RoutedEventArgs e) { if (!String.IsNullOrEmpty(SelectedPath)) { BackupDirectories.Remove(SelectedPath); } }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { using (var dialog = new WinForms.FolderBrowserDialog()) { WinForms.DialogResult result = dialog.ShowDialog(); if (result == WinForms.DialogResult.OK) { BackupDirectories.Add(dialog.SelectedPath); } } }
/// <summary> /// Reads a text file encoded like below: /// 1:path /// 2:username /// 3:password /// 4:local-path /// 4: ... /// 4: local-path /// 5: excluded-path /// 5: ... /// </summary> /// <param name="file"></param> private void ReadSettings(String file) { BackupDirectories.Clear(); if (!File.Exists(file)) { return; } String line = String.Empty; using (StreamReader sr = new StreamReader(file)) { while ((line = sr.ReadLine()) != null && !String.IsNullOrEmpty(line.Trim())) { if (line.StartsWith("1:")) { TextBoxPath.Text = line.Substring(2); } else if (line.StartsWith("2:")) { TextBoxUsername.Text = line.Substring(2); } else if (line.StartsWith("3:")) { TextBoxPassword.Text = line.Substring(2); } else if (line.StartsWith("4:")) { BackupDirectories.Add(line.Substring(2)); } else if (line.StartsWith("5:")) { ExcludedDirectories.Add(line.Substring(2)); } else { throw new Exception(line); } } sr.Close(); } }
/// <summary> /// Refreshes the backup info /// </summary> /// <returns>The task</returns> public async Task RefreshAsync(ProgramDataSource dataSource) { ExistingBackups = await GetExistingBackupsAsync(); // Get the latest backup version to restore from LatestAvailableRestoreVersion = GetPrimaryBackup?.BackupVersion ?? -1; BackupDirectories = AllBackupDirectories.TryGetValue(LatestAvailableBackupVersion)?. Select(x => x.GetBackupReadSearchPattern(dataSource)). ToArray() ?? Array.Empty <BackupSearchPattern>(); RestoreDirectories = LatestAvailableRestoreVersion == -1 ? Array.Empty <BackupSearchPattern>() : AllBackupDirectories.TryGetValue(LatestAvailableRestoreVersion)?. SelectMany(x => x.GetBackupWriteSearchPatterns(dataSource)). ToArray() ?? Array.Empty <BackupSearchPattern>(); if (BackupDirectories.GroupBy(x => x.ID).Any(x => x.Count() > 1)) { throw new InvalidOperationException("Multiple backup directories can not use the same ID starting from version 13.0.0"); } }