ProgressCallback: Remove modal methods

Still required for the updater, but I've moved that to an
updater-specific class in the heirarchy.
This commit is contained in:
Stenzek
2025-11-22 22:05:37 +10:00
parent 548887449e
commit 4290f75951
18 changed files with 71 additions and 174 deletions

View File

@@ -101,39 +101,3 @@ void ProgressCallback::IncrementProgressValue()
{
SetProgressValue((m_progress_value - m_base_progress_value) + 1);
}
void ProgressCallback::DisplayError(const std::string_view message)
{
ERROR_LOG(message);
}
void ProgressCallback::DisplayWarning(const std::string_view message)
{
WARNING_LOG(message);
}
void ProgressCallback::DisplayInformation(const std::string_view message)
{
INFO_LOG(message);
}
void ProgressCallback::DisplayDebugMessage(const std::string_view message)
{
DEV_LOG(message);
}
void ProgressCallback::ModalError(const std::string_view message)
{
ERROR_LOG(message);
}
bool ProgressCallback::ModalConfirmation(const std::string_view message)
{
INFO_LOG(message);
return false;
}
void ProgressCallback::ModalInformation(const std::string_view message)
{
INFO_LOG(message);
}

View File

@@ -30,15 +30,6 @@ public:
virtual void SetProgressValue(u32 value);
virtual void IncrementProgressValue();
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 ModalError(const std::string_view message);
virtual bool ModalConfirmation(const std::string_view message);
virtual void ModalInformation(const std::string_view message);
#define MAKE_PROGRESS_CALLBACK_FORWARDER(from, to) \
template<typename... T> \
void from(fmt::format_string<T...> fmt, T&&... args) \
@@ -49,13 +40,6 @@ public:
}
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);
#undef MAKE_PROGRESS_CALLBACK_FORWARDER

View File

@@ -55,10 +55,6 @@ public:
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) 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;
void SetCancelled();
private:
@@ -90,9 +86,6 @@ public:
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override;
void ModalError(const std::string_view message) override;
bool ModalConfirmation(const std::string_view message) override;
private:
void Redraw(bool force);

View File

@@ -4235,23 +4235,6 @@ void FullscreenUI::BackgroundProgressCallback::Redraw(bool force)
UpdateBackgroundProgressDialog(m_name, m_status_text, 0, 100, percent);
}
void FullscreenUI::BackgroundProgressCallback::ModalError(const std::string_view message)
{
Host::ReportErrorAsync("Error", message);
}
bool FullscreenUI::BackgroundProgressCallback::ModalConfirmation(const std::string_view message)
{
// Not used.
INFO_LOG(message);
return true;
}
void FullscreenUI::BackgroundProgressCallback::ModalInformation(const std::string_view message)
{
Host::ReportErrorAsync("Information", message);
}
void FullscreenUI::BackgroundProgressCallback::SetCancelled()
{
if (m_cancellable)
@@ -4662,19 +4645,6 @@ void FullscreenUI::LoadingScreenProgressCallback::Redraw(bool force)
m_last_progress_percent = percent;
}
void FullscreenUI::LoadingScreenProgressCallback::ModalError(const std::string_view message)
{
ERROR_LOG(message);
Host::ReportErrorAsync("Error", message);
}
bool FullscreenUI::LoadingScreenProgressCallback::ModalConfirmation(const std::string_view message)
{
// Not used.
INFO_LOG(message);
return true;
}
//////////////////////////////////////////////////////////////////////////
// Notifications
//////////////////////////////////////////////////////////////////////////

View File

