private void btnRun_Click(object sender, EventArgs e) { //btnRun.Enabled = false; try { root = txtMaster.Text.Trim(); fout = txtOutput.Text.Trim(); if (root != null && root.Length > 0 && Directory.Exists(txtMaster.Text) == true) { root = root.Replace('/', '\\').Trim('\\') + "\\"; List <TreeNode> foldersMaster = new List <TreeNode>(); List <TreeNode> leafMaster = new List <TreeNode>(); GetTree(root, foldersMaster, leafMaster, Color.DarkGreen); if (foldersMaster.Count > 0 && leafMaster.Count > 0) { leafMaster.ForEach(n => ProcessZip(n)); tf = new TreeForm(); tf.tv.Nodes.Add(foldersMaster[0]); } else { MessageBox.Show("No folders found", "Not found"); return; } if (fout != null && fout.Trim().Length > 0) { try { StreamWriter sw = File.CreateText(fout); sw.Close(); } catch {} } tf.tv.TopNode = foldersMaster[0]; tf.Setup(foldersMaster, root); tf.ShowDialog(this); } else { MessageBox.Show("Folder Target not specified", "Folder not found"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception occurred"); } }
private void btnRun_Click(object sender, EventArgs e) { //btnRun.Enabled = false; try { remdirs = new Dictionary <string, string>(); adddirs = new Dictionary <string, string>(); remlfs = new Dictionary <string, string>(); addlfs = new Dictionary <string, string>(); root = txtMaster.Text.Trim(); dest = txtTarget.Text.Trim(); fout = txtOutput.Text.Trim(); if (root != null && root.Length > 0 && Directory.Exists(txtMaster.Text) == true) { if (dest != null && dest.Length > 0 && Path.IsPathRooted(dest) == true) { root = root.Replace('/', '\\').Trim('\\') + "\\"; dest = dest.Replace('/', '\\').Trim('\\') + "\\"; if (Directory.Exists(dest) == false) { DialogResult result = MessageBox.Show("Create folder?", "Folder not found", MessageBoxButtons.YesNo); if (result != System.Windows.Forms.DialogResult.Yes) { return; } Directory.CreateDirectory(dest); if (Directory.Exists(dest) == false) { MessageBox.Show("Could not create folder: " + dest, "Error creating folder"); return; } } List <TreeNode> foldersMaster = new List <TreeNode>(); List <TreeNode> foldersTarget = new List <TreeNode>(); List <TreeNode> leafMaster = new List <TreeNode>(); List <TreeNode> leafTarget = new List <TreeNode>(); GetTree(root, dest, foldersMaster, leafMaster, Color.DarkGreen); GetTree(dest, root, foldersTarget, leafTarget, Color.Red); if (foldersMaster.Count > 0) { tf = new TreeForm(); tf.tv.Nodes.Add(foldersMaster[0]); } else { MessageBox.Show("No folders found", "Not found"); return; } var unmatchedfoldersTarget = foldersTarget.Where(n => unmatched(n, foldersMaster, Color.Black)); int iunmatchedfoldersTarget = unmatchedfoldersTarget.Count(); var unmatchedfoldersMaster = foldersMaster.Where(n => unmatched(n, foldersTarget, Color.Black)); int iunmatchedfoldersMaster = unmatchedfoldersMaster.Count(); var unmatchedleafMaster = leafMaster.Where(n => unmatched(n, leafTarget, Color.Black)); int iunmatchedleafMaster = unmatchedleafMaster.Count(); var unmatchedleafTarget = leafTarget.Where(n => unmatched(n, leafMaster, Color.Black)); int iunmatchedleafTarget = unmatchedleafTarget.Count(); foreach (TreeNode tn in unmatchedfoldersMaster) { AddCreateCommand(tn, foldersTarget); } foreach (TreeNode tn in unmatchedleafMaster) { AddCreateCommand(tn, foldersTarget); } foreach (TreeNode tn in unmatchedleafTarget) { SpliceDestNode(tn, foldersMaster, leafMaster); } foreach (TreeNode tn in unmatchedfoldersTarget) { SpliceDestNode(tn, foldersMaster, leafMaster); } if (fout != null && fout.Trim().Length > 0) { try { StreamWriter sw = File.CreateText(fout); var sortedDict = from entry in adddirs orderby entry.Key ascending select entry; foreach (KeyValuePair <string, string> kvp in sortedDict) { sw.WriteLine(kvp.Value); } foreach (KeyValuePair <string, string> kvp in addlfs) { sw.WriteLine(kvp.Value); } foreach (KeyValuePair <string, string> kvp in remlfs) { sw.WriteLine(kvp.Value); } sortedDict = from entry in remdirs orderby entry.Key descending select entry; foreach (KeyValuePair <string, string> kvp in sortedDict) { sw.WriteLine(kvp.Value); } sw.Close(); } catch {} } tf.tv.TopNode = foldersMaster[0]; tf.Setup(foldersMaster, root); tf.ShowDialog(this); } else { MessageBox.Show("Folder Target not specified", "Folder not found"); } } else { MessageBox.Show("Folder Master must be an existing Master folder", "Folder not found"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception occurred"); } }