private async Task CreateProjectFromArchive(string archivePath) { var settings = _settingsService.LoadSettings(); var dialog = new CreateProjectFromArchiveDialog(settings.PrintsPath, archivePath) { Owner = Application.Current.MainWindow }; if (dialog.ShowDialog() == true) { await ExecuteLoadingAction( string.Format(_translationManager.GetTranslation(nameof(StringTable.Prog_CreateProject)), dialog.ProjectName), async() => { var project = await dialog.CreateProject(); PrintElements.Add(project); SelectedElement = project; }, _translationManager.GetTranslation(nameof(StringTable.Suc_CreateProject)), _translationManager.GetTranslation(nameof(StringTable.Fail_CreateProject))); } }
public async Task DownloadFiles(Uri webAddress, PrintElement printElement) { var zipFilePath = Path.GetTempFileName(); var fileUri = await GetResponseUri(webAddress); using (var response = await _httpClient.GetAsync(fileUri)) using (var fs = new FileStream(zipFilePath, FileMode.Create)) await response.Content.CopyToAsync(fs); if (Path.GetExtension(fileUri.ToString()).ToLower() == ".zip") { using var zipFile = ZipFile.OpenRead(zipFilePath); await CreateProjectFromArchiveDialog.GetFilesToExtract(zipFile, printElement.DirectoryLocation) .Where(x => !x.Entry.Name.ToLower().In("license.html", "readme.pdf") && !x.Entry.Name.ToLower().EndsWith("-attribution.pdf")) .ForEachAsync(x => Task.Run(() => x.Entry.ExtractToFile(x.TargetPath))); } else { File.Copy(zipFilePath, Path.Combine(printElement.DirectoryLocation, Path.GetFileName(fileUri.ToString()))); } File.Delete(zipFilePath); }