Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/libimhex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(LIBIMHEX_SOURCES
source/helpers/keys.cpp
source/helpers/udp_server.cpp
source/helpers/scaling.cpp
source/helpers/ram.cpp

source/test/tests.cpp

Expand All @@ -63,6 +64,7 @@ if (APPLE)
set(LIBIMHEX_SOURCES ${LIBIMHEX_SOURCES}
source/helpers/utils_macos.m
source/helpers/macos_menu.m
source/helpers/ram.cpp
)
endif ()

Expand Down
7 changes: 7 additions & 0 deletions lib/libimhex/include/hex/helpers/ram.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <hex.hpp>

namespace hex {
u64 getPhysicalRAM();
}
10 changes: 9 additions & 1 deletion lib/libimhex/source/api/content_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,15 @@ namespace hex {

void SliderDataSize::load(const nlohmann::json &data) {
if (data.is_number_integer()) {
m_value = data.get<u64>();
u64 value = data.get<u64>();

if (value < m_min) {
m_value = m_min;
} else if (value > m_max) {
m_value = m_max;
} else {
m_value = value;
}
} else {
log::warn("Invalid data type loaded from settings for slider!");
}
Expand Down
45 changes: 45 additions & 0 deletions lib/libimhex/source/helpers/ram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <hex/helpers/ram.hpp>

#if defined(OS_WINDOWS)
#include <windows.h>
#elif defined(OS_MACOS)
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(OS_LINUX)
#include <fstream>
#endif

namespace hex {
u64 getPhysicalRAM() {
#if defined(OS_WINDOWS)
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
if (GlobalMemoryStatusEx(&status)) {
return status.ullTotalPhys;
}
return 0;

#elif defined(OS_MACOS)
int64_t mem;
size_t len = sizeof(mem);
if (sysctlbyname("hw.memsize", &mem, &len, nullptr, 0) == 0) {
return mem;
}
return 0;

#elif defined(OS_LINUX)
std::ifstream meminfo("/proc/meminfo");
std::string line;
while (std::getline(meminfo, line)) {
if (line.starts_with("MemTotal:")) {
std::string value = line.substr(9);
return std::stoll(value) * 1024; // kB to bytes
}
}
return 0;

#else
return 0;
#endif
}
}
3 changes: 2 additions & 1 deletion plugins/builtin/source/content/settings_entries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/ram.hpp>

#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
Expand Down Expand Up @@ -757,7 +758,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.show_tips", false);
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.save_recent_providers", true);
ContentRegistry::Settings::add<AutoBackupWidget>("hex.builtin.setting.general", "", "hex.builtin.setting.general.auto_backup_time");
ContentRegistry::Settings::add<Widgets::SliderDataSize>("hex.builtin.setting.general", "", "hex.builtin.setting.general.max_mem_file_size", 512_MiB, 0_bytes, 32_GiB, 1_MiB)
ContentRegistry::Settings::add<Widgets::SliderDataSize>("hex.builtin.setting.general", "", "hex.builtin.setting.general.max_mem_file_size", 512_MiB, 0_bytes, getPhysicalRAM(), 1_MiB)
.setTooltip("hex.builtin.setting.general.max_mem_file_size.desc");
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.pattern_data_max_filter_items", 128, 32, 1024);

Expand Down