From 6176a21ff1691c2e9d1b91c43077481fd111b448 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 19 Jul 2024 14:49:12 +1000 Subject: [PATCH] ProgressCallback: Eliminate redundancy and drop C format strings --- src/common/error.h | 20 +- src/common/progress_callback.cpp | 371 +++--------------- src/common/progress_callback.h | 137 +++---- src/core/game_list.cpp | 2 +- src/core/host_interface_progress_callback.cpp | 49 +-- src/core/host_interface_progress_callback.h | 18 +- src/duckstation-qt/gamelistrefreshthread.cpp | 50 +-- src/duckstation-qt/gamelistrefreshthread.h | 18 +- src/duckstation-qt/qtprogresscallback.cpp | 105 ++--- src/duckstation-qt/qtprogresscallback.h | 36 +- src/updater/cocoa_main.mm | 4 +- src/updater/cocoa_progress_callback.h | 24 +- src/updater/cocoa_progress_callback.mm | 66 ++-- src/updater/updater.cpp | 69 ++-- src/updater/win32_main.cpp | 7 +- src/updater/win32_progress_callback.cpp | 63 +-- src/updater/win32_progress_callback.h | 22 +- src/util/cd_image_hasher.cpp | 5 +- src/util/cd_image_memory.cpp | 6 +- src/util/postprocessing.cpp | 4 +- 20 files changed, 345 insertions(+), 731 deletions(-) diff --git a/src/common/error.h b/src/common/error.h index a101dfd55..b5287ae8c 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -99,26 +99,38 @@ public: template void AddPrefixFmt(fmt::format_string fmt, T&&... args) { - AddPrefix(TinyString::from_vformat(fmt::string_view(fmt), fmt::make_format_args(args...))); + TinyString str; + fmt::vformat_to(std::back_inserter(str), fmt, fmt::make_format_args(args...)); + AddPrefix(str.view()); } template void AddSuffixFmt(fmt::format_string fmt, T&&... args) { - AddSuffix(TinyString::from_vformat(fmt::string_view(fmt), fmt::make_format_args(args...))); + TinyString str; + fmt::vformat_to(std::back_inserter(str), fmt, fmt::make_format_args(args...)); + AddSuffix(str.view()); } template static void AddPrefixFmt(Error* errptr, fmt::format_string fmt, T&&... args) { if (errptr) - Error::AddPrefix(errptr, TinyString::from_vformat(fmt::string_view(fmt), fmt::make_format_args(args...))); + { + TinyString str; + fmt::vformat_to(std::back_inserter(str), fmt, fmt::make_format_args(args...)); + errptr->AddPrefix(str.view()); + } } template static void AddSuffixFmt(Error* errptr, fmt::format_string fmt, T&&... args) { if (errptr) - Error::AddSuffix(errptr, TinyString::from_vformat(fmt::string_view(fmt), fmt::make_format_args(args...))); + { + TinyString str; + fmt::vformat_to(std::back_inserter(str), fmt, fmt::make_format_args(args...)); + errptr->AddSuffix(str.view()); + } } Error& operator=(const Error& e); diff --git a/src/common/progress_callback.cpp b/src/common/progress_callback.cpp index 3f7b0d085..2d0b4b06a 100644 --- a/src/common/progress_callback.cpp +++ b/src/common/progress_callback.cpp @@ -1,229 +1,88 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "progress_callback.h" #include "assert.h" #include "byte_stream.h" #include "log.h" + #include #include #include + Log_SetChannel(ProgressCallback); +static ProgressCallback s_nullProgressCallbacks; +ProgressCallback* ProgressCallback::NullProgressCallback = &s_nullProgressCallbacks; + ProgressCallback::~ProgressCallback() { + std::unique_ptr pNextState = std::move(m_saved_state); + while (pNextState) + pNextState = std::move(pNextState->next_saved_state); } -void ProgressCallback::SetFormattedStatusText(const char* Format, ...) +void ProgressCallback::PushState() { - SmallString str; - va_list ap; - - va_start(ap, Format); - str.vsprintf(Format, ap); - va_end(ap); - - SetStatusText(str); -} - -void ProgressCallback::DisplayFormattedError(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - DisplayError(str); -} - -void ProgressCallback::DisplayFormattedWarning(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - DisplayWarning(str); -} - -void ProgressCallback::DisplayFormattedInformation(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - DisplayInformation(str); -} - -void ProgressCallback::DisplayFormattedDebugMessage(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - DisplayDebugMessage(str); -} - -void ProgressCallback::DisplayFormattedModalError(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - ModalError(str); -} - -bool ProgressCallback::DisplayFormattedModalConfirmation(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - return ModalConfirmation(str); -} - -void ProgressCallback::DisplayFormattedModalInformation(const char* format, ...) -{ - SmallString str; - va_list ap; - - va_start(ap, format); - str.vsprintf(format, ap); - va_end(ap); - - ModalInformation(str); -} - -void ProgressCallback::UpdateProgressFromStream(ByteStream* pStream) -{ - u32 streamSize = (u32)pStream->GetSize(); - u32 streamPosition = (u32)pStream->GetPosition(); - - SetProgressRange(streamSize); - SetProgressValue(streamPosition); -} - -class NullProgressCallbacks final : public ProgressCallback -{ -public: - void PushState() override {} - void PopState() override {} - - bool IsCancelled() const override { return false; } - bool IsCancellable() const override { return false; } - - void SetCancellable(bool cancellable) override {} - void SetTitle(const char* title) override {} - void SetStatusText(const char* statusText) override {} - void SetProgressRange(u32 range) override {} - void SetProgressValue(u32 value) override {} - void IncrementProgressValue() override {} - - void DisplayError(const char* message) override { ERROR_LOG(message); } - void DisplayWarning(const char* message) override { WARNING_LOG(message); } - void DisplayInformation(const char* message) override { INFO_LOG(message); } - void DisplayDebugMessage(const char* message) override { DEV_LOG(message); } - - void ModalError(const char* message) override { ERROR_LOG(message); } - bool ModalConfirmation(const char* message) override - { - INFO_LOG(message); - return false; - } - void ModalInformation(const char* message) override { INFO_LOG(message); } -}; - -static NullProgressCallbacks s_nullProgressCallbacks; -ProgressCallback* ProgressCallback::NullProgressCallback = &s_nullProgressCallbacks; - -BaseProgressCallback::BaseProgressCallback() - : m_cancellable(false), m_cancelled(false), m_progress_range(1), m_progress_value(0), m_base_progress_value(0), - m_saved_state(NULL) -{ -} - -BaseProgressCallback::~BaseProgressCallback() -{ - State* pNextState = m_saved_state; - while (pNextState != NULL) - { - State* pCurrentState = pNextState; - pNextState = pCurrentState->next_saved_state; - delete pCurrentState; - } -} - -void BaseProgressCallback::PushState() -{ - State* pNewState = new State; + std::unique_ptr pNewState = std::make_unique(); pNewState->cancellable = m_cancellable; pNewState->status_text = m_status_text; pNewState->progress_range = m_progress_range; pNewState->progress_value = m_progress_value; pNewState->base_progress_value = m_base_progress_value; - pNewState->next_saved_state = m_saved_state; - m_saved_state = pNewState; + pNewState->next_saved_state = std::move(m_saved_state); + m_saved_state = std::move(pNewState); } -void BaseProgressCallback::PopState() +void ProgressCallback::PopState() { DebugAssert(m_saved_state); - State* state = m_saved_state; - m_saved_state = nullptr; // impose the current position into the previous range const u32 new_progress_value = (m_progress_range != 0) ? - static_cast(((float)m_progress_value / (float)m_progress_range) * (float)state->progress_range) : - state->progress_value; + static_cast(((float)m_progress_value / (float)m_progress_range) * (float)m_saved_state->progress_range) : + m_saved_state->progress_value; - m_cancellable = state->cancellable; - m_status_text = std::move(state->status_text); - m_progress_range = state->progress_range; + m_cancellable = m_saved_state->cancellable; + m_status_text = std::move(m_saved_state->status_text); + m_progress_range = m_saved_state->progress_range; m_progress_value = new_progress_value; - m_base_progress_value = state->base_progress_value; - m_saved_state = state->next_saved_state; - delete state; + m_base_progress_value = m_saved_state->base_progress_value; + m_saved_state = std::move(m_saved_state->next_saved_state); } -bool BaseProgressCallback::IsCancelled() const -{ - return m_cancelled; -} - -bool BaseProgressCallback::IsCancellable() const +bool ProgressCallback::IsCancellable() const { return m_cancellable; } -void BaseProgressCallback::SetCancellable(bool cancellable) +bool ProgressCallback::IsCancelled() const +{ + return m_cancelled; +} + +void ProgressCallback::SetTitle(const std::string_view title) +{ +} + +void ProgressCallback::SetStatusText(const std::string_view text) +{ + m_status_text.assign(text); +} + +void ProgressCallback::SetCancellable(bool cancellable) { m_cancellable = cancellable; } -void BaseProgressCallback::SetStatusText(const char* text) +void ProgressCallback::SetProgressValue(u32 value) { - m_status_text = text; + m_progress_value = m_base_progress_value + value; } -void BaseProgressCallback::SetProgressRange(u32 range) +void ProgressCallback::SetProgressRange(u32 range) { if (m_saved_state) { @@ -239,177 +98,43 @@ void BaseProgressCallback::SetProgressRange(u32 range) } } -void BaseProgressCallback::SetProgressValue(u32 value) -{ - m_progress_value = m_base_progress_value + value; -} - -void BaseProgressCallback::IncrementProgressValue() +void ProgressCallback::IncrementProgressValue() { SetProgressValue((m_progress_value - m_base_progress_value) + 1); } -ConsoleProgressCallback::ConsoleProgressCallback() - : BaseProgressCallback(), m_last_percent_complete(std::numeric_limits::infinity()), - m_last_bar_length(0xFFFFFFFF) +void ProgressCallback::DisplayError(const std::string_view message) { -} - -ConsoleProgressCallback::~ConsoleProgressCallback() -{ - Clear(); -} - -void ConsoleProgressCallback::PushState() -{ - BaseProgressCallback::PushState(); -} - -void ConsoleProgressCallback::PopState() -{ - BaseProgressCallback::PopState(); - Redraw(false); -} - -void ConsoleProgressCallback::SetCancellable(bool cancellable) -{ - BaseProgressCallback::SetCancellable(cancellable); - Redraw(false); -} - -void ConsoleProgressCallback::SetTitle(const char* title) -{ - Clear(); - std::fprintf(stdout, "== %s ==\n", title); - Redraw(false); -} - -void ConsoleProgressCallback::SetStatusText(const char* text) -{ - BaseProgressCallback::SetStatusText(text); - Redraw(false); -} - -void ConsoleProgressCallback::SetProgressRange(u32 range) -{ - u32 last_range = m_progress_range; - - BaseProgressCallback::SetProgressRange(range); - - if (m_progress_range != last_range) - Redraw(false); -} - -void ConsoleProgressCallback::SetProgressValue(u32 value) -{ - u32 lastValue = m_progress_value; - - BaseProgressCallback::SetProgressValue(value); - - if (m_progress_value != lastValue) - Redraw(true); -} - -void ConsoleProgressCallback::Clear() -{ - SmallString message; - for (u32 i = 0; i < COLUMNS; i++) - message.append(' '); - message.append('\r'); - - std::fwrite(message.c_str(), message.length(), 1, stderr); - std::fflush(stderr); -} - -void ConsoleProgressCallback::Redraw(bool update_value_only) -{ - float percent_complete = (m_progress_range > 0) ? ((float)m_progress_value / (float)m_progress_range) * 100.0f : 0.0f; - if (percent_complete > 100.0f) - percent_complete = 100.0f; - - const u32 current_length = static_cast(m_status_text.length()) + 14; - const u32 max_bar_length = (current_length < COLUMNS) ? COLUMNS - current_length : 0; - const u32 current_bar_length = - (max_bar_length > 0) ? (static_cast(percent_complete / 100.0f * (float)max_bar_length)) : 0; - - if (update_value_only && (current_bar_length == m_last_bar_length) && - std::abs(percent_complete - m_last_percent_complete) < 0.01f) - { - return; - } - - m_last_bar_length = current_bar_length; - m_last_percent_complete = percent_complete; - - SmallString message; - message.append(m_status_text); - message.append_format(" [{:.2f}%]", percent_complete); - - if (max_bar_length > 0) - { - message.append(" |"); - - u32 i; - for (i = 0; i < current_bar_length; i++) - message.append('='); - for (; i < max_bar_length; i++) - message.append(' '); - - message.append('|'); - } - - message.append('\r'); - - std::fwrite(message.c_str(), message.length(), 1, stderr); - std::fflush(stderr); -} - -void ConsoleProgressCallback::DisplayError(const char* message) -{ - Clear(); ERROR_LOG(message); - Redraw(false); } -void ConsoleProgressCallback::DisplayWarning(const char* message) +void ProgressCallback::DisplayWarning(const std::string_view message) { - Clear(); WARNING_LOG(message); - Redraw(false); } -void ConsoleProgressCallback::DisplayInformation(const char* message) +void ProgressCallback::DisplayInformation(const std::string_view message) { - Clear(); INFO_LOG(message); - Redraw(false); } -void ConsoleProgressCallback::DisplayDebugMessage(const char* message) +void ProgressCallback::DisplayDebugMessage(const std::string_view message) { - Clear(); DEV_LOG(message); - Redraw(false); } -void ConsoleProgressCallback::ModalError(const char* message) +void ProgressCallback::ModalError(const std::string_view message) { - Clear(); ERROR_LOG(message); - Redraw(false); } -bool ConsoleProgressCallback::ModalConfirmation(const char* message) +bool ProgressCallback::ModalConfirmation(const std::string_view message) { - Clear(); INFO_LOG(message); - Redraw(false); return false; } -void ConsoleProgressCallback::ModalInformation(const char* message) +void ProgressCallback::ModalInformation(const std::string_view message) { - Clear(); INFO_LOG(message); - Redraw(false); } diff --git a/src/common/progress_callback.h b/src/common/progress_callback.h index 425ddd633..106bd9574 100644 --- a/src/common/progress_callback.h +++ b/src/common/progress_callback.h @@ -1,78 +1,67 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once + #include "small_string.h" #include "types.h" -class ByteStream; +#include "fmt/core.h" + +#include class ProgressCallback { public: virtual ~ProgressCallback(); - virtual void PushState() = 0; - virtual void PopState() = 0; + virtual void PushState(); + virtual void PopState(); - virtual bool IsCancelled() const = 0; - virtual bool IsCancellable() const = 0; + virtual bool IsCancelled() const; + virtual bool IsCancellable() const; - virtual void SetCancellable(bool cancellable) = 0; + virtual void SetCancellable(bool cancellable); - virtual void SetTitle(const char* title) = 0; - virtual void SetStatusText(const char* text) = 0; - virtual void SetProgressRange(u32 range) = 0; - virtual void SetProgressValue(u32 value) = 0; - virtual void IncrementProgressValue() = 0; + virtual void SetTitle(const std::string_view title); + virtual void SetStatusText(const std::string_view text); + virtual void SetProgressRange(u32 range); + virtual void SetProgressValue(u32 value); + virtual void IncrementProgressValue(); - void SetFormattedStatusText(const char* Format, ...) printflike(2, 3); + virtual void DisplayError(const std::string_view message); + virtual void DisplayWarning(const std::string_view message); + virtual void DisplayInformation(const std::string_view message); + virtual void DisplayDebugMessage(const std::string_view message); - virtual void DisplayError(const char* message) = 0; - virtual void DisplayWarning(const char* message) = 0; - virtual void DisplayInformation(const char* message) = 0; - virtual void DisplayDebugMessage(const char* message) = 0; + virtual void ModalError(const std::string_view message); + virtual bool ModalConfirmation(const std::string_view message); + virtual void ModalInformation(const std::string_view message); - virtual void ModalError(const char* message) = 0; - virtual bool ModalConfirmation(const char* message) = 0; - virtual void ModalInformation(const char* message) = 0; +#define MAKE_PROGRESS_CALLBACK_FORWARDER(from, to) \ + template \ + void from(fmt::format_string fmt, T&&... args) \ + { \ + TinyString str; \ + fmt::vformat_to(std::back_inserter(str), fmt, fmt::make_format_args(args...)); \ + to(str.view()); \ + } - void DisplayFormattedError(const char* format, ...) printflike(2, 3); - void DisplayFormattedWarning(const char* format, ...) printflike(2, 3); - void DisplayFormattedInformation(const char* format, ...) printflike(2, 3); - void DisplayFormattedDebugMessage(const char* format, ...) printflike(2, 3); - void DisplayFormattedModalError(const char* format, ...) printflike(2, 3); - bool DisplayFormattedModalConfirmation(const char* format, ...) printflike(2, 3); - void DisplayFormattedModalInformation(const char* format, ...) printflike(2, 3); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatStatusText, SetStatusText); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatError, DisplayError); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatWarning, DisplayWarning); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatInformation, DisplayInformation); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatDebugMessage, DisplayDebugMessage); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatModalError, ModalError); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatModalConfirmation, ModalConfirmation); + MAKE_PROGRESS_CALLBACK_FORWARDER(FormatModalInformation, ModalInformation); - void UpdateProgressFromStream(ByteStream* stream); - -public: - static ProgressCallback* NullProgressCallback; -}; - -class BaseProgressCallback : public ProgressCallback -{ -public: - BaseProgressCallback(); - virtual ~BaseProgressCallback(); - - virtual void PushState() override; - virtual void PopState() override; - - virtual bool IsCancelled() const override; - virtual bool IsCancellable() const override; - - virtual void SetCancellable(bool cancellable) override; - virtual void SetStatusText(const char* text) override; - virtual void SetProgressRange(u32 range) override; - virtual void SetProgressValue(u32 value) override; - virtual void IncrementProgressValue() override; +#undef MAKE_PROGRESS_CALLBACK_FORWARDER protected: struct State { - State* next_saved_state; + std::unique_ptr next_saved_state; std::string status_text; u32 progress_range; u32 progress_value; @@ -80,48 +69,16 @@ protected: bool cancellable; }; - bool m_cancellable; - bool m_cancelled; + bool m_cancellable = false; + bool m_cancelled = false; std::string m_status_text; - u32 m_progress_range; - u32 m_progress_value; + u32 m_progress_range = 1; + u32 m_progress_value = 0; - u32 m_base_progress_value; + u32 m_base_progress_value = 0; - State* m_saved_state; -}; - -class ConsoleProgressCallback final : public BaseProgressCallback -{ -public: - static const u32 COLUMNS = 78; + std::unique_ptr m_saved_state; public: - ConsoleProgressCallback(); - ~ConsoleProgressCallback(); - - void PushState() override; - void PopState() override; - - void SetCancellable(bool cancellable) override; - void SetTitle(const char* title) override; - void SetStatusText(const char* text) override; - void SetProgressRange(u32 range) override; - void SetProgressValue(u32 value) override; - - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; - - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; - -private: - void Clear(); - void Redraw(bool update_value_only); - - float m_last_percent_complete; - u32 m_last_bar_length; + static ProgressCallback* NullProgressCallback; }; diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index ff1b529be..c4f012da9 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1500,7 +1500,7 @@ bool GameList::DownloadCovers(const std::vector& url_templates, boo continue; } - progress->SetFormattedStatusText("Downloading cover for %s...", entry->title.c_str()); + progress->FormatStatusText("Downloading cover for {}...", entry->title); } // we could actually do a few in parallel here... diff --git a/src/core/host_interface_progress_callback.cpp b/src/core/host_interface_progress_callback.cpp index cb1c314f4..0bb8098fc 100644 --- a/src/core/host_interface_progress_callback.cpp +++ b/src/core/host_interface_progress_callback.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "host_interface_progress_callback.h" @@ -6,35 +6,35 @@ #include "host.h" Log_SetChannel(HostInterfaceProgressCallback); -HostInterfaceProgressCallback::HostInterfaceProgressCallback() : BaseProgressCallback() +HostInterfaceProgressCallback::HostInterfaceProgressCallback() : ProgressCallback() { } void HostInterfaceProgressCallback::PushState() { - BaseProgressCallback::PushState(); + ProgressCallback::PushState(); } void HostInterfaceProgressCallback::PopState() { - BaseProgressCallback::PopState(); + ProgressCallback::PopState(); Redraw(true); } void HostInterfaceProgressCallback::SetCancellable(bool cancellable) { - BaseProgressCallback::SetCancellable(cancellable); + ProgressCallback::SetCancellable(cancellable); Redraw(true); } -void HostInterfaceProgressCallback::SetTitle(const char* title) +void HostInterfaceProgressCallback::SetTitle(const std::string_view title) { // todo? } -void HostInterfaceProgressCallback::SetStatusText(const char* text) +void HostInterfaceProgressCallback::SetStatusText(const std::string_view text) { - BaseProgressCallback::SetStatusText(text); + ProgressCallback::SetStatusText(text); Redraw(true); } @@ -42,7 +42,7 @@ void HostInterfaceProgressCallback::SetProgressRange(u32 range) { u32 last_range = m_progress_range; - BaseProgressCallback::SetProgressRange(range); + ProgressCallback::SetProgressRange(range); if (m_progress_range != last_range) Redraw(false); @@ -52,7 +52,7 @@ void HostInterfaceProgressCallback::SetProgressValue(u32 value) { u32 lastValue = m_progress_value; - BaseProgressCallback::SetProgressValue(value); + ProgressCallback::SetProgressValue(value); if (m_progress_value != lastValue) Redraw(false); @@ -73,39 +73,14 @@ void HostInterfaceProgressCallback::Redraw(bool force) static_cast(m_progress_value)); } -void HostInterfaceProgressCallback::DisplayError(const char* message) -{ - ERROR_LOG(message); -} - -void HostInterfaceProgressCallback::DisplayWarning(const char* message) -{ - WARNING_LOG(message); -} - -void HostInterfaceProgressCallback::DisplayInformation(const char* message) -{ - INFO_LOG(message); -} - -void HostInterfaceProgressCallback::DisplayDebugMessage(const char* message) -{ - DEV_LOG(message); -} - -void HostInterfaceProgressCallback::ModalError(const char* message) +void HostInterfaceProgressCallback::ModalError(const std::string_view message) { ERROR_LOG(message); Host::ReportErrorAsync("Error", message); } -bool HostInterfaceProgressCallback::ModalConfirmation(const char* message) +bool HostInterfaceProgressCallback::ModalConfirmation(const std::string_view message) { INFO_LOG(message); return Host::ConfirmMessage("Confirm", message); } - -void HostInterfaceProgressCallback::ModalInformation(const char* message) -{ - INFO_LOG(message); -} diff --git a/src/core/host_interface_progress_callback.h b/src/core/host_interface_progress_callback.h index 9b96b2867..d8358da94 100644 --- a/src/core/host_interface_progress_callback.h +++ b/src/core/host_interface_progress_callback.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -6,7 +6,7 @@ #include "common/progress_callback.h" #include "common/timer.h" -class HostInterfaceProgressCallback final : public BaseProgressCallback +class HostInterfaceProgressCallback final : public ProgressCallback { public: HostInterfaceProgressCallback(); @@ -17,19 +17,13 @@ public: void PopState() override; void SetCancellable(bool cancellable) override; - void SetTitle(const char* title) override; - void SetStatusText(const char* text) override; + void SetTitle(const std::string_view title) override; + void SetStatusText(const std::string_view text) override; void SetProgressRange(u32 range) override; void SetProgressValue(u32 value) override; - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; - - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; + void ModalError(const std::string_view message) override; + bool ModalConfirmation(const std::string_view message) override; private: void Redraw(bool force); diff --git a/src/duckstation-qt/gamelistrefreshthread.cpp b/src/duckstation-qt/gamelistrefreshthread.cpp index b2f2749ad..712712042 100644 --- a/src/duckstation-qt/gamelistrefreshthread.cpp +++ b/src/duckstation-qt/gamelistrefreshthread.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "gamelistrefreshthread.h" +#include "qtutils.h" #include "core/game_list.h" @@ -11,7 +12,9 @@ #include -AsyncRefreshProgressCallback::AsyncRefreshProgressCallback(GameListRefreshThread* parent) : m_parent(parent) {} +AsyncRefreshProgressCallback::AsyncRefreshProgressCallback(GameListRefreshThread* parent) : m_parent(parent) +{ +} void AsyncRefreshProgressCallback::Cancel() { @@ -19,9 +22,9 @@ void AsyncRefreshProgressCallback::Cancel() m_cancelled = true; } -void AsyncRefreshProgressCallback::SetStatusText(const char* text) +void AsyncRefreshProgressCallback::SetStatusText(const std::string_view text) { - QString new_text(QString::fromUtf8(text)); + const QString new_text = QtUtils::StringViewToQString(text); if (new_text == m_status_text) return; @@ -31,7 +34,7 @@ void AsyncRefreshProgressCallback::SetStatusText(const char* text) void AsyncRefreshProgressCallback::SetProgressRange(u32 range) { - BaseProgressCallback::SetProgressRange(range); + ProgressCallback::SetProgressRange(range); if (static_cast(m_progress_range) == m_last_range) return; @@ -41,7 +44,7 @@ void AsyncRefreshProgressCallback::SetProgressRange(u32 range) void AsyncRefreshProgressCallback::SetProgressValue(u32 value) { - BaseProgressCallback::SetProgressValue(value); + ProgressCallback::SetProgressValue(value); if (static_cast(m_progress_value) == m_last_value) return; @@ -49,41 +52,20 @@ void AsyncRefreshProgressCallback::SetProgressValue(u32 value) fireUpdate(); } -void AsyncRefreshProgressCallback::SetTitle(const char* title) {} - -void AsyncRefreshProgressCallback::DisplayError(const char* message) +void AsyncRefreshProgressCallback::ModalError(const std::string_view message) { - QMessageBox::critical(nullptr, QStringLiteral("Error"), QString::fromUtf8(message)); + QMessageBox::critical(nullptr, QStringLiteral("Error"), QtUtils::StringViewToQString(message)); } -void AsyncRefreshProgressCallback::DisplayWarning(const char* message) +bool AsyncRefreshProgressCallback::ModalConfirmation(const std::string_view message) { - QMessageBox::warning(nullptr, QStringLiteral("Warning"), QString::fromUtf8(message)); + return QMessageBox::question(nullptr, QStringLiteral("Question"), QtUtils::StringViewToQString(message)) == + QMessageBox::Yes; } -void AsyncRefreshProgressCallback::DisplayInformation(const char* message) +void AsyncRefreshProgressCallback::ModalInformation(const std::string_view message) { - QMessageBox::information(nullptr, QStringLiteral("Information"), QString::fromUtf8(message)); -} - -void AsyncRefreshProgressCallback::DisplayDebugMessage(const char* message) -{ - Log::Write("AsyncRefreshProgressCallback", "", LOGLEVEL_DEV, message); -} - -void AsyncRefreshProgressCallback::ModalError(const char* message) -{ - QMessageBox::critical(nullptr, QStringLiteral("Error"), QString::fromUtf8(message)); -} - -bool AsyncRefreshProgressCallback::ModalConfirmation(const char* message) -{ - return QMessageBox::question(nullptr, QStringLiteral("Question"), QString::fromUtf8(message)) == QMessageBox::Yes; -} - -void AsyncRefreshProgressCallback::ModalInformation(const char* message) -{ - QMessageBox::information(nullptr, QStringLiteral("Information"), QString::fromUtf8(message)); + QMessageBox::information(nullptr, QStringLiteral("Information"), QtUtils::StringViewToQString(message)); } void AsyncRefreshProgressCallback::fireUpdate() diff --git a/src/duckstation-qt/gamelistrefreshthread.h b/src/duckstation-qt/gamelistrefreshthread.h index 5876d2cab..647281209 100644 --- a/src/duckstation-qt/gamelistrefreshthread.h +++ b/src/duckstation-qt/gamelistrefreshthread.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -11,24 +11,20 @@ class GameListRefreshThread; -class AsyncRefreshProgressCallback : public BaseProgressCallback +class AsyncRefreshProgressCallback : public ProgressCallback { public: AsyncRefreshProgressCallback(GameListRefreshThread* parent); void Cancel(); - void SetStatusText(const char* text) override; + void SetStatusText(const std::string_view text) override; void SetProgressRange(u32 range) override; void SetProgressValue(u32 value) override; - void SetTitle(const char* title) override; - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; + + void ModalError(const std::string_view message) override; + bool ModalConfirmation(const std::string_view message) override; + void ModalInformation(const std::string_view message) override; private: void fireUpdate(); diff --git a/src/duckstation-qt/qtprogresscallback.cpp b/src/duckstation-qt/qtprogresscallback.cpp index 832e72755..18fe69844 100644 --- a/src/duckstation-qt/qtprogresscallback.cpp +++ b/src/duckstation-qt/qtprogresscallback.cpp @@ -1,8 +1,11 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "qtprogresscallback.h" +#include "qtutils.h" + #include "common/assert.h" + #include #include #include @@ -27,27 +30,27 @@ void QtModalProgressCallback::SetCancellable(bool cancellable) if (m_cancellable == cancellable) return; - BaseProgressCallback::SetCancellable(cancellable); + ProgressCallback::SetCancellable(cancellable); m_dialog.setCancelButtonText(cancellable ? tr("Cancel") : QString()); } -void QtModalProgressCallback::SetTitle(const char* title) +void QtModalProgressCallback::SetTitle(const std::string_view title) { - m_dialog.setWindowTitle(QString::fromUtf8(title)); + m_dialog.setWindowTitle(QtUtils::StringViewToQString(title)); } -void QtModalProgressCallback::SetStatusText(const char* text) +void QtModalProgressCallback::SetStatusText(const std::string_view text) { - BaseProgressCallback::SetStatusText(text); + ProgressCallback::SetStatusText(text); checkForDelayedShow(); if (m_dialog.isVisible()) - m_dialog.setLabelText(QString::fromUtf8(text)); + m_dialog.setLabelText(QtUtils::StringViewToQString(text)); } void QtModalProgressCallback::SetProgressRange(u32 range) { - BaseProgressCallback::SetProgressRange(range); + ProgressCallback::SetProgressRange(range); checkForDelayedShow(); if (m_dialog.isVisible()) @@ -56,7 +59,7 @@ void QtModalProgressCallback::SetProgressRange(u32 range) void QtModalProgressCallback::SetProgressValue(u32 value) { - BaseProgressCallback::SetProgressValue(value); + ProgressCallback::SetProgressValue(value); checkForDelayedShow(); if (m_dialog.isVisible() && static_cast(m_dialog.value()) != m_progress_range) @@ -65,40 +68,20 @@ void QtModalProgressCallback::SetProgressValue(u32 value) QCoreApplication::processEvents(); } -void QtModalProgressCallback::DisplayError(const char* message) +void QtModalProgressCallback::ModalError(const std::string_view message) { - qWarning() << message; + QMessageBox::critical(&m_dialog, tr("Error"), QtUtils::StringViewToQString(message)); } -void QtModalProgressCallback::DisplayWarning(const char* message) +bool QtModalProgressCallback::ModalConfirmation(const std::string_view message) { - qWarning() << message; -} - -void QtModalProgressCallback::DisplayInformation(const char* message) -{ - qWarning() << message; -} - -void QtModalProgressCallback::DisplayDebugMessage(const char* message) -{ - qWarning() << message; -} - -void QtModalProgressCallback::ModalError(const char* message) -{ - QMessageBox::critical(&m_dialog, tr("Error"), QString::fromUtf8(message)); -} - -bool QtModalProgressCallback::ModalConfirmation(const char* message) -{ - return (QMessageBox::question(&m_dialog, tr("Question"), QString::fromUtf8(message), QMessageBox::Yes, + return (QMessageBox::question(&m_dialog, tr("Question"), QtUtils::StringViewToQString(message), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes); } -void QtModalProgressCallback::ModalInformation(const char* message) +void QtModalProgressCallback::ModalInformation(const std::string_view message) { - QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message)); + QMessageBox::information(&m_dialog, tr("Information"), QtUtils::StringViewToQString(message)); } void QtModalProgressCallback::dialogCancelled() @@ -120,7 +103,9 @@ void QtModalProgressCallback::checkForDelayedShow() } // NOTE: We deliberately don't set the thread parent, because otherwise we can't move it. -QtAsyncProgressThread::QtAsyncProgressThread(QWidget* parent) : QThread() {} +QtAsyncProgressThread::QtAsyncProgressThread(QWidget* parent) : QThread() +{ +} QtAsyncProgressThread::~QtAsyncProgressThread() = default; @@ -134,66 +119,46 @@ void QtAsyncProgressThread::SetCancellable(bool cancellable) if (m_cancellable == cancellable) return; - BaseProgressCallback::SetCancellable(cancellable); + ProgressCallback::SetCancellable(cancellable); } -void QtAsyncProgressThread::SetTitle(const char* title) +void QtAsyncProgressThread::SetTitle(const std::string_view title) { - emit titleUpdated(QString::fromUtf8(title)); + emit titleUpdated(QtUtils::StringViewToQString(title)); } -void QtAsyncProgressThread::SetStatusText(const char* text) +void QtAsyncProgressThread::SetStatusText(const std::string_view text) { - BaseProgressCallback::SetStatusText(text); - emit statusUpdated(QString::fromUtf8(text)); + ProgressCallback::SetStatusText(text); + emit statusUpdated(QtUtils::StringViewToQString(text)); } void QtAsyncProgressThread::SetProgressRange(u32 range) { - BaseProgressCallback::SetProgressRange(range); + ProgressCallback::SetProgressRange(range); emit progressUpdated(static_cast(m_progress_value), static_cast(m_progress_range)); } void QtAsyncProgressThread::SetProgressValue(u32 value) { - BaseProgressCallback::SetProgressValue(value); + ProgressCallback::SetProgressValue(value); emit progressUpdated(static_cast(m_progress_value), static_cast(m_progress_range)); } -void QtAsyncProgressThread::DisplayError(const char* message) +void QtAsyncProgressThread::ModalError(const std::string_view message) { - qWarning() << message; + QMessageBox::critical(parentWidget(), tr("Error"), QtUtils::StringViewToQString(message)); } -void QtAsyncProgressThread::DisplayWarning(const char* message) +bool QtAsyncProgressThread::ModalConfirmation(const std::string_view message) { - qWarning() << message; -} - -void QtAsyncProgressThread::DisplayInformation(const char* message) -{ - qWarning() << message; -} - -void QtAsyncProgressThread::DisplayDebugMessage(const char* message) -{ - qWarning() << message; -} - -void QtAsyncProgressThread::ModalError(const char* message) -{ - QMessageBox::critical(parentWidget(), tr("Error"), QString::fromUtf8(message)); -} - -bool QtAsyncProgressThread::ModalConfirmation(const char* message) -{ - return (QMessageBox::question(parentWidget(), tr("Question"), QString::fromUtf8(message), QMessageBox::Yes, + return (QMessageBox::question(parentWidget(), tr("Question"), QtUtils::StringViewToQString(message), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes); } -void QtAsyncProgressThread::ModalInformation(const char* message) +void QtAsyncProgressThread::ModalInformation(const std::string_view message) { - QMessageBox::information(parentWidget(), tr("Information"), QString::fromUtf8(message)); + QMessageBox::information(parentWidget(), tr("Information"), QtUtils::StringViewToQString(message)); } void QtAsyncProgressThread::start() diff --git a/src/duckstation-qt/qtprogresscallback.h b/src/duckstation-qt/qtprogresscallback.h index 98ab41e97..1733622d2 100644 --- a/src/duckstation-qt/qtprogresscallback.h +++ b/src/duckstation-qt/qtprogresscallback.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -11,7 +11,7 @@ #include #include -class QtModalProgressCallback final : public QObject, public BaseProgressCallback +class QtModalProgressCallback final : public QObject, public ProgressCallback { Q_OBJECT @@ -22,19 +22,14 @@ public: QProgressDialog& GetDialog() { return m_dialog; } void SetCancellable(bool cancellable) override; - void SetTitle(const char* title) override; - void SetStatusText(const char* text) override; + void SetTitle(const std::string_view title) override; + void SetStatusText(const std::string_view text) override; void SetProgressRange(u32 range) override; void SetProgressValue(u32 value) override; - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; - - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; + void ModalError(const std::string_view message) override; + bool ModalConfirmation(const std::string_view message) override; + void ModalInformation(const std::string_view message) override; private Q_SLOTS: void dialogCancelled(); @@ -47,7 +42,7 @@ private: float m_show_delay; }; -class QtAsyncProgressThread : public QThread, public BaseProgressCallback +class QtAsyncProgressThread : public QThread, public ProgressCallback { Q_OBJECT @@ -58,19 +53,14 @@ public: bool IsCancelled() const override; void SetCancellable(bool cancellable) override; - void SetTitle(const char* title) override; - void SetStatusText(const char* text) override; + void SetTitle(const std::string_view title) override; + void SetStatusText(const std::string_view text) override; void SetProgressRange(u32 range) override; void SetProgressValue(u32 value) override; - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; - - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; + void ModalError(const std::string_view message) override; + bool ModalConfirmation(const std::string_view message) override; + void ModalInformation(const std::string_view message) override; Q_SIGNALS: void titleUpdated(const QString& title); diff --git a/src/updater/cocoa_main.mm b/src/updater/cocoa_main.mm index bd5aa1bab..5df36a6c8 100644 --- a/src/updater/cocoa_main.mm +++ b/src/updater/cocoa_main.mm @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) if (!updater.OpenUpdateZip(zip_path.c_str())) { - progress.DisplayFormattedModalError("Could not open update zip '%s'. Update not installed.", zip_path.c_str()); + progress.FormatModalError("Could not open update zip '{}'. Update not installed.", zip_path); result = EXIT_FAILURE; return; } @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) if (result == EXIT_SUCCESS) { - progress.DisplayFormattedInformation("Launching '%s'...", program_to_launch.c_str()); + progress.FormatInformation("Launching '{}'...", program_to_launch); LaunchApplication(program_to_launch.c_str()); } diff --git a/src/updater/cocoa_progress_callback.h b/src/updater/cocoa_progress_callback.h index 689c3045b..8acf054a3 100644 --- a/src/updater/cocoa_progress_callback.h +++ b/src/updater/cocoa_progress_callback.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -16,7 +16,7 @@ #error ARC should not be enabled. #endif -class CocoaProgressCallback final : public BaseProgressCallback +class CocoaProgressCallback final : public ProgressCallback { public: CocoaProgressCallback(); @@ -26,19 +26,19 @@ public: void PopState() override; void SetCancellable(bool cancellable) override; - void SetTitle(const char* title) override; - void SetStatusText(const char* text) override; + void SetTitle(const std::string_view title) override; + void SetStatusText(const std::string_view text) override; void SetProgressRange(u32 range) override; void SetProgressValue(u32 value) override; - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; + void DisplayError(const std::string_view message) override; + void DisplayWarning(const std::string_view message) override; + void DisplayInformation(const std::string_view message) override; + void DisplayDebugMessage(const std::string_view message) override; - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; + void ModalError(const std::string_view message) override; + bool ModalConfirmation(const std::string_view message) override; + void ModalInformation(const std::string_view message) override; private: enum : int @@ -53,7 +53,7 @@ private: bool Create(); void Destroy(); void UpdateProgress(); - void AppendMessage(const char* message); + void AppendMessage(const std::string_view message); NSWindow* m_window = nil; NSView* m_view = nil; diff --git a/src/updater/cocoa_progress_callback.mm b/src/updater/cocoa_progress_callback.mm index ade99927a..495823e6d 100644 --- a/src/updater/cocoa_progress_callback.mm +++ b/src/updater/cocoa_progress_callback.mm @@ -1,13 +1,14 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "cocoa_progress_callback.h" +#include "common/cocoa_tools.h" #include "common/log.h" Log_SetChannel(CocoaProgressCallback); -CocoaProgressCallback::CocoaProgressCallback() : BaseProgressCallback() +CocoaProgressCallback::CocoaProgressCallback() : ProgressCallback() { Create(); } @@ -19,46 +20,50 @@ CocoaProgressCallback::~CocoaProgressCallback() void CocoaProgressCallback::PushState() { - BaseProgressCallback::PushState(); + ProgressCallback::PushState(); } void CocoaProgressCallback::PopState() { - BaseProgressCallback::PopState(); + ProgressCallback::PopState(); UpdateProgress(); } void CocoaProgressCallback::SetCancellable(bool cancellable) { - BaseProgressCallback::SetCancellable(cancellable); + ProgressCallback::SetCancellable(cancellable); } -void CocoaProgressCallback::SetTitle(const char* title) +void CocoaProgressCallback::SetTitle(const std::string_view title) { - dispatch_async(dispatch_get_main_queue(), [this, title = [[NSString alloc] initWithUTF8String:title]]() { - [m_window setTitle:title]; - [title release]; - }); + @autoreleasepool { + dispatch_async(dispatch_get_main_queue(), [this, title = [CocoaTools::StringViewToNSString(title) retain]]() { + [m_window setTitle:title]; + [title release]; + }); + } } -void CocoaProgressCallback::SetStatusText(const char* text) +void CocoaProgressCallback::SetStatusText(const std::string_view text) { - BaseProgressCallback::SetStatusText(text); - dispatch_async(dispatch_get_main_queue(), [this, title = [[NSString alloc] initWithUTF8String:text]]() { - [m_status setStringValue:title]; - [title release]; - }); + ProgressCallback::SetStatusText(text); + @autoreleasepool { + dispatch_async(dispatch_get_main_queue(), [this, text = [CocoaTools::StringViewToNSString(text) retain]]() { + [m_status setStringValue:text]; + [text release]; + }); + } } void CocoaProgressCallback::SetProgressRange(u32 range) { - BaseProgressCallback::SetProgressRange(range); + ProgressCallback::SetProgressRange(range); UpdateProgress(); } void CocoaProgressCallback::SetProgressValue(u32 value) { - BaseProgressCallback::SetProgressValue(value); + ProgressCallback::SetProgressValue(value); UpdateProgress(); } @@ -148,30 +153,29 @@ void CocoaProgressCallback::UpdateProgress() }); } -void CocoaProgressCallback::DisplayError(const char* message) +void CocoaProgressCallback::DisplayError(const std::string_view message) { ERROR_LOG(message); AppendMessage(message); } -void CocoaProgressCallback::DisplayWarning(const char* message) +void CocoaProgressCallback::DisplayWarning(const std::string_view message) { WARNING_LOG(message); AppendMessage(message); } -void CocoaProgressCallback::DisplayInformation(const char* message) +void CocoaProgressCallback::DisplayInformation(const std::string_view message) { INFO_LOG(message); AppendMessage(message); } -void CocoaProgressCallback::AppendMessage(const char* message) +void CocoaProgressCallback::AppendMessage(const std::string_view message) { @autoreleasepool { - NSString* nsmessage = [[[NSString stringWithUTF8String:message] stringByAppendingString:@"\n"] retain]; - dispatch_async(dispatch_get_main_queue(), [this, nsmessage]() { + dispatch_async(dispatch_get_main_queue(), [this, nsmessage = [CocoaTools::StringViewToNSString(message) retain]]() { @autoreleasepool { NSAttributedString* attr = [[[NSAttributedString alloc] initWithString:nsmessage] autorelease]; @@ -183,12 +187,12 @@ void CocoaProgressCallback::AppendMessage(const char* message) } } -void CocoaProgressCallback::DisplayDebugMessage(const char* message) +void CocoaProgressCallback::DisplayDebugMessage(const std::string_view message) { DEV_LOG(message); } -void CocoaProgressCallback::ModalError(const char* message) +void CocoaProgressCallback::ModalError(const std::string_view message) { if (![NSThread isMainThread]) { @@ -199,13 +203,13 @@ void CocoaProgressCallback::ModalError(const char* message) @autoreleasepool { NSAlert* alert = [[[NSAlert alloc] init] autorelease]; - [alert setMessageText:[NSString stringWithUTF8String:message]]; + [alert setMessageText:CocoaTools::StringViewToNSString(message)]; [alert setAlertStyle:NSAlertStyleCritical]; [alert runModal]; } } -bool CocoaProgressCallback::ModalConfirmation(const char* message) +bool CocoaProgressCallback::ModalConfirmation(const std::string_view message) { if (![NSThread isMainThread]) { @@ -218,7 +222,7 @@ bool CocoaProgressCallback::ModalConfirmation(const char* message) @autoreleasepool { NSAlert* alert = [[[NSAlert alloc] init] autorelease]; - [alert setMessageText:[NSString stringWithUTF8String:message]]; + [alert setMessageText:CocoaTools::StringViewToNSString(message)]; [alert addButtonWithTitle:@"Yes"]; [alert addButtonWithTitle:@"No"]; result = ([alert runModal] == NSAlertFirstButtonReturn); @@ -227,7 +231,7 @@ bool CocoaProgressCallback::ModalConfirmation(const char* message) return result; } -void CocoaProgressCallback::ModalInformation(const char* message) +void CocoaProgressCallback::ModalInformation(const std::string_view message) { if (![NSThread isMainThread]) { @@ -238,7 +242,7 @@ void CocoaProgressCallback::ModalInformation(const char* message) @autoreleasepool { NSAlert* alert = [[[NSAlert alloc] init] autorelease]; - [alert setMessageText:[NSString stringWithUTF8String:message]]; + [alert setMessageText:CocoaTools::StringViewToNSString(message)]; [alert runModal]; } } diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index 06722d785..2501f9ead 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -46,8 +46,8 @@ bool Updater::Initialize(std::string staging_directory, std::string destination_ { m_staging_directory = std::move(staging_directory); m_destination_directory = std::move(destination_directory); - m_progress->DisplayFormattedInformation("Destination directory: '%s'", m_destination_directory.c_str()); - m_progress->DisplayFormattedInformation("Staging directory: '%s'", m_staging_directory.c_str()); + m_progress->FormatInformation("Destination directory: '{}'", m_destination_directory); + m_progress->FormatInformation("Staging directory: '{}'", m_staging_directory); return true; } @@ -80,7 +80,7 @@ void Updater::RemoveUpdateZip() CloseUpdateZip(); if (!FileSystem::DeleteFile(m_zip_path.c_str())) - m_progress->DisplayFormattedError("Failed to remove update zip '%s'", m_zip_path.c_str()); + m_progress->FormatError("Failed to remove update zip '{}'", m_zip_path); } bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) @@ -93,7 +93,8 @@ bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) HRESULT hr = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL, IID_PPV_ARGS(fo.ReleaseAndGetAddressOf())); if (FAILED(hr)) { - m_progress->DisplayFormattedError("CoCreateInstance() for IFileOperation failed: %08X", hr); + m_progress->FormatError("CoCreateInstance() for IFileOperation failed: {}", + Error::CreateHResult(hr).GetDescription()); return false; } @@ -102,18 +103,22 @@ bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) IID_PPV_ARGS(item.ReleaseAndGetAddressOf())); if (FAILED(hr)) { - m_progress->DisplayFormattedError("SHCreateItemFromParsingName() for delete failed: %08X", hr); + m_progress->FormatError("SHCreateItemFromParsingName() for delete failed: {}", + Error::CreateHResult(hr).GetDescription()); return false; } hr = fo->SetOperationFlags(FOF_NOCONFIRMATION | FOF_SILENT); if (FAILED(hr)) - m_progress->DisplayFormattedWarning("IFileOperation::SetOperationFlags() failed: %08X", hr); + { + m_progress->FormatWarning("IFileOperation::SetOperationFlags() failed: {}", + Error::CreateHResult(hr).GetDescription()); + } hr = fo->DeleteItem(item.Get(), nullptr); if (FAILED(hr)) { - m_progress->DisplayFormattedError("IFileOperation::DeleteItem() failed: %08X", hr); + m_progress->FormatError("IFileOperation::DeleteItem() failed: {}", Error::CreateHResult(hr).GetDescription()); return false; } @@ -121,7 +126,8 @@ bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) hr = fo->PerformOperations(); if (FAILED(hr)) { - m_progress->DisplayFormattedError("IFileOperation::PerformOperations() failed: %08X", hr); + m_progress->FormatError("IFileOperation::PerformOperations() failed: {}", + Error::CreateHResult(hr).GetDescription()); return false; } @@ -140,7 +146,7 @@ bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) } else { - m_progress->DisplayFormattedInformation("Removing directory '%s'.", fd.FileName.c_str()); + m_progress->FormatInformation("Removing directory '{}'.", fd.FileName); if (!FileSystem::DeleteFile(fd.FileName.c_str())) return false; } @@ -150,7 +156,7 @@ bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) if (!remove_dir) return true; - m_progress->DisplayFormattedInformation("Removing directory '%s'.", path); + m_progress->FormatInformation("Removing directory '{}'.", path); return FileSystem::DeleteDirectory(path); #endif } @@ -216,7 +222,7 @@ bool Updater::ParseZip() if (process_file) { entry.destination_filename = filename_to_add; - m_progress->DisplayFormattedInformation("Found file in zip: '%s'", entry.destination_filename.c_str()); + m_progress->FormatInformation("Found file in zip: '{}'", entry.destination_filename); m_update_paths.push_back(std::move(entry)); } } @@ -256,7 +262,7 @@ bool Updater::ParseZip() std::sort(m_update_directories.begin(), m_update_directories.end()); for (const std::string& dir : m_update_directories) - m_progress->DisplayFormattedDebugMessage("Directory: %s", dir.c_str()); + m_progress->FormatDebugMessage("Directory: {}", dir); return true; } @@ -265,7 +271,7 @@ bool Updater::PrepareStagingDirectory() { if (FileSystem::DirectoryExists(m_staging_directory.c_str())) { - m_progress->DisplayFormattedWarning("Update staging directory already exists, removing"); + m_progress->DisplayWarning("Update staging directory already exists, removing"); if (!RecursiveDeleteDirectory(m_staging_directory.c_str(), true) || FileSystem::DirectoryExists(m_staging_directory.c_str())) { @@ -275,19 +281,19 @@ bool Updater::PrepareStagingDirectory() } if (!FileSystem::CreateDirectory(m_staging_directory.c_str(), false)) { - m_progress->DisplayFormattedModalError("Failed to create staging directory %s", m_staging_directory.c_str()); + m_progress->FormatModalError("Failed to create staging directory {}", m_staging_directory); return false; } // create subdirectories in staging directory for (const std::string& subdir : m_update_directories) { - m_progress->DisplayFormattedInformation("Creating subdirectory in staging: %s", subdir.c_str()); + m_progress->FormatInformation("Creating subdirectory in staging: {}", subdir); const std::string staging_subdir = Path::Combine(m_staging_directory, subdir); if (!FileSystem::CreateDirectory(staging_subdir.c_str(), false)) { - m_progress->DisplayFormattedModalError("Failed to create staging subdirectory %s", staging_subdir.c_str()); + m_progress->FormatModalError("Failed to create staging subdirectory {}", staging_subdir); return false; } } @@ -302,27 +308,26 @@ bool Updater::StageUpdate() for (const FileToUpdate& ftu : m_update_paths) { - m_progress->SetFormattedStatusText("Extracting '%s' (mode %o)...", ftu.original_zip_filename.c_str(), - ftu.file_mode); + m_progress->FormatStatusText("Extracting '{}' (mode {:o})...", ftu.original_zip_filename, ftu.file_mode); if (unzLocateFile(m_zf, ftu.original_zip_filename.c_str(), 0) != UNZ_OK) { - m_progress->DisplayFormattedModalError("Unable to locate file '%s' in zip", ftu.original_zip_filename.c_str()); + m_progress->FormatModalError("Unable to locate file '{}' in zip", ftu.original_zip_filename); return false; } else if (unzOpenCurrentFile(m_zf) != UNZ_OK) { - m_progress->DisplayFormattedModalError("Failed to open file '%s' in zip", ftu.original_zip_filename.c_str()); + m_progress->FormatModalError("Failed to open file '{}' in zip", ftu.original_zip_filename); return false; } - m_progress->DisplayFormattedInformation("Extracting '%s'...", ftu.destination_filename.c_str()); + m_progress->FormatInformation("Extracting '{}'...", ftu.destination_filename); const std::string destination_file = Path::Combine(m_staging_directory, ftu.destination_filename); std::FILE* fp = FileSystem::OpenCFile(destination_file.c_str(), "wb"); if (!fp) { - m_progress->DisplayFormattedModalError("Failed to open staging output file '%s'", destination_file.c_str()); + m_progress->FormatModalError("Failed to open staging output file '{}'", destination_file); unzCloseCurrentFile(m_zf); return false; } @@ -334,7 +339,7 @@ bool Updater::StageUpdate() int byte_count = unzReadCurrentFile(m_zf, buffer, CHUNK_SIZE); if (byte_count < 0) { - m_progress->DisplayFormattedModalError("Failed to read file '%s' from zip", ftu.original_zip_filename.c_str()); + m_progress->FormatModalError("Failed to read file '{}' from zip", ftu.original_zip_filename); std::fclose(fp); FileSystem::DeleteFile(destination_file.c_str()); unzCloseCurrentFile(m_zf); @@ -348,7 +353,7 @@ bool Updater::StageUpdate() if (std::fwrite(buffer, static_cast(byte_count), 1, fp) != 1) { - m_progress->DisplayFormattedModalError("Failed to write to file '%s'", destination_file.c_str()); + m_progress->FormatModalError("Failed to write to file '{}'", destination_file); std::fclose(fp); FileSystem::DeleteFile(destination_file.c_str()); unzCloseCurrentFile(m_zf); @@ -363,8 +368,8 @@ bool Updater::StageUpdate() const int res = (fd >= 0) ? fchmod(fd, ftu.file_mode) : -1; if (res < 0) { - m_progress->DisplayFormattedModalError("Failed to set mode for file '%s' (fd %d) to %u: errno %d", - destination_file.c_str(), fd, res, errno); + m_progress->FormatModalError("Failed to set mode for file '{}' (fd {}) to {:o}: errno {}", destination_file, fd, + res, errno); std::fclose(fp); FileSystem::DeleteFile(destination_file.c_str()); unzCloseCurrentFile(m_zf); @@ -391,7 +396,7 @@ bool Updater::CommitUpdate() const std::string dest_subdir = Path::Combine(m_destination_directory, subdir); if (!FileSystem::DirectoryExists(dest_subdir.c_str()) && !FileSystem::CreateDirectory(dest_subdir.c_str(), false)) { - m_progress->DisplayFormattedModalError("Failed to create target directory '%s'", dest_subdir.c_str()); + m_progress->FormatModalError("Failed to create target directory '{}'", dest_subdir); return false; } } @@ -401,7 +406,7 @@ bool Updater::CommitUpdate() { const std::string staging_file_name = Path::Combine(m_staging_directory, ftu.destination_filename); const std::string dest_file_name = Path::Combine(m_destination_directory, ftu.destination_filename); - m_progress->DisplayFormattedInformation("Moving '%s' to '%s'", staging_file_name.c_str(), dest_file_name.c_str()); + m_progress->FormatInformation("Moving '{}' to '{}'", staging_file_name, dest_file_name); Error error; #ifdef _WIN32 @@ -413,11 +418,13 @@ bool Updater::CommitUpdate() const bool result = CocoaTools::MoveFile(staging_file_name.c_str(), dest_file_name.c_str(), &error); #else const bool result = (rename(staging_file_name.c_str(), dest_file_name.c_str()) == 0); + if (!result) + error.SetErrno(errno); #endif if (!result) { - m_progress->DisplayFormattedModalError("Failed to rename '%s' to '%s': %s", staging_file_name.c_str(), - dest_file_name.c_str(), error.GetDescription().c_str()); + m_progress->FormatModalError("Failed to rename '{}' to '{}': {}", staging_file_name, dest_file_name, + error.GetDescription()); return false; } } @@ -429,7 +436,7 @@ void Updater::CleanupStagingDirectory() { // remove staging directory itself if (!RecursiveDeleteDirectory(m_staging_directory.c_str(), true)) - m_progress->DisplayFormattedError("Failed to remove staging directory '%s'", m_staging_directory.c_str()); + m_progress->FormatError("Failed to remove staging directory '{}'", m_staging_directory); } bool Updater::ClearDestinationDirectory() diff --git a/src/updater/win32_main.cpp b/src/updater/win32_main.cpp index e38152883..08728d97f 100644 --- a/src/updater/win32_main.cpp +++ b/src/updater/win32_main.cpp @@ -65,7 +65,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi Log::SetFileOutputParams(true, Path::Combine(destination_directory, "updater.log").c_str()); - progress.SetFormattedStatusText("Waiting for parent process %d to exit...", parent_process_id); + progress.FormatStatusText("Waiting for parent process {} to exit...", parent_process_id); WaitForProcessToExit(parent_process_id); Updater updater(&progress); @@ -77,7 +77,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi if (!updater.OpenUpdateZip(zip_path.c_str())) { - progress.DisplayFormattedModalError("Could not open update zip '%s'. Update not installed.", zip_path.c_str()); + progress.FormatModalError("Could not open update zip '{}'. Update not installed.", zip_path); return 1; } @@ -103,8 +103,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi updater.CleanupStagingDirectory(); updater.RemoveUpdateZip(); - progress.DisplayFormattedInformation("Launching '%s'...", - StringUtil::WideStringToUTF8String(program_to_launch).c_str()); + progress.FormatInformation("Launching '{}'...", StringUtil::WideStringToUTF8String(program_to_launch)); ShellExecuteW(nullptr, L"open", program_to_launch.c_str(), L"-updatecleanup", nullptr, SW_SHOWNORMAL); return 0; } diff --git a/src/updater/win32_progress_callback.cpp b/src/updater/win32_progress_callback.cpp index 79ad2beee..e35742e16 100644 --- a/src/updater/win32_progress_callback.cpp +++ b/src/updater/win32_progress_callback.cpp @@ -1,53 +1,57 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "win32_progress_callback.h" + #include "common/log.h" +#include "common/string_util.h" + #include + Log_SetChannel(Win32ProgressCallback); -Win32ProgressCallback::Win32ProgressCallback() : BaseProgressCallback() +Win32ProgressCallback::Win32ProgressCallback() : ProgressCallback() { Create(); } void Win32ProgressCallback::PushState() { - BaseProgressCallback::PushState(); + ProgressCallback::PushState(); } void Win32ProgressCallback::PopState() { - BaseProgressCallback::PopState(); + ProgressCallback::PopState(); Redraw(true); } void Win32ProgressCallback::SetCancellable(bool cancellable) { - BaseProgressCallback::SetCancellable(cancellable); + ProgressCallback::SetCancellable(cancellable); Redraw(true); } -void Win32ProgressCallback::SetTitle(const char* title) +void Win32ProgressCallback::SetTitle(const std::string_view title) { - SetWindowTextA(m_window_hwnd, title); + SetWindowTextW(m_window_hwnd, StringUtil::UTF8StringToWideString(title).c_str()); } -void Win32ProgressCallback::SetStatusText(const char* text) +void Win32ProgressCallback::SetStatusText(const std::string_view text) { - BaseProgressCallback::SetStatusText(text); + ProgressCallback::SetStatusText(text); Redraw(true); } void Win32ProgressCallback::SetProgressRange(u32 range) { - BaseProgressCallback::SetProgressRange(range); + ProgressCallback::SetProgressRange(range); Redraw(false); } void Win32ProgressCallback::SetProgressValue(u32 value) { - BaseProgressCallback::SetProgressValue(value); + ProgressCallback::SetProgressValue(value); Redraw(false); } @@ -185,51 +189,56 @@ LRESULT CALLBACK Win32ProgressCallback::WndProc(HWND hwnd, UINT msg, WPARAM wpar return 0; } -void Win32ProgressCallback::DisplayError(const char* message) +void Win32ProgressCallback::DisplayError(const std::string_view message) { ERROR_LOG(message); - SendMessageA(m_list_box_hwnd, LB_ADDSTRING, 0, reinterpret_cast(message)); - SendMessageA(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0); + SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0, + reinterpret_cast(StringUtil::UTF8StringToWideString(message).c_str())); + SendMessageW(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0); PumpMessages(); } -void Win32ProgressCallback::DisplayWarning(const char* message) +void Win32ProgressCallback::DisplayWarning(const std::string_view message) { WARNING_LOG(message); - SendMessageA(m_list_box_hwnd, LB_ADDSTRING, 0, reinterpret_cast(message)); - SendMessageA(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0); + SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0, + reinterpret_cast(StringUtil::UTF8StringToWideString(message).c_str())); + SendMessageW(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0); PumpMessages(); } -void Win32ProgressCallback::DisplayInformation(const char* message) +void Win32ProgressCallback::DisplayInformation(const std::string_view message) { INFO_LOG(message); - SendMessageA(m_list_box_hwnd, LB_ADDSTRING, 0, reinterpret_cast(message)); - SendMessageA(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0); + SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0, + reinterpret_cast(StringUtil::UTF8StringToWideString(message).c_str())); + SendMessageW(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0); PumpMessages(); } -void Win32ProgressCallback::DisplayDebugMessage(const char* message) +void Win32ProgressCallback::DisplayDebugMessage(const std::string_view message) { DEV_LOG(message); } -void Win32ProgressCallback::ModalError(const char* message) +void Win32ProgressCallback::ModalError(const std::string_view message) { PumpMessages(); - MessageBoxA(m_window_hwnd, message, "Error", MB_ICONERROR | MB_OK); + MessageBoxW(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Error", MB_ICONERROR | MB_OK); PumpMessages(); } -bool Win32ProgressCallback::ModalConfirmation(const char* message) +bool Win32ProgressCallback::ModalConfirmation(const std::string_view message) { PumpMessages(); - bool result = MessageBoxA(m_window_hwnd, message, "Confirmation", MB_ICONQUESTION | MB_YESNO) == IDYES; + bool result = MessageBoxW(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Confirmation", + MB_ICONQUESTION | MB_YESNO) == IDYES; PumpMessages(); return result; } -void Win32ProgressCallback::ModalInformation(const char* message) +void Win32ProgressCallback::ModalInformation(const std::string_view message) { - MessageBoxA(m_window_hwnd, message, "Information", MB_ICONINFORMATION | MB_OK); + MessageBoxW(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Information", + MB_ICONINFORMATION | MB_OK); } diff --git a/src/updater/win32_progress_callback.h b/src/updater/win32_progress_callback.h index 12ecd2333..443426a61 100644 --- a/src/updater/win32_progress_callback.h +++ b/src/updater/win32_progress_callback.h @@ -1,11 +1,11 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once #include "common/progress_callback.h" #include "common/windows_headers.h" -class Win32ProgressCallback final : public BaseProgressCallback +class Win32ProgressCallback final : public ProgressCallback { public: Win32ProgressCallback(); @@ -14,19 +14,19 @@ public: void PopState() override; void SetCancellable(bool cancellable) override; - void SetTitle(const char* title) override; - void SetStatusText(const char* text) override; + void SetTitle(const std::string_view title) override; + void SetStatusText(const std::string_view text) override; void SetProgressRange(u32 range) override; void SetProgressValue(u32 value) override; - void DisplayError(const char* message) override; - void DisplayWarning(const char* message) override; - void DisplayInformation(const char* message) override; - void DisplayDebugMessage(const char* message) override; + void DisplayError(const std::string_view message) override; + void DisplayWarning(const std::string_view message) override; + void DisplayInformation(const std::string_view message) override; + void DisplayDebugMessage(const std::string_view message) override; - void ModalError(const char* message) override; - bool ModalConfirmation(const char* message) override; - void ModalInformation(const char* message) override; + void ModalError(const std::string_view message) override; + bool ModalConfirmation(const std::string_view message) override; + void ModalInformation(const std::string_view message) override; private: enum : int diff --git a/src/util/cd_image_hasher.cpp b/src/util/cd_image_hasher.cpp index f60052eea..f2a14398f 100644 --- a/src/util/cd_image_hasher.cpp +++ b/src/util/cd_image_hasher.cpp @@ -29,8 +29,7 @@ bool CDImageHasher::ReadIndex(CDImage* image, u8 track, u8 index, MD5Digest* dig if (!image->Seek(index_start)) { - progress_callback->DisplayFormattedModalError("Failed to seek to sector %u for track %u index %u", index_start, - track, index); + progress_callback->FormatModalError("Failed to seek to sector {} for track {} index {}", index_start, track, index); return false; } @@ -42,7 +41,7 @@ bool CDImageHasher::ReadIndex(CDImage* image, u8 track, u8 index, MD5Digest* dig if (!image->ReadRawSector(sector.data(), nullptr)) { - progress_callback->DisplayFormattedModalError("Failed to read sector %u from image", image->GetPositionOnDisc()); + progress_callback->FormatModalError("Failed to read sector {} from image", image->GetPositionOnDisc()); return false; } diff --git a/src/util/cd_image_memory.cpp b/src/util/cd_image_memory.cpp index 7c8a827f9..f29455b17 100644 --- a/src/util/cd_image_memory.cpp +++ b/src/util/cd_image_memory.cpp @@ -62,17 +62,17 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress) if ((static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors)) >= static_cast(std::numeric_limits::max())) { - progress->DisplayFormattedModalError("Insufficient address space"); + progress->ModalError("Insufficient address space"); return false; } - progress->SetFormattedStatusText("Allocating memory for %u sectors...", m_memory_sectors); + progress->FormatStatusText("Allocating memory for {} sectors...", m_memory_sectors); m_memory = static_cast(std::malloc(static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors))); if (!m_memory) { - progress->DisplayFormattedModalError("Failed to allocate memory for %u sectors", m_memory_sectors); + progress->FormatModalError("Failed to allocate memory for {} sectors", m_memory_sectors); return false; } diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index 936c32c8c..52fa184b7 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -417,7 +417,7 @@ void PostProcessing::Chain::LoadStages() } lock.unlock(); - progress.SetFormattedStatusText("Loading shader %s...", stage_name.c_str()); + progress.FormatStatusText("Loading shader {}...", stage_name); std::unique_ptr shader = TryLoadingShader(stage_name, false, &error); if (!shader) @@ -585,7 +585,7 @@ bool PostProcessing::Chain::CheckTargets(GPUTexture::Format target_format, u32 t { Shader* const shader = m_stages[i].get(); - progress->SetFormattedStatusText("Compiling %s...", shader->GetName().c_str()); + progress->FormatStatusText("Compiling {}...", shader->GetName()); if (!shader->CompilePipeline(target_format, target_width, target_height, progress) || !shader->ResizeOutput(target_format, target_width, target_height))