Allow progress ui failure

This commit is contained in:
Maurice Heumann 2023-05-16 10:24:45 +02:00
parent 371548245a
commit 649d44479b
2 changed files with 46 additions and 11 deletions

View File

@ -5,7 +5,9 @@
namespace updater namespace updater
{ {
progress_ui::progress_ui() progress_ui::progress_ui(const bool allow_failure)
{
try
{ {
this->dialog_ = utils::com::create_progress_dialog(); this->dialog_ = utils::com::create_progress_dialog();
if (!this->dialog_) if (!this->dialog_)
@ -13,34 +15,62 @@ namespace updater
throw std::runtime_error{"Failed to create dialog"}; throw std::runtime_error{"Failed to create dialog"};
} }
} }
catch (...)
{
if (!allow_failure)
{
throw;
}
}
}
progress_ui::~progress_ui() progress_ui::~progress_ui()
{
if (this->dialog_)
{ {
this->dialog_->StopProgressDialog(); this->dialog_->StopProgressDialog();
} }
}
void progress_ui::show() const void progress_ui::show() const
{
if (this->dialog_)
{ {
this->dialog_->StartProgressDialog(nullptr, nullptr, PROGDLG_AUTOTIME, nullptr); this->dialog_->StartProgressDialog(nullptr, nullptr, PROGDLG_AUTOTIME, nullptr);
} }
}
void progress_ui::set_progress(const size_t current, const size_t max) const void progress_ui::set_progress(const size_t current, const size_t max) const
{
if (this->dialog_)
{ {
this->dialog_->SetProgress64(current, max); this->dialog_->SetProgress64(current, max);
} }
}
void progress_ui::set_line(const int line, const std::string& text) const void progress_ui::set_line(const int line, const std::string& text) const
{
if (this->dialog_)
{ {
this->dialog_->SetLine(line, utils::string::convert(text).data(), false, nullptr); this->dialog_->SetLine(line, utils::string::convert(text).data(), false, nullptr);
} }
}
void progress_ui::set_title(const std::string& title) const void progress_ui::set_title(const std::string& title) const
{
if (this->dialog_)
{ {
this->dialog_->SetTitle(utils::string::convert(title).data()); this->dialog_->SetTitle(utils::string::convert(title).data());
} }
}
bool progress_ui::is_cancelled() const bool progress_ui::is_cancelled() const
{
if (this->dialog_)
{ {
return this->dialog_->HasUserCancelled(); return this->dialog_->HasUserCancelled();
} }
return false;
}
} }

View File

@ -7,7 +7,7 @@ namespace updater
class progress_ui class progress_ui
{ {
public: public:
progress_ui(); progress_ui(bool allow_failure = true);
~progress_ui(); ~progress_ui();
void show() const; void show() const;
@ -18,6 +18,11 @@ namespace updater
bool is_cancelled() const; bool is_cancelled() const;
operator bool() const
{
return this->dialog_;
}
private: private:
CComPtr<IProgressDialog> dialog_{}; CComPtr<IProgressDialog> dialog_{};
}; };