diff --git a/src/dusk/iso_validate.cpp b/src/dusk/iso_validate.cpp index 6914a0a4ba..5304b8eeea 100644 --- a/src/dusk/iso_validate.cpp +++ b/src/dusk/iso_validate.cpp @@ -94,7 +94,6 @@ struct NodHandleWrapper { NodHandle* handle; NodHandleWrapper() : handle(nullptr) {} - ~NodHandleWrapper() { if (handle != nullptr) { nod_free(handle); @@ -103,7 +102,7 @@ struct NodHandleWrapper { } }; -static ValidationError convertNodError(NodResult result) { +static ValidationError convert_nod_error(NodResult result) { switch (result) { case NOD_RESULT_ERR_IO: return ValidationError::IOError; @@ -118,34 +117,27 @@ s64 StreamReadAt(void* user_data, u64 offset, void* out, size_t len) { if (len == 0) { return 0; } - - auto io = static_cast(user_data); - - auto ret = SDL_SeekIO(io, static_cast(offset), SDL_IO_SEEK_SET); + auto* io = static_cast(user_data); + const auto ret = SDL_SeekIO(io, static_cast(offset), SDL_IO_SEEK_SET); if (ret < 0) { return -1; } - - auto read = SDL_ReadIO(io, out, len); + const auto read = SDL_ReadIO(io, out, len); if (read == 0) { if (SDL_GetIOStatus(io) == SDL_IO_STATUS_EOF) { return 0; } - return -1; } - return static_cast(read); } s64 StreamLength(void* user_data) { - auto io = static_cast(user_data); - return SDL_GetIOSize(io); + return SDL_GetIOSize(static_cast(user_data)); } void StreamClose(void* user_data) { - auto io = static_cast(user_data); - SDL_CloseIO(io); + SDL_CloseIO(static_cast(user_data)); } ValidationError verify_disc(NodHandle* disc, VerificationStatus& status) { @@ -176,28 +168,25 @@ ValidationError verify_disc(NodHandle* disc, VerificationStatus& status) { if (!XXH128_isEqual(hash, status.knownDisc->hash)) { return ValidationError::HashMismatch; } - return ValidationError::Success; } ValidationError validate(const char* path, VerificationStatus& status) { - NodHandleWrapper disc; - const auto sdlStream = SDL_IOFromFile(path, "rb"); if (sdlStream == nullptr) { return ValidationError::IOError; } + NodHandleWrapper disc; const NodDiscStream nod_stream{ .user_data = sdlStream, .read_at = StreamReadAt, .stream_len = StreamLength, .close = StreamClose, }; - auto result = nod_disc_open_stream(&nod_stream, nullptr, &disc.handle); if (disc.handle == nullptr || result != NOD_RESULT_OK) { - return convertNodError(result); + return convert_nod_error(result); } status.bytesTotal.store(nod_disc_size(disc.handle), std::memory_order_relaxed); @@ -205,53 +194,42 @@ ValidationError validate(const char* path, VerificationStatus& status) { NodDiscHeader header{}; result = nod_disc_header(disc.handle, &header); if (result != NOD_RESULT_OK) { - return convertNodError(result); + return convert_nod_error(result); } const auto knownDisc = find_disc(std::string_view(header.game_id, 6)); - if (!knownDisc) { return ValidationError::WrongGame; } - status.knownDisc = knownDisc; - if (!knownDisc->supported) { return ValidationError::WrongVersion; } - return verify_disc(disc.handle, status); } -ValidationError validate(const char* path) { - VerificationStatus status{}; - return validate(path, status); -} - ValidationError inspect(const char* path, DiscInfo& info) { - NodHandleWrapper disc; - const auto sdlStream = SDL_IOFromFile(path, "rb"); if (sdlStream == nullptr) { return ValidationError::IOError; } + NodHandleWrapper disc; const NodDiscStream nod_stream{ .user_data = sdlStream, .read_at = StreamReadAt, .stream_len = StreamLength, .close = StreamClose, }; - auto result = nod_disc_open_stream(&nod_stream, nullptr, &disc.handle); if (disc.handle == nullptr || result != NOD_RESULT_OK) { - return convertNodError(result); + return convert_nod_error(result); } NodDiscHeader header{}; result = nod_disc_header(disc.handle, &header); if (result != NOD_RESULT_OK) { - return convertNodError(result); + return convert_nod_error(result); } const auto knownDisc = find_disc(std::string_view(header.game_id, 6)); diff --git a/src/dusk/iso_validate.hpp b/src/dusk/iso_validate.hpp index 4bc42709de..830b88eaba 100644 --- a/src/dusk/iso_validate.hpp +++ b/src/dusk/iso_validate.hpp @@ -30,7 +30,6 @@ struct DiscInfo { ValidationError inspect(const char* path, DiscInfo& info); ValidationError validate(const char* path, VerificationStatus& status); -ValidationError validate(const char* path); bool isPal(const char* path); } // namespace dusk::iso diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 497eca379f..7b01091ef6 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -618,28 +618,35 @@ int game_main(int argc, char* argv[]) { dusk::ui::push_document(std::make_unique(), true, true); dusk::ui::push_document(std::make_unique(), false); - // Invalidate a bad saved isoPath so that Dusk can't get blocked from starting up + // Invalidate a bad saved isoPath so that Dusk can't get blocked from starting up. + // This is only a metadata check; full hash verification is handled by the prelaunch UI. const std::string p = dusk::getSettings().backend.isoPath; - if (!p.empty() && dusk::iso::validate(p.c_str()) < dusk::iso::ValidationError::HashMismatch) { + dusk::iso::DiscInfo discInfo{}; + if (!p.empty() && + dusk::iso::inspect(p.c_str(), discInfo) != dusk::iso::ValidationError::Success) + { dusk::getSettings().backend.isoPath.setValue(""); + dusk::getSettings().backend.isoVerification.setValue(dusk::DiscVerificationState::Unknown); } std::string dvd_path; bool dvd_opened = false; if (parsed_arg_options.count("dvd")) { dvd_path = parsed_arg_options["dvd"].as(); - if (dusk::iso::validate(dvd_path.c_str()) >= dusk::iso::ValidationError::HashMismatch) { + if (dusk::iso::inspect(dvd_path.c_str(), discInfo) == dusk::iso::ValidationError::Success) { DuskLog.info("Loading DVD image from command line: {}", dvd_path); dvd_opened = aurora_dvd_open(dvd_path.c_str()); if (!dvd_opened) { DuskLog.warn("Failed to open DVD image from command line: {}, opening prelaunch UI", dvd_path); } else { dusk::getSettings().backend.isoPath.setValue(dvd_path); + dusk::getSettings().backend.isoVerification.setValue( + dusk::DiscVerificationState::Unknown); dusk::config::Save(); dusk::IsGameLaunched = true; } } else { - DuskLog.warn("DVD image from command line failed verification: {}, opening prelaunch UI", dvd_path); + DuskLog.warn("DVD image from command line failed validation: {}, opening prelaunch UI", dvd_path); } } @@ -668,8 +675,9 @@ int game_main(int argc, char* argv[]) { DuskLog.fatal("No DVD image specified, unable to boot!"); } if (!dusk::IsGameLaunched && - dusk::iso::validate(dvd_path.c_str()) < dusk::iso::ValidationError::HashMismatch) { - DuskLog.fatal("DVD image failed verification: {}", dvd_path); + dusk::iso::inspect(dvd_path.c_str(), discInfo) != dusk::iso::ValidationError::Success) + { + DuskLog.fatal("DVD image failed validation: {}", dvd_path); } DuskLog.info("Loading DVD image: {}", dvd_path); if (!aurora_dvd_open(dvd_path.c_str())) {