Compare commits
No commits in common. "e8b9054134d668e469696a3716ff61d73d7efbde" and "8e7907fd202ea2528b2c19f09e2b9173a41dd8af" have entirely different histories.
e8b9054134
...
8e7907fd20
6 changed files with 1 additions and 145 deletions
2
.clangd
2
.clangd
|
@ -1,2 +0,0 @@
|
|||
CompileFlags:
|
||||
Add: [-std=c++20]
|
|
@ -15,9 +15,4 @@ file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
|
|||
add_library(openblocks STATIC ${SOURCES})
|
||||
set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks")
|
||||
target_link_libraries(openblocks ${GLEW_LIBRARIES} OpenGL::GL ReactPhysics3D::ReactPhysics3D pugixml::pugixml)
|
||||
target_include_directories(openblocks PUBLIC "src" "../include")
|
||||
|
||||
# Windows-specific dependencies
|
||||
if(WIN32)
|
||||
target_link_libraries(openblocks shell32.lib)
|
||||
endif()
|
||||
target_include_directories(openblocks PUBLIC "src" "../include")
|
|
@ -1,25 +0,0 @@
|
|||
#include "logger.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
|
||||
static std::ofstream logStream;
|
||||
|
||||
void Logger::init() {
|
||||
initProgramLogsDir();
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
|
||||
std::string fileName = std::format("log_{0:%Y%m%d}_{0:%H%M%S}.txt", now);
|
||||
|
||||
logStream = std::ofstream(getProgramLogsDir() + "/" + fileName);
|
||||
Logger::debug("Logger initialized");
|
||||
}
|
||||
|
||||
void Logger::finish() {
|
||||
Logger::debug("Closing logger...");
|
||||
logStream.close();
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Logger {
|
||||
enum class LogLevel {
|
||||
INFO,
|
||||
DEBUG,
|
||||
WARNING,
|
||||
ERROR,
|
||||
FATAL_ERROR,
|
||||
};
|
||||
|
||||
void init();
|
||||
void finish();
|
||||
|
||||
void log(std::string message, LogLevel logLevel);
|
||||
inline void info(std::string message) { log(message, LogLevel::INFO); }
|
||||
inline void debug(std::string message) { log(message, LogLevel::DEBUG); }
|
||||
inline void warning(std::string message) { log(message, LogLevel::WARNING); }
|
||||
inline void error(std::string message) { log(message, LogLevel::ERROR); }
|
||||
inline void fatalError(std::string message) { log(message, LogLevel::FATAL_ERROR); }
|
||||
};
|
|
@ -1,66 +0,0 @@
|
|||
#include "platform.h"
|
||||
#include <filesystem>
|
||||
|
||||
// GNU/Linux implementation
|
||||
#if defined(_POSIX_VERSION) || defined(__linux) || defined(__linux__)
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
std::string getProgramDataDir() {
|
||||
// https://stackoverflow.com/a/26696759/16255372
|
||||
|
||||
const char *homedir;
|
||||
|
||||
if ((homedir = getenv("HOME")) == NULL) {
|
||||
homedir = getpwuid(getuid())->pw_dir;
|
||||
}
|
||||
|
||||
return std::string(homedir) + "/openblocks";
|
||||
}
|
||||
|
||||
void printErrorMessage(std::string message) {
|
||||
fprintf(stderr, "%s\n", message.c_str());
|
||||
}
|
||||
|
||||
#endif // GNU/Linux
|
||||
|
||||
// Windows implementation
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <shlobj.h>
|
||||
#include <winuser.h>
|
||||
|
||||
std::string getProgramDataDir() {
|
||||
CHAR localAppData[MAX_PATH];
|
||||
int status = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, localAppData);
|
||||
if (status != 0) {
|
||||
printErrorMessage("Failed to find local appdata folder");
|
||||
abort();
|
||||
}
|
||||
return localAppData + "/openblocks";
|
||||
}
|
||||
|
||||
void printErrorMessage(std::string message) {
|
||||
fprintf(stderr, "%s\n", message.c_str());
|
||||
MessageBoxA(NULL, message.c_str(), "Fatal Error", MB_OK);
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
std::string getProgramLogsDir() {
|
||||
return getProgramDataDir() + "/logs";
|
||||
}
|
||||
|
||||
void initProgramDataDir() {
|
||||
std::filesystem::create_directories(getProgramDataDir());
|
||||
}
|
||||
|
||||
void initProgramLogsDir() {
|
||||
std::filesystem::create_directories(getProgramLogsDir());
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Collection of platform-dependent APIs
|
||||
|
||||
// Gets the local data directory under the user's home directory
|
||||
// Windows: %localappdata%/openblocks
|
||||
// Linux: ~/.local/share/openblocks
|
||||
std::string getProgramDataDir();
|
||||
|
||||
// Gets the local logs directory under the program's data directory
|
||||
// Windows: %localappdata%/openblocks/logs
|
||||
// Linux: ~/.local/share/openblocks/logs
|
||||
std::string getProgramLogsDir();
|
||||
|
||||
// Creates the local data directory
|
||||
void initProgramDataDir();
|
||||
// Creates the local logs directory
|
||||
void initProgramLogsDir();
|
||||
|
||||
// Displays an error message box on Windows, or prints to eprintf
|
||||
void printErrorMessage(std::string message);
|
Loading…
Add table
Reference in a new issue