mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
97 lines
2.3 KiB
C++
97 lines
2.3 KiB
C++
#include "storm/Error.hpp"
|
|
|
|
#include <cstdarg>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <windows.h>
|
|
|
|
std::string errorf(const char *format, ...) {
|
|
va_list args;
|
|
va_start(args, format);
|
|
|
|
constexpr size_t size = 1024;
|
|
|
|
char buf[size] = {0};
|
|
auto n = vsnprintf(buf, size, format, args);
|
|
|
|
va_end(args);
|
|
|
|
if (n < 0) {
|
|
return "";
|
|
} else if (n >= size) {
|
|
std::string result(buf, n);
|
|
return result;
|
|
} else {
|
|
return std::string(buf);
|
|
}
|
|
}
|
|
|
|
[[noreturn]] void SErrDisplayAppFatal(const char* format, ...) {
|
|
// Format arguments
|
|
constexpr size_t size = 1024;
|
|
char buffer[size] = {0};
|
|
va_list args;
|
|
va_start(args, format);
|
|
vsnprintf(buffer, size, format, args);
|
|
va_end(args);
|
|
|
|
// Print formatted message to debugger
|
|
OutputDebugString(buffer);
|
|
|
|
// Display error to GUI
|
|
MessageBox(nullptr, buffer, "Fatal error!", MB_ICONERROR);
|
|
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7) {
|
|
std::string s = "";
|
|
s.reserve(1024);
|
|
|
|
s += errorf("\n=========================================================\n");
|
|
|
|
if (linenumber == -5) {
|
|
s += errorf("Exception Raised!\n\n");
|
|
|
|
s += errorf(" App: %s\n", "GenericBlizzardApp");
|
|
|
|
if (errorcode != 0x85100000) {
|
|
s += errorf(" Error Code: 0x%08X\n", errorcode);
|
|
}
|
|
|
|
// TODO output time
|
|
|
|
s += errorf(" Error: %s\n\n", description);
|
|
} else {
|
|
s += errorf("Assertion Failed!\n\n");
|
|
|
|
s += errorf(" App: %s\n", "GenericBlizzardApp");
|
|
s += errorf(" File: %s\n", filename);
|
|
s += errorf(" Line: %d\n", linenumber);
|
|
|
|
if (errorcode != 0x85100000) {
|
|
s += errorf(" Error Code: 0x%08X\n", errorcode);
|
|
}
|
|
|
|
// TODO output time
|
|
|
|
s += errorf(" Assertion: %s\n", description);
|
|
}
|
|
|
|
// Print error in debugger
|
|
OutputDebugString(s.c_str());
|
|
|
|
// Title
|
|
const char* caption = recoverable ? "Error" : "Unrecoverable error";
|
|
|
|
// Icon/type
|
|
UINT icon = recoverable ? MB_ICONWARNING : MB_ICONERROR;
|
|
|
|
MessageBox(nullptr, s.c_str(), caption, icon);
|
|
|
|
if (recoverable) {
|
|
return 1;
|
|
} else {
|
|
exit(exitcode);
|
|
}
|
|
}
|