Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string newSourcePath = string.Empty;
            string newTargetPath = string.Empty;
            FolderBrowserDialog folderChooser = new FolderBrowserDialog();
            DialogResult        result        = folderChooser.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                newSourcePath = folderChooser.SelectedPath;
            }

            result = folderChooser.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                newTargetPath = folderChooser.SelectedPath;
            }
            DirectoryPair newDirectoryPair = new DirectoryPair
            {
                SourcePath = newSourcePath,
                TargetPath = newTargetPath
            };

            prefs.DirectoryPairs.Add(newDirectoryPair);
            RefreshPrefs();
        }
Ejemplo n.º 2
0
        private Preferences GetPreferences()
        {
            try
            {
                string currentPath = Directory.GetCurrentDirectory() + @"\preferences.xml";
                if (!File.Exists(currentPath))
                {
                    XDocument doc = new XDocument(new XElement("DirectoryComparerPreferences",
                                                               new XElement("Preferences",
                                                                            new XElement("DirectoryPairs",
                                                                                         new XElement("DirectoryPair", "C:/,D:/")))));
                    doc.Save(currentPath);
                }

                XmlTextReader reader = new XmlTextReader(currentPath);
                prefs = new Preferences();
                prefs.DirectoryPairs = new List <DirectoryPair>();
                int i = 0;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        while (reader.LocalName == "DirectoryPair")
                        {
                            string        dirPair = reader.ReadElementString("DirectoryPair");
                            DirectoryPair pair    = new DirectoryPair();
                            pair.Enabled       = Convert.ToBoolean(dirPair.Split(',')[0]);
                            pair.ComparisonSet = i;
                            pair.SourcePath    = dirPair.Split(',')[1];
                            pair.TargetPath    = dirPair.Split(',')[2];
                            prefs.DirectoryPairs.Add(pair);
                            i++;
                        }
                    }
                }
                reader.Close();
                return(prefs);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (resultsGrid.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please select a row to edit");
                return;
            }
            Rowindex = resultsGrid.SelectedRows[0].Index;
            string newSourcePath = string.Empty;
            string newTargetPath = string.Empty;
            FolderBrowserDialog folderChooser = new FolderBrowserDialog();
            DialogResult        result        = folderChooser.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                newSourcePath = folderChooser.SelectedPath;
            }

            result = folderChooser.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                newTargetPath = folderChooser.SelectedPath;
            }

            DirectoryPair newDirectoryPair = new DirectoryPair
            {
                SourcePath = newSourcePath,
                TargetPath = newTargetPath
            };
            string status = ValidateInputs(newDirectoryPair.SourcePath, newDirectoryPair.TargetPath);

            if (status != string.Empty)
            {
                MessageBox.Show("Invalid Path values!\r\n" + status);
                return;
            }
            prefs.DirectoryPairs.RemoveAt(Rowindex);
            prefs.DirectoryPairs.Add(newDirectoryPair);
            RefreshPrefs();
        }