Skip to content

Commit 1d7cee0

Browse files
authored
Fix: Improved the speed graph (#13629)
1 parent b6bbe52 commit 1d7cee0

File tree

5 files changed

+141
-97
lines changed

5 files changed

+141
-97
lines changed

src/Files.App/UserControls/StatusCenter.xaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
Text="{x:Bind Header, Mode=OneWay}"
141141
TextTrimming="CharacterEllipsis"
142142
TextWrapping="NoWrap"
143-
ToolTipService.ToolTip="{x:Bind Header, Mode=OneWay}" />
143+
ToolTipService.ToolTip="{x:Bind HeaderTooltip, Mode=OneWay}" />
144144

145145
</StackPanel>
146146

@@ -235,17 +235,30 @@
235235
CornerRadius="4"
236236
Visibility="{x:Bind IsExpanded, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
237237

238-
<!-- NOTE: The Graph Control Somehow Includes Slight Padding, Which Is Removed By Setting Negative Margin -->
239-
<Grid Margin="-2,0,0,-2">
238+
<Grid Padding="-2,-2,-2,-2">
239+
240+
<!-- Background Fill -->
240241
<livecharts2:CartesianChart
241-
x:Name="MainCartesianChart"
242+
x:Name="BackgroundCartesianChart"
242243
Height="72"
243244
VerticalAlignment="Bottom"
244245
AnimationsSpeed="00:00:00.001"
246+
Series="{x:Bind SpeedGraphBackgroundSeries, Mode=OneWay}"
247+
TooltipPosition="Hidden"
248+
XAxes="{x:Bind SpeedGraphBackgroundXAxes, Mode=OneWay}"
249+
YAxes="{x:Bind SpeedGraphBackgroundYAxes, Mode=OneWay}" />
250+
251+
<!-- Main Graph -->
252+
<livecharts2:CartesianChart
253+
x:Name="MainCartesianChart"
254+
Height="48"
255+
VerticalAlignment="Bottom"
256+
AnimationsSpeed="00:00:00.001"
245257
Series="{x:Bind SpeedGraphSeries, Mode=OneWay}"
246258
TooltipPosition="Hidden"
247259
XAxes="{x:Bind SpeedGraphXAxes, Mode=OneWay}"
248260
YAxes="{x:Bind SpeedGraphYAxes, Mode=OneWay}" />
261+
249262
</Grid>
250263

251264
<!-- Speed Text -->

src/Files.App/Utils/Archives/CompressHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public static async Task CompressArchiveAsync(ICompressArchiveModel creator)
9797
StatusCenterHelper.AddCard_Compress(
9898
creator.Sources,
9999
archivePath.CreateEnumerable(),
100-
ReturnResult.Failed,
100+
creator.CancellationToken.IsCancellationRequested
101+
? ReturnResult.Cancelled
102+
: ReturnResult.Failed,
101103
creator.Sources.Count());
102104
}
103105
}

src/Files.App/Utils/Archives/DecompressHelper.cs

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,15 @@ public static class DecompressHelper
1818

1919
private static IThreadingService _threadingService = Ioc.Default.GetRequiredService<IThreadingService>();
2020

