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

@@ -154,4 +154,13 @@ struct std::hash<hex::UnlocalizedString> {
std::size_t operator()(const hex::UnlocalizedString &string) const noexcept {
return std::hash<std::string>{}(string.get());
}
};
};
namespace fmt {
template<typename ... Args>
auto format(const hex::Lang &entry, Args &&... args) {
return fmt::format(fmt::runtime(entry.get()), std::forward<Args>(args)...);
}
}

View File

@@ -3,13 +3,4 @@
#include <string_view>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <fmt/ostream.h>
namespace hex {
template<typename... Args>
std::string format(std::string_view format, Args... args) {
return fmt::format(fmt::runtime(format), args...);
}
}
#include <fmt/ostream.h>

View File

@@ -12,9 +12,9 @@ EXPORT_MODULE namespace hex::log {
namespace impl {
FILE *getDestination();
wolv::io::File& getFile();
bool isRedirected();
[[nodiscard]] FILE *getDestination();
[[nodiscard]] wolv::io::File& getFile();
[[nodiscard]] bool isRedirected();
[[maybe_unused]] void redirectToFile();
[[maybe_unused]] void enableColorPrinting();
@@ -25,17 +25,18 @@ EXPORT_MODULE namespace hex::log {
void unlockLoggerMutex();
struct LogEntry {
std::string project;
std::string level;
std::string_view project;
std::string_view level;
std::string message;
};
std::vector<LogEntry>& getLogEntries();
void addLogEntry(std::string_view project, std::string_view level, std::string_view message);
const std::vector<LogEntry>& getLogEntries();
void addLogEntry(std::string_view project, std::string_view level, std::string message);
[[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level, const char *projectName);
[[maybe_unused]] void printPrefix(FILE *dest, fmt::text_style ts, std::string_view level, std::string_view projectName);
[[maybe_unused]] void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto && ... args) {
template<typename ... Args>
[[maybe_unused]] void print(fmt::text_style ts, std::string_view level, fmt::format_string<Args...> fmt, Args && ... args) {
if (isLoggingSuspended()) [[unlikely]]
return;
@@ -46,12 +47,14 @@ EXPORT_MODULE namespace hex::log {
try {
printPrefix(dest, ts, level, IMHEX_PROJECT_NAME);
auto message = fmt::format(fmt::runtime(fmt), args...);
fmt::print(dest, "{}\n", message);
fflush(dest);
auto message = fmt::format(fmt, std::forward<Args>(args)...);
fmt::println(dest, "{}", message);
std::fflush(dest);
addLogEntry(IMHEX_PROJECT_NAME, level, std::move(message));
} catch (const std::exception&) { }
} catch (const std::exception&) {
/* Ignore any exceptions, we can't do anything anyway */
}
}
namespace color {
@@ -70,52 +73,61 @@ EXPORT_MODULE namespace hex::log {
void resumeLogging();
void enableDebugLogging();
[[maybe_unused]] void debug(const std::string &fmt, auto && ... args) {
template<typename ... Args>
[[maybe_unused]] void debug(fmt::format_string<Args...> fmt, Args && ... args) {
if (impl::isDebugLoggingEnabled()) [[unlikely]] {
hex::log::impl::print(fg(impl::color::debug()) | fmt::emphasis::bold, "[DEBUG]", fmt, args...);
impl::print(fg(impl::color::debug()) | fmt::emphasis::bold, "[DEBUG]", fmt, std::forward<Args>(args)...);
} else {
impl::addLogEntry(IMHEX_PROJECT_NAME, "[DEBUG]", fmt::format(fmt::runtime(fmt), args...));
impl::addLogEntry(IMHEX_PROJECT_NAME, "[DEBUG]", fmt::format(fmt, std::forward<Args>(args)...));
}
}
[[maybe_unused]] void info(const std::string &fmt, auto && ... args) {
hex::log::impl::print(fg(impl::color::info()) | fmt::emphasis::bold, "[INFO] ", fmt, args...);
template<typename ... Args>
[[maybe_unused]] void info(fmt::format_string<Args...> fmt, Args && ... args) {
impl::print(fg(impl::color::info()) | fmt::emphasis::bold, "[INFO] ", fmt, std::forward<Args>(args)...);
}
[[maybe_unused]] void warn(const std::string &fmt, auto && ... args) {
hex::log::impl::print(fg(impl::color::warn()) | fmt::emphasis::bold, "[WARN] ", fmt, args...);
template<typename ... Args>
[[maybe_unused]] void warn(fmt::format_string<Args...> fmt, Args && ... args) {
impl::print(fg(impl::color::warn()) | fmt::emphasis::bold, "[WARN] ", fmt, std::forward<Args>(args)...);
}
[[maybe_unused]] void error(const std::string &fmt, auto && ... args) {
hex::log::impl::print(fg(impl::color::error()) | fmt::emphasis::bold, "[ERROR]", fmt, args...);
template<typename ... Args>
[[maybe_unused]] void error(fmt::format_string<Args...> fmt, Args && ... args) {
impl::print(fg(impl::color::error()) | fmt::emphasis::bold, "[ERROR]", fmt, std::forward<Args>(args)...);
}
[[maybe_unused]] void fatal(const std::string &fmt, auto && ... args) {
hex::log::impl::print(fg(impl::color::fatal()) | fmt::emphasis::bold, "[FATAL]", fmt, args...);
template<typename ... Args>
[[maybe_unused]] void fatal(fmt::format_string<Args...> fmt, Args && ... args) {
impl::print(fg(impl::color::fatal()) | fmt::emphasis::bold, "[FATAL]", fmt, std::forward<Args>(args)...);
}
[[maybe_unused]] void print(const std::string &fmt, auto && ... args) {
template<typename ... Args>
[[maybe_unused]] void print(fmt::format_string<Args...> fmt, Args && ... args) {
impl::lockLoggerMutex();
ON_SCOPE_EXIT { impl::unlockLoggerMutex(); };
try {
auto dest = impl::getDestination();
auto message = fmt::format(fmt::runtime(fmt), args...);
fmt::print(dest, "{}", message);
fflush(dest);
} catch (const std::exception&) { }
fmt::print(dest, fmt, std::forward<Args>(args)...);
std::fflush(dest);
} catch (const std::exception&) {
/* Ignore any exceptions, we can't do anything anyway */
}
}
[[maybe_unused]] void println(const std::string &fmt, auto && ... args) {
template<typename ... Args>
[[maybe_unused]] void println(fmt::format_string<Args...> fmt, Args && ... args) {
impl::lockLoggerMutex();
ON_SCOPE_EXIT { impl::unlockLoggerMutex(); };
try {
auto dest = impl::getDestination();
auto message = fmt::format(fmt::runtime(fmt), args...);
fmt::print(dest, "{}\n", message);
fflush(dest);
} catch (const std::exception&) { }
fmt::println(dest, fmt, std::forward<Args>(args)...);
std::fflush(dest);
} catch (const std::exception&) {
/* Ignore any exceptions, we can't do anything anyway */
}
}
}

View File

@@ -37,13 +37,13 @@ namespace hex::prv::undo {
if (m_formattedContent.size() <= 10)
m_formattedContent.emplace_back(newOperation->format());
else
m_formattedContent.back() = hex::format("[{}x] ...", (m_operations.size() - 10) + 1);
m_formattedContent.back() = fmt::format("[{}x] ...", (m_operations.size() - 10) + 1);
m_operations.emplace_back(std::move(newOperation));
}
[[nodiscard]] std::string format() const override {
return hex::format("{}", Lang(m_unlocalizedName));
return fmt::format("{}", Lang(m_unlocalizedName));
}
[[nodiscard]] Region getRegion() const override {

View File

@@ -30,7 +30,7 @@
auto ret = (x); \
if (!ret) { \
hex::log::error("Test assert '" #x "' failed {} at {}:{}", \
hex::format("" __VA_ARGS__), \
fmt::format("" __VA_ARGS__), \
__FILE__, \
__LINE__); \
return EXIT_FAILURE; \

View File

@@ -200,13 +200,13 @@ namespace ImGuiExt {
if constexpr (sizeof...(args) == 0) {
ImGui::TextUnformatted(fmt.data(), fmt.data() + fmt.size());
} else {
const auto string = hex::format(fmt, std::forward<decltype(args)>(args)...);
const auto string = fmt::format(fmt::runtime(fmt), std::forward<decltype(args)>(args)...);
ImGui::TextUnformatted(string.c_str(), string.c_str() + string.size());
}
}
void TextFormattedSelectable(std::string_view fmt, auto &&...args) {
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
auto text = fmt::format(fmt::runtime(fmt), std::forward<decltype(args)>(args)...);
ImGui::PushID(text.c_str());
@@ -254,7 +254,7 @@ namespace ImGuiExt {
void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) {
// Manually wrap text, using the letter M (generally the widest character in non-monospaced fonts) to calculate the character width to use.
auto text = wolv::util::trim(wolv::util::wrapMonospacedString(
hex::format(fmt, std::forward<decltype(args)>(args)...),
fmt::format(fmt::runtime(fmt), std::forward<decltype(args)>(args)...),
ImGui::CalcTextSize("M").x,
ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize
));
@@ -285,13 +285,13 @@ namespace ImGuiExt {
void TextUnformattedCentered(const char *text);
void TextFormattedCentered(std::string_view fmt, auto &&...args) {
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
auto text = fmt::format(fmt::runtime(fmt), std::forward<decltype(args)>(args)...);
TextUnformattedCentered(text.c_str());
}
void TextFormattedCenteredHorizontal(std::string_view fmt, auto &&...args) {
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
auto text = fmt::format(fmt::runtime(fmt), std::forward<decltype(args)>(args)...);
auto availableSpace = ImGui::GetContentRegionAvail();
auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F);

View File

@@ -143,7 +143,7 @@ namespace hex {
void draw() final {
if (this->shouldDraw()) {
ImGui::SetNextWindowSizeConstraints(this->getMinSize(), this->getMaxSize());
const auto title = hex::format("{} {}", this->getIcon(), View::toWindowName(this->getUnlocalizedName()));
const auto title = fmt::format("{} {}", this->getIcon(), View::toWindowName(this->getUnlocalizedName()));
if (ImGui::Begin(title.c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | this->getWindowFlags())) {
this->drawContent();
}

View File

@@ -873,7 +873,7 @@ namespace hex {
LocalizationManager::impl::setFallbackLanguage(code.get<std::string>());
}
impl::s_languages->emplace(code.get<std::string>(), hex::format("{} ({})", language.get<std::string>(), country.get<std::string>()));
impl::s_languages->emplace(code.get<std::string>(), fmt::format("{} ({})", language.get<std::string>(), country.get<std::string>()));
std::map<std::string, std::string> translationDefinitions;
for (auto &[key, value] : translations.items()) {

View File

@@ -817,7 +817,7 @@ namespace hex {
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
::GetVersionExA(&info);
return hex::format("{}.{}.{}", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber);
return fmt::format("{}.{}.{}", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber);
#elif defined(OS_LINUX) || defined(OS_MACOS) || defined(OS_WEB)
struct utsname details = { };
@@ -950,7 +950,7 @@ namespace hex {
EventImHexClosing::subscribe([executablePath, updateTypeString] {
hex::startProgram(
hex::format("\"{}\" \"{}\"",
fmt::format("\"{}\" \"{}\"",
wolv::util::toUTF8String(executablePath),
updateTypeString
)

View File

@@ -71,14 +71,14 @@ namespace hex {
const auto fileName = path.stem().string();
m_functions.initializePluginFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>("initializePlugin");
m_functions.initializeLibraryFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>(hex::format("initializeLibrary_{}", fileName));
m_functions.initializeLibraryFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>(fmt::format("initializeLibrary_{}", fileName));
m_functions.getPluginNameFunction = getPluginFunction<PluginFunctions::GetPluginNameFunc>("getPluginName");
m_functions.getLibraryNameFunction = getPluginFunction<PluginFunctions::GetLibraryNameFunc>(hex::format("getLibraryName_{}", fileName));
m_functions.getLibraryNameFunction = getPluginFunction<PluginFunctions::GetLibraryNameFunc>(fmt::format("getLibraryName_{}", fileName));
m_functions.getPluginAuthorFunction = getPluginFunction<PluginFunctions::GetPluginAuthorFunc>("getPluginAuthor");
m_functions.getPluginDescriptionFunction = getPluginFunction<PluginFunctions::GetPluginDescriptionFunc>("getPluginDescription");
m_functions.getCompatibleVersionFunction = getPluginFunction<PluginFunctions::GetCompatibleVersionFunc>("getCompatibleVersion");
m_functions.setImGuiContextFunction = getPluginFunction<PluginFunctions::SetImGuiContextFunc>("setImGuiContext");
m_functions.setImGuiContextLibraryFunction = getPluginFunction<PluginFunctions::SetImGuiContextFunc>(hex::format("setImGuiContext_{}", fileName));
m_functions.setImGuiContextLibraryFunction = getPluginFunction<PluginFunctions::SetImGuiContextFunc>(fmt::format("setImGuiContext_{}", fileName));
m_functions.getSubCommandsFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getSubCommands");
m_functions.getFeaturesFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getFeatures");
m_functions.isBuiltinPluginFunction = getPluginFunction<PluginFunctions::IsBuiltinPluginFunc>("isBuiltinPlugin");
@@ -176,7 +176,7 @@ namespace hex {
if (this->isLibraryPlugin())
return m_functions.getLibraryNameFunction();
else
return hex::format("Unknown Plugin @ 0x{0:016X}", m_handle);
return fmt::format("Unknown Plugin @ 0x{0:016X}", m_handle);
}
}

View File

@@ -24,7 +24,7 @@ namespace hex::dp {
auto attribute = this->getConnectedInputAttribute(index);
if (attribute == nullptr)
throwNodeError(hex::format("Nothing connected to input '{0}'", Lang(m_attributes[index].getUnlocalizedName())));
throwNodeError(fmt::format("Nothing connected to input '{0}'", Lang(m_attributes[index].getUnlocalizedName())));
if (attribute->getType() != Attribute::Type::Buffer)
throwNodeError("Tried to read buffer from non-buffer attribute");

View File

@@ -56,7 +56,7 @@ namespace hex::fs {
std::ignore = ShellExecuteW(nullptr, L"open", filePath.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#elif defined(OS_MACOS)
std::ignore = system(
hex::format("open {}", wolv::util::toUTF8String(filePath)).c_str()
fmt::format("open {}", wolv::util::toUTF8String(filePath)).c_str()
);
#elif defined(OS_LINUX)
executeCmd({"xdg-open", wolv::util::toUTF8String(filePath)});
@@ -76,7 +76,7 @@ namespace hex::fs {
ShellExecuteW(nullptr, L"open", L"explorer.exe", args.c_str(), nullptr, SW_SHOWNORMAL);
#elif defined(OS_MACOS)
std::ignore = system(
hex::format("open {}", wolv::util::toUTF8String(dirPath)).c_str()
fmt::format("open {}", wolv::util::toUTF8String(dirPath)).c_str()
);
#elif defined(OS_LINUX)
executeCmd({"xdg-open", wolv::util::toUTF8String(dirPath)});
@@ -96,7 +96,7 @@ namespace hex::fs {
ShellExecuteW(nullptr, L"open", L"explorer.exe", args.c_str(), nullptr, SW_SHOWNORMAL);
#elif defined(OS_MACOS)
std::ignore = system(
hex::format(
fmt::format(
R"(osascript -e 'tell application "Finder" to reveal POSIX file "{}"')",
wolv::util::toUTF8String(selectedFilePath)
).c_str()

View File

@@ -29,7 +29,7 @@ namespace hex {
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
result += c;
else
result += hex::format("%02X", c);
result += fmt::format("%02X", c);
}
return result;
}

View File

@@ -178,7 +178,7 @@ namespace hex {
ON_SCOPE_EXIT { curl_slist_free_all(headersList); };
for (auto &[key, value] : headers) {
std::string header = hex::format("{}: {}", key, value);
std::string header = fmt::format("{}: {}", key, value);
headersList = curl_slist_append(headersList, header.c_str());
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headersList);

View File

@@ -84,7 +84,7 @@ namespace hex::log {
for (const auto &path : paths::Logs.all()) {
wolv::io::fs::createDirectories(path);
time_t time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
s_loggerFile = wolv::io::File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", *std::localtime(&time)), wolv::io::File::Mode::Create);
s_loggerFile = wolv::io::File(path / fmt::format("{0:%Y%m%d_%H%M%S}.log", *std::localtime(&time)), wolv::io::File::Mode::Create);
s_loggerFile.disableBuffering();
if (s_loggerFile.isValid()) {
@@ -109,40 +109,43 @@ namespace hex::log {
#endif
}
std::vector<LogEntry>& getLogEntries() {
static std::vector<LogEntry> logEntries;
return logEntries;
static std::vector<LogEntry> s_logEntries;
const std::vector<LogEntry>& getLogEntries() {
return s_logEntries;
}
void addLogEntry(std::string_view project, std::string_view level, std::string_view message) {
getLogEntries().emplace_back(project.data(), level.data(), message.data());
void addLogEntry(std::string_view project, std::string_view level, std::string message) {
s_logEntries.emplace_back(
std::move(project),
std::move(level),
std::move(message)
);
}
void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level, const char *projectName) {
void printPrefix(FILE *dest, fmt::text_style ts, std::string_view level, std::string_view projectName) {
const auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
const auto now = *std::localtime(&time);
fmt::print(dest, "[{0:%H:%M:%S}] ", now);
if (s_colorOutputEnabled)
fmt::print(dest, ts, "{0} ", level);
else
fmt::print(dest, "{0} ", level);
std::string projectThreadTag = projectName;
if (auto threadName = TaskManager::getCurrentThreadName(); !threadName.empty())
projectThreadTag += fmt::format(" | {0}", threadName);
auto threadName = TaskManager::getCurrentThreadName();
if (threadName.empty()) [[unlikely]] {
threadName = "???";
}
constexpr static auto MaxTagLength = 25;
if (projectThreadTag.length() > MaxTagLength)
projectThreadTag.resize(MaxTagLength);
const auto totalLength = std::min(static_cast<size_t>(MaxTagLength),
projectName.length() + (threadName.empty() ? 0 : 3 + threadName.length()));
fmt::print(dest, "[{0}] ", projectThreadTag);
const auto remainingSpace = MaxTagLength - projectName.length() - 3;
const auto projectNameLength = projectThreadTag.length();
fmt::print(dest, "{0}", std::string(projectNameLength > MaxTagLength ? 0 : MaxTagLength - projectNameLength, ' '));
fmt::print(dest, "[{0:%H:%M:%S}] {1} [{2} | {3}] {4: <{5}} ",
now,
s_colorOutputEnabled ? fmt::format(ts, "{}", level) : level,
projectName.substr(0, std::min(projectName.length(), static_cast<size_t>(MaxTagLength))),
threadName.substr(0, remainingSpace),
"",
MaxTagLength - totalLength
);
}
void assertionHandler(const char* exprString, const char* file, int line) {

View File

@@ -109,7 +109,7 @@ namespace hex {
auto result = wolv::util::combineStrings(m_parts, ".");
if (withBuildType && !m_buildType.empty())
result += hex::format("-{}", m_buildType);
result += fmt::format("-{}", m_buildType);
return result;
}

View File

@@ -95,7 +95,7 @@ namespace hex {
}
std::string Tar::getOpenErrorString() const {
return hex::format("{}: {}", mtar_strerror(m_tarOpenErrno), std::strerror(m_fileOpenErrno));
return fmt::format("{}: {}", mtar_strerror(m_tarOpenErrno), std::strerror(m_fileOpenErrno));
}
void Tar::close() {

View File

@@ -158,9 +158,9 @@ namespace hex {
std::string result;
if (unitIndex == 0)
result = hex::format("{0:}", value);
result = fmt::format("{0:}", value);
else
result = hex::format("{0:.2f}", value);
result = fmt::format("{0:.2f}", value);
switch (unitIndex) {
case 0:
@@ -197,7 +197,7 @@ namespace hex {
if (std::isprint(c))
result += c;
else
result += hex::format("\\x{0:02X}", u8(c));
result += fmt::format("\\x{0:02X}", u8(c));
}
return result;
@@ -302,9 +302,9 @@ namespace hex {
void startProgram(const std::string &command) {
#if defined(OS_WINDOWS)
std::ignore = system(hex::format("start \"\" {0}", command).c_str());
std::ignore = system(fmt::format("start \"\" {0}", command).c_str());
#elif defined(OS_MACOS)
std::ignore = system(hex::format("{0}", command).c_str());
std::ignore = system(fmt::format("{0}", command).c_str());
#elif defined(OS_LINUX)
executeCmd({"xdg-open", command});
#elif defined(OS_WEB)
@@ -377,7 +377,7 @@ namespace hex {
result += "\\v";
break;
default:
result += hex::format("\\x{:02X}", byte);
result += fmt::format("\\x{:02X}", byte);
break;
}
}
@@ -682,8 +682,8 @@ namespace hex {
u8 byte = *it;
if ((address % 0x10) == 0) {
result += hex::format(" {}", asciiRow);
result += hex::format("\n{0:08X} ", address);
result += fmt::format(" {}", asciiRow);
result += fmt::format("\n{0:08X} ", address);
asciiRow.clear();
@@ -700,7 +700,7 @@ namespace hex {
}
}
result += hex::format("{0:02X} ", byte);
result += fmt::format("{0:02X} ", byte);
asciiRow += std::isprint(byte) ? char(byte) : '.';
if ((address % 0x10) == 0x07)
result += " ";
@@ -712,7 +712,7 @@ namespace hex {
for (u32 i = 0; i < (0x10 - (address % 0x10)); i++)
result += " ";
result += hex::format(" {}", asciiRow);
result += fmt::format(" {}", asciiRow);
return result;
}

View File

@@ -15,7 +15,7 @@ namespace hex::subcommands {
std::optional<SubCommand> findSubCommand(const std::string &arg) {
for (auto &plugin : PluginManager::getPlugins()) {
for (auto &subCommand : plugin.getSubCommands()) {
if (hex::format("--{}", subCommand.commandLong) == arg || hex::format("-{}", subCommand.commandShort) == arg) {
if (fmt::format("--{}", subCommand.commandLong) == arg || fmt::format("-{}", subCommand.commandShort) == arg) {
return subCommand;
}
}
@@ -106,13 +106,13 @@ namespace hex::subcommands {
data.pop_back();
}
SendMessageToMainInstance::post(hex::format("command/{}", cmdName), data);
SendMessageToMainInstance::post(fmt::format("command/{}", cmdName), data);
}
void registerSubCommand(const std::string &cmdName, const ForwardCommandHandler &handler) {
log::debug("Registered new forward command handler: {}", cmdName);
ImHexApi::Messaging::registerHandler(hex::format("command/{}", cmdName), [handler](const std::vector<u8> &eventData){
ImHexApi::Messaging::registerHandler(fmt::format("command/{}", cmdName), [handler](const std::vector<u8> &eventData){
std::string string(reinterpret_cast<const char *>(eventData.data()), eventData.size());
std::vector<std::string> args;

View File

@@ -964,13 +964,13 @@ namespace ImGuiExt {
std::string format;
if (*value < 1024) {
format = hex::format("{} Bytes", *value);
format = fmt::format("{} Bytes", *value);
} else if (*value < 1024 * 1024) {
format = hex::format("{:.2f} KB", *value / 1024.0);
format = fmt::format("{:.2f} KB", *value / 1024.0);
} else if (*value < 1024 * 1024 * 1024) {
format = hex::format("{:.2f} MB", *value / (1024.0 * 1024.0));
format = fmt::format("{:.2f} MB", *value / (1024.0 * 1024.0));
} else {
format = hex::format("{:.2f} GB", *value / (1024.0 * 1024.0 * 1024.0));
format = fmt::format("{:.2f} GB", *value / (1024.0 * 1024.0 * 1024.0));
}
*value /= stepSize;
@@ -1266,7 +1266,7 @@ namespace ImGuiExt {
bool result = false;
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0F);
if (ImGui::BeginChild(hex::format("{}##SubWindow", label).c_str(), size, ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY | flags, hasMenuBar ? ImGuiWindowFlags_MenuBar : ImGuiWindowFlags_None)) {
if (ImGui::BeginChild(fmt::format("{}##SubWindow", label).c_str(), size, ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY | flags, hasMenuBar ? ImGuiWindowFlags_MenuBar : ImGuiWindowFlags_None)) {
result = true;
if (hasMenuBar && ImGui::BeginMenuBar()) {