public void Remove(ShelfResourceItem nr) { if (Nodes.Remove(nr)) { nr.Path = ""; } }
public void Build() { Task.Run(() => { string dir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Shelf"); Stack <string> stack = new Stack <string>(); stack.Push(dir); while (stack.Count > 0) { List <string> sorter = new List <string>(); Dictionary <string, string> lookup = new Dictionary <string, string>(); string d = stack.Pop(); ShelfBuilderItem child = null; var tmp = d.Replace(dir, ""); if (string.IsNullOrEmpty(tmp)) { child = Root; } else { child = Root.FindChild(d.Replace(dir, "")); } if (System.IO.Directory.Exists(d)) { string[] subs = System.IO.Directory.GetDirectories(d); foreach (string s in subs) { string ds = System.IO.Path.Combine(d, s); var split = ds.Split(System.IO.Path.DirectorySeparatorChar); var achild = new ShelfBuilderItem(split[split.Length - 1]); child.Add(achild); stack.Push(ds); } string[] files = System.IO.Directory.GetFiles(d); foreach (string p in files) { if (System.IO.Path.GetExtension(p).Equals(".mtg") || System.IO.Path.GetExtension(p).Equals(".mti") || System.IO.Path.GetExtension(p).Equals(".mtga")) { string fname = System.IO.Path.GetFileNameWithoutExtension(p); sorter.Add(fname); lookup[fname] = System.IO.Path.Combine(d, p); } } sorter.Sort(); foreach (string fname in sorter) { string p = null; if (lookup.TryGetValue(fname, out p)) { ShelfResourceItem r = new ShelfResourceItem(); r.Title = fname; if (System.IO.Path.GetExtension(p).Equals(".mtg") || System.IO.Path.GetExtension(p).Equals(".mtga")) { r.Type = p; child.Add(r); } else if (System.IO.Path.GetExtension(p).Equals(".mti")) { r.Type = System.IO.File.ReadAllText(p); child.Add(r); } } } } } App.Current.Dispatcher.Invoke(() => { if (OnBuildComplete != null) { OnBuildComplete.Invoke(this); } }); }); }
public void Add(ShelfResourceItem nr) { nr.Path = Path; Nodes.Add(nr); }