Don't hash on startup & cleanup

This commit is contained in:
Luke Street
2026-05-06 23:33:55 -06:00
parent c50d777309
commit 647394c875
3 changed files with 26 additions and 41 deletions
+12 -34
View File
@@ -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<SDL_IOStream*>(user_data);
auto ret = SDL_SeekIO(io, static_cast<s64>(offset), SDL_IO_SEEK_SET);
auto* io = static_cast<SDL_IOStream*>(user_data);
const auto ret = SDL_SeekIO(io, static_cast<s64>(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<s64>(read);
}
s64 StreamLength(void* user_data) {
auto io = static_cast<SDL_IOStream*>(user_data);
return SDL_GetIOSize(io);
return SDL_GetIOSize(static_cast<SDL_IOStream*>(user_data));
}
void StreamClose(void* user_data) {
auto io = static_cast<SDL_IOStream*>(user_data);
SDL_CloseIO(io);
SDL_CloseIO(static_cast<SDL_IOStream*>(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));
-1
View File
@@ -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
+14 -6
View File
@@ -618,28 +618,35 @@ int game_main(int argc, char* argv[]) {
dusk::ui::push_document(std::make_unique<dusk::ui::Overlay>(), true, true);
dusk::ui::push_document(std::make_unique<dusk::ui::MenuBar>(), 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<std::string>();
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())) {