diff --git a/src/xenia/base/cvar.cc b/src/xenia/base/cvar.cc index 2b9856a23..2f48c6c46 100644 --- a/src/xenia/base/cvar.cc +++ b/src/xenia/base/cvar.cc @@ -16,6 +16,7 @@ #include "xenia/base/logging.h" #include "xenia/base/main.h" +#include "xenia/base/system.h" namespace utfcpp = utf8; @@ -67,7 +68,8 @@ void ParseLaunchArguments(int& argc, char**& argv, if (xe::has_console_attached()) { PrintHelpAndExit(); } else { - xe::ShowInfoMessageBox(options.help({""})); + xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Help, + options.help({""})); exit(0); } } @@ -92,7 +94,7 @@ void ParseLaunchArguments(int& argc, char**& argv, } else { std::string m = "Invalid launch options were given.\n" + options.help({""}); - xe::ShowErrorMessageBox(m); + xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error, m); exit(0); } } diff --git a/src/xenia/base/logging.cc b/src/xenia/base/logging.cc index d928ec56a..02fa787a4 100644 --- a/src/xenia/base/logging.cc +++ b/src/xenia/base/logging.cc @@ -26,6 +26,7 @@ #include "xenia/base/memory.h" #include "xenia/base/ring_buffer.h" #include "xenia/base/string.h" +#include "xenia/base/system.h" #include "xenia/base/threading.h" // For MessageBox: @@ -353,28 +354,12 @@ void logging::AppendLogLine(LogLevel log_level, const char prefix_char, void FatalError(const std::string_view str) { logging::AppendLogLine(LogLevel::Error, 'X', str); -#if XE_PLATFORM_WIN32 if (!xe::has_console_attached()) { - MessageBoxW(NULL, (LPCWSTR)xe::to_utf16(str).c_str(), L"Xenia Error", - MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + ShowSimpleMessageBox(SimpleMessageBoxType::Error, str); } -#endif // WIN32 + ShutdownLogging(); std::exit(1); } -void ShowInfoMessageBox(std::string m) { -#if XE_PLATFORM_WIN32 - MessageBoxW(NULL, (LPCWSTR)xe::to_utf16(m).c_str(), L"Xenia Help", - MB_OK | MB_ICONINFORMATION | MB_APPLMODAL | MB_SETFOREGROUND); -#endif // WIN32 -} - -void ShowErrorMessageBox(std::string m) { -#if XE_PLATFORM_WIN32 - MessageBoxW(NULL, (LPCWSTR)xe::path_to_utf16(m).c_str(), L"Xenia Error", - MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); -#endif // WIN32 -} - } // namespace xe diff --git a/src/xenia/base/logging.h b/src/xenia/base/logging.h index e3144a056..d2df15cce 100644 --- a/src/xenia/base/logging.h +++ b/src/xenia/base/logging.h @@ -95,11 +95,6 @@ void AppendLogLine(LogLevel log_level, const char prefix_char, // Logs a fatal error and aborts the program. void FatalError(const std::string_view str); -// Shows error box -void ShowErrorMessageBox(std::string m); - -// Show info box -void ShowInfoMessageBox(std::string m); } // namespace xe #if XE_OPTION_ENABLE_LOGGING diff --git a/src/xenia/base/system.h b/src/xenia/base/system.h index 9ffbfa88f..75594db63 100644 --- a/src/xenia/base/system.h +++ b/src/xenia/base/system.h @@ -20,6 +20,15 @@ namespace xe { void LaunchWebBrowser(const std::string& url); void LaunchFileExplorer(const std::filesystem::path& path); +enum class SimpleMessageBoxType { + Help, + Warning, + Error, +}; + +// This is expected to block the caller until the message box is closed. +void ShowSimpleMessageBox(SimpleMessageBoxType type, std::string_view message); + } // namespace xe #endif // XENIA_BASE_SYSTEM_H_ diff --git a/src/xenia/base/system_linux.cc b/src/xenia/base/system_linux.cc index 80773618a..368acd172 100644 --- a/src/xenia/base/system_linux.cc +++ b/src/xenia/base/system_linux.cc @@ -25,4 +25,8 @@ void LaunchWebBrowser(const std::string& url) { void LaunchFileExplorer(const std::filesystem::path& path) { assert_always(); } +void ShowSimpleMessageBox(SimpleMessageBoxType type, std::string_view message) { + assert_always(); +} + } // namespace xe diff --git a/src/xenia/base/system_win.cc b/src/xenia/base/system_win.cc index 0b6198445..8094ddb90 100644 --- a/src/xenia/base/system_win.cc +++ b/src/xenia/base/system_win.cc @@ -24,4 +24,28 @@ void LaunchFileExplorer(const std::filesystem::path& url) { SW_SHOWNORMAL); } +void ShowSimpleMessageBox(SimpleMessageBoxType type, + const std::string_view message) { + const wchar_t* title; + std::u16string wide_message = xe::to_utf16(message); + DWORD type_flags = MB_OK | MB_APPLMODAL | MB_SETFOREGROUND; + switch (type) { + default: + case SimpleMessageBoxType::Help: + title = L"Xenia Help"; + type_flags |= MB_ICONINFORMATION; + break; + case SimpleMessageBoxType::Warning: + title = L"Xenia Warning"; + type_flags |= MB_ICONWARNING; + break; + case SimpleMessageBoxType::Error: + title = L"Xenia Error"; + type_flags |= MB_ICONERROR; + break; + } + MessageBoxW(nullptr, reinterpret_cast(wide_message.c_str()), title, + type_flags); +} + } // namespace xe