diff --git a/src/core/bios.cpp b/src/core/bios.cpp index 921fb8842..2ce44ab00 100644 --- a/src/core/bios.cpp +++ b/src/core/bios.cpp @@ -367,6 +367,35 @@ std::optional> BIOS::FindBIOSImageInDirectory(ConsoleRegion regi return fallback_image; } +std::string BIOS::FindBIOSPathWithHash(const char* directory, const Hash& hash) +{ + FileSystem::FindResultsArray files; + FileSystem::FindFiles(directory, "*", + FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES | FILESYSTEM_FIND_RELATIVE_PATHS, &files); + + std::string ret; + + for (FILESYSTEM_FIND_DATA& fd : files) + { + if (fd.Size != BIOS_SIZE && fd.Size != BIOS_SIZE_PS2 && fd.Size != BIOS_SIZE_PS3) + continue; + + std::string full_path(Path::Combine(directory, fd.FileName)); + std::optional found_image = LoadImageFromFile(full_path.c_str()); + if (!found_image) + continue; + + const BIOS::Hash found_hash = GetImageHash(found_image.value()); + if (found_hash == hash) + { + ret = std::move(full_path); + break; + } + } + + return ret; +} + std::vector> BIOS::FindBIOSImagesInDirectory(const char* directory) { std::vector> results; diff --git a/src/core/bios.h b/src/core/bios.h index 55e38a954..d5f114abb 100644 --- a/src/core/bios.h +++ b/src/core/bios.h @@ -80,6 +80,9 @@ std::optional> GetBIOSImage(ConsoleRegion region); /// BIOS image within 512KB and 4MB will be used. std::optional> FindBIOSImageInDirectory(ConsoleRegion region, const char* directory); +/// Returns a BIOS image which matches the specified hash. +std::string FindBIOSPathWithHash(const char* directory, const BIOS::Hash& hash); + /// Returns a list of filenames and descriptions for BIOS images in a directory. std::vector> FindBIOSImagesInDirectory(const char* directory);