mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 22:05:38 +00:00
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.
This commit is contained in:
parent
5cd261a5b2
commit
8f5c20bdf5
|
@ -301,6 +301,7 @@ std::optional<std::vector<u8>> HostInterface::FindBIOSImageInDirectory(ConsoleRe
|
||||||
|
|
||||||
std::string fallback_path;
|
std::string fallback_path;
|
||||||
std::optional<BIOS::Image> fallback_image;
|
std::optional<BIOS::Image> fallback_image;
|
||||||
|
const BIOS::ImageInfo* fallback_info = nullptr;
|
||||||
|
|
||||||
for (const FILESYSTEM_FIND_DATA& fd : results)
|
for (const FILESYSTEM_FIND_DATA& fd : results)
|
||||||
{
|
{
|
||||||
|
@ -320,14 +321,21 @@ std::optional<std::vector<u8>> HostInterface::FindBIOSImageInDirectory(ConsoleRe
|
||||||
BIOS::Hash found_hash = BIOS::GetHash(*found_image);
|
BIOS::Hash found_hash = BIOS::GetHash(*found_image);
|
||||||
Log_DevPrintf("Hash for BIOS '%s': %s", fd.FileName.c_str(), found_hash.ToString().c_str());
|
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))
|
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;
|
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_path = std::move(full_path);
|
||||||
fallback_image = std::move(found_image);
|
fallback_image = std::move(found_image);
|
||||||
|
fallback_info = ii;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fallback_image.has_value())
|
if (!fallback_image.has_value())
|
||||||
|
@ -338,7 +346,16 @@ std::optional<std::vector<u8>> HostInterface::FindBIOSImageInDirectory(ConsoleRe
|
||||||
return std::nullopt;
|
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;
|
return fallback_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue