impr: Add warning to disk provider if ImHex is not running elevated

This commit is contained in:
WerWolv 2023-12-17 23:16:55 +01:00
parent 71dd349044
commit 7a0680c2cb
3 changed files with 15 additions and 3 deletions

View file

@ -60,6 +60,7 @@ namespace hex::plugin::builtin {
std::set<DriveInfo> m_availableDrives;
std::fs::path m_path;
std::string m_friendlyName;
bool m_elevated = false;
#if defined(OS_WINDOWS)
void *m_diskHandle = reinterpret_cast<void*>(-1);

View file

@ -515,6 +515,7 @@
"hex.builtin.provider.error.open": "Failed to open provider: {}",
"hex.builtin.provider.disk": "Raw Disk Provider",
"hex.builtin.provider.disk.disk_size": "Disk Size",
"hex.builtin.provider.disk.elevation": "Accessing raw disks most likely requires elevated privileges",
"hex.builtin.provider.disk.reload": "Reload",
"hex.builtin.provider.disk.sector_size": "Sector Size",
"hex.builtin.provider.disk.selected_disk": "Disk",

View file

@ -1,10 +1,11 @@
#if !defined(OS_WEB)
#include <hex/helpers/logger.hpp>
#include "content/providers/disk_provider.hpp"
#include <hex/api/localization_manager.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
@ -15,6 +16,7 @@
#include <filesystem>
#include <imgui.h>
#include <fonts/codicons_font.h>
#include <nlohmann/json.hpp>
@ -428,12 +430,20 @@ namespace hex::plugin::builtin {
bool DiskProvider::drawLoadInterface() {
#if defined(OS_WINDOWS)
if (this->m_availableDrives.empty())
if (this->m_availableDrives.empty()) {
this->reloadDrives();
this->m_elevated = hex::isProcessElevated();
}
if (!this->m_elevated) {
ImGui::PushTextWrapPos(0);
ImGuiExt::TextFormattedColored(ImGuiExt::GetCustomColorU32(ImGuiCustomCol_LoggerError), ICON_VS_SHIELD "{}", "hex.builtin.provider.disk.elevation"_lang);
ImGui::PopTextWrapPos();
ImGui::NewLine();
}
ImGui::PushItemWidth(300_scaled);
if (ImGui::BeginListBox("hex.builtin.provider.disk.selected_disk"_lang)) {
ImGui::PushID(1);
for (const auto &[path, friendlyName] : this->m_availableDrives) {
if (ImGui::Selectable(friendlyName.c_str(), this->m_path == path)) {