ProgressCallback: Eliminate redundancy and drop C format strings

This commit is contained in:
Stenzek
2024-07-19 14:49:12 +10:00
parent 24ef76bfee
commit 6176a21ff1
20 changed files with 345 additions and 731 deletions

View File

@ -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());
}

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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;

View File

@ -1,13 +1,14 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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];
}
}

View File

@ -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<size_t>(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()

View File

@ -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;
}

View File

@ -1,53 +1,57 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 <CommCtrl.h>
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<LPARAM>(message));
SendMessageA(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(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<LPARAM>(message));
SendMessageA(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(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<LPARAM>(message));
SendMessageA(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(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);
}

View File

@ -1,11 +1,11 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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