private async Task <bool> RecursiveDownloadFolder(String downloadPath, NodeViewModel folderNode) { if (String.IsNullOrWhiteSpace(folderNode.Name)) { await new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title, AppMessages.AM_DownloadNodeFailedNoErrorCode, this.AppInformation).ShowDialogAsync(); return(false); } // Check for illegal characters in the folder name if (FolderService.HasIllegalChars(folderNode.Name)) { await new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title, String.Format(AppMessages.InvalidFolderNameOrPath, folderNode.Name), this.AppInformation).ShowDialogAsync(); return(false); } try { String newDownloadPath = Path.Combine(downloadPath, folderNode.Name); if (!await CheckDownloadPath(newDownloadPath)) { return(false); } MNodeList childList = MegaSdk.getChildren(folderNode.OriginalMNode); bool result = true; // Default value in case that the folder is empty for (int i = 0; i < childList.size(); i++) { // To avoid pass null values to CreateNew if (childList.get(i) == null) { continue; } var childNode = NodeService.CreateNew(this.MegaSdk, this.AppInformation, childList.get(i), ContainerType.CloudDrive); // If node creation failed for some reason, continue with the rest and leave this one if (childNode == null) { continue; } bool partialResult; if (childNode.IsFolder) { partialResult = await RecursiveDownloadFolder(newDownloadPath, childNode); } else { partialResult = await DownloadFile(newDownloadPath, childNode); } // Only change the global result if the partial result indicates an error if (!partialResult) { result = partialResult; } } return(result); } catch (Exception e) { OnUiThread(() => { new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title, String.Format(AppMessages.DownloadNodeFailed, e.Message), App.AppInformation).ShowDialog(); }); return(false); } }
public async void Download(TransferQueue transferQueue, string downloadPath = null) { // User must be online to perform this operation if (!IsUserOnline()) { return; } if (AppInformation.PickerOrAsyncDialogIsOpen) { return; } if (downloadPath == null) { if (!await FolderService.SelectDownloadFolder(this)) { return; } else { downloadPath = AppService.GetSelectedDownloadDirectoryPath(); } } OnUiThread(() => ProgressService.SetProgressIndicator(true, ProgressMessages.PrepareDownloads)); // Extra check to try avoid null values if (String.IsNullOrWhiteSpace(downloadPath)) { OnUiThread(() => ProgressService.SetProgressIndicator(false)); await new CustomMessageDialog(AppMessages.SelectFolderFailed_Title, AppMessages.SelectFolderFailed, App.AppInformation, MessageDialogButtons.Ok).ShowDialogAsync(); return; } // Check for illegal characters in the download path if (FolderService.HasIllegalChars(downloadPath)) { OnUiThread(() => ProgressService.SetProgressIndicator(false)); await new CustomMessageDialog(AppMessages.SelectFolderFailed_Title, String.Format(AppMessages.InvalidFolderNameOrPath, downloadPath), this.AppInformation).ShowDialogAsync(); return; } if (!await CheckDownloadPath(downloadPath)) { OnUiThread(() => ProgressService.SetProgressIndicator(false)); return; } // If selected file is a folder then also select it childnodes to download if (this.IsFolder) { await RecursiveDownloadFolder(downloadPath, this); } else { await DownloadFile(downloadPath, this); } OnUiThread(() => ProgressService.SetProgressIndicator(false)); // TODO Remove this global declaration in method App.CloudDrive.NoFolderUpAction = true; }