// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Text; namespace EpicGames.Core { /// /// Writes a status message to the log, which can be updated with a progress indicator as a slow task is being performed. /// public sealed class LogStatusScope : IDisposable { /// /// The base status message /// string _message; /// /// Constructor /// /// The status message public LogStatusScope(string message) { _message = message; Log.PushStatus(message); } /// /// Constructor /// /// The format specifier for the message /// Arguments for the status message public LogStatusScope(string format, params object[] args) : this(String.Format(format, args)) { } /// /// Updates the base status message passed into the constructor. /// /// The status message public void SetMessage(string message) { _message = message; Log.UpdateStatus(message); } /// /// Updates the base status message passed into the constructor. /// /// The format specifier for the message /// Arguments for the status message public void SetMessage(string format, params object[] args) { SetMessage(String.Format(format, args)); } /// /// Appends a progress string to the status message. Overwrites any previous progress message. /// /// The progress message public void SetProgress(string progress) { StringBuilder fullMessage = new StringBuilder(_message); fullMessage.Append(' '); fullMessage.Append(progress); Log.UpdateStatus(fullMessage.ToString()); } /// /// Appends a progress string to the status message. Overwrites any previous progress message. /// /// The format specifier for the message /// Arguments for the status message public void SetProgress(string format, params object[] args) { StringBuilder fullMessage = new StringBuilder(_message); fullMessage.Append(' '); fullMessage.AppendFormat(format, args); Log.UpdateStatus(fullMessage.ToString()); } /// /// Pops the status message from the log. /// public void Dispose() { if(_message != null) { Log.PopStatus(); _message = null!; } } } }