// Copyright Epic Games, Inc. All Rights Reserved. #include #include namespace zen { class StandardProgressBase; class StandardProgressBar : public ProgressBase::ProgressBar { public: StandardProgressBar(StandardProgressBase& Owner, std::string_view InSubTask) : m_Owner(Owner), m_SubTask(InSubTask) {} virtual void UpdateState(const State& NewState, bool DoLinebreak) override; virtual void ForceLinebreak() override {} virtual void Finish() override; private: LoggerRef Log(); StandardProgressBase& m_Owner; std::string m_SubTask; State m_State; }; class StandardProgressBase : public ProgressBase { public: StandardProgressBase(LoggerRef Log) : m_Log(Log) {} virtual void SetLogOperationName(std::string_view Name) override { m_LogOperationName = Name; ZEN_INFO("{}", m_LogOperationName); } virtual void SetLogOperationProgress(uint32_t StepIndex, uint32_t StepCount) override { const size_t PercentDone = StepCount > 0u ? (100u * StepIndex) / StepCount : 0u; ZEN_INFO("{}: {}%", m_LogOperationName, PercentDone); } virtual void PushLogOperation(std::string_view Name) override { ZEN_UNUSED(Name); } virtual void PopLogOperation() override {} virtual uint32_t GetProgressUpdateDelayMS() const override { return 2000; } virtual std::unique_ptr CreateProgressBar(std::string_view InSubTask) override { return std::make_unique(*this, InSubTask); } private: friend class StandardProgressBar; LoggerRef m_Log; std::string m_LogOperationName; LoggerRef Log() { return m_Log; } }; LoggerRef StandardProgressBar::Log() { return m_Owner.Log(); } void StandardProgressBar::UpdateState(const State& NewState, bool DoLinebreak) { ZEN_UNUSED(DoLinebreak); const size_t PercentDone = NewState.TotalCount > 0u ? (100u * (NewState.TotalCount - NewState.RemainingCount)) / NewState.TotalCount : 0u; std::string Task = NewState.Task; switch (NewState.Status) { case State::EStatus::Aborted: Task = "Aborting"; break; case State::EStatus::Paused: Task = "Paused"; break; default: break; } ZEN_INFO("{}: {}%{}", Task, PercentDone, NewState.Details.empty() ? "" : fmt::format(" {}", NewState.Details)); m_State = NewState; } void StandardProgressBar::Finish() { if (m_State.RemainingCount > 0) { State NewState = m_State; NewState.RemainingCount = 0; NewState.Details = ""; UpdateState(NewState, /*DoLinebreak*/ true); } } ProgressBase* CreateStandardProgress(LoggerRef Log) { return new StandardProgressBase(Log); } } // namespace zen