impr: Remove hex::format, improve format and logging type safety

This commit is contained in:
WerWolv
2025-08-06 20:01:58 +02:00
parent d429424f67
commit 9cff9043ee
109 changed files with 473 additions and 455 deletions

View File

@@ -39,7 +39,7 @@ namespace hex::crash {
void resetCrashHandlers();
static void sendNativeMessage(const std::string& message) {
hex::nativeErrorMessage(hex::format("ImHex crashed during initial setup!\nError: {}", message));
hex::nativeErrorMessage(fmt::format("ImHex crashed during initial setup!\nError: {}", message));
}
// Function that decides what should happen on a crash
@@ -48,9 +48,9 @@ namespace hex::crash {
static CrashCallback crashCallback = sendNativeMessage;
static void saveCrashFile(const std::string& message) {
log::fatal(message);
log::fatal("{}", message);
nlohmann::json crashData {
const nlohmann::json crashData {
{ "logFile", wolv::io::fs::toNormalizedPathString(hex::log::impl::getFile().getPath()) },
{ "project", wolv::io::fs::toNormalizedPathString(ProjectFile::getPath()) },
};
@@ -123,8 +123,8 @@ namespace hex::crash {
printStackTrace();
// Flush all streams
fflush(stdout);
fflush(stderr);
std::fflush(stdout);
std::fflush(stderr);
#if defined(IMGUI_TEST_ENGINE)
ImGuiTestEngine_CrashHandler();
@@ -144,7 +144,7 @@ namespace hex::crash {
resetCrashHandlers();
// Actually handle the crash
handleCrash(hex::format("Received signal '{}' ({})", signalName, signalNumber));
handleCrash(fmt::format("Received signal '{}' ({})", signalName, signalNumber));
// Detect if the crash was due to an uncaught exception
if (std::uncaught_exceptions() > 0) {
@@ -162,7 +162,7 @@ namespace hex::crash {
try {
std::rethrow_exception(std::current_exception());
} catch (std::exception &ex) {
std::string exceptionStr = hex::format("{}()::what() -> {}", trace::demangle(typeid(ex).name()), ex.what());
std::string exceptionStr = fmt::format("{}()::what() -> {}", trace::demangle(typeid(ex).name()), ex.what());
handleCrash(exceptionStr);
log::fatal("Program terminated with uncaught exception: {}", exceptionStr);

View File

@@ -70,7 +70,7 @@
return "";
} catch (const std::exception &e) {
static std::string message;
message = hex::format("Failed to deinitialize ImHex!\nThis is just a message warning you of this, the application has already closed, you probably can't do anything about it.\n\nError: {}", e.what());
message = fmt::format("Failed to deinitialize ImHex!\nThis is just a message warning you of this, the application has already closed, you probably can't do anything about it.\n\nError: {}", e.what());
return message.c_str();
}
});

View File

@@ -356,14 +356,14 @@ namespace hex::init {
drawList->AddImage(m_splashTextTexture, ImVec2(0, 0), WindowSize);
// Draw the "copyright" notice
drawList->AddText(ImVec2(35, 85), ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("WerWolv\n2020 - {0}", &__DATE__[7]).c_str());
drawList->AddText(ImVec2(35, 85), ImColor(0xFF, 0xFF, 0xFF, 0xFF), fmt::format("WerWolv\n2020 - {0}", &__DATE__[7]).c_str());
// Draw version information
// In debug builds, also display the current commit hash and branch
#if defined(DEBUG)
const static auto VersionInfo = hex::format("{0} : {1}@{2}", ImHexApi::System::getImHexVersion().get(), ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash());
const static auto VersionInfo = fmt::format("{0} : {1}@{2}", ImHexApi::System::getImHexVersion().get(), ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash());
#else
const static auto VersionInfo = hex::format("{0}", ImHexApi::System::getImHexVersion().get());
const static auto VersionInfo = fmt::format("{0}", ImHexApi::System::getImHexVersion().get());
#endif
drawList->AddText(ImVec2((WindowSize.x - ImGui::CalcTextSize(VersionInfo.c_str()).x) / 2, 105), ImColor(0xFF, 0xFF, 0xFF, 0xFF), VersionInfo.c_str());
@@ -384,7 +384,7 @@ namespace hex::init {
// Draw task names separated by | characters
drawList->PushClipRect(progressBackgroundStart, progressBackgroundStart + progressBackgroundSize, true);
drawList->AddText(progressStart + ImVec2(5, -20), ImColor(0xFF, 0xFF, 0xFF, 0xFF), m_currTaskNames.empty() ? "Ready!" : hex::format("{}", fmt::join(m_currTaskNames, " | ")).c_str());
drawList->AddText(progressStart + ImVec2(5, -20), ImColor(0xFF, 0xFF, 0xFF, 0xFF), m_currTaskNames.empty() ? "Ready!" : fmt::format("{}", fmt::join(m_currTaskNames, " | ")).c_str());
drawList->PopClipRect();
}
@@ -472,7 +472,7 @@ namespace hex::init {
// Create the splash screen window
m_window = glfwCreateWindow(1, 1, "Starting ImHex...", nullptr, nullptr);
if (m_window == nullptr) {
hex::nativeErrorMessage(hex::format(
hex::nativeErrorMessage(fmt::format(
"Failed to create GLFW window: [{}] {}.\n"
"You may not have a renderer available.\n"
"The most common cause of this is using a virtual machine\n"

View File

@@ -46,7 +46,7 @@ namespace hex {
}
void nativeErrorMessage(const std::string &message) {
log::fatal(message);
log::fatal("{}", message);
if (isFileInPath("zenity")) {
executeCmd({"zenity", "--error", "--text", message});
} else if (isFileInPath("notify-send")) {
@@ -138,7 +138,7 @@ namespace hex {
// Add plugin library folders to dll search path
for (const auto &path : paths::Libraries.read()) {
if (std::fs::exists(path))
setenv("LD_LIBRARY_PATH", hex::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true);
setenv("LD_LIBRARY_PATH", fmt::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true);
}
// Redirect stdout to log file if we're not running in a terminal

View File

@@ -41,7 +41,7 @@ namespace hex {
// Add plugin library folders to dll search path
for (const auto &path : paths::Libraries.read()) {
if (std::fs::exists(path))
setenv("LD_LIBRARY_PATH", hex::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true);
setenv("LD_LIBRARY_PATH", fmt::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true);
}
// Redirect stdout to log file if we're not running in a terminal

View File

@@ -656,7 +656,7 @@ namespace hex {
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5_scaled);
ImGui::SetNextWindowSize(ImVec2(350_scaled, toastHeight));
ImGui::SetNextWindowPos((ImHexApi::System::getMainWindowPosition() + ImHexApi::System::getMainWindowSize()) - scaled({ 10, 10 }) - scaled({ 0, (10 + toastHeight) * index }), ImGuiCond_Always, ImVec2(1, 1));
if (ImGui::Begin(hex::format("##Toast_{}", index).c_str(), nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing)) {
if (ImGui::Begin(fmt::format("##Toast_{}", index).c_str(), nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing)) {
auto drawList = ImGui::GetWindowDrawList();
const auto min = ImGui::GetWindowPos();