BIOS: Add option to set search directory elsewhere

This commit is contained in:
Connor McLaughlin
2020-09-23 22:53:51 +10:00
parent a0a78087fe
commit d728bc091b
9 changed files with 166 additions and 64 deletions

View File

@ -199,53 +199,57 @@ void HostInterface::AddFormattedOSDMessage(float duration, const char* format, .
AddOSDMessage(std::move(message), duration);
}
std::string HostInterface::GetBIOSDirectory() const
std::string HostInterface::GetBIOSDirectory()
{
std::string dir = GetStringSettingValue("BIOS", "SearchDirectory", "");
if (!dir.empty())
return dir;
return GetUserDirectoryRelativePath("bios");
}
std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
{
const std::string* bios_path;
std::string bios_dir = GetBIOSDirectory();
std::string bios_name;
switch (region)
{
case ConsoleRegion::NTSC_J:
bios_path = &g_settings.bios_path_ntsc_j;
bios_name = GetStringSettingValue("BIOS", "PathNTSCJ", "");
break;
case ConsoleRegion::PAL:
bios_path = &g_settings.bios_path_pal;
bios_name = GetStringSettingValue("BIOS", "PAL", "");
break;
case ConsoleRegion::NTSC_U:
default:
bios_path = &g_settings.bios_path_ntsc_u;
bios_name = GetStringSettingValue("BIOS", "PathNTSCU", "");
break;
}
if (bios_path->empty())
if (bios_name.empty())
{
// auto-detect
return FindBIOSImageInDirectory(region, GetBIOSDirectory().c_str());
return FindBIOSImageInDirectory(region, bios_dir.c_str());
}
// try the configured path
std::optional<BIOS::Image> image = BIOS::LoadImageFromFile(
StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", GetBIOSDirectory().c_str(), bios_path->c_str())
.c_str());
StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", bios_dir.c_str(), bios_name.c_str()).c_str());
if (!image.has_value())
{
g_host_interface->ReportFormattedError(
g_host_interface->TranslateString("HostInterface", "Failed to load configured BIOS file '%s'"),
bios_path->c_str());
bios_name.c_str());
return std::nullopt;
}
BIOS::Hash found_hash = BIOS::GetHash(*image);
Log_DevPrintf("Hash for BIOS '%s': %s", bios_path->c_str(), found_hash.ToString().c_str());
Log_DevPrintf("Hash for BIOS '%s': %s", bios_name.c_str(), found_hash.ToString().c_str());
if (!BIOS::IsValidHashForRegion(region, found_hash))
Log_WarningPrintf("Hash for BIOS '%s' does not match region. This may cause issues.", bios_path->c_str());
Log_WarningPrintf("Hash for BIOS '%s' does not match region. This may cause issues.", bios_name.c_str());
return image;
}
@ -330,11 +334,6 @@ HostInterface::FindBIOSImagesInDirectory(const char* directory)
return results;
}
std::vector<std::pair<std::string, const BIOS::ImageInfo*>> HostInterface::FindBIOSImagesInUserDirectory()
{
return FindBIOSImagesInDirectory(GetUserDirectoryRelativePath("bios").c_str());
}
bool HostInterface::LoadState(const char* filename)
{
std::unique_ptr<ByteStream> stream = FileSystem::OpenFile(filename, BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED);
@ -464,6 +463,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetBoolValue("Audio", "Sync", true);
si.SetBoolValue("Audio", "DumpOnBoot", false);
si.SetStringValue("BIOS", "SearchDirectory", "");
si.SetStringValue("BIOS", "PathNTSCU", "");
si.SetStringValue("BIOS", "PathNTSCJ", "");
si.SetStringValue("BIOS", "PathPAL", "");

View File

@ -119,7 +119,7 @@ public:
virtual std::string TranslateStdString(const char* context, const char* str) const;
/// Returns the path to the directory to search for BIOS images.
virtual std::string GetBIOSDirectory() const;
virtual std::string GetBIOSDirectory();
/// Loads the BIOS image for the specified region.
std::optional<std::vector<u8>> GetBIOSImage(ConsoleRegion region);
@ -130,7 +130,6 @@ public:
/// Returns a list of filenames and descriptions for BIOS images in a directory.
std::vector<std::pair<std::string, const BIOS::ImageInfo*>> FindBIOSImagesInDirectory(const char* directory);
std::vector<std::pair<std::string, const BIOS::ImageInfo*>> FindBIOSImagesInUserDirectory();
virtual void OnRunningGameChanged();
virtual void OnSystemPerformanceCountersUpdated();

View File

@ -157,9 +157,6 @@ void Settings::Load(SettingsInterface& si)
gpu_fifo_size = static_cast<u32>(si.GetIntValue("Hacks", "GPUFIFOSize", DEFAULT_GPU_FIFO_SIZE));
gpu_max_run_ahead = si.GetIntValue("Hacks", "GPUMaxRunAhead", DEFAULT_GPU_MAX_RUN_AHEAD);
bios_path_ntsc_u = si.GetStringValue("BIOS", "PathNTSCU", "");
bios_path_ntsc_j = si.GetStringValue("BIOS", "PathNTSCJ", "");
bios_path_pal = si.GetStringValue("BIOS", "PathPAL", "");
bios_patch_tty_enable = si.GetBoolValue("BIOS", "PatchTTYEnable", false);
bios_patch_fast_boot = si.GetBoolValue("BIOS", "PatchFastBoot", false);
@ -273,9 +270,6 @@ void Settings::Save(SettingsInterface& si) const
si.SetIntValue("Hacks", "GPUFIFOSize", gpu_fifo_size);
si.SetIntValue("Hacks", "GPUMaxRunAhead", gpu_max_run_ahead);
si.SetStringValue("BIOS", "PathNTSCJ", bios_path_ntsc_j.c_str());
si.SetStringValue("BIOS", "PathNTSCU", bios_path_ntsc_u.c_str());
si.SetStringValue("BIOS", "PathPAL", bios_path_pal.c_str());
si.SetBoolValue("BIOS", "PatchTTYEnable", bios_patch_tty_enable);
si.SetBoolValue("BIOS", "PatchFastBoot", bios_patch_fast_boot);

View File

@ -147,9 +147,6 @@ struct Settings
// TODO: Controllers, memory cards, etc.
std::string bios_path_ntsc_j;
std::string bios_path_ntsc_u;
std::string bios_path_pal;
bool bios_patch_tty_enable = false;
bool bios_patch_fast_boot = false;