Skip to content

Feature: Display uncompressed size when viewing properties for archives #9782

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 4 commits into from
Aug 21, 2022
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
20 changes: 20 additions & 0 deletions src/Files.Uwp/Filesystem/StorageItems/ZipStorageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ public static bool IsZipPath(string path, bool includeRoot = true)
return (marker == path.Length && includeRoot) || (marker < path.Length && path[marker] is '\\');
}

public async Task<long> GetUncompressedSize()
{
long uncompressedSize = 0;
using (SevenZipExtractor zipFile = await FilesystemTasks.Wrap(async () =>
{
var arch = await OpenZipFileAsync();
return arch?.ArchiveFileData is null ? null : arch; // Force load archive (1665013614u)
}))

if (zipFile != null)
{
foreach (var info in zipFile.ArchiveFileData.Where(x => !x.IsDirectory))
{
uncompressedSize += (long)info.Size;
}
}

return uncompressedSize;
}

private static ConcurrentDictionary<string, Task<bool>> defaultAppDict = new();
public static async Task<bool> CheckDefaultZipApp(string filePath)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Files.Uwp/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<data name="PropertiesItemSize.Text" xml:space="preserve">
<value>Size:</value>
</data>
<data name="UncompressedSize" xml:space="preserve">
<value>Uncompressed Size:</value>
</data>
<data name="ErrorDialogThisActionCannotBeDone" xml:space="preserve">
<value>This action cannot be done</value>
</data>
Expand Down
14 changes: 13 additions & 1 deletion src/Files.Uwp/ViewModels/Properties/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public override async void GetSpecialProperties()
}
}

BaseStorageFile file = await AppInstance.FilesystemViewModel.GetFileFromPathAsync((Item as ShortcutItem)?.TargetPath ?? Item.ItemPath);
string filePath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
BaseStorageFile file = await AppInstance.FilesystemViewModel.GetFileFromPathAsync(filePath);

if (file == null)
{
// Could not access file, can't show any other property
Expand All @@ -141,6 +143,16 @@ public override async void GetSpecialProperties()
return;
}

if (FileExtensionHelpers.IsBrowsableZipFile(Item.FileExtension, out _))
{
if (await ZipStorageFolder.FromPathAsync(Item.ItemPath) is ZipStorageFolder zipFolder)
{
var uncompressedSize = await zipFolder.GetUncompressedSize();
ViewModel.UncompressedItemSize = uncompressedSize.ToLongSizeString();
ViewModel.UncompressedItemSizeBytes = uncompressedSize;
}
}

if (file.Properties != null)
{
GetOtherProperties(file.Properties);
Expand Down
12 changes: 1 addition & 11 deletions src/Files.Uwp/ViewModels/Properties/FolderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,7 @@ public async override void GetSpecialProperties()
}

string folderPath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
BaseStorageFolder storageFolder;
try
{
storageFolder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(folderPath);
}
catch (Exception ex)
{
App.Logger.Warn(ex, ex.Message);
// Could not access folder, can't show any other property
return;
}
BaseStorageFolder storageFolder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(folderPath);

if (storageFolder != null)
{
Expand Down
28 changes: 28 additions & 0 deletions src/Files.Uwp/ViewModels/SelectedItemsPropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ public string ItemSize
set => SetProperty(ref itemSize, value);
}

private string uncompresseditemSize;

public string UncompressedItemSize
{
get => uncompresseditemSize;
set
{
IsUncompressedItemSizeVisibile = true;
SetProperty(ref uncompresseditemSize, value);
}
}

private bool itemSizeVisibility = false;

public bool ItemSizeVisibility
Expand All @@ -176,6 +188,14 @@ public bool ItemSizeVisibility
set => SetProperty(ref itemSizeVisibility, value);
}

private bool isUncompressedItemSizeVisibile = false;

public bool IsUncompressedItemSizeVisibile
{
get => isUncompressedItemSizeVisibile;
set => SetProperty(ref isUncompressedItemSizeVisibile, value);
}

private long itemSizeBytes;

public long ItemSizeBytes
Expand All @@ -184,6 +204,14 @@ public long ItemSizeBytes
set => SetProperty(ref itemSizeBytes, value);
}

private long uncompresseditemSizeBytes;

public long UncompressedItemSizeBytes
{
get => uncompresseditemSizeBytes;
set => SetProperty(ref uncompresseditemSizeBytes, value);
}

private bool itemSizeProgressVisibility = false;

