-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Feature: Implement the fundamental for rich progress #10814
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
35d8465
Types and interfaces
hez2010 42572a9
FileSystemProgress revision
hez2010 1407b5d
FileSystemOperation port to new FileSystemProgress
hez2010 493b31b
WIP: FileSystemProgress
hez2010 9994a95
FIxes to progress
hez2010 e560d19
Zip: TotalSize -> ItemsCount
hez2010 a7a266a
Fix indents
hez2010 1aa1b0b
Fix format
hez2010 ec77fe3
Constructor
hez2010 b29b1d2
Merge from main
hez2010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
indent_style = tab | ||
indent_size = 4 | ||
tab_width = 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/Files.App/Filesystem/FilesystemOperations/FileSystemProgress.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Files.App.Helpers; | ||
using Files.Shared.Enums; | ||
using System; | ||
|
||
namespace Files.App.Filesystem | ||
{ | ||
public class FileSystemProgress | ||
{ | ||
private readonly IProgress<FileSystemProgress>? progress; | ||
private readonly IntervalSampler sampler; | ||
private FileSystemStatusCode? status; | ||
private bool criticalReport; | ||
private bool enumerationCompleted; | ||
|
||
public FileSystemStatusCode? Status | ||
{ | ||
get => status; | ||
set | ||
{ | ||
if (status != value) | ||
{ | ||
criticalReport = true; | ||
} | ||
status = value; | ||
} | ||
} | ||
public string? FileName { get; set; } | ||
public long TotalSize { get; set; } | ||
public long ProcessedSize { get; set; } | ||
public long ItemsCount { get; set; } | ||
public long ProcessedItemsCount { get; set; } | ||
public DateTimeOffset StartTime { get; } | ||
public DateTimeOffset CompletedTime { get; private set; } | ||
public bool EnumerationCompleted | ||
{ | ||
get => enumerationCompleted; | ||
set | ||
{ | ||
if (enumerationCompleted != value) | ||
{ | ||
criticalReport = true; | ||
} | ||
enumerationCompleted = value; | ||
} | ||
} | ||
/// <summary> | ||
/// Only used when detailed count isn't available. | ||
/// </summary> | ||
public float? Percentage { get; set; } | ||
|
||
public FileSystemProgress( | ||
IProgress<FileSystemProgress>? progress, | ||
bool enumerationCompleted = false, | ||
FileSystemStatusCode? status = null, | ||
long itemsCount = 0, | ||
long totalSize = 0, | ||
int samplerInterval = 100) | ||
{ | ||
this.StartTime = DateTimeOffset.Now; | ||
this.progress = progress; | ||
this.sampler = new(samplerInterval); | ||
this.EnumerationCompleted = enumerationCompleted; | ||
this.Status = status; | ||
this.ItemsCount = itemsCount; | ||
this.TotalSize = totalSize; | ||
} | ||
|
||
public void Report(float? percentage = null) | ||
{ | ||
Percentage = percentage; | ||
if (((EnumerationCompleted && (ProcessedItemsCount == ItemsCount || ProcessedSize == TotalSize)) || | ||
(percentage is float f && MathF.Abs(f - 100f) <= float.Epsilon)) && | ||
status is FileSystemStatusCode.InProgress or null) | ||
{ | ||
status = FileSystemStatusCode.Success; | ||
CompletedTime = DateTimeOffset.Now; | ||
} | ||
|
||
if (status is FileSystemStatusCode.Success) | ||
CompletedTime = DateTimeOffset.Now; | ||
|
||
if (progress is not null && (criticalReport || sampler.CheckNow())) | ||
{ | ||
progress.Report(this); | ||
criticalReport = false; | ||
} | ||
} | ||
|
||
public void ReportStatus(FileSystemStatusCode status) | ||
{ | ||
Status = status; | ||
Report(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.