Skip to content

Commit b66d535

Browse files
authored
Feature: Added discovering phase to the Status Center (#17697)
1 parent 7bd2dde commit b66d535

File tree

6 files changed

+90
-14
lines changed

6 files changed

+90
-14
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,6 +3487,9 @@
34873487
<data name="ProcessingItems" xml:space="preserve">
34883488
<value>Processing items...</value>
34893489
</data>
3490+
<data name="DiscoveringItems" xml:space="preserve">
3491+
<value>Discovery in progress...</value>
3492+
</data>
34903493
<data name="SpeedWithColon" xml:space="preserve">
34913494
<value>Speed:</value>
34923495
</data>
@@ -3618,6 +3621,10 @@
36183621
<value>Copying {0, plural, one {# item} other {# items}} from "{1}" to "{2}"</value>
36193622
<comment>Shown in a StatusCenter card.</comment>
36203623
</data>
3624+
<data name="StatusCenter_CopyDiscovery_Header" xml:space="preserve">
3625+
<value>Discovered {0, plural, one {# item} other {# items}}</value>
3626+
<comment>Shown in a StatusCenter card during file discovery phase.</comment>
3627+
</data>
36213628
<data name="StatusCenter_DecompressCanceled_Header" xml:space="preserve">
36223629
<value>Canceled extracting "{0}" to "{1}"</value>
36233630
<comment>Shown in a StatusCenter card.</comment>
@@ -3670,6 +3677,10 @@
36703677
<value>Deleting {0, plural, one {# item} other {# items}} from "{1}"</value>
36713678
<comment>Shown in a StatusCenter card.</comment>
36723679
</data>
3680+
<data name="StatusCenter_DeleteDiscovery_Header" xml:space="preserve">
3681+
<value>Discovered {0, plural, one {# item} other {# items}}</value>
3682+
<comment>Shown in a StatusCenter card during file discovery phase.</comment>
3683+
</data>
36733684
<data name="StatusCenter_MoveCanceled_Header" xml:space="preserve">
36743685
<value>Canceled moving {0, plural, one {# item} other {# items}} to "{1}"</value>
36753686
<comment>Shown in a StatusCenter card.</comment>
@@ -3694,6 +3705,10 @@
36943705
<value>Moving {0, plural, one {# item} other {# items}} from "{1}" to "{2}"</value>
36953706
<comment>Shown in a StatusCenter card.</comment>
36963707
</data>
3708+
<data name="StatusCenter_MoveDiscovery_Header" xml:space="preserve">
3709+
<value>Discovered {0, plural, one {# item} other {# items}}</value>
3710+
<comment>Shown in a StatusCenter card during file discovery phase.</comment>
3711+
</data>
36973712
<data name="StatusCenter_MoveFailed_Header" xml:space="preserve">
36983713
<value>Error moving {0, plural, one {# item} other {# items}} to "{1}"</value>
36993714
<comment>Shown in a StatusCenter card.</comment>

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public static StatusCenterItem AddCard_Prepare()
611611
false);
612612
}
613613

614-
public static void UpdateCardStrings(StatusCenterItem card)
614+
public static void UpdateCardStrings(StatusCenterItem card, StatusCenterItemProgressModel? progressValue = null)
615615
{
616616
// Aren't used for now
617617
string sourcePath = string.Empty;
@@ -645,9 +645,17 @@ public static void UpdateCardStrings(StatusCenterItem card)
645645
{
646646
case FileOperationType.Copy:
647647
{
648-
string headerString = string.IsNullOrWhiteSpace(card.HeaderStringResource) ? string.Empty
649-
: card.HeaderStringResource.GetLocalizedFormatResource(card.TotalItemsCount, destinationDirName);
650-
card.Header = headerString;
648+
string headerResource = card.HeaderStringResource;
649+
650+
if (card.IsDiscovering && card.TotalItemsCount > 0 && card.IsInProgress)
651+
headerResource = "StatusCenter_CopyDiscovery_Header";
652+
653+
if (string.IsNullOrWhiteSpace(headerResource))
654+
card.Header = string.Empty;
655+
else if (headerResource == "StatusCenter_CopyDiscovery_Header")
656+
card.Header = headerResource.GetLocalizedFormatResource(card.TotalItemsCount);
657+
else
658+
card.Header = headerResource.GetLocalizedFormatResource(card.TotalItemsCount, destinationDirName);
651659

652660
string subHeaderString = string.IsNullOrWhiteSpace(card.SubHeaderStringResource) ? string.Empty
653661
: card.SubHeaderStringResource.GetLocalizedFormatResource(card.TotalItemsCount, sourcePath, destinationPath);
@@ -656,9 +664,17 @@ public static void UpdateCardStrings(StatusCenterItem card)
656664
}
657665
case FileOperationType.Move:
658666
{
659-
string headerString = string.IsNullOrWhiteSpace(card.HeaderStringResource) ? string.Empty
660-
: card.HeaderStringResource.GetLocalizedFormatResource(card.TotalItemsCount, destinationDirName);
661-
card.Header = headerString;
667+
string headerResource = card.HeaderStringResource;
668+
669+
if (card.IsDiscovering && card.TotalItemsCount > 0 && card.IsInProgress)
670+
headerResource = "StatusCenter_MoveDiscovery_Header";
671+
672+
if (string.IsNullOrWhiteSpace(headerResource))
673+
card.Header = string.Empty;
674+
else if (headerResource == "StatusCenter_MoveDiscovery_Header")
675+
card.Header = headerResource.GetLocalizedFormatResource(card.TotalItemsCount);
676+
else
677+
card.Header = headerResource.GetLocalizedFormatResource(card.TotalItemsCount, destinationDirName);
662678

663679
string subHeaderString = string.IsNullOrWhiteSpace(card.SubHeaderStringResource) ? string.Empty
664680
: card.SubHeaderStringResource.GetLocalizedFormatResource(card.TotalItemsCount, sourcePath, destinationPath);
@@ -667,9 +683,17 @@ public static void UpdateCardStrings(StatusCenterItem card)
667683
}
668684
case FileOperationType.Delete:
669685
{
670-
string headerString = string.IsNullOrWhiteSpace(card.HeaderStringResource) ? string.Empty
671-
: card.HeaderStringResource.GetLocalizedFormatResource(card.TotalItemsCount, sourceDirName);
672-
card.Header = headerString;
686+
string headerResource = card.HeaderStringResource;
687+
688+
if (card.IsDiscovering && card.TotalItemsCount > 0 && card.IsInProgress)
689+
headerResource = "StatusCenter_DeleteDiscovery_Header";
690+
691+
if (string.IsNullOrWhiteSpace(headerResource))
692+
card.Header = string.Empty;
693+
else if (headerResource == "StatusCenter_DeleteDiscovery_Header")
694+
card.Header = headerResource.GetLocalizedFormatResource(card.TotalItemsCount);
695+
else
696+
card.Header = headerResource.GetLocalizedFormatResource(card.TotalItemsCount, sourceDirName);
673697

674698
string subHeaderString = string.IsNullOrWhiteSpace(card.SubHeaderStringResource) ? string.Empty
675699
: card.SubHeaderStringResource.GetLocalizedFormatResource(card.TotalItemsCount, sourcePath);

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public StatusCenterItemProgressModel Progress
147147

148148
public bool IsInProgress { get; private set; }
149149

150+
public bool IsDiscovering { get; private set; } = true;
151+
150152
public IEnumerable<string>? Source { get; private set; }
151153

152154
public IEnumerable<string>? Destination { get; private set; }
@@ -199,7 +201,7 @@ public StatusCenterItem(
199201
AnimatedIconState = "NormalOff";
200202
SpeedGraphValues = [];
201203
CancelCommand = new RelayCommand(ExecuteCancelCommand);
202-
Message = Strings.ProcessingItems.GetLocalizedResource();
204+
Message = Strings.DiscoveringItems.GetLocalizedResource();
203205
Source = source;
204206
Destination = destination;
205207

@@ -327,8 +329,14 @@ private void ReportProgress(StatusCenterItemProgressModel value)
327329
if (TotalSize < value.TotalSize)
328330
TotalSize = value.TotalSize;
329331

332+
if (value.EnumerationCompleted && IsDiscovering)
333+
{
334+
IsDiscovering = false;
335+
Message = Strings.ProcessingItems.GetLocalizedResource();
336+
}
337+
330338
// Update UI for strings
331-
StatusCenterHelper.UpdateCardStrings(this);
339+
StatusCenterHelper.UpdateCardStrings(this, value);
332340
OnPropertyChanged(nameof(HeaderTooltip));
333341

334342
// Graph item point
@@ -382,7 +390,7 @@ private void ReportProgress(StatusCenterItemProgressModel value)
382390
SpeedGraphValues?.Add(point);
383391

384392
// Add percentage to the header
385-
if (!IsIndeterminateProgress)
393+
if (!IsIndeterminateProgress && value.EnumerationCompleted)
386394
Header = $"{Header} ({ProgressPercentage}%)";
387395

388396
// Update UI of the address bar

src/Files.App/Utils/Storage/Operations/FileOperationsHelpers.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
207207

208208
var cts = new CancellationTokenSource();
209209
var sizeCalculator = new FileSizeCalculator(fileToDeletePath);
210+
211+
// Track the count and update the progress
212+
sizeCalculator.ItemsCountChanged += (newCount) =>
213+
{
214+
fsProgress.ItemsCount = newCount;
215+
fsProgress.Report();
216+
};
217+
210218
var sizeTask = sizeCalculator.ComputeSizeAsync(cts.Token);
211219
sizeTask.ContinueWith(_ =>
212220
{
@@ -405,6 +413,14 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
405413

406414
var cts = new CancellationTokenSource();
407415
var sizeCalculator = new FileSizeCalculator(fileToMovePath);
416+
417+
// Track the count and update the progress
418+
sizeCalculator.ItemsCountChanged += (newCount) =>
419+
{
420+
fsProgress.ItemsCount = newCount;
421+
fsProgress.Report();
422+
};
423+
408424
var sizeTask = sizeCalculator.ComputeSizeAsync(cts.Token);
409425
sizeTask.ContinueWith(_ =>
410426
{
@@ -533,6 +549,14 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
533549

534550
var cts = new CancellationTokenSource();
535551
var sizeCalculator = new FileSizeCalculator(fileToCopyPath);
552+
553+
// Track the count and update the progress
554+
sizeCalculator.ItemsCountChanged += (newCount) =>
555+
{
556+
fsProgress.ItemsCount = newCount;
557+
fsProgress.Report();
558+
};
559+
536560
var sizeTask = sizeCalculator.ComputeSizeAsync(cts.Token);
537561
sizeTask.ContinueWith(_ =>
538562
{

src/Files.App/Utils/Storage/Operations/FileSizeCalculator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ internal sealed class FileSizeCalculator
1818
public int ItemsCount => _computedFiles.Count;
1919
public bool Completed { get; private set; }
2020

21+
public event Action<int>? ItemsCountChanged;
22+
2123
public FileSizeCalculator(params string[] paths)
2224
{
2325
_paths = paths;
@@ -118,7 +120,10 @@ private long ComputeFileSize(string path)
118120
null);
119121

120122
if (!hFile.IsInvalid && PInvoke.GetFileSizeEx(hFile, out size) && _computedFiles.TryAdd(path, size))
123+
{
121124
Interlocked.Add(ref _size, size);
125+
ItemsCountChanged?.Invoke(ItemsCount);
126+
}
122127

123128
return size;
124129
}

src/Files.App/Utils/Storage/Operations/ShellFilesystemOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<IStorageHistory> CopyItemsAsync(IList<IStorageItemWithPath> so
4949

5050
StatusCenterItemProgressModel fsProgress = new(
5151
progress,
52-
true,
52+
false,
5353
FileSystemStatusCode.InProgress,
5454
source.Count);
5555

0 commit comments

Comments
 (0)