21-
private static async Task<SevenZipExtractor?> GetZipFile(BaseStorageFile archive, string password = "")
22-
{
23-
return await FilesystemTasks.Wrap(async () =>
24-
{
25-
var arch = new SevenZipExtractor(await archive.OpenStreamForReadAsync(), password);
26-
return arch?.ArchiveFileData is null ? null : arch; // Force load archive (1665013614u)
27-
});
28-
}
29-
30-
public static async Task<bool> IsArchiveEncrypted(BaseStorageFile archive)
31-
{
32-
using SevenZipExtractor? zipFile = await GetZipFile(archive);
33-
if (zipFile is null)
34-
return true;
35-
36-
return zipFile.ArchiveFileData.Any(file => file.Encrypted || file.Method.Contains("Crypto") || file.Method.Contains("AES"));
37-
}
38-
39-
public static async Task ExtractArchiveAsync(BaseStorageFile archive, BaseStorageFolder destinationFolder, string password, IProgress<StatusCenterItemProgressModel> progress, CancellationToken cancellationToken)
21+
public static async Task<bool> DecompressArchiveAsync(BaseStorageFile archive, BaseStorageFolder destinationFolder, string password, IProgress<StatusCenterItemProgressModel> progress, CancellationToken cancellationToken)
4022
{
4123
using SevenZipExtractor? zipFile = await GetZipFile(archive, password);
4224
if (zipFile is null)
43-
return;
25+
return false;
4426

45-
if (cancellationToken.IsCancellationRequested) // Check if canceled
46-
return;
27+
// Check if the decompress operation canceled
28+
if (cancellationToken.IsCancellationRequested)
29+
return false;
4730

4831
// Fill files
4932

@@ -88,34 +71,55 @@ public static async Task ExtractArchiveAsync(BaseStorageFile archive, BaseStorag
8871

8972
try
9073
{
74+
// TODO: Get this method return result
9175
await zipFile.ExtractArchiveAsync(destinationFolder.Path);
9276
}
9377
catch (Exception ex)
9478
{
9579
App.Logger.LogWarning(ex, $"Error extracting file: {archive.Name}");
96-
return; // TODO: handle error
80+
81+
return false;
9782
}
83+
84+
return true;
9885
}
9986

100-
private static async Task ExtractArchiveAsync(BaseStorageFile archive, BaseStorageFolder? destinationFolder, string password)
87+
private static async Task DecompressArchiveAsync(BaseStorageFile archive, BaseStorageFolder? destinationFolder, string password)
10188
{
10289
if (archive is null || destinationFolder is null)
10390
return;
10491

105-
var banner = StatusCenterHelper.AddCard_Decompress(
92+
// Initialize a new in-progress status card
93+
var statusCard = StatusCenterHelper.AddCard_Decompress(
10694
archive.Path.CreateEnumerable(),
10795
destinationFolder.Path.CreateEnumerable(),
10896
ReturnResult.InProgress);
10997

110-
await FilesystemTasks.Wrap(() =>
111-
ExtractArchiveAsync(archive, destinationFolder, password, banner.ProgressEventSource, banner.CancellationToken));
98+
// Operate decompress
99+
var result = await FilesystemTasks.Wrap(() =>
100+
DecompressArchiveAsync(archive, destinationFolder, password, statusCard.ProgressEventSource, statusCard.CancellationToken));
112101

113-
_statusCenterViewModel.RemoveItem(banner);
102+
// Remove the in-progress status card
103+
_statusCenterViewModel.RemoveItem(statusCard);
114104

115-
StatusCenterHelper.AddCard_Decompress(
116-
archive.Path.CreateEnumerable(),
117-
destinationFolder.Path.CreateEnumerable(),
118-
ReturnResult.Success);
105+
if (result.Result)
106+
{
107+
// Successful
108+
StatusCenterHelper.AddCard_Decompress(
109+
archive.Path.CreateEnumerable(),
110+
destinationFolder.Path.CreateEnumerable(),
111+
ReturnResult.Success);
112+
}
113+
else
114+
{
115+
// Error
116+
StatusCenterHelper.AddCard_Decompress(
117+
archive.Path.CreateEnumerable(),
118+
destinationFolder.Path.CreateEnumerable(),
119+
statusCard.CancellationToken.IsCancellationRequested
120+
? ReturnResult.Cancelled
121+
: ReturnResult.Failed);
122+
}
119123
}
120124

121125
public static async Task DecompressArchiveAsync(IShellPage associatedInstance)
@@ -161,7 +165,7 @@ public static async Task DecompressArchiveAsync(IShellPage associatedInstance)
161165
destinationFolder = await FilesystemTasks.Wrap(() => parentFolder.CreateFolderAsync(Path.GetFileName(destinationFolderPath), CreationCollisionOption.GenerateUniqueName).AsTask());
162166
}
163167

164-
await ExtractArchiveAsync(archive, destinationFolder, password);
168+
await DecompressArchiveAsync(archive, destinationFolder, password);
165169

166170
if (decompressArchiveViewModel.OpenDestinationFolderOnCompletion)
167171
await NavigationHelpers.OpenPath(destinationFolderPath, associatedInstance, FilesystemItemType.Directory);
@@ -199,7 +203,7 @@ public static async Task DecompressArchiveHereAsync(IShellPage associatedInstanc
199203
password = Encoding.UTF8.GetString(decompressArchiveViewModel.Password);
200204
}
201205

202-
await ExtractArchiveAsync(archive, currentFolder, password);
206+
await DecompressArchiveAsync(archive, currentFolder, password);
203207
}
204208
}
205209

@@ -239,8 +243,26 @@ public static async Task DecompressArchiveToChildFolderAsync(IShellPage associat
239243
if (currentFolder is not null)
240244
destinationFolder = await FilesystemTasks.Wrap(() => currentFolder.CreateFolderAsync(Path.GetFileNameWithoutExtension(archive.Path), CreationCollisionOption.GenerateUniqueName).AsTask());
241245

242-
await ExtractArchiveAsync(archive, destinationFolder, password);
246+
await DecompressArchiveAsync(archive, destinationFolder, password);
243247
}
244248
}
249+
250+
private static async Task<SevenZipExtractor?> GetZipFile(BaseStorageFile archive, string password = "")
251+
{
252+
return await FilesystemTasks.Wrap(async () =>
253+
{
254+
var arch = new SevenZipExtractor(await archive.OpenStreamForReadAsync(), password);
255+
return arch?.ArchiveFileData is null ? null : arch; // Force load archive (1665013614u)
256+
});
257+
}
258+
259+
private static async Task<bool> IsArchiveEncrypted(BaseStorageFile archive)
260+
{
261+
using SevenZipExtractor? zipFile = await GetZipFile(archive);
262+
if (zipFile is null)
263+
return true;
264+
265+
return zipFile.ArchiveFileData.Any(file => file.Encrypted || file.Method.Contains("Crypto") || file.Method.Contains("AES"));
266+
}
245267
}
246268
}

src/Files.App/Utils/StatusCenter/StatusCenterHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public static void UpdateCardStrings(StatusCenterItem card)
512512
if (card.Destination is not null && card.Destination.Any())
513513
{
514514
destinationPath = PathNormalization.GetParentDir(card.Destination.First());
515-
destinationDirName = card.Destination.First().Split('\\').Last();
515+
destinationDirName = destinationPath.Split('\\').Last();
516516
}
517517

518518
string headerString = string.IsNullOrWhiteSpace(card.HeaderStringResource) ? string.Empty : card.HeaderStringResource.GetLocalizedResource();

0 commit comments

Comments
 (0)