@@ -79,25 +79,6 @@ void GameListRefreshThread::SetProgressValue(u32 value)
fireUpdate();
}
void GameListRefreshThread::ModalError(const std::string_view message)
{
// Not used.
WARNING_LOG(message);
}
bool GameListRefreshThread::ModalConfirmation(const std::string_view message)
{
// Not used.
WARNING_LOG(message);
return true;
}
void GameListRefreshThread::ModalInformation(const std::string_view message)
{
// Not used.
WARNING_LOG(message);
}
void GameListRefreshThread::fireUpdate()
{
emit refreshProgress(m_status_text, m_last_value, m_last_range, static_cast<int>(GameList::GetEntryCount()),

View File

@@ -33,10 +33,6 @@ private:
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) 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;
void fireUpdate();
Timer m_start_time;

View File

@@ -79,22 +79,6 @@ void QtModalProgressCallback::SetProgressValue(u32 value)
QCoreApplication::processEvents();
}
void QtModalProgressCallback::ModalError(const std::string_view message)
{
QtUtils::MessageBoxCritical(&m_dialog, m_dialog.windowTitle(), QtUtils::StringViewToQString(message));
}
bool QtModalProgressCallback::ModalConfirmation(const std::string_view message)
{
return (QtUtils::MessageBoxQuestion(&m_dialog, m_dialog.windowTitle(), QtUtils::StringViewToQString(message)) ==
QMessageBox::Yes);
}
void QtModalProgressCallback::ModalInformation(const std::string_view message)
{
QtUtils::MessageBoxInformation(&m_dialog, m_dialog.windowTitle(), QtUtils::StringViewToQString(message));
}
void QtModalProgressCallback::dialogCancelled()
{
m_cancelled = true;
@@ -161,22 +145,6 @@ void QtAsyncProgressThread::SetProgressValue(u32 value)
emit progressUpdated(static_cast<int>(m_progress_value), static_cast<int>(m_progress_range));
}
void QtAsyncProgressThread::ModalError(const std::string_view message)
{
QtUtils::MessageBoxCritical(parentWidget(), tr("Error"), QtUtils::StringViewToQString(message));
}
bool QtAsyncProgressThread::ModalConfirmation(const std::string_view message)
{
return (QtUtils::MessageBoxQuestion(parentWidget(), tr("Question"), QtUtils::StringViewToQString(message)) ==
QMessageBox::Yes);
}
void QtAsyncProgressThread::ModalInformation(const std::string_view message)
{
QtUtils::MessageBoxInformation(parentWidget(), tr("Information"), QtUtils::StringViewToQString(message));
}
void QtAsyncProgressThread::start()
{
Assert(!isRunning());

View File

@@ -27,10 +27,6 @@ public:
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) 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;
void MakeVisible();
private:
@@ -63,10 +59,6 @@ public:
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) 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;
void start();
void join();

View File

