private void GetTree(string troot, List <TreeNode> folders, List <TreeNode> leafs, Color color) { ActorFile ad = new ActorFile(troot, troot, false); TreeNode tn = new TreeNode(ad.fileName); tn.ForeColor = color; tn.Tag = ad; folders.Add(tn); int ix = 0; AddFiles(troot, tn, leafs, color); while (ix < folders.Count) { string[] dirs = Directory.GetDirectories((folders[ix].Tag as ActorFile).filePath); if (dirs.Length > 0) { foreach (string dir in dirs) { ad = new ActorFile(troot, dir, false); tn = new TreeNode(ad.fileName); tn.ForeColor = color; tn.Tag = ad; folders.Add(tn); folders[ix].Nodes.Add(tn); AddFiles(troot, tn, leafs, color); } } ix++; } }
private void AddCreateCommand(TreeNode node, List <TreeNode> list) { try { if (node != null && node.Tag != null && node.Tag is ActorFile && list != null && list.Count > 0 && list[0].Tag != null && list[0].Tag is ActorFile) { ActorFile createFile = node.Tag as ActorFile; ActorFile referFile = list[0].Tag as ActorFile; if (createFile != null && referFile != null) { if (createFile.leaf == false) { string destfile = Path.Combine(referFile.basePath, createFile.relativePath); adddirs.Add(destfile, string.Format("if not exist \"{0}\" mkdir \"{0}\"", destfile)); } else { string destfile = Path.Combine(referFile.basePath, createFile.relativePath); addlfs.Add(destfile, string.Format("if not exist \"{1}\" copy \"{0}\" \"{1}\"", createFile.filePath, destfile)); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception occurred: AddCreateCommand"); } }
private bool ismatch(ActorFile a1, ActorFile a2) { if (a1 != null && a2 != null && a1.relativePath == a2.relativePath) { return(true); } return(false); }
public bool Matches(object o) { if (o is ActorFile) { ActorFile af = o as ActorFile; if (af.relativePath == relativePath) { return(true); } } return(false); }
private bool unmatched(TreeNode a, List <TreeNode> target, Color color) { ActorFile af = a.Tag as ActorFile; var m = target.Where(n => af.Matches(n.Tag)); if (m.Count() > 0) { a.ForeColor = color; return(false); } return(true); }
private void AddFiles(string troot, TreeNode tn, List <TreeNode> leafs, Color color) { var files = Directory.EnumerateFiles((tn.Tag as ActorFile).filePath, "*.*", SearchOption.TopDirectoryOnly) .Where(s => s.EndsWith(".zip")); foreach (var file in files) { ActorFile af = new ActorFile(troot, file.ToString(), true); TreeNode child = new TreeNode(af.fileName); child.ForeColor = color; child.Tag = af; tn.Nodes.Add(child); leafs.Add(child); } }
private TreeNode matched(ActorFile af, List <TreeNode> list) { var masters = list.Where(n => ismatch(n.Tag as ActorFile, af) == true); if (masters.Count() == 1) { foreach (TreeNode tn in masters) { if (tn.Tag != null && tn.Tag is ActorFile) { return(tn); } } } return(null); }
private bool ProcessZip(TreeNode tn) { bool found = false; if (tn != null && tn.Tag != null && tn.Tag is ActorFile) { ActorFile af = tn.Tag as ActorFile; using (ZipArchive za = ZipFile.Open(af.filePath, ZipArchiveMode.Update)) { if (za.Entries != null && za.Entries.Count == 2) { List <ZipArchiveEntry> dentries = new List <ZipArchiveEntry>(); List <string> files = new List <string>(); foreach (ZipArchiveEntry entry in za.Entries) { if (string.Compare(Path.GetFileNameWithoutExtension(af.fileName), Path.GetFileNameWithoutExtension(entry.Name), true) > 0) { string ext = Path.GetExtension(entry.Name); string file = Path.GetFileNameWithoutExtension(af.fileName); string path = Path.Combine(Path.GetDirectoryName(af.filePath), file + ext); entry.ExtractToFile(path); dentries.Add(entry); files.Add(path); } } if (files.Count == 2 && dentries.Count == 2) { dentries[0].Delete(); dentries[1].Delete(); za.CreateEntryFromFile(files[0], Path.GetFileName(files[0])); za.CreateEntryFromFile(files[1], Path.GetFileName(files[1])); File.Delete(files[0]); File.Delete(files[1]); tn.ForeColor = Color.DarkRed; } else { tn.ForeColor = Color.DarkBlue; } found = true; } } } return(found); }
private void impactView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { if (e.Node != null && e.Node.Tag != null && e.Node.Tag is ActorFile) { ActorFile af = e.Node.Tag as ActorFile; if (af.leaf == false) { _topVis = impactView.TopNode; contextMenuStripExp.Items["toolStripMenuItemCollapse"].Visible = e.Node.IsExpanded; contextMenuStripExp.Items["toolStripMenuItemExpandAll"].Visible = contextMenuStripExp.Items["toolStripMenuItemExpandDiff"].Visible = true; contextMenuStripExp.Tag = e.Node; e.Node.ContextMenuStrip = contextMenuStripExp; contextMenuStripExp.Visible = true; contextMenuStripExp.Refresh(); } } } }
private TreeNode MatchNode(TreeNode node, List <TreeNode> folders, List <TreeNode> leafs) { if (node != null && node.Tag != null && node.Tag is ActorFile) { ActorFile tf = node.Tag as ActorFile; TreeNode tn = null; if (tf.leaf == true) { tn = matched(tf, leafs); } else { tn = matched(tf, folders); } if (tn != null && tn.Tag != null && tn.Tag is ActorFile) { return(tn); } } return(null); }
private void AddRemoveCommand(ActorFile delFile) { try { if (delFile != null) { if (delFile.leaf == false) { remdirs.Add(delFile.filePath, string.Format("if exist \"{0}\" rmdir \"{0}\"", delFile.filePath)); } else { remlfs.Add(delFile.filePath, string.Format("if exist \"{0}\" del \"{0}\"", delFile.filePath)); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception occurred: AddRemoveCommand"); } }
private void SpliceDestNode(TreeNode node, List <TreeNode> folders, List <TreeNode> leafs) { try { if (node.Tag != null && node.Tag is ActorFile) { ActorFile af = node.Tag as ActorFile; if (af != null) { List <TreeNode> descendents = new List <TreeNode>(); descendents.Add(node); TreeNode parent = node.Parent; while (parent != null) { descendents.Add(parent); parent = parent.Parent; } descendents.Reverse(); TreeNode last = null; List <TreeNode> matchednodes = new List <TreeNode>(); foreach (TreeNode descendent in descendents) { TreeNode matchNode = MatchNode(descendent, folders, leafs); matchednodes.Add(matchNode); if (matchNode != null) { last = descendent; } } bool goon = false; int i = 0; foreach (TreeNode descendent in descendents) { if (goon && i > 0) { TreeNode tnode = descendent; TreeNode mnode = matchednodes[i - 1]; if (mnode == null) { mnode = last; } ActorFile mact = null; ActorFile tact = tnode.Tag as ActorFile; if (mnode != null) { mact = mnode.Tag as ActorFile; } TreeNode newnode = new TreeNode(tact.fileName); newnode.Tag = tact; newnode.ForeColor = tnode.ForeColor; if (mnode != null) { mnode.Nodes.Add(newnode); if (tact.leaf == false) { folders.Add(newnode); } } if (chkSuperset.Checked == false) { newnode.NodeFont = new Font(tf.tv.Font, FontStyle.Strikeout); AddRemoveCommand(tact); } else { if (af.leaf == true) { AddCreateCommand(node, leafs); } else { AddCreateCommand(node, folders); } } } if (descendent == last) { goon = true; last = descendent; } i++; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception occurred: CheckNode"); } }