Skip to content

Commit d9b6632

Browse files
Fix: Fixed issue where progress is shown in decimals (#11777)
1 parent eb53785 commit d9b6632

File tree

4 files changed

+41
-55
lines changed

4 files changed

+41
-55
lines changed

src/Files.App/Filesystem/FilesystemOperations/FileSystemProgress.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public bool EnumerationCompleted
4646
/// <summary>
4747
/// Only used when detailed count isn't available.
4848
/// </summary>
49-
public float? Percentage { get; set; }
49+
public int? Percentage { get; set; }
5050

5151
public FileSystemProgress(
5252
IProgress<FileSystemProgress>? progress,
@@ -65,11 +65,12 @@ public FileSystemProgress(
6565
TotalSize = totalSize;
6666
}
6767

68-
public void Report(float? percentage = null)
68+
public void Report(int? percentage = null)
6969
{
7070
Percentage = percentage;
71-
if (((EnumerationCompleted && ProcessedItemsCount == ItemsCount && ProcessedSize == TotalSize) ||
72-
(percentage is float f && MathF.Abs(f - 100f) <= float.Epsilon)) &&
71+
if (EnumerationCompleted &&
72+
ProcessedItemsCount == ItemsCount &&
73+
ProcessedSize == TotalSize &&
7374
status is FileSystemStatusCode.InProgress or null)
7475
{
7576
status = FileSystemStatusCode.Success;

src/Files.App/Helpers/RecycleBinHelpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static async Task EmptyRecycleBin()
7171
var banner = App.OngoingTasksViewModel.PostBanner(
7272
bannerTitle,
7373
"EmptyingRecycleBin".GetLocalizedResource(),
74-
0.0f,
74+
0,
7575
ReturnResult.InProgress,
7676
FileOperationType.Delete);
7777

@@ -81,14 +81,14 @@ public static async Task EmptyRecycleBin()
8181
App.OngoingTasksViewModel.PostBanner(
8282
bannerTitle,
8383
"BinEmptyingSucceded".GetLocalizedResource(),
84-
100.0f,
84+
100,
8585
ReturnResult.Success,
8686
FileOperationType.Delete);
8787
else
8888
App.OngoingTasksViewModel.PostBanner(
8989
bannerTitle,
9090
"BinEmptyingFailed".GetLocalizedResource(),
91-
100.0f,
91+
100,
9292
ReturnResult.Failed,
9393
FileOperationType.Delete);
9494
}

src/Files.App/Interacts/IStatusCenterActions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IOngoingTasksActions
99
{
1010
event EventHandler<PostedStatusBanner> ProgressBannerPosted;
1111

12-
float MedianOperationProgressValue { get; }
12+
int MedianOperationProgressValue { get; }
1313

1414
int OngoingOperationsCount { get; }
1515

@@ -27,7 +27,7 @@ public interface IOngoingTasksActions
2727
/// <param name="status"></param>
2828
/// <param name="operation"></param>
2929
/// <returns>A StatusBanner object which may be used to track/update the progress of an operation.</returns>
30-
PostedStatusBanner PostBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation);
30+
PostedStatusBanner PostBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation);
3131

3232
/// <summary>
3333
/// Posts a new banner with expanded height to the Status Center control. This is typically
@@ -51,7 +51,7 @@ public interface IOngoingTasksActions
5151
/// <param name="operation"></param>
5252
/// <param name="cancellationTokenSource"></param>
5353
/// <returns></returns>
54-
PostedStatusBanner PostOperationBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource);
54+
PostedStatusBanner PostOperationBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource);
5555

5656
/// <summary>
5757
/// Dismisses <paramref name="banner"/> and removes it from the collection

src/Files.App/ViewModels/StatusCenterViewModel.cs

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ namespace Files.App.ViewModels
1616
{
1717
public class OngoingTasksViewModel : ObservableObject, IOngoingTasksActions
1818
{
19-
#region Public Properties
19+
// Public Properties
2020

2121
public ObservableCollection<StatusBanner> StatusBannersSource { get; private set; } = new ObservableCollection<StatusBanner>();
2222

23-
private float medianOperationProgressValue = 0.0f;
24-
25-
public OngoingTasksViewModel()
26-
{
27-
StatusBannersSource.CollectionChanged += (s, e) => OnPropertyChanged(nameof(AnyBannersPresent));
28-
}
29-
30-
public float MedianOperationProgressValue
23+
private int medianOperationProgressValue = 0;
24+
public int MedianOperationProgressValue
3125
{
3226
get => medianOperationProgressValue;
3327
private set => SetProperty(ref medianOperationProgressValue, value);
@@ -82,17 +76,20 @@ public int InfoBadgeValue
8276
get => OngoingOperationsCount > 0 ? OngoingOperationsCount : -1;
8377
}
8478

85-
#endregion Public Properties
86-
87-
#region Events
79+
// Events
8880

8981
public event EventHandler<PostedStatusBanner> ProgressBannerPosted;
9082

91-
#endregion Events
83+
// Constructors
84+
85+
public OngoingTasksViewModel()
86+
{
87+
StatusBannersSource.CollectionChanged += (s, e) => OnPropertyChanged(nameof(AnyBannersPresent));
88+
}
9289

93-
#region IOngoingTasksActions
90+
// IOngoingTasksActions
9491

95-
public PostedStatusBanner PostBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation)
92+
public PostedStatusBanner PostBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation)
9693
{
9794
StatusBanner banner = new StatusBanner(message, title, initialProgress, status, operation);
9895
PostedStatusBanner postedBanner = new PostedStatusBanner(banner, this);
@@ -105,7 +102,7 @@ public PostedStatusBanner PostBanner(string title, string message, float initial
105102
return postedBanner;
106103
}
107104

108-
public PostedStatusBanner PostOperationBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource)
105+
public PostedStatusBanner PostOperationBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource)
109106
{
110107
StatusBanner banner = new StatusBanner(message, title, initialProgress, status, operation)
111108
{
@@ -161,36 +158,31 @@ public void UpdateMedianProgress()
161158
{
162159
if (AnyOperationsOngoing)
163160
{
164-
MedianOperationProgressValue = StatusBannersSource.Where((item) => item.IsProgressing).Average(x => x.Progress);
161+
MedianOperationProgressValue = (int)StatusBannersSource.Where((item) => item.IsProgressing).Average(x => x.Progress);
165162
}
166163
}
167-
168-
#endregion IOngoingTasksActions
169164
}
170165

171166
public class PostedStatusBanner
172167
{
173-
#region Private Members
168+
// Private Members
174169

175170
private readonly IOngoingTasksActions OngoingTasksActions;
176171

177172
private readonly StatusBanner Banner;
178173

179174
private readonly CancellationTokenSource cancellationTokenSource;
180175

181-
#endregion Private Members
182176

183-
#region Public Members
177+
// Public Members
184178

185179
public readonly FileSystemProgress Progress;
186180

187181
public readonly Progress<FileSystemProgress> ProgressEventSource;
188182

189183
public CancellationToken CancellationToken => cancellationTokenSource?.Token ?? default;
190184

191-
#endregion Public Members
192-
193-
#region Constructor
185+
// Constructor
194186

195187
public PostedStatusBanner(StatusBanner banner, IOngoingTasksActions OngoingTasksActions)
196188
{
@@ -211,9 +203,7 @@ public PostedStatusBanner(StatusBanner banner, IOngoingTasksActions OngoingTasks
211203
Progress = new(ProgressEventSource, status: FileSystemStatusCode.InProgress);
212204
}
213205

214-
#endregion Constructor
215-
216-
#region Private Helpers
206+
// Private Helpers
217207

218208
private void ReportProgressToBanner(FileSystemProgress value)
219209
{
@@ -226,10 +216,10 @@ private void ReportProgressToBanner(FileSystemProgress value)
226216

227217
Banner.IsProgressing = (value.Status & FileSystemStatusCode.InProgress) != 0;
228218

229-
if (value.Percentage is float f)
219+
if (value.Percentage is int p)
230220
{
231-
Banner.Progress = f;
232-
Banner.FullTitle = $"{Banner.Title} ({Banner.Progress:0.00}%)";
221+
Banner.Progress = p;
222+
Banner.FullTitle = $"{Banner.Title} ({Banner.Progress}%)";
233223

234224
// TODO: Show detailed progress if Size/Count information available
235225
}
@@ -238,18 +228,18 @@ private void ReportProgressToBanner(FileSystemProgress value)
238228
switch (value.TotalSize, value.ItemsCount)
239229
{
240230
case (not 0, not 0):
241-
Banner.Progress = value.ProcessedSize * 100f / value.TotalSize;
242-
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} ({value.ProcessedSize.ToSizeString()}) / {value.ItemsCount} ({value.TotalSize.ToSizeString()}): {Banner.Progress:0.00}%)";
231+
Banner.Progress = (int)(value.ProcessedSize * 100f / value.TotalSize);
232+
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} ({value.ProcessedSize.ToSizeString()}) / {value.ItemsCount} ({value.TotalSize.ToSizeString()}): {Banner.Progress}%)";
243233
break;
244234

245235
case (not 0, _):
246-
Banner.Progress = value.ProcessedSize * 100f / value.TotalSize;
247-
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedSize.ToSizeString()} / {value.TotalSize.ToSizeString()}: {Banner.Progress:0.00}%)";
236+
Banner.Progress = (int)(value.ProcessedSize * 100 / value.TotalSize);
237+
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedSize.ToSizeString()} / {value.TotalSize.ToSizeString()}: {Banner.Progress}%)";
248238
break;
249239

