1
0
mirror of synced 2025-02-17 18:59:21 +01:00

impr: Display a more detailed errors when opening a raw disk provider failed (#970)

PR title is self explaining

I may modify other providers implementations to display a detailed error
message later

I'm not sure how to deal with other locales because the format changed.
Before, I had to add and comment the key in all locale files, now I'm
not so sure.
This commit is contained in:
Thomas 2023-03-21 10:33:00 +01:00 committed by GitHub
parent e6959dc572
commit 8731b7582b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 1 deletions

View File

@ -103,6 +103,9 @@ namespace hex::prv {
void skipLoadInterface() { this->m_skipLoadInterface = true; }
[[nodiscard]] bool shouldSkipLoadInterface() const { return this->m_skipLoadInterface; }
void setErrorMessage(const std::string &errorMessage) { this->m_errorMessage = errorMessage; }
[[nodiscard]] const std::string& getErrorMessage() const { return this->m_errorMessage; }
protected:
u32 m_currPage = 0;
u64 m_baseAddress = 0;
@ -116,6 +119,8 @@ namespace hex::prv {
bool m_dirty = false;
bool m_skipLoadInterface = false;
std::string m_errorMessage;
private:
static u32 s_idCounter;
};

View File

@ -335,6 +335,8 @@
"hex.builtin.provider.disk.reload",
"hex.builtin.provider.disk.sector_size",
"hex.builtin.provider.disk.selected_disk",
"hex.builtin.provider.disk.error.read_ro",
"hex.builtin.provider.disk.error.read_rw",
"hex.builtin.provider.file",
"hex.builtin.provider.file.access",
"hex.builtin.provider.file.creation",
@ -742,6 +744,7 @@
"hex.builtin.view.pattern_editor.sections",
"hex.builtin.view.pattern_editor.settings",
"hex.builtin.view.provider_settings.load_error",
"hex.builtin.view.provider_settings.load_error_details",
"hex.builtin.view.provider_settings.load_popup",
"hex.builtin.view.provider_settings.name",
"hex.builtin.view.settings.name",

View File

@ -375,6 +375,8 @@
"hex.builtin.provider.disk.reload": "Reload",
"hex.builtin.provider.disk.sector_size": "Sector Size",
"hex.builtin.provider.disk.selected_disk": "Disk",
"hex.builtin.provider.disk.error.read_ro": "Failed to open disk {} in read/write: {}",
"hex.builtin.provider.disk.error.read_rw": "Failed to open disk {} in read/write: {}",
"hex.builtin.provider.file": "File Provider",
"hex.builtin.provider.file.access": "Last access time",
"hex.builtin.provider.file.creation": "Creation time",
@ -791,6 +793,7 @@
"hex.builtin.view.pattern_editor.sections": "Sections",
"hex.builtin.view.pattern_editor.settings": "Settings",
"hex.builtin.view.provider_settings.load_error": "An error occurred while trying to open this provider!",
"hex.builtin.view.provider_settings.load_error_details": "An error occurred while trying to open this provider!\nDetails: {}",
"hex.builtin.view.provider_settings.load_popup": "Open Provider",
"hex.builtin.view.provider_settings.name": "Provider Settings",
"hex.builtin.view.settings.name": "Settings",

View File

@ -1,3 +1,5 @@
#include <hex/helpers/logger.hpp>
#include "content/providers/disk_provider.hpp"
#include <hex/api/localization.hpp>
@ -123,11 +125,15 @@ namespace hex::plugin::builtin {
this->m_diskHandle = ::open(path.c_str(), O_RDWR);
if (this->m_diskHandle == -1) {
this->setErrorMessage(hex::format("hex.builtin.provider.disk.error.read_rw"_lang, path, ::strerror(errno)));
log::warn(this->getErrorMessage());
this->m_diskHandle = ::open(path.c_str(), O_RDONLY);
this->m_writable = false;
}
if (this->m_diskHandle == -1) {
this->setErrorMessage(hex::format("hex.builtin.provider.disk.error.read_ro"_lang, path, ::strerror(errno)));
log::warn(this->getErrorMessage());
this->m_readable = false;
return false;
}

View File

@ -41,7 +41,12 @@ namespace hex::plugin::builtin {
ImGui::CloseCurrentPopup();
}
else {
View::showErrorPopup("hex.builtin.view.provider_settings.load_error"_lang);
auto errorMessage = provider->getErrorMessage();
if (errorMessage.empty()) {
View::showErrorPopup("hex.builtin.view.provider_settings.load_error"_lang);
} else {
View::showErrorPopup(hex::format("hex.builtin.view.provider_settings.load_error_details"_lang, errorMessage));
}
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
}
}