/// <inheritdoc /> public async Task <string> DownloadAsync(string packageFolder, IProgress <double>?progress, CancellationToken token = default) { // Wait for background sync operation. await _initialiseTask; using var tempDownloadDir = new TemporaryFolderAllocation(); using var tempExtractDir = new TemporaryFolderAllocation(); var tempDownloadPath = Path.Combine(tempDownloadDir.FolderPath, Path.GetRandomFileName()); var progressSlicer = new ProgressSlicer(progress); // Download Package var downloadSlice = progressSlicer.Slice(0.9f); await PackageResolver.DownloadPackageAsync(Version !, tempDownloadPath, new ReleaseMetadataVerificationInfo() { FolderPath = tempDownloadPath }, downloadSlice, token); // Extract package. var extractSlice = progressSlicer.Slice(0.1f); var archiveExtractor = new SevenZipSharpExtractor(); await archiveExtractor.ExtractPackageAsync(tempDownloadPath, tempExtractDir.FolderPath, extractSlice, token); // Copy all packages from download. return(WebDownloadablePackage.CopyPackagesFromExtractFolderToTargetDir(packageFolder, tempExtractDir.FolderPath, token)); }
/// <inheritdoc /> public async Task <string> DownloadAsync(string packageFolder, IProgress <double>?progress, CancellationToken token = default) { using var tempDownloadDirectory = new TemporaryFolderAllocation(); using var tempExtractDirectory = new TemporaryFolderAllocation(); var tempFilePath = Path.Combine(tempDownloadDirectory.FolderPath, Path.GetRandomFileName()); var progressSlicer = new ProgressSlicer(progress); // Start the modification download. using var httpClient = new HttpClient(); var downloadProgress = progressSlicer.Slice(0.9); await using var fileStream = new FileStream(tempFilePath, FileMode.OpenOrCreate); var archiveStream = await httpClient.GetStreamAsync(_url, token).ConfigureAwait(false); await archiveStream.CopyToAsyncEx(fileStream, 262144, downloadProgress, FileSize.GetValueOrDefault(1), token); if (token.IsCancellationRequested) { return(string.Empty); } /* Extract to Temp Directory */ var archiveExtractor = new SevenZipSharpExtractor(); var extractProgress = progressSlicer.Slice(0.1); await archiveExtractor.ExtractPackageAsync(tempFilePath, tempExtractDirectory.FolderPath, extractProgress, token); /* Get name of package. */ return(CopyPackagesFromExtractFolderToTargetDir(packageFolder, tempExtractDirectory.FolderPath, token)); }