public void BuildTree(ItemModel root, string path, object file) { if (path == null) { return; } var paths = path.Split('/'); ItemModel parent = root; for (int i = 0; i < paths.Length; i++) { var name = paths[i]; var isFile = (i + 1 == paths.Length); var next = parent.GetChildItem(name); if (next is null) {//no exist node // build new node if (isFile) { next = new FileModel(name); next.Record = file; } else { next = new FolderModel(name); } parent.AddChildItem(next); } parent = next; } }
public void BuildTree(ItemModel root, string path, object file) { if (file is BundleRecord) { foreach (var f in ((BundleRecord)file).Files) { if (ic.Hashes[f.Hash].ToLower().Contains(filtered)) { loadedBundles.Add((BundleRecord)file); goto S; } } return; } else if (!path.ToLower().Contains(filtered)) { return; } S: var SplittedPath = path.Split('/'); ItemModel parent = root; for (int i = 0; i < SplittedPath.Length; i++) { var name = SplittedPath[i]; var isFile = (i + 1 == SplittedPath.Length); var next = parent.GetChildItem(name); if (next is null) { //No exist node, Build a new node if (isFile) { next = new FileModel(name) { Record = file } } ; else { next = new FolderModel(name); } parent.AddChildItem(next); } parent = next; } }