public INode EnsureFolders(IEnumerable <INode> nodes, string folderName, INode rootNode = null) { var paths = MegaApiClientHelper.SplitSubPaths(folderName); var parent = rootNode ?? FindRoot(nodes); if (parent != null) { for (int i = 0; i < paths.Length; i++) { var folderNode = FindDirectory(nodes, paths[i], parent); if (folderNode == null) { folderNode = CreateFolder(paths[i], parent); } if (folderNode == null) { break; } if (i == (paths.Length - 1)) { return(folderNode); } parent = folderNode; } } return(null); }
private INode FindFolder(IEnumerable <INode> nodes, string folderName) { var paths = MegaApiClientHelper.SplitSubPaths(folderName); var parentId = FindRoot(nodes)?.Id; if (!string.IsNullOrEmpty(parentId)) { for (int i = 0; i < paths.Length; i++) { var folderNode = FindDirectory(nodes, paths[i], parentId); if (folderNode == null) { return(null); } if (i == (paths.Length - 1)) { return(folderNode); } parentId = folderNode.Id; } } return(null); }