From 8f5c20bdf5640b8b7cd24ed5e16c2ebc91f02551 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 5 Jan 2021 12:20:21 +1000 Subject: [PATCH] BIOS: Improve robustness of BIOS searching Always prefer a known BIOS image over an unknown image. Hopefully this will stop people getting crashes on startup due to other files in the BIOS directory confusing it. --- src/core/host_interface.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index ef29745cf..2a7638125 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -301,6 +301,7 @@ std::optional> HostInterface::FindBIOSImageInDirectory(ConsoleRe std::string fallback_path; std::optional fallback_image; + const BIOS::ImageInfo* fallback_info = nullptr; for (const FILESYSTEM_FIND_DATA& fd : results) { @@ -320,14 +321,21 @@ std::optional> HostInterface::FindBIOSImageInDirectory(ConsoleRe BIOS::Hash found_hash = BIOS::GetHash(*found_image); Log_DevPrintf("Hash for BIOS '%s': %s", fd.FileName.c_str(), found_hash.ToString().c_str()); + const BIOS::ImageInfo* ii = BIOS::GetImageInfoForHash(found_hash); + if (BIOS::IsValidHashForRegion(region, found_hash)) { - Log_InfoPrintf("Using BIOS '%s'", fd.FileName.c_str()); + Log_InfoPrintf("Using BIOS '%s': %s", fd.FileName.c_str(), ii ? ii->description : ""); return found_image; } + // don't let an unknown bios take precedence over a known one + if (!fallback_path.empty() && (fallback_info || !ii)) + continue; + fallback_path = std::move(full_path); fallback_image = std::move(found_image); + fallback_info = ii; } if (!fallback_image.has_value()) @@ -338,7 +346,16 @@ std::optional> HostInterface::FindBIOSImageInDirectory(ConsoleRe return std::nullopt; } - Log_WarningPrintf("Falling back to possibly-incompatible image '%s'", fallback_path.c_str()); + if (!fallback_info) + { + Log_WarningPrintf("Using unknown BIOS '%s'. This may crash.", fallback_path.c_str()); + } + else + { + Log_WarningPrintf("Falling back to possibly-incompatible image '%s': %s", fallback_path.c_str(), + fallback_info->description); + } + return fallback_image; }