feat: Display detailed error message when loading of project fails (#1135)

In order to do this I add to make some other additions :
- Add a warning popup (TODO, maybe add some icons to differentiate
error/warning popups in a future PR ?)
- create showError() and showWarning() functions, as helpers to show a
message both to the logs and as a popup
This commit is contained in:
iTrooz
2023-06-21 20:07:36 +02:00
committed by GitHub
parent 3fe6cd057b
commit b7d8e46288
13 changed files with 363 additions and 182 deletions

View File

@@ -2,6 +2,7 @@
#include <hex/helpers/literals.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/fmt.hpp>
#include <wolv/io/file.hpp>
@@ -10,7 +11,7 @@ namespace hex {
using namespace hex::literals;
Tar::Tar(const std::fs::path &path, Mode mode) {
int error = MTAR_ESUCCESS;
int tar_error = MTAR_ESUCCESS;
// Explicitly create file so a short path gets generated
if (mode == Mode::Create) {
@@ -20,16 +21,23 @@ namespace hex {
auto shortPath = wolv::io::fs::toShortPath(path);
if (mode == Tar::Mode::Read)
error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "r");
tar_error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "r");
else if (mode == Tar::Mode::Write)
error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "a");
tar_error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "a");
else if (mode == Tar::Mode::Create)
error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "w");
tar_error = mtar_open(&this->m_ctx, shortPath.string().c_str(), "w");
else
error = MTAR_EFAILURE;
tar_error = MTAR_EFAILURE;
this->m_path = path;
this->m_valid = (error == MTAR_ESUCCESS);
this->m_valid = (tar_error == MTAR_ESUCCESS);
if (!this->m_valid) {
this->m_tarOpenErrno = tar_error;
// hopefully this errno corresponds to the file open call in mtar_open
this->m_fileOpenErrno = errno;
}
}
Tar::~Tar() {
@@ -40,6 +48,8 @@ namespace hex {
this->m_ctx = other.m_ctx;
this->m_path = other.m_path;
this->m_valid = other.m_valid;
this->m_tarOpenErrno = other.m_tarOpenErrno;
this->m_fileOpenErrno = other.m_fileOpenErrno;
other.m_ctx = { };
other.m_valid = false;
@@ -54,6 +64,8 @@ namespace hex {
this->m_valid = other.m_valid;
other.m_valid = false;
this->m_tarOpenErrno = other.m_tarOpenErrno;
this->m_fileOpenErrno = other.m_fileOpenErrno;
return *this;
}
@@ -79,6 +91,10 @@ namespace hex {
return mtar_find(&this->m_ctx, path.string().c_str(), &header) == MTAR_ESUCCESS;
}
std::string Tar::getOpenErrorString(){
return hex::format("{}: {}", mtar_strerror(this->m_tarOpenErrno), std::strerror(this->m_fileOpenErrno));
}
void Tar::close() {
if (this->m_valid) {
mtar_finalize(&this->m_ctx);