public async void DecompressArchiveToChildFolder() { var selectedItem = associatedInstance?.SlimContentPage?.SelectedItem; if (selectedItem == null) { return; } BaseStorageFile archive = await StorageHelpers.ToStorageItem <BaseStorageFile>(selectedItem.ItemPath); BaseStorageFolder currentFolder = await StorageHelpers.ToStorageItem <BaseStorageFolder>(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath); BaseStorageFolder destinationFolder = null; if (currentFolder != null) { destinationFolder = await FilesystemTasks.Wrap(() => currentFolder.CreateFolderAsync(Path.GetFileNameWithoutExtension(archive.Path), CreationCollisionOption.OpenIfExists).AsTask()); } if (archive != null && destinationFolder != null) { CancellationTokenSource extractCancellation = new CancellationTokenSource(); PostedStatusBanner banner = App.OngoingTasksViewModel.PostOperationBanner( string.Empty, "ExtractingArchiveText".GetLocalized(), 0, ReturnResult.InProgress, FileOperationType.Extract, extractCancellation); Stopwatch sw = new Stopwatch(); sw.Start(); await ZipHelpers.ExtractArchive(archive, destinationFolder, banner.Progress, extractCancellation.Token); sw.Stop(); banner.Remove(); if (sw.Elapsed.TotalSeconds >= 6) { App.OngoingTasksViewModel.PostBanner( "ExtractingCompleteText".GetLocalized(), "ArchiveExtractionCompletedSuccessfullyText".GetLocalized(), 0, ReturnResult.Success, FileOperationType.Extract); } } }
public async void DecompressArchiveToChildFolder() { StorageFile archive = await StorageItemHelpers.ToStorageItem <StorageFile>(associatedInstance.SlimContentPage.SelectedItem.ItemPath); StorageFolder currentFolder = await StorageItemHelpers.ToStorageItem <StorageFolder>(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath); StorageFolder destinationFolder = null; if (currentFolder != null) { destinationFolder = await currentFolder.CreateFolderAsync(Path.GetFileNameWithoutExtension(archive.Path), CreationCollisionOption.OpenIfExists); } if (archive != null && destinationFolder != null) { CancellationTokenSource extractCancellation = new CancellationTokenSource(); PostedStatusBanner banner = App.StatusCenterViewModel.PostOperationBanner( string.Empty, "Extracting archive", 0, ReturnResult.InProgress, FileOperationType.Extract, extractCancellation); Stopwatch sw = new Stopwatch(); sw.Start(); await ZipHelpers.ExtractArchive(archive, destinationFolder, banner.Progress, extractCancellation.Token); sw.Stop(); banner.Remove(); if (sw.Elapsed.TotalSeconds >= 6) { App.StatusCenterViewModel.PostBanner( "Extracting complete!", "The archive extraction completed successfully.", 0, ReturnResult.Success, FileOperationType.Extract); } } }
public async void DecompressArchiveHere() { StorageFile archive = await StorageItemHelpers.ToStorageItem <StorageFile>(associatedInstance.SlimContentPage.SelectedItem.ItemPath); StorageFolder currentFolder = await StorageItemHelpers.ToStorageItem <StorageFolder>(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath); if (archive != null && currentFolder != null) { CancellationTokenSource extractCancellation = new CancellationTokenSource(); PostedStatusBanner banner = App.StatusCenterViewModel.PostOperationBanner( string.Empty, "ExtractingArchiveText".GetLocalized(), 0, ReturnResult.InProgress, FileOperationType.Extract, extractCancellation); Stopwatch sw = new Stopwatch(); sw.Start(); await ZipHelpers.ExtractArchive(archive, currentFolder, banner.Progress, extractCancellation.Token); sw.Stop(); banner.Remove(); if (sw.Elapsed.TotalSeconds >= 6) { App.StatusCenterViewModel.PostBanner( "ExtractingCompleteText".GetLocalized(), "ArchiveExtractionCompletedSuccessfullyText".GetLocalized(), 0, ReturnResult.Success, FileOperationType.Extract); } } }
public async void DecompressArchive() { BaseStorageFile archive = await StorageHelpers.ToStorageItem <BaseStorageFile>(associatedInstance.SlimContentPage.SelectedItem.ItemPath); if (archive != null) { DecompressArchiveDialog decompressArchiveDialog = new DecompressArchiveDialog(); DecompressArchiveDialogViewModel decompressArchiveViewModel = new DecompressArchiveDialogViewModel(archive); decompressArchiveDialog.ViewModel = decompressArchiveViewModel; ContentDialogResult option = await decompressArchiveDialog.ShowAsync(); if (option == ContentDialogResult.Primary) { // Check if archive still exists if (!StorageHelpers.Exists(archive.Path)) { return; } CancellationTokenSource extractCancellation = new CancellationTokenSource(); PostedStatusBanner banner = App.OngoingTasksViewModel.PostOperationBanner( string.Empty, "ExtractingArchiveText".GetLocalized(), 0, ReturnResult.InProgress, FileOperationType.Extract, extractCancellation); BaseStorageFolder destinationFolder = decompressArchiveViewModel.DestinationFolder; string destinationFolderPath = decompressArchiveViewModel.DestinationFolderPath; if (destinationFolder == null) { BaseStorageFolder parentFolder = await StorageHelpers.ToStorageItem <BaseStorageFolder>(Path.GetDirectoryName(archive.Path)); destinationFolder = await FilesystemTasks.Wrap(() => parentFolder.CreateFolderAsync(Path.GetFileName(destinationFolderPath), CreationCollisionOption.GenerateUniqueName).AsTask()); } if (destinationFolder == null) { return; // Could not create dest folder } Stopwatch sw = new Stopwatch(); sw.Start(); await ZipHelpers.ExtractArchive(archive, destinationFolder, banner.Progress, extractCancellation.Token); sw.Stop(); banner.Remove(); if (sw.Elapsed.TotalSeconds >= 6) { App.OngoingTasksViewModel.PostBanner( "ExtractingCompleteText".GetLocalized(), "ArchiveExtractionCompletedSuccessfullyText".GetLocalized(), 0, ReturnResult.Success, FileOperationType.Extract); } if (decompressArchiveViewModel.OpenDestinationFolderOnCompletion) { await NavigationHelpers.OpenPath(destinationFolderPath, associatedInstance, FilesystemItemType.Directory); } } } }