@@ -8,6 +8,7 @@ target_link_libraries(updater PRIVATE common minizip ZLIB::ZLIB)
if(WIN32)
target_sources(updater PRIVATE
updater.rc
updater_progress_callback.h
win32_main.cpp
win32_progress_callback.cpp
win32_progress_callback.h
@@ -22,6 +23,7 @@ if(APPLE)
cocoa_main.mm
cocoa_progress_callback.mm
cocoa_progress_callback.h
updater_progress_callback.h
)
target_sources(updater PRIVATE ${MAC_SOURCES})
set_source_files_properties(${MAC_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)

View File

@@ -3,7 +3,7 @@
#pragma once
#include "common/progress_callback.h"
#include "updater_progress_callback.h"
#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
@@ -16,7 +16,7 @@
#error ARC should not be enabled.
#endif
class CocoaProgressCallback final : public ProgressCallback
class CocoaProgressCallback final : public UpdaterProgressCallback
{
public:
CocoaProgressCallback();

View File

@@ -8,7 +8,7 @@
LOG_CHANNEL(Host);
CocoaProgressCallback::CocoaProgressCallback() : ProgressCallback()
CocoaProgressCallback::CocoaProgressCallback() : UpdaterProgressCallback()
{
Create();
}
@@ -20,18 +20,18 @@ CocoaProgressCallback::~CocoaProgressCallback()
void CocoaProgressCallback::PushState()
{
ProgressCallback::PushState();
UpdaterProgressCallback::PushState();
}
void CocoaProgressCallback::PopState()
{
ProgressCallback::PopState();
UpdaterProgressCallback::PopState();
UpdateProgress();
}
void CocoaProgressCallback::SetCancellable(bool cancellable)
{
ProgressCallback::SetCancellable(cancellable);
UpdaterProgressCallback::SetCancellable(cancellable);
}
void CocoaProgressCallback::SetTitle(const std::string_view title)
@@ -46,7 +46,7 @@ void CocoaProgressCallback::SetTitle(const std::string_view title)
void CocoaProgressCallback::SetStatusText(const std::string_view text)
{
ProgressCallback::SetStatusText(text);
UpdaterProgressCallback::SetStatusText(text);
@autoreleasepool {
dispatch_async(dispatch_get_main_queue(), [this, text = [CocoaTools::StringViewToNSString(text) retain]]() {
[m_status setStringValue:text];
@@ -57,13 +57,13 @@ void CocoaProgressCallback::SetStatusText(const std::string_view text)
void CocoaProgressCallback::SetProgressRange(u32 range)
{
ProgressCallback::SetProgressRange(range);
UpdaterProgressCallback::SetProgressRange(range);
UpdateProgress();
}
void CocoaProgressCallback::SetProgressValue(u32 value)
{
ProgressCallback::SetProgressValue(value);
UpdaterProgressCallback::SetProgressValue(value);
UpdateProgress();
}

View File

@@ -32,7 +32,7 @@
#include "common/cocoa_tools.h"
#endif
Updater::Updater(ProgressCallback* progress) : m_progress(progress)
Updater::Updater(UpdaterProgressCallback* progress) : m_progress(progress)
{
progress->SetTitle("DuckStation Update Installer");
}

View File

@@ -2,15 +2,18 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#pragma once
#include "common/progress_callback.h"
#include "updater_progress_callback.h"
#include "unzip.h"
#include <string>
#include <vector>
class Updater
{
public:
explicit Updater(ProgressCallback* progress);
explicit Updater(UpdaterProgressCallback* progress);
~Updater();
bool Initialize(std::string staging_directory, std::string destination_directory);
@@ -43,6 +46,6 @@ private:
std::vector<FileToUpdate> m_update_paths;
std::vector<std::string> m_update_directories;
ProgressCallback* m_progress;
UpdaterProgressCallback* m_progress;
unzFile m_zf = nullptr;
};

View File

@@ -13,6 +13,7 @@
<ItemGroup>
<ClInclude Include="resource.h" />
<ClInclude Include="updater.h" />
<ClInclude Include="updater_progress_callback.h" />
<ClInclude Include="win32_progress_callback.h" />
</ItemGroup>
<ItemGroup>

View File

@@ -13,6 +13,7 @@
<ClInclude Include="updater.h" />
<ClInclude Include="win32_progress_callback.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="updater_progress_callback.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="updater.rc" />

View File

@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#pragma once
#include "common/progress_callback.h"
class UpdaterProgressCallback : public ProgressCallback
{
public:
UpdaterProgressCallback() = default;
virtual ~UpdaterProgressCallback() override = default;
virtual void DisplayError(const std::string_view message) = 0;
virtual void DisplayWarning(const std::string_view message) = 0;
virtual void DisplayInformation(const std::string_view message) = 0;
virtual void DisplayDebugMessage(const std::string_view message) = 0;
virtual void ModalError(const std::string_view message) = 0;
virtual bool ModalConfirmation(const std::string_view message) = 0;
virtual void ModalInformation(const std::string_view message) = 0;
#define MAKE_PROGRESS_CALLBACK_FORWARDER(from, to) \
template<typename... T> \
void from(fmt::format_string<T...> fmt, T&&... args) \
{ \
TinyString str; \
fmt::vformat_to(std::back_inserter(str), fmt, fmt::make_format_args(args...)); \
to(str.view()); \
}
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);
#undef MAKE_PROGRESS_CALLBACK_FORWARDER
};

View File

@@ -12,7 +12,7 @@
LOG_CHANNEL(Host);
Win32ProgressCallback::Win32ProgressCallback() : ProgressCallback()
Win32ProgressCallback::Win32ProgressCallback() : UpdaterProgressCallback()
{
Create();
}
@@ -24,18 +24,18 @@ Win32ProgressCallback::~Win32ProgressCallback()
void Win32ProgressCallback::PushState()
{
ProgressCallback::PushState();
UpdaterProgressCallback::PushState();
}
void Win32ProgressCallback::PopState()
{
ProgressCallback::PopState();
UpdaterProgressCallback::PopState();
Redraw(true);
}
void Win32ProgressCallback::SetCancellable(bool cancellable)
{
ProgressCallback::SetCancellable(cancellable);
UpdaterProgressCallback::SetCancellable(cancellable);
Redraw(true);
}
@@ -46,19 +46,19 @@ void Win32ProgressCallback::SetTitle(const std::string_view title)
void Win32ProgressCallback::SetStatusText(const std::string_view text)
{
ProgressCallback::SetStatusText(text);
UpdaterProgressCallback::SetStatusText(text);
Redraw(true);
}
void Win32ProgressCallback::SetProgressRange(u32 range)
{
ProgressCallback::SetProgressRange(range);
UpdaterProgressCallback::SetProgressRange(range);
Redraw(false);
}
void Win32ProgressCallback::SetProgressValue(u32 value)
{
ProgressCallback::SetProgressValue(value);
UpdaterProgressCallback::SetProgressValue(value);
Redraw(false);
}

View File

@@ -2,10 +2,12 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#pragma once
#include "common/progress_callback.h"
#include "updater_progress_callback.h"
#include "common/windows_headers.h"
class Win32ProgressCallback final : public ProgressCallback
class Win32ProgressCallback final : public UpdaterProgressCallback
{
public:
Win32ProgressCallback();