250240
case (_, not 0):
251-
Banner.Progress = value.ProcessedItemsCount * 100f / value.ItemsCount;
252-
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} / {value.ItemsCount}: {Banner.Progress:0.00}%)";
241+
Banner.Progress = (int)(value.ProcessedItemsCount * 100 / value.ItemsCount);
242+
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} / {value.ItemsCount}: {Banner.Progress}%)";
253243
break;
254244

255245
default:
@@ -272,9 +262,7 @@ private void ReportProgressToBanner(FileSystemProgress value)
272262
OngoingTasksActions.UpdateMedianProgress();
273263
}
274264

275-
#endregion Private Helpers
276-
277-
#region Public Helpers
265+
// Public Helpers
278266

279267
public void Remove()
280268
{
@@ -285,8 +273,6 @@ public void RequestCancellation()
285273
{
286274
cancellationTokenSource?.Cancel();
287275
}
288-
289-
#endregion Public Helpers
290276
}
291277

292278
public class StatusBanner : ObservableObject
@@ -303,9 +289,8 @@ public class StatusBanner : ObservableObject
303289

304290
#region Public Properties
305291

306-
private float progress = 0.0f;
307-
308-
public float Progress
292+
private int progress = 0;
293+
public int Progress
309294
{
310295
get => progress;
311296
set => SetProperty(ref progress, value);

0 commit comments

Comments
 (0)