fix(logging): bugs in windows implementation

This commit is contained in:
maelstrom 2025-03-18 00:22:54 +01:00
parent b8b0646e9f
commit 5d97ef58f5
3 changed files with 9 additions and 9 deletions

View file

@ -35,10 +35,10 @@ void Logger::log(std::string message, Logger::LogLevel logLevel) {
std::string formattedLogLine = std::format("[{:%Y-%m-%d %X}] [{}] {}", now, logLevelStr, message); std::string formattedLogLine = std::format("[{:%Y-%m-%d %X}] [{}] {}", now, logLevelStr, message);
printf("%s\n", formattedLogLine.c_str());
logStream << formattedLogLine << std::endl; logStream << formattedLogLine << std::endl;
printf("FATAL ERROR: %s\n", message.c_str());
if (logLevel == Logger::LogLevel::FATAL_ERROR) { if (logLevel == Logger::LogLevel::FATAL_ERROR) {
displayErrorMessage(formattedLogLine); displayErrorMessage(message);
} }
} }

View file

@ -15,7 +15,7 @@ void panic() {
abort(); abort();
trySafeAbort = true; trySafeAbort = true;
#ifndef NDEBUG #ifdef NDEBUG
displayErrorMessage(std::string("A fatal error has occurred and Openblocks had to shut down.\n\ displayErrorMessage(std::string("A fatal error has occurred and Openblocks had to shut down.\n\
The currently open document will be attempted to be saved, and logs will be written to " + getProgramLogsDir())); The currently open document will be attempted to be saved, and logs will be written to " + getProgramLogsDir()));
#endif #endif
@ -26,4 +26,4 @@ The currently open document will be attempted to be saved, and logs will be writ
// TODO: Autosave document // TODO: Autosave document
abort(); abort();
} }

View file

@ -42,15 +42,15 @@ std::string getProgramDataDir() {
CHAR localAppData[MAX_PATH]; CHAR localAppData[MAX_PATH];
int status = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, localAppData); int status = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, localAppData);
if (status != 0) { if (status != 0) {
printErrorMessage("Failed to find local appdata folder"); displayErrorMessage("Failed to find local appdata folder");
panic(); panic();
} }
return localAppData + "/openblocks"; return std::string(localAppData) + "/openblocks";
} }
void displayErrorMessage(std::string message) { void displayErrorMessage(std::string message) {
fprintf(stderr, "%s\n", message.c_str()); fprintf(stderr, "%s\n", message.c_str());
MessageBoxA(NULL, message.c_str(), "Fatal Error", MB_OK); MessageBoxA(NULL, message.c_str(), "Fatal Error", MB_OK | MB_ICONERROR);
} }
#endif // WIN32 #endif // WIN32
@ -65,4 +65,4 @@ void initProgramDataDir() {
void initProgramLogsDir() { void initProgramLogsDir() {
std::filesystem::create_directories(getProgramLogsDir()); std::filesystem::create_directories(getProgramLogsDir());
} }