private async Task DownloadAdvanced(Directory directory, string toLocalPath) { labelAction.Text = "Downloading..."; labelContent.Text = directory.Path; bool rootDownload = directory.Path == BrickExplorer.ROOT_PATH; string localPath = (rootDownload) ? System.IO.Path.Combine(toLocalPath, Manager.Brick.Name) : System.IO.Path.Combine(toLocalPath, directory.Name); System.IO.Directory.CreateDirectory(localPath); File[] files = await BrickExplorer.GetFiles(directory.Path); foreach (File file in files) { labelContent.Text = file.Path; byte[] data = await file.Download(); if (data != null && data.Length > 0) { string filePath = System.IO.Path.Combine(localPath, file.FileName); using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create)) { fs.Write(data, 0, data.Length); } } } Directory[] subDirectories = await BrickExplorer.GetDirectories(directory.Path); foreach (Directory subDirectory in subDirectories) { await DownloadAdvanced(subDirectory, localPath); } }
private async Task AdvancedTree(TreeNode parent) { Directory[] directories = await BrickExplorer.GetDirectories(((Directory)parent.Tag).Path); foreach (Directory directory in directories) { TreeNode node = ConvertToNode(directory); parent.Nodes.Add(node); await AdvancedTree(node); } }
public async Task Refresh(Directory directory) { tree.BeginUpdate(); TreeNode node = Find(directory); if (node != null) { Directory[] directories; switch (UserSettings.Mode) { case Mode.BASIC: { switch (directory.Path) { case BrickExplorer.PROJECTS_PATH: { directories = await Manager.Brick.Drive.GetDirectories(); break; } case BrickExplorer.SDCARD_PATH: { directories = await Manager.Brick.SDCard.GetDirectories(); break; } default: { //Should never get here throw new InvalidOperationException(nameof(tree)); } } break; } default: { directories = await BrickExplorer.GetDirectories(directory.Path); break; } } node.Nodes.Clear(); foreach (Directory dir in directories) { node.Nodes.Add(ConvertToNode(dir)); } //int nodeCount = node.Nodes.Count; //int ni = 0; //for (int i = 0; i < dirs.Length; i++) //{ // if (i < nodeCount) // { // if (((Directory)node.Nodes[ni].Tag).Path != dirs[i].Path) // { // node.Nodes.Insert(i, ConvertToNode(dirs[i])); // break; // } // } // else // { // node.Nodes.Add(ConvertToNode(dirs[i])); // } // ni++; //} } tree.EndUpdate(); }