private TreeDirectoryInfo LoadFiles(DirectoryInfo dir, DirectoryInfo root, TreeNode dirNode) { TreeDirectoryInfo tdInfo = new TreeDirectoryInfo(); string[] filter = Options.GetInstance().Files.Split(';', ',', '|'); FileInfo[] files = { }; foreach (string pattern in filter) { if (pattern.Length > 0) { FileInfo[] matches = GetFiles(dir, pattern); if (matches.Length > 0) { //BPM: changed logic to grab ub first so the insert is at the correct index after resize // to fix crash bug anytime more than one file type was matched separately in the same dir int ub = files.GetUpperBound(0); Array.Resize(ref files, files.Length + matches.Length); matches.CopyTo(files, (files[0] == null ? 0 : ub + 1)); } } } if (Options.GetInstance().Files != project.FileFilter) { //The filter has changed, so we need to remove any items that may still be in the project //that no longer match the new filter criteria. string[] oldFilter = project.FileFilter.Split(';', ',', '|'); foreach (string oldPattern in oldFilter) { bool remove = true; foreach (string pattern in filter) { if (pattern == oldPattern) { remove = false; break; } } if (remove) { //Old pattern is not in the new filter, so remove matching files FileInfo[] oldFiles = GetFiles(dir, oldPattern); foreach (FileInfo fi in oldFiles) { project.RemoveFile(project.GetPath(fi.FullName)); } } } } foreach (FileInfo f in files) { tdInfo.fileCount++; TreeNode fileNode = new FileNode(f.Name, 9, f.FullName, f, root); fileNode.Checked = project.IsSelected(project.GetPath(f.FullName)); dirNode.Nodes.Add(fileNode); if (fileNode.Checked) { tdInfo.selectedFileCount++; } } return(tdInfo); }
public OutputForm(Target t) { Project p = Project.GetInstance(); InitializeComponent(); files.BeginUpdate(); if (t == null) { this.target = new Target("New Target", "$output\\target.js", new List <string>()); this.originalName = ""; } else { this.target = t; this.originalName = target.Name; } List <FileInfo> selFiles = p.SelectedFiles; ListViewItem[] incItems = new ListViewItem[target.Includes.Count]; foreach (FileInfo sf in selFiles) { string name = p.GetPath(sf.FullName); int index = target.Includes.IndexOf(name); if (index != -1) { (incItems[index] = new ListViewItem(new string[] { sf.Name, sf.FullName }, 9)).Name = name; } else { ListViewItem li = files.Items.Add(name, sf.Name, 9); li.SubItems.Add(sf.FullName); } } incs.BeginUpdate(); foreach (ListViewItem li in incItems) { if (li != null) { incs.Items.Add(li); } } incs.EndUpdate(); files.EndUpdate(); txtName.DataBindings.Add("Text", target, "Name"); txtFile.DataBindings.Add("Text", target, "File"); cbWrap.DataBindings.Add("Checked", target, "Shorthand"); txtList.DataBindings.Add("Text", target, "ShorthandList"); debug.DataBindings.Add("Checked", target, "Debug"); if (t == null) { FileInfo fi = new FileInfo(new FileInfo(Application.ExecutablePath).Directory.FullName + "\\shorthand.txt"); if (fi.Exists) { StreamReader sr = new StreamReader(fi.FullName); this.target.ShorthandList = sr.ReadToEnd(); sr.Close(); } } }