Skip to content

Properties: Show progress when calculating MD5 hash #1082

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 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Files/Interacts/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,24 @@ public void PushJumpChar(char letter)
App.CurrentInstance.ViewModel.JumpString += letter.ToString().ToLower();
}

public async Task<string> GetHashForFile(ListedItem fileItem, string nameOfAlg, CancellationToken token)
public async Task<string> GetHashForFile(ListedItem fileItem, string nameOfAlg, CancellationToken token, ProgressBar progress)
{
HashAlgorithmProvider algorithmProvider = HashAlgorithmProvider.OpenAlgorithm(nameOfAlg);
var itemFromPath = await StorageFile.GetFileFromPathAsync(fileItem.ItemPath);
var stream = await itemFromPath.OpenStreamForReadAsync();
var inputStream = stream.AsInputStream();
uint capacity = 100000000;
var str = inputStream.AsStreamForRead();
var cap = (long)(0.5 * str.Length) / 100;
uint capacity;
if (cap >= uint.MaxValue)
{
capacity = uint.MaxValue;
}
else
{
capacity = Convert.ToUInt32(cap);
}

Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer(capacity);
var hash = algorithmProvider.CreateHash();
while (!token.IsCancellationRequested)
Expand All @@ -1134,6 +1145,8 @@ public async Task<string> GetHashForFile(ListedItem fileItem, string nameOfAlg,
{
break;
}

progress.Value = (double)str.Position / str.Length * 100;
}
inputStream.Dispose();
stream.Dispose();
Expand Down
1 change: 0 additions & 1 deletion Files/Views/Pages/Properties.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
Grid.Row="5"
Grid.Column="1"
Margin="20,0,0,0"
IsIndeterminate="True"
Visibility="{x:Bind ItemProperties.ItemMD5HashProgressVisibility, Mode=OneWay}" />

<MenuFlyoutSeparator
Expand Down
2 changes: 1 addition & 1 deletion Files/Views/Pages/Properties.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private async void Properties_Loaded(object sender, RoutedEventArgs e)
// Get file MD5 hash
var hashAlgTypeName = HashAlgorithmNames.Md5;
ItemProperties.ItemMD5HashProgressVisibility = Visibility.Visible;
ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName, _tokenSource.Token);
ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName, _tokenSource.Token, ItemMD5HashProgress);
ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed;
ItemProperties.ItemMD5HashVisibility = Visibility.Visible;
}
Expand Down