From 636dce392f1961e6a7709e4954bae1917e548a73 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 16 May 2023 17:31:58 +0200 Subject: [PATCH] Disable progress ui on wine --- src/client/updater/progress_ui.cpp | 76 ------------------------------ src/client/updater/progress_ui.hpp | 29 ------------ src/client/updater/updater_ui.cpp | 4 +- src/client/updater/updater_ui.hpp | 4 +- src/common/utils/progress_ui.cpp | 56 ++++++++++++++++++---- src/common/utils/progress_ui.hpp | 7 ++- 6 files changed, 56 insertions(+), 120 deletions(-) delete mode 100644 src/client/updater/progress_ui.cpp delete mode 100644 src/client/updater/progress_ui.hpp diff --git a/src/client/updater/progress_ui.cpp b/src/client/updater/progress_ui.cpp deleted file mode 100644 index 07ede0c3..00000000 --- a/src/client/updater/progress_ui.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include "progress_ui.hpp" - -#include - -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; - } -} diff --git a/src/client/updater/progress_ui.hpp b/src/client/updater/progress_ui.hpp deleted file mode 100644 index 68f102ed..00000000 --- a/src/client/updater/progress_ui.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -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 dialog_{}; - }; -} diff --git a/src/client/updater/updater_ui.cpp b/src/client/updater/updater_ui.cpp index 505ae606..2d3a2296 100644 --- a/src/client/updater/updater_ui.cpp +++ b/src/client/updater/updater_ui.cpp @@ -18,9 +18,9 @@ namespace updater this->downloaded_files_.clear(); this->downloading_files_.clear(); - this->progress_ui_ = {}; + this->progress_ui_ = {true}; this->progress_ui_.set_title("BOIII Updater"); - this->progress_ui_.show(); + this->progress_ui_.show(false); // Is it good to add artificial sleeps? // Makes the ui nice, for sure. diff --git a/src/client/updater/updater_ui.hpp b/src/client/updater/updater_ui.hpp index 7f653e09..a0afabb9 100644 --- a/src/client/updater/updater_ui.hpp +++ b/src/client/updater/updater_ui.hpp @@ -1,9 +1,9 @@ #pragma once -#include "progress_ui.hpp" #include "progress_listener.hpp" #include +#include namespace updater { @@ -19,7 +19,7 @@ namespace updater std::vector downloaded_files_{}; std::unordered_map> downloading_files_{}; - progress_ui progress_ui_{}; + utils::progress_ui progress_ui_{true}; void update_files(const std::vector& files) override; void done_update() override; diff --git a/src/common/utils/progress_ui.cpp b/src/common/utils/progress_ui.cpp index 5b437016..09b4a894 100644 --- a/src/common/utils/progress_ui.cpp +++ b/src/common/utils/progress_ui.cpp @@ -4,42 +4,78 @@ namespace utils { - 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"}; + 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() { - this->dialog_->StopProgressDialog(); + if (this->dialog_) + { + this->dialog_->StopProgressDialog(); + } } 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 { - 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; } } diff --git a/src/common/utils/progress_ui.hpp b/src/common/utils/progress_ui.hpp index 944005b3..20112809 100644 --- a/src/common/utils/progress_ui.hpp +++ b/src/common/utils/progress_ui.hpp @@ -7,7 +7,7 @@ namespace utils class progress_ui { public: - progress_ui(); + progress_ui(bool allow_failure); ~progress_ui(); void show(bool marquee, HWND parent = nullptr) const; @@ -18,6 +18,11 @@ namespace utils bool is_cancelled() const; + operator bool() const + { + return this->dialog_; + } + private: CComPtr dialog_{}; };