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

View File

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