Exemple #1
0
 private void Download(object parameter)
 {
     System.Windows.Forms.FolderBrowserDialog downloadPathDialog = new System.Windows.Forms.FolderBrowserDialog
     {
         Description  = "请选择下载文件夹",
         SelectedPath = KnownFolders.Downloads.Path
     };
     if (downloadPathDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         Task.Run(() =>
         {
             GenericResult <FileMetaData> x = fileSystem.GetDetailsByUUID(UUID);
             if (!string.IsNullOrWhiteSpace(x.Result.DownloadAddress))
             {
                 DownloadingListViewModel.NewTask(x.Result.DownloadAddress, downloadPathDialog.SelectedPath, Name);
             }
         });
     }
 }
Exemple #2
0
        private async void Download(object parameter)
        {
            using System.Windows.Forms.FolderBrowserDialog downloadPathDialog = new System.Windows.Forms.FolderBrowserDialog
                  {
                      Description  = "请选择下载文件夹",
                      SelectedPath = DefaultDownloadPath ?? KnownFolders.Downloads.Path
                  };
            if (downloadPathDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DefaultDownloadPath = downloadPathDialog.SelectedPath;

                if (Directory)
                {
                    await DownloadHelper(UUID, System.IO.Path.Combine(downloadPathDialog.SelectedPath, Name), 0);

                    async Task DownloadHelper(string uuid, string localParentPath, int depthIndex)
                    {
                        await foreach (FileMetaData child in GetChild(uuid))
                        {
                            if (!child.Directory)
                            {
                                DownloadingListViewModel.NewTask(child.UUID, localParentPath, child.Name);
                            }
                            else
                            {
                                string nextPath = System.IO.Path.Combine(localParentPath, child.Name);
                                System.IO.Directory.CreateDirectory(nextPath);
                                if (depthIndex < 32)
                                {
                                    await DownloadHelper(child.UUID, nextPath, depthIndex + 1);
                                }
                                else
                                {
                                    System.Threading.ThreadPool.QueueUserWorkItem((state) => DownloadHelper(child.UUID, nextPath, 0).Wait(), null);
                                }
                            }
                        }
                    }