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

impr: Show an error message when ImHex can't open a file (#1050)

This PR does two correlated things:

- Show a generic error message (Failed to open provider) rather than a
file-specific message (Failed to open file) when a provider fails to
open
- Set the error to something more specific when opening a file fails
This commit is contained in:
iTrooz 2023-04-30 18:37:22 +02:00 committed by GitHub
parent 1bdc1d7241
commit 13a3942f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 4 deletions

View File

@ -369,7 +369,6 @@
"hex.builtin.popup.error.create": "Failed to create new file!",
"hex.builtin.popup.error.file_dialog.common": "An error occurred while opening the file browser: {}",
"hex.builtin.popup.error.file_dialog.portal": "There was an error while opening the file browser: {}.\nThis might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n\nOn KDE, it's xdg-desktop-portal-kde.\nOn Gnome it's xdg-desktop-portal-gnome.\nOn wlroots it's xdg-desktop-portal-wlr.\nOtherwise, you can try to use xdg-desktop-portal-gtk.\n\nReboot your system after installing it.\n\nIf the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n\nIn the meantime files can still be opened by dragging them onto the ImHex window!",
"hex.builtin.popup.error.open": "Failed to open file!",
"hex.builtin.popup.error.project.load": "Failed to load project!",
"hex.builtin.popup.error.project.save": "Failed to save project!",
"hex.builtin.popup.error.read_only": "Couldn't get write access. File opened in read-only mode.",
@ -378,6 +377,7 @@
"hex.builtin.popup.exit_application.title": "Exit Application?",
"hex.builtin.popup.waiting_for_tasks.title": "Waiting for Tasks",
"hex.builtin.popup.waiting_for_tasks.desc": "There are still tasks running in the background.\nImHex will close after they are finished.",
"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.reload": "Reload",
@ -386,6 +386,7 @@
"hex.builtin.provider.disk.error.read_ro": "Failed to open disk {} in read-only mode: {}",
"hex.builtin.provider.disk.error.read_rw": "Failed to open disk {} in read/write mode: {}",
"hex.builtin.provider.file": "File Provider",
"hex.builtin.provider.file.error.open": "Failed to open file {}: {}",
"hex.builtin.provider.file.access": "Last access time",
"hex.builtin.provider.file.creation": "Creation time",
"hex.builtin.provider.file.modification": "Last modification time",

View File

@ -109,7 +109,7 @@ namespace hex::plugin::builtin {
return;
}
if (!provider->open()) {
PopupError::open("hex.builtin.popup.error.open"_lang);
PopupError::open(hex::format("hex.builtin.provider.error.open"_lang, provider->getErrorMessage()));
TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); });
return;
}
@ -120,7 +120,7 @@ namespace hex::plugin::builtin {
EventManager::post<RequestOpenPopup>(View::toWindowName("hex.builtin.view.provider_settings.load_popup"));
else {
if (!provider->open() || !provider->isAvailable()) {
PopupError::open("hex.builtin.popup.error.open"_lang);
PopupError::open(hex::format("hex.builtin.provider.error.open"_lang, provider->getErrorMessage()));
TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); });
return;
}

View File

@ -215,6 +215,7 @@ namespace hex::plugin::builtin {
if (!file.isValid()) {
this->m_writable = false;
this->m_readable = false;
this->setErrorMessage(hex::format("hex.builtin.provider.file.error.open"_lang, this->m_path.string(), ::strerror(errno)));
return false;
}

View File

@ -180,7 +180,7 @@ namespace hex::plugin::builtin {
provider->loadSettings(recentProvider.data);
if (!provider->open() || !provider->isAvailable()) {
PopupError::open("hex.builtin.popup.error.open"_lang);
PopupError::open(hex::format("hex.builtin.provider.error.open"_lang, provider->getErrorMessage()));
TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); });
return;
}