From 44000d2518012c308e7df4bdecd14841bb6cef06 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 6 Jun 2021 19:17:51 +0200 Subject: [PATCH] sys: Move windows-only footer items to the windows plugin --- plugins/builtin/CMakeLists.txt | 2 - .../builtin/source/content/footer_items.cpp | 31 -------------- plugins/builtin/source/plugin_builtin.cpp | 4 -- plugins/windows/CMakeLists.txt | 2 + .../windows/source/content/footer_items.cpp | 40 +++++++++++++++++++ plugins/windows/source/plugin_windows.cpp | 3 ++ 6 files changed, 45 insertions(+), 37 deletions(-) delete mode 100644 plugins/builtin/source/content/footer_items.cpp create mode 100644 plugins/windows/source/content/footer_items.cpp diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index ca00aac7a..c521a3e3f 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -13,8 +13,6 @@ add_library(${PROJECT_NAME} SHARED source/content/tools_entries.cpp source/content/data_processor_nodes.cpp - source/content/footer_items.cpp - source/math_evaluator.cpp source/lang/en_US.cpp diff --git a/plugins/builtin/source/content/footer_items.cpp b/plugins/builtin/source/content/footer_items.cpp deleted file mode 100644 index 061a7def9..000000000 --- a/plugins/builtin/source/content/footer_items.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#if defined(OS_WINDOWS) - #include - #include -#endif - -namespace hex::plugin::builtin { - - void addFooterItems() { - - #if defined(OS_WINDOWS) - ContentRegistry::Interface::addFooterItem([] { - static MEMORYSTATUSEX memInfo; - static PROCESS_MEMORY_COUNTERS_EX pmc; - - if (ImGui::GetFrameCount() % 60 == 0) { - memInfo.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&memInfo); - GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast(&pmc), sizeof(pmc)); - } - - auto totalMem = memInfo.ullTotalPhys; - auto usedMem = pmc.PrivateUsage; - - ImGui::TextUnformatted(hex::format("{0} / {1}", hex::toByteString(usedMem), hex::toByteString(totalMem)).c_str()); - }); - #endif - } - -} \ No newline at end of file diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 58fae7bdc..271094347 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -9,8 +9,6 @@ namespace hex::plugin::builtin { void registerSettings(); void registerDataProcessorNodes(); - void addFooterItems(); - void registerLanguageEnUS(); void registerLanguageDeDE(); void registerLanguageItIT(); @@ -28,8 +26,6 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") { registerSettings(); registerDataProcessorNodes(); - addFooterItems(); - registerLanguageEnUS(); registerLanguageDeDE(); registerLanguageItIT(); diff --git a/plugins/windows/CMakeLists.txt b/plugins/windows/CMakeLists.txt index b8750fda8..456a2a64b 100644 --- a/plugins/windows/CMakeLists.txt +++ b/plugins/windows/CMakeLists.txt @@ -11,6 +11,8 @@ if (WIN32) source/views/view_tty_console.cpp source/lang/en_US.cpp + + source/content/footer_items.cpp ) # Add additional include directories here # diff --git a/plugins/windows/source/content/footer_items.cpp b/plugins/windows/source/content/footer_items.cpp new file mode 100644 index 000000000..391004aeb --- /dev/null +++ b/plugins/windows/source/content/footer_items.cpp @@ -0,0 +1,40 @@ +#include + +#include +#include + +namespace hex::plugin::windows { + + static ULONGLONG subtractTimes(const FILETIME &left, const FILETIME &right) { + LARGE_INTEGER a, b; + + a.LowPart = left.dwLowDateTime; + a.HighPart = left.dwHighDateTime; + + b.LowPart = right.dwLowDateTime; + b.HighPart = right.dwHighDateTime; + + return a.QuadPart - b.QuadPart; + } + + void addFooterItems() { + + ContentRegistry::Interface::addFooterItem([] { + static MEMORYSTATUSEX memInfo; + static PROCESS_MEMORY_COUNTERS_EX pmc; + + if (ImGui::GetFrameCount() % 60 == 0) { + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&memInfo); + GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast(&pmc), sizeof(pmc)); + } + + auto totalMem = memInfo.ullTotalPhys; + auto usedMem = pmc.PrivateUsage; + + ImGui::TextUnformatted(hex::format(ICON_FA_MICROCHIP " {0} / {1}", hex::toByteString(usedMem), hex::toByteString(totalMem)).c_str()); + }); + + } + +} \ No newline at end of file diff --git a/plugins/windows/source/plugin_windows.cpp b/plugins/windows/source/plugin_windows.cpp index f0f19a82f..4a310867d 100644 --- a/plugins/windows/source/plugin_windows.cpp +++ b/plugins/windows/source/plugin_windows.cpp @@ -8,6 +8,7 @@ namespace hex::plugin::windows { void registerLanguageEnUS(); + void addFooterItems(); } @@ -17,6 +18,8 @@ IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { ContentRegistry::Views::add(); registerLanguageEnUS(); + + addFooterItems(); }