Improve displayed error messages

This commit is contained in:
Maschell 2022-07-28 13:32:02 +02:00
parent bb6734a499
commit 8ece8d1886
4 changed files with 96 additions and 122 deletions

View File

@ -226,7 +226,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
auto discHeaderOpt = WiiUDiscHeader::make_unique(discReader); auto discHeaderOpt = WiiUDiscHeader::make_unique(discReader);
if (!discHeaderOpt.has_value()) { if (!discHeaderOpt.has_value()) {
DEBUG_FUNCTION_LINE_ERR("Failed to read DiscHeader"); DEBUG_FUNCTION_LINE_ERR("Failed to read DiscHeader");
this->setError(ERROR_PARSE_DISCHEADER); this->setError(ERROR_PARSE_DISC_HEADER);
return SUBSTATE_RUNNING; return SUBSTATE_RUNNING;
} }
this->discHeader = std::move(discHeaderOpt.value()); this->discHeader = std::move(discHeaderOpt.value());
@ -448,108 +448,77 @@ std::string GMPartitionsDumperState::getPathForDevice(eDumpTarget target) const
} }
std::string GMPartitionsDumperState::ErrorMessage() const { std::string GMPartitionsDumperState::ErrorMessage() const {
if (this->errorState == ERROR_MALLOC_FAILED) { switch (this->errorState) {
return "ERROR_MALLOC_FAILED"; case ERROR_NONE:
} return "ERROR_NONE";
if (this->errorState == ERROR_NO_DISC_ID) { case ERROR_MALLOC_FAILED:
return "ERROR_NO_DISC_ID"; return "ERROR_MALLOC_FAILED";
} case ERROR_READ_FIRST_SECTOR:
if (this->errorState == ERROR_READ_FIRST_SECTOR) { return "ERROR_READ_FIRST_SECTOR";
return "ERROR_READ_FIRST_SECTOR"; case ERROR_OPEN_ODD1:
} return "ERROR_OPEN_ODD1";
if (this->errorState == ERROR_OPEN_ODD1) { case ERROR_PARSE_DISC_HEADER:
return "ERROR_OPEN_ODD1"; return "ERROR_PARSE_DISC_HEADER";
} case ERROR_NO_GM_PARTITION:
if (this->errorState == ERROR_PARSE_DISCHEADER) { return "ERROR_NO_GM_PARTITION";
return "ERROR_PARSE_DISCHEADER"; case ERROR_CREATE_DIR:
} return "ERROR_CREATE_DIR";
if (this->errorState == ERROR_NO_GM_PARTITION) { case ERROR_FAILED_TO_GET_NUSTITLE:
return "ERROR_NO_GM_PARTITION"; return "ERROR_FAILED_TO_GET_NUSTITLE";
} case ERROR_FAILED_WRITE_TMD:
if (this->errorState == ERROR_CREATE_DIR) { return "ERROR_FAILED_WRITE_TMD";
return "ERROR_CREATE_DIR"; case ERROR_FAILED_WRITE_TICKET:
} return "ERROR_FAILED_WRITE_TICKET";
if (this->errorState == ERROR_FAILED_TO_GET_NUSTITLE) { case ERROR_FAILED_WRITE_CERT:
return "ERROR_FAILED_TO_GET_NUSTITLE"; return "ERROR_FAILED_WRITE_CERT";
} case ERROR_FIND_CONTENT_BY_INDEX:
if (this->errorState == ERROR_FAILED_WRITE_TMD) { return "ERROR_FIND_CONTENT_BY_INDEX";
return "ERROR_FAILED_WRITE_TMD"; case ERROR_FAILED_CREATE_FILE:
} return "ERROR_FAILED_CREATE_FILE";
if (this->errorState == ERROR_FAILED_WRITE_TICKET) { case ERROR_FAILED_WRITE_H3:
return "ERROR_FAILED_WRITE_TICKET"; return "ERROR_FAILED_WRITE_H3";
} case ERROR_READ_CONTENT:
if (this->errorState == ERROR_FAILED_WRITE_CERT) { return "ERROR_READ_CONTENT";
return "ERROR_FAILED_WRITE_CERT"; case ERROR_WRITE_CONTENT:
} return "ERROR_WRITE_CONTENT";
if (this->errorState == ERROR_FIND_CONTENT_BY_INDEX) {
return "ERROR_FIND_CONTENT_BY_INDEX";
}
if (this->errorState == ERROR_FAILED_CREATE_FILE) {
return "ERROR_FAILED_CREATE_FILE";
}
if (this->errorState == ERROR_FAILED_WRITE_H3) {
return "ERROR_FAILED_WRITE_H3";
}
if (this->errorState == ERROR_READ_CONTENT) {
return "ERROR_READ_CONTENT";
}
if (this->errorState == ERROR_WRITE_CONTENT) {
return "ERROR_WRITE_CONTENT";
}
if (this->errorState == ERROR_MALLOC_FAILED) {
return "ERROR_MALLOC_FAILED";
} }
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }
std::string GMPartitionsDumperState::ErrorDescription() const { std::string GMPartitionsDumperState::ErrorDescription() const {
if (this->errorState == ERROR_MALLOC_FAILED) { switch (this->errorState) {
return "ERROR_MALLOC_FAILED"; case ERROR_NONE:
} break;
if (this->errorState == ERROR_NO_DISC_ID) { case ERROR_MALLOC_FAILED:
return "ERROR_NO_DISC_ID"; return "Failed to allocate memory.";
} case ERROR_READ_FIRST_SECTOR:
if (this->errorState == ERROR_READ_FIRST_SECTOR) { return "Failed to read first sector.";
return "ERROR_READ_FIRST_SECTOR"; case ERROR_OPEN_ODD1:
} return "Failed to read from disc.";
if (this->errorState == ERROR_OPEN_ODD1) { case ERROR_PARSE_DISC_HEADER:
return "ERROR_OPEN_ODD1"; return "Failed to parse the disc header.";
} case ERROR_NO_GM_PARTITION:
if (this->errorState == ERROR_PARSE_DISCHEADER) { return "No games were found on this disc.";
return "ERROR_PARSE_DISCHEADER"; case ERROR_CREATE_DIR:
} return "Failed to create a directory. \nMake sure to have enough space on the storage device.";
if (this->errorState == ERROR_NO_GM_PARTITION) { case ERROR_FAILED_TO_GET_NUSTITLE:
return "ERROR_NO_GM_PARTITION"; return "Failed to parse partition as NUSTitle";
} case ERROR_FAILED_WRITE_TMD:
if (this->errorState == ERROR_FAILED_TO_GET_NUSTITLE) { return "Failed to dump the title.tmd";
return "ERROR_FAILED_TO_GET_NUSTITLE"; case ERROR_FAILED_WRITE_TICKET:
} return "Failed to dump the title.tik";
if (this->errorState == ERROR_FAILED_WRITE_TMD) { case ERROR_FAILED_WRITE_CERT:
return "ERROR_FAILED_WRITE_TMD"; return "Failed to dump the title.cert";
} case ERROR_FIND_CONTENT_BY_INDEX:
if (this->errorState == ERROR_FAILED_WRITE_TICKET) { return "Failed to find requested index";
return "ERROR_FAILED_WRITE_TICKET"; case ERROR_FAILED_CREATE_FILE:
} return "Failed to create a file. \nMake sure to have enough space on the storage device.";
if (this->errorState == ERROR_FAILED_WRITE_CERT) { case ERROR_FAILED_WRITE_H3:
return "ERROR_FAILED_WRITE_CERT"; return "Failed to dump the a .h3 file";
} case ERROR_READ_CONTENT:
if (this->errorState == ERROR_FIND_CONTENT_BY_INDEX) { return "Failed to read the a .app file from disc";
return "ERROR_FIND_CONTENT_BY_INDEX"; case ERROR_WRITE_CONTENT:
} return "Failed to dump a .app. \nMake sure to have enough space on the storage device.";
if (this->errorState == ERROR_FAILED_CREATE_FILE) {
return "ERROR_FAILED_CREATE_FILE";
}
if (this->errorState == ERROR_FAILED_WRITE_H3) {
return "ERROR_FAILED_WRITE_H3";
}
if (this->errorState == ERROR_READ_CONTENT) {
return "ERROR_READ_CONTENT";
}
if (this->errorState == ERROR_WRITE_CONTENT) {
return "ERROR_WRITE_CONTENT";
}
if (this->errorState == ERROR_MALLOC_FAILED) {
return "ERROR_MALLOC_FAILED";
} }
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }

View File

@ -55,10 +55,9 @@ public:
enum eErrorState { enum eErrorState {
ERROR_NONE, ERROR_NONE,
ERROR_MALLOC_FAILED, ERROR_MALLOC_FAILED,
ERROR_NO_DISC_ID,
ERROR_READ_FIRST_SECTOR, ERROR_READ_FIRST_SECTOR,
ERROR_OPEN_ODD1, ERROR_OPEN_ODD1,
ERROR_PARSE_DISCHEADER, ERROR_PARSE_DISC_HEADER,
ERROR_NO_GM_PARTITION, ERROR_NO_GM_PARTITION,
ERROR_CREATE_DIR, ERROR_CREATE_DIR,
ERROR_FAILED_TO_GET_NUSTITLE, ERROR_FAILED_TO_GET_NUSTITLE,

View File

@ -132,7 +132,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
SECTOR_SIZE, targetDevice == TARGET_SD); SECTOR_SIZE, targetDevice == TARGET_SD);
} }
if (!this->fileHandle->isOpen()) { if (!this->fileHandle->isOpen()) {
DEBUG_FUNCTION_LINE("Failed to open file"); DEBUG_FUNCTION_LINE_ERR("Failed to open file.");
this->setError(ERROR_FILE_OPEN_FAILED); this->setError(ERROR_FILE_OPEN_FAILED);
return ApplicationState::SUBSTATE_RUNNING; return ApplicationState::SUBSTATE_RUNNING;
} }
@ -255,6 +255,7 @@ void WUDDumperState::render() {
WiiUScreen::drawLinef("Error: %s", ErrorMessage().c_str()); WiiUScreen::drawLinef("Error: %s", ErrorMessage().c_str());
WiiUScreen::drawLinef("Description: %s", ErrorDescription().c_str()); WiiUScreen::drawLinef("Description: %s", ErrorDescription().c_str());
WiiUScreen::drawLine(); WiiUScreen::drawLine();
WiiUScreen::drawLine();
WiiUScreen::drawLine("Press A to return."); WiiUScreen::drawLine("Press A to return.");
} else if (this->state == STATE_OPEN_ODD1) { } else if (this->state == STATE_OPEN_ODD1) {
WiiUScreen::drawLine("Open /dev/odd01"); WiiUScreen::drawLine("Open /dev/odd01");
@ -328,31 +329,37 @@ void WUDDumperState::setError(WUDDumperState::eErrorState err) {
} }
std::string WUDDumperState::ErrorMessage() const { std::string WUDDumperState::ErrorMessage() const {
if (this->errorState == ERROR_READ_FIRST_SECTOR) { switch (this->errorState) {
return "ERROR_READ_FIRST_SECTOR"; case ERROR_READ_FIRST_SECTOR:
} else if (this->errorState == ERROR_FILE_OPEN_FAILED) { return "ERROR_READ_FIRST_SECTOR";
return "ERROR_FILE_OPEN_FAILED"; case ERROR_NONE:
} else if (this->errorState == ERROR_MALLOC_FAILED) { return "ERROR_NONE";
return "ERROR_MALLOC_FAILED"; case ERROR_FILE_OPEN_FAILED:
} else if (this->errorState == ERROR_NO_DISC_ID) { return "ERROR_FILE_OPEN_FAILED";
return "ERROR_NO_DISC_ID"; case ERROR_MALLOC_FAILED:
} else if (this->errorState == ERROR_WRITE_FAILED) { return "ERROR_MALLOC_FAILED";
return "ERROR_WRITE_FAILED"; case ERROR_WRITE_FAILED:
return "ERROR_WRITE_FAILED";
case ERROR_NO_DISC_FOUND:
return "ERROR_NO_DISC_FOUND";
} }
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }
std::string WUDDumperState::ErrorDescription() const { std::string WUDDumperState::ErrorDescription() const {
if (this->errorState == ERROR_READ_FIRST_SECTOR) { switch (this->errorState) {
return "Failed to read first sector."; case ERROR_READ_FIRST_SECTOR:
} else if (this->errorState == ERROR_MALLOC_FAILED) { return "Failed to read first sector.";
return "Failed to allocate data."; case ERROR_NONE:
} else if (this->errorState == ERROR_FILE_OPEN_FAILED) { return "ERROR_NONE";
return "Failed to create file"; case ERROR_FILE_OPEN_FAILED:
} else if (this->errorState == ERROR_NO_DISC_ID) { return "Failed to create file \nMake sure to have enough space on the storage device.";
return "Failed to get the disc id"; case ERROR_MALLOC_FAILED:
} else if (this->errorState == ERROR_WRITE_FAILED) { return "Failed to allocate data.";
return "Failed to write the file. \nMake sure to have enough space on the storage"; case ERROR_WRITE_FAILED:
return "Failed to write the file. \nMake sure to have enough space on the storage device.";
case ERROR_NO_DISC_FOUND:
return "Please insert a Wii U disc.";
} }
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }

View File

@ -57,7 +57,6 @@ public:
ERROR_READ_FIRST_SECTOR, ERROR_READ_FIRST_SECTOR,
ERROR_FILE_OPEN_FAILED, ERROR_FILE_OPEN_FAILED,
ERROR_MALLOC_FAILED, ERROR_MALLOC_FAILED,
ERROR_NO_DISC_ID,
ERROR_WRITE_FAILED, ERROR_WRITE_FAILED,
ERROR_NO_DISC_FOUND ERROR_NO_DISC_FOUND
}; };