-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Added a dialog for extracting archives #5175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
8b50bdb
Initial archive extracting
d2dyno1 c3bd7ee
Added ZipHelpers
d2dyno1 249421a
Improve zip helpers
d2dyno1 a774f45
tmp rm
d2dyno1 20c6ec5
Improve decompressing operation
d2dyno1 d7e59b8
Small performance improvement
d2dyno1 a7b6e10
Added status banner
d2dyno1 f6288aa
Blazingly fast performance
d2dyno1 74a3b18
Improve extraction UI
d2dyno1 e3bc657
Remove status banner when completed
d2dyno1 8260f83
Added the option to cancel extracting operation
d2dyno1 9de0459
Merge branch 'main' into cmprs
d2dyno1 6a7f07a
Added glyph icon to context menu item
d2dyno1 0d11206
Improved dialog's design
d2dyno1 50d981d
Added check to open destination directory upon extraction
d2dyno1 3453949
Fix codestyle
d2dyno1 54e973b
Do everything in uwp & code simplify
gave92 91bb2ff
Use WindowsNameTransform to get item name
gave92 6be2919
Fix folder tree creation
gave92 0f8d5bf
Added strings
d2dyno1 f9ec75e
Merge branch 'main' into cmprs
d2dyno1 cc2052c
Added strings and more context menu options
d2dyno1 754ac3f
Fix conflicts
d2dyno1 2e89cb5
Some string changes
d2dyno1 59b27b9
Hide extract shell option & show extract for msix
gave92 a3f9c3b
Fix crash when destination folder already exists
gave92 9eaf45d
Merge branch 'cmprs' of https://github.com/d2dyno1/Files into rev_cmprs
gave92 ef731b6
Lower case extension checking
d2dyno1 f0a49ad
Fix nullreferenceexception when clicking on a folder
d2dyno1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<ContentDialog | ||
x:Class="Files.Dialogs.DecompressArchiveDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:helpers="using:Files.Helpers" | ||
xmlns:local="using:Files.Dialogs" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
Title="Select a destination and extract files" | ||
CornerRadius="{StaticResource OverlayCornerRadius}" | ||
DefaultButton="Primary" | ||
PrimaryButtonText="Extract" | ||
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}" | ||
SecondaryButtonText="Cancel" | ||
Style="{StaticResource DefaultContentDialogStyle}" | ||
mc:Ignorable="d"> | ||
|
||
<Grid | ||
MinWidth="400" | ||
Margin="0,16,0,0" | ||
ColumnSpacing="6" | ||
RowSpacing="3"> | ||
d2dyno1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
d2dyno1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<TextBox | ||
HorizontalAlignment="Stretch" | ||
VerticalAlignment="Center" | ||
IsReadOnly="True" | ||
Text="{x:Bind ViewModel.DestinationFolderPath, Mode=OneWay}" /> | ||
d2dyno1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<Button | ||
Grid.Column="1" | ||
VerticalAlignment="Center" | ||
Background="Transparent" | ||
Command="{x:Bind ViewModel.SelectDestinationCommand}" | ||
Content="Browse" /> | ||
d2dyno1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<CheckBox | ||
Grid.Row="1" | ||
Content="Open destination folder when complete" | ||
IsChecked="{x:Bind ViewModel.OpenDestinationFolderOnCompletion, Mode=TwoWay}" /> | ||
d2dyno1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Grid> | ||
</ContentDialog> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Files.ViewModels.Dialogs; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace Files.Dialogs | ||
{ | ||
public sealed partial class DecompressArchiveDialog : ContentDialog | ||
{ | ||
public DecompressArchiveDialogViewModel ViewModel | ||
{ | ||
get => (DecompressArchiveDialogViewModel)DataContext; | ||
set => DataContext = value; | ||
} | ||
|
||
public DecompressArchiveDialog() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using ICSharpCode.SharpZipLib.Zip; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Windows.Foundation.Collections; | ||
using Windows.Storage; | ||
|
||
namespace Files.Helpers | ||
{ | ||
public static class ZipHelpers | ||
{ | ||
public static async Task ExtractArchive(StorageFile archive, StorageFolder destinationFolder, IProgress<float> progressDelegate, CancellationToken cancellationToken) | ||
{ | ||
using (ZipFile zipFile = new ZipFile(await archive.OpenStreamForReadAsync())) | ||
{ | ||
zipFile.IsStreamOwner = true; | ||
|
||
List<ZipEntry> directoryEntries = new List<ZipEntry>(); | ||
List<ZipEntry> fileEntries = new List<ZipEntry>(); | ||
|
||
foreach (ZipEntry entry in zipFile) | ||
{ | ||
if (entry.IsFile) | ||
{ | ||
fileEntries.Add(entry); | ||
} | ||
else | ||
{ | ||
directoryEntries.Add(entry); | ||
} | ||
} | ||
|
||
if (cancellationToken.IsCancellationRequested) // Check if cancelled | ||
{ | ||
return; | ||
} | ||
|
||
var directories = new List<string>(); | ||
directories.AddRange(directoryEntries.Select((item) => Path.Combine(destinationFolder.Path, item.Name))); | ||
directories.AddRange(fileEntries.Select((item) => Path.Combine(destinationFolder.Path, Path.GetDirectoryName(item.Name)))); | ||
foreach (var dir in directories.Distinct().OrderBy(x => x.Length)) | ||
{ | ||
NativeFileOperationsHelper.CreateDirectoryFromApp(dir, IntPtr.Zero); | ||
} | ||
|
||
if (cancellationToken.IsCancellationRequested) // Check if cancelled | ||
{ | ||
return; | ||
} | ||
|
||
// Fill files | ||
|
||
byte[] buffer = new byte[4096]; | ||
int entriesAmount = fileEntries.Count; | ||
int entriesFinished = 0; | ||
|
||
foreach (var entry in fileEntries) | ||
{ | ||
if (cancellationToken.IsCancellationRequested) // Check if cancelled | ||
{ | ||
return; | ||
} | ||
|
||
string filePath = Path.Combine(destinationFolder.Path, entry.Name.Replace('/', '\\')); | ||
|
||
var hFile = NativeFileOperationsHelper.CreateFileForWrite(filePath); | ||
|
||
using (FileStream destinationStream = new FileStream(hFile, FileAccess.ReadWrite)) | ||
{ | ||
int currentBlockSize = 0; | ||
|
||
using (Stream entryStream = zipFile.GetInputStream(entry)) | ||
{ | ||
while ((currentBlockSize = await entryStream.ReadAsync(buffer, 0, buffer.Length)) > 0) | ||
{ | ||
await destinationStream.WriteAsync(buffer, 0, buffer.Length); | ||
|
||
if (cancellationToken.IsCancellationRequested) // Check if cancelled | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
// We don't close handleContext because FileStream.Dispose() already does that | ||
|
||
entriesFinished++; | ||
float percentage = (float)((float)entriesFinished / (float)entriesAmount) * 100.0f; | ||
progressDelegate?.Report(percentage); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.