Disable progress ui on wine

This commit is contained in:
momo5502 2023-05-16 17:31:58 +02:00
parent 1461c11bb4
commit 636dce392f
6 changed files with 56 additions and 120 deletions

View File

@ -1,76 +0,0 @@
#include <std_include.hpp>
#include "progress_ui.hpp"
#include <utils/string.hpp>
namespace updater
{
progress_ui::progress_ui(const bool allow_failure)
{
try
{
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()
{
if (this->dialog_)
{
this->dialog_->StopProgressDialog();
}
}
void progress_ui::show() const
{
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
{
if (this->dialog_)
{
this->dialog_->SetProgress64(current, max);
}
}
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);
}
}
void progress_ui::set_title(const std::string& title) const
{
if (this->dialog_)
{
this->dialog_->SetTitle(utils::string::convert(title).data());
}
}
bool progress_ui::is_cancelled() const
{
if (this->dialog_)
{
return this->dialog_->HasUserCancelled();
}
return false;
}
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <utils/com.hpp>
namespace updater
{
class progress_ui
{
public:
progress_ui(bool allow_failure = true);
~progress_ui();
void show() const;
void set_progress(size_t current, size_t max) const;
void set_line(int line, const std::string& text) const;
void set_title(const std::string& title) const;
bool is_cancelled() const;
operator bool() const
{
return this->dialog_;
}
private:
CComPtr<IProgressDialog> dialog_{};
};
}

View File

@ -18,9 +18,9 @@ namespace updater
this->downloaded_files_.clear(); this->downloaded_files_.clear();
this->downloading_files_.clear(); this->downloading_files_.clear();
this->progress_ui_ = {}; this->progress_ui_ = {true};
this->progress_ui_.set_title("BOIII Updater"); this->progress_ui_.set_title("BOIII Updater");
this->progress_ui_.show(); this->progress_ui_.show(false);
// Is it good to add artificial sleeps? // Is it good to add artificial sleeps?
// Makes the ui nice, for sure. // Makes the ui nice, for sure.

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "progress_ui.hpp"
#include "progress_listener.hpp" #include "progress_listener.hpp"
#include <utils/concurrency.hpp> #include <utils/concurrency.hpp>
#include <utils/progress_ui.hpp>
namespace updater namespace updater
{ {
@ -19,7 +19,7 @@ namespace updater
std::vector<file_info> downloaded_files_{}; std::vector<file_info> downloaded_files_{};
std::unordered_map<std::string, std::pair<size_t, size_t>> downloading_files_{}; std::unordered_map<std::string, std::pair<size_t, size_t>> downloading_files_{};
progress_ui progress_ui_{}; utils::progress_ui progress_ui_{true};
void update_files(const std::vector<file_info>& files) override; void update_files(const std::vector<file_info>& files) override;
void done_update() override; void done_update() override;

View File

@ -4,42 +4,78 @@
namespace utils namespace utils
{ {
progress_ui::progress_ui() progress_ui::progress_ui(const bool allow_failure)
{ {
this->dialog_ = utils::com::create_progress_dialog(); try
if (!this->dialog_)
{ {
throw std::runtime_error{"Failed to create dialog"}; if(utils::nt::is_wine())
{
throw std::runtime_error{ "Disabled on wine" };
}
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() progress_ui::~progress_ui()
{ {
this->dialog_->StopProgressDialog(); if (this->dialog_)
{
this->dialog_->StopProgressDialog();
}
} }
void progress_ui::show(const bool marquee, HWND parent) const void progress_ui::show(const bool marquee, HWND parent) const
{ {
this->dialog_->StartProgressDialog(parent, nullptr, PROGDLG_AUTOTIME | (marquee ? PROGDLG_MARQUEEPROGRESS : 0), nullptr); if (this->dialog_)
{
this->dialog_->StartProgressDialog(parent, nullptr,
PROGDLG_AUTOTIME | (marquee ? PROGDLG_MARQUEEPROGRESS : 0), 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
{ {
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 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 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 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 utils
class progress_ui class progress_ui
{ {
public: public:
progress_ui(); progress_ui(bool allow_failure);
~progress_ui(); ~progress_ui();
void show(bool marquee, HWND parent = nullptr) const; void show(bool marquee, HWND parent = nullptr) const;
@ -18,6 +18,11 @@ namespace utils
bool is_cancelled() const; bool is_cancelled() const;
operator bool() const
{
return this->dialog_;
}
private: private:
CComPtr<IProgressDialog> dialog_{}; CComPtr<IProgressDialog> dialog_{};
}; };