Skip to content
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

Add progress to Copy-Item #18735

Merged
merged 15 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add speed and time remaining
  • Loading branch information
SteveL-MSFT committed Jan 25, 2023
commit 0433cc7680ae5307e295b0257b740c79b587d49b
Original file line number Diff line number Diff line change
Expand Up @@ -3563,6 +3563,7 @@ private static bool DirectoryInfoHasChildItems(DirectoryInfo directory)
GetTotalFiles(path, recurse);
});
t.Start();
_copyStartTime = DateTime.Now;
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -3938,13 +3939,17 @@ private void CopyFileInfoItem(FileInfo file, string destinationPath, bool force,
{
_copiedFiles++;
_copiedBytes += file.Length;
var copiedMegabytes = _copiedBytes / 1024 / 1024;
double speed = (double)copiedMegabytes / (DateTime.Now - _copyStartTime).TotalSeconds;
int timeRemaining = (int)((_totalBytes - _copiedBytes) / 1024 / 1024 / speed);
var progress = new ProgressRecord(
COPY_FILE_ACTIVITY_ID,
StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _totalFiles - _copiedFiles),
StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, _copiedBytes / 1024 / 1024, _totalBytes / 1024 / 1024)
StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, copiedMegabytes, _totalBytes / 1024 / 1024, speed)
);
progress.PercentComplete = (int)((_copiedBytes * 100) / _totalBytes);
progress.RecordType = ProgressRecordType.Processing;
progress.SecondsRemaining = timeRemaining;
WriteProgress(progress);
}
}
Expand Down Expand Up @@ -4875,6 +4880,7 @@ private bool PathIsReservedDeviceName(string destinationPath, string errorId)
private long _totalBytes = 0;
private long _copiedFiles = 0;
private long _copiedBytes = 0;
private DateTime _copyStartTime;

#endregion CopyItem

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,6 @@
<value>Copying {0} files</value>
</data>
<data name="CopyingLocalBytesStatus" xml:space="preserve">
<value>{0} MB of {1} MB</value>
<value>{0} MB of {1} MB ({2:0.0} MB/s)</value>
</data>
</root>