public bool ItemSizeProgressVisibility
Expand Down
44 changes: 31 additions & 13 deletions src/Files.Uwp/Views/Pages/PropertiesGeneral.xaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<local:PropertiesTab
x:Class="Files.Uwp.Views.PropertiesGeneral"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.Uwp.Helpers"
xmlns:usercontrols="using:Files.Uwp.UserControls"
xmlns:local="using:Files.Uwp.ViewModels.Properties"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:usercontrols="using:Files.Uwp.UserControls"
Loaded="Properties_Loaded"
mc:Ignorable="d">

Expand Down Expand Up @@ -81,8 +81,8 @@
<TextBox
x:Name="ItemFileName"
x:Load="{x:Bind ViewModel.ItemNameVisibility, Mode=OneWay}"
Text="{x:Bind ViewModel.ItemName, Mode=TwoWay}"
PlaceholderText="{helpers:ResourceString Name=PropertiesItemFileName/PlaceholderText}" />
PlaceholderText="{helpers:ResourceString Name=PropertiesItemFileName/PlaceholderText}"
Text="{x:Bind ViewModel.ItemName, Mode=TwoWay}" />
<TextBlock
x:Name="itemFilesAndFoldersCountValueTop"
x:Load="{x:Bind ViewModel.FilesAndFoldersCountVisibility, Mode=OneWay}"
Expand Down Expand Up @@ -151,6 +151,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Item path -->
<TextBlock
Expand Down Expand Up @@ -199,53 +200,70 @@
Visibility="{x:Bind ViewModel.ItemSizeProgressVisibility, Mode=OneWay}" />
</Grid>

<MenuFlyoutSeparator
<!-- Uncompressed Item size -->
<TextBlock
Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Left"
Style="{StaticResource PropertyName}"
Text="{helpers:ResourceString Name=UncompressedSize}"
Visibility="{x:Bind ViewModel.IsUncompressedItemSizeVisibile, Mode=OneWay}" />
<TextBlock
x:Name="UncompresseditemSizeValue"
Grid.Row="2"
Grid.Column="1"
IsTextSelectionEnabled="True"
Style="{StaticResource PropertyValueTextBlock}"
Text="{x:Bind ViewModel.UncompressedItemSize, Mode=OneWay}"
Visibility="{x:Bind ViewModel.IsUncompressedItemSizeVisibile, Mode=OneWay}" />

<MenuFlyoutSeparator
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="-12,0"
Background="{ThemeResource CardStrokeColorDefaultBrush}" />

<!-- Date created -->
<TextBlock
Grid.Row="3"
Grid.Row="4"
Grid.Column="0"
Style="{StaticResource PropertyName}"
Text="{helpers:ResourceString Name=PropertiesCreated/Text}"
Visibility="{x:Bind ViewModel.ItemCreatedTimestampVisibiity, Mode=OneWay}" />
<TextBlock
x:Name="itemCreatedTimestampValue"
Grid.Row="3"
Grid.Row="4"
Grid.Column="1"
Style="{StaticResource PropertyValueTextBlock}"
Text="{x:Bind ViewModel.ItemCreatedTimestamp, Mode=OneWay}"
Visibility="{x:Bind ViewModel.ItemCreatedTimestampVisibiity, Mode=OneWay}" />

<!-- Date modified -->
<TextBlock
Grid.Row="4"
Grid.Row="5"
Grid.Column="0"
Style="{StaticResource PropertyName}"
Text="{helpers:ResourceString Name=PropertiesModified/Text}"
Visibility="{x:Bind ViewModel.ItemModifiedTimestampVisibility, Mode=OneWay}" />
<TextBlock
x:Name="itemModifiedTimestampValue"
Grid.Row="4"
Grid.Row="5"
Grid.Column="1"
Style="{StaticResource PropertyValueTextBlock}"
Text="{x:Bind ViewModel.ItemModifiedTimestamp, Mode=OneWay}"
Visibility="{x:Bind ViewModel.ItemModifiedTimestampVisibility, Mode=OneWay}" />

<!-- Date accessed -->
<TextBlock
Grid.Row="5"
Grid.Row="6"
Grid.Column="0"
Style="{StaticResource PropertyName}"
Text="{helpers:ResourceString Name=Accessed}"
Visibility="{x:Bind ViewModel.ItemAccessedTimestampVisibility, Mode=OneWay}" />
<TextBlock
x:Name="itemAccessedTimestampValue"
Grid.Row="5"
Grid.Row="6"
Grid.Column="1"
Style="{StaticResource PropertyValueTextBlock}"
Text="{x:Bind ViewModel.ItemAccessedTimestamp, Mode=OneWay}"
Expand Down