예제 #1
0
        private string ParseAction(BackupProfile config)
        {
            var builder = new StringBuilder();

            builder.AppendLine("[Flags]");
            builder.AppendLine("profile=" + config.ActionName);
            builder.AppendLine("mode=" + config.Mode);
            builder.AppendLine("compare=" + config.Comparator);
            builder.AppendLine("history=" + config.BackupCopies);
            builder.AppendLine("archive=" + (config.Archive ? "yes" : "no:"));
            builder.AppendLine("password="******"[Files]");
            var sources      = new StringBuilder();
            var destinations = new StringBuilder();

            foreach (string src in config.SourcePath)
            {
                sources.AppendFormat("\"{0}\",", src);
            }
            sources.Remove(sources.Length - 1, 1);
            builder.AppendLine("sources=" + sources);
            foreach (string src in config.DestinationPath)
            {
                destinations.AppendFormat("\"{0}\",", src);
            }
            destinations.Remove(destinations.Length - 1, 1);
            builder.AppendLine("destinations=" + destinations);

            return(builder.ToString());
        }
예제 #2
0
        private void UpdateViewFromAction(BackupProfile backupProfile)
        {
            profileNameTextBox.Text = backupProfile.ActionName;
            if (backupProfile.Mode == "database")
            {
                modeComboBox.SelectedIndex = 0;
            }
            if (backupProfile.Mode == "simple")
            {
                modeComboBox.SelectedIndex = 1;
            }
            if (backupProfile.Comparator == "bydate")
            {
                comparatorComboBox.SelectedIndex = 0;
            }
            if (backupProfile.Comparator == "byhash")
            {
                comparatorComboBox.SelectedIndex = 1;
            }
            copiesNumericUpDown.Value = backupProfile.BackupCopies;
            archiveYes.Checked        = backupProfile.Archive;
            archiveNo.Checked         = !backupProfile.Archive;
            passwordTextBox.Text      = backupProfile.ArchivePassword;


            sourcesTextBox.Lines      = backupProfile.SourcePath;
            destinationsTextBox.Lines = backupProfile.DestinationPath;

            profileNameTextBox.Enabled         = sourcesTextBox.Enabled =
                destinationsTextBox.Enabled    = modeComboBox.Enabled =
                    comparatorComboBox.Enabled = copiesNumericUpDown.Enabled = !backupProfile.Locked;
        }
예제 #3
0
        public Form1()
        {
            InitializeComponent();
            currentProfile             = new BackupProfile();
            handler                    = new ConfigHandler();
            profilesListBox.DataSource = PopulateProfileList();

            //UpdateViewFromAction(currentProfile);
        }
예제 #4
0
 private void profilesListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (profilesListBox.SelectedIndex >= 0)
     {
         currentProfile = profilesListBox.SelectedItem as BackupProfile;
         UpdateViewFromAction(currentProfile);
     }
     //UpdateViewFromAction(profilesListBox.SelectedIndex == -1? new BackupProfile() : profilesListBox.SelectedItem as BackupProfile);
 }
예제 #5
0
 public bool SaveConfigToFile(string path, BackupProfile config, bool ask = true)
 {
     if (File.Exists(path) && ask && MessageBox.Show("Do you wish to overwrite existing profile?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
     {
         return(false);
     }
     if (string.IsNullOrEmpty(config.ActionName) ||
         config.DestinationPath == null || config.SourcePath == null ||
         config.DestinationPath.Length == 0 || config.SourcePath.Length == 0)
     {
         MessageBox.Show("Error in profile!");
         return(false);
     }
     using (var writer = new StreamWriter(path, false))
     {
         writer.Write(ParseAction(config));
     }
     return(true);
 }
예제 #6
0
        private void pickFileButton_Click(object sender, EventArgs e)
        {
            try
            {
                pickConfigDialog.ShowDialog();

                currentProfile = handler.OpenConfigFile(pickConfigDialog.FileName);
                if (currentProfile == null)
                {
                    currentProfile = new BackupProfile();
                    throw new ArgumentException(
                              "Configuration file either does not exist or is invalid! Check the examples.");
                }

                UpdateViewFromAction(currentProfile);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                MessageBox.Show(exception.ToString());
            }
        }
예제 #7
0
 private void newButton_Click(object sender, EventArgs e)
 {
     profilesListBox.SelectedIndex = -1;
     currentProfile = new BackupProfile();
     UpdateViewFromAction(currentProfile);
 }