Skip to content

Commit f6db0c6

Browse files
authored
Feature: Display uncompressed size when viewing properties for archives (#9782)
1 parent 3cf5671 commit f6db0c6

File tree

6 files changed

+96
-25
lines changed

6 files changed

+96
-25
lines changed

src/Files.Uwp/Filesystem/StorageItems/ZipStorageFolder.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ public static bool IsZipPath(string path, bool includeRoot = true)
7373
return (marker == path.Length && includeRoot) || (marker < path.Length && path[marker] is '\\');
7474
}
7575

76+
public async Task<long> GetUncompressedSize()
77+
{
78+
long uncompressedSize = 0;
79+
using (SevenZipExtractor zipFile = await FilesystemTasks.Wrap(async () =>
80+
{
81+
var arch = await OpenZipFileAsync();
82+
return arch?.ArchiveFileData is null ? null : arch; // Force load archive (1665013614u)
83+
}))
84+
85+
if (zipFile != null)
86+
{
87+
foreach (var info in zipFile.ArchiveFileData.Where(x => !x.IsDirectory))
88+
{
89+
uncompressedSize += (long)info.Size;
90+
}
91+
}
92+
93+
return uncompressedSize;
94+
}
95+
7696
private static ConcurrentDictionary<string, Task<bool>> defaultAppDict = new();
7797
public static async Task<bool> CheckDefaultZipApp(string filePath)
7898
{

src/Files.Uwp/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@
165165
<data name="PropertiesItemSize.Text" xml:space="preserve">
166166
<value>Size:</value>
167167
</data>
168+
<data name="UncompressedSize" xml:space="preserve">
169+
<value>Uncompressed Size:</value>
170+
</data>
168171
<data name="ErrorDialogThisActionCannotBeDone" xml:space="preserve">
169172
<value>This action cannot be done</value>
170173
</data>

src/Files.Uwp/ViewModels/Properties/FileProperties.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public override async void GetSpecialProperties()
128128
}
129129
}
130130

131-
BaseStorageFile file = await AppInstance.FilesystemViewModel.GetFileFromPathAsync((Item as ShortcutItem)?.TargetPath ?? Item.ItemPath);
131+
string filePath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
132+
BaseStorageFile file = await AppInstance.FilesystemViewModel.GetFileFromPathAsync(filePath);
133+
132134
if (file == null)
133135
{
134136
// Could not access file, can't show any other property
@@ -141,6 +143,16 @@ public override async void GetSpecialProperties()
141143
return;
142144
}
143145

146+
if (FileExtensionHelpers.IsBrowsableZipFile(Item.FileExtension, out _))
147+
{
148+
if (await ZipStorageFolder.FromPathAsync(Item.ItemPath) is ZipStorageFolder zipFolder)
149+
{
150+
var uncompressedSize = await zipFolder.GetUncompressedSize();
151+
ViewModel.UncompressedItemSize = uncompressedSize.ToLongSizeString();
152+
ViewModel.UncompressedItemSizeBytes = uncompressedSize;
153+
}
154+
}
155+
144156
if (file.Properties != null)
145157
{
146158
GetOtherProperties(file.Properties);

src/Files.Uwp/ViewModels/Properties/FolderProperties.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,7 @@ public async override void GetSpecialProperties()
9797
}
9898

9999
string folderPath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
100-
BaseStorageFolder storageFolder;
101-
try
102-
{
103-
storageFolder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(folderPath);
104-
}
105-
catch (Exception ex)
106-
{
107-
App.Logger.Warn(ex, ex.Message);
108-
// Could not access folder, can't show any other property
109-
return;
110-
}
100+
BaseStorageFolder storageFolder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(folderPath);
111101

112102
if (storageFolder != null)
113103
{

src/Files.Uwp/ViewModels/SelectedItemsPropertiesViewModel.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ public string ItemSize
168168
set => SetProperty(ref itemSize, value);
169169
}
170170

171+
private string uncompresseditemSize;
172+
173+
public string UncompressedItemSize
174+
{
175+
get => uncompresseditemSize;
176+
set
177+
{
178+
IsUncompressedItemSizeVisibile = true;
179+
SetProperty(ref uncompresseditemSize, value);
180+
}
181+
}
182+
171183
private bool itemSizeVisibility = false;
172184

173185
public bool ItemSizeVisibility
@@ -176,6 +188,14 @@ public bool ItemSizeVisibility
176188
set => SetProperty(ref itemSizeVisibility, value);
177189
}
178190

191+
private bool isUncompressedItemSizeVisibile = false;
192+
193+
public bool IsUncompressedItemSizeVisibile
194+
{
195+
get => isUncompressedItemSizeVisibile;
196+
set => SetProperty(ref isUncompressedItemSizeVisibile, value);
197+
}
198+
179199
private long itemSizeBytes;
180200

181201
public long ItemSizeBytes
@@ -184,6 +204,14 @@ public long ItemSizeBytes
184204
set => SetProperty(ref itemSizeBytes, value);
185205
}
186206

207+
private long uncompresseditemSizeBytes;
208+
209+
public long UncompressedItemSizeBytes
210+
{
211+
get => uncompresseditemSizeBytes;
212+
set => SetProperty(ref uncompresseditemSizeBytes, value);
213+
}
214+
187215
private bool itemSizeProgressVisibility = false;
188216

189217
public bool ItemSizeProgressVisibility

src/Files.Uwp/Views/Pages/PropertiesGeneral.xaml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<local:PropertiesTab
22
x:Class="Files.Uwp.Views.PropertiesGeneral"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
54
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:helpers="using:Files.Uwp.Helpers"
8-
xmlns:usercontrols="using:Files.Uwp.UserControls"
98
xmlns:local="using:Files.Uwp.ViewModels.Properties"
10-
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1110
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
11+
xmlns:usercontrols="using:Files.Uwp.UserControls"
1212
Loaded="Properties_Loaded"
1313
mc:Ignorable="d">
1414

@@ -81,8 +81,8 @@
8181
<TextBox
8282
x:Name="ItemFileName"
8383
x:Load="{x:Bind ViewModel.ItemNameVisibility, Mode=OneWay}"
84-
Text="{x:Bind ViewModel.ItemName, Mode=TwoWay}"
85-
PlaceholderText="{helpers:ResourceString Name=PropertiesItemFileName/PlaceholderText}" />
84+
PlaceholderText="{helpers:ResourceString Name=PropertiesItemFileName/PlaceholderText}"
85+
Text="{x:Bind ViewModel.ItemName, Mode=TwoWay}" />
8686
<TextBlock
8787
x:Name="itemFilesAndFoldersCountValueTop"
8888
x:Load="{x:Bind ViewModel.FilesAndFoldersCountVisibility, Mode=OneWay}"
@@ -151,6 +151,7 @@
151151
<RowDefinition Height="Auto" />
152152
<RowDefinition Height="Auto" />
153153
<RowDefinition Height="Auto" />
154+
<RowDefinition Height="Auto" />
154155
</Grid.RowDefinitions>
155156
<!-- Item path -->
156157
<TextBlock
@@ -199,53 +200,70 @@
199200
Visibility="{x:Bind ViewModel.ItemSizeProgressVisibility, Mode=OneWay}" />
200201
</Grid>
201202

202-
<MenuFlyoutSeparator
203+
<!-- Uncompressed Item size -->
204+
<TextBlock
203205
Grid.Row="2"
204206
Grid.Column="0"
207+
HorizontalAlignment="Left"
208+
Style="{StaticResource PropertyName}"
209+
Text="{helpers:ResourceString Name=UncompressedSize}"
210+
Visibility="{x:Bind ViewModel.IsUncompressedItemSizeVisibile, Mode=OneWay}" />
211+
<TextBlock
212+
x:Name="UncompresseditemSizeValue"
213+
Grid.Row="2"
214+
Grid.Column="1"
215+
IsTextSelectionEnabled="True"
216+
Style="{StaticResource PropertyValueTextBlock}"
217+
Text="{x:Bind ViewModel.UncompressedItemSize, Mode=OneWay}"
218+
Visibility="{x:Bind ViewModel.IsUncompressedItemSizeVisibile, Mode=OneWay}" />
219+
220+
<MenuFlyoutSeparator
221+
Grid.Row="3"
222+
Grid.Column="0"
205223
Grid.ColumnSpan="2"
206224
Margin="-12,0"
207225
Background="{ThemeResource CardStrokeColorDefaultBrush}" />
208226

209227
<!-- Date created -->
210228
<TextBlock
211-
Grid.Row="3"
229+
Grid.Row="4"
212230
Grid.Column="0"
213231
Style="{StaticResource PropertyName}"
214232
Text="{helpers:ResourceString Name=PropertiesCreated/Text}"
215233
Visibility="{x:Bind ViewModel.ItemCreatedTimestampVisibiity, Mode=OneWay}" />
216234
<TextBlock
217235
x:Name="itemCreatedTimestampValue"
218-
Grid.Row="3"
236+
Grid.Row="4"
219237
Grid.Column="1"
220238
Style="{StaticResource PropertyValueTextBlock}"
221239
Text="{x:Bind ViewModel.ItemCreatedTimestamp, Mode=OneWay}"
222240
Visibility="{x:Bind ViewModel.ItemCreatedTimestampVisibiity, Mode=OneWay}" />
223241

224242
<!-- Date modified -->
225243
<TextBlock
226-
Grid.Row="4"
244+
Grid.Row="5"
227245
Grid.Column="0"
228246
Style="{StaticResource PropertyName}"
229247
Text="{helpers:ResourceString Name=PropertiesModified/Text}"
230248
Visibility="{x:Bind ViewModel.ItemModifiedTimestampVisibility, Mode=OneWay}" />
231249
<TextBlock
232250
x:Name="itemModifiedTimestampValue"
233-
Grid.Row="4"
251+
Grid.Row="5"
234252
Grid.Column="1"
235253
Style="{StaticResource PropertyValueTextBlock}"
236254
Text="{x:Bind ViewModel.ItemModifiedTimestamp, Mode=OneWay}"
237255
Visibility="{x:Bind ViewModel.ItemModifiedTimestampVisibility, Mode=OneWay}" />
238256

239257
<!-- Date accessed -->
240258
<TextBlock
241-
Grid.Row="5"
259+
Grid.Row="6"
242260
Grid.Column="0"
243261
Style="{StaticResource PropertyName}"
244262
Text="{helpers:ResourceString Name=Accessed}"
245263
Visibility="{x:Bind ViewModel.ItemAccessedTimestampVisibility, Mode=OneWay}" />
246264
<TextBlock
247265
x:Name="itemAccessedTimestampValue"
248-
Grid.Row="5"
266+
Grid.Row="6"
249267
Grid.Column="1"
250268
Style="{StaticResource PropertyValueTextBlock}"
251269
Text="{x:Bind ViewModel.ItemAccessedTimestamp, Mode=OneWay}"

0 commit comments

Comments
 (0)