private void LoadDirectories() { if (Directory.Exists(_path)) { var stack = new Stack <Tuple <string, ApplicationDirectoryState> >(); var root = new ApplicationDirectoryState("/", null); var dirs = Directory.GetDirectories(_path); var parent = root; foreach (var dir in dirs) { stack.Push(new Tuple <string, ApplicationDirectoryState>(dir, parent)); } while (stack.Count > 0) { var working = stack.Pop(); var workingState = new ApplicationDirectoryState(working.Item1.Replace(_path, ""), working.Item2); working.Item2.AddDirectory(workingState); parent = workingState; // set new parent for children dirs = Directory.GetDirectories(working.Item1); // get children foreach (var dir in dirs) { stack.Push(new Tuple <string, ApplicationDirectoryState>(dir, parent)); } var files = Directory.GetFiles(working.Item1); foreach (var file in files) { if (file.EndsWith(".bnk", true, CultureInfo.CurrentCulture)) { var applicationFileState = ApplicationFileState.Create(file, _path); workingState.AddFile(applicationFileState); _files.Add(applicationFileState); } } } PruneEmptyDirectories(root, null); RootDirectory = root; } }
internal void AddFile(ApplicationFileState file) { Files.Add(file); }