[Base] Clean up simple message box utility.
This commit is contained in:
parent
bf5f700f9e
commit
80cafd9358
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<LPCWSTR>(wide_message.c_str()), title,
|
||||
type_flags);
|
||||
}
|
||||
|
||||
} // namespace xe
|
||||
|
|
Loading…
Reference in New Issue