diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 71233d43b..b7b85bb1a 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -365,6 +365,14 @@ void BuildPathRelativeToFile(String& Destination, const char* CurrentFileName, c BuildOSPath(Destination, Destination.GetCharArray()); } +String BuildPathRelativeToFile(const char* CurrentFileName, const char* NewFileName, bool OSPath /*= true*/, + bool Canonicalize /*= true*/) +{ + String ret; + BuildPathRelativeToFile(ret, CurrentFileName, NewFileName, OSPath, Canonicalize); + return ret; +} + std::unique_ptr OpenFile(const char* FileName, u32 Flags) { // has a path diff --git a/src/common/file_system.h b/src/common/file_system.h index 43c059812..bb972e272 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -128,6 +128,8 @@ void BuildPathRelativeToFile(char* Destination, u32 cbDestination, const char* C bool OSPath = true, bool Canonicalize = true); void BuildPathRelativeToFile(String& Destination, const char* CurrentFileName, const char* NewFileName, bool OSPath = true, bool Canonicalize = true); +String BuildPathRelativeToFile(const char* CurrentFileName, const char* NewFileName, bool OSPath = true, + bool Canonicalize = true); // sanitizes a filename for use in a filesystem. void SanitizeFileName(char* Destination, u32 cbDestination, const char* FileName, bool StripSlashes = true); diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index c83af9a5a..648f3ae0b 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -25,30 +25,6 @@ Log_SetChannel(HostInterface); #include #endif -#if defined(ANDROID) || (defined(__GNUC__) && __GNUC__ < 8) - -static std::string GetRelativePath(const std::string& path, const char* new_filename) -{ - const char* last = std::strrchr(path.c_str(), '/'); - if (!last) - return new_filename; - - std::string new_path(path.c_str(), last - path.c_str() + 1); - new_path += new_filename; - return new_path; -} - -#else - -#include - -static std::string GetRelativePath(const std::string& path, const char* new_filename) -{ - return std::filesystem::path(path).replace_filename(new_filename).string(); -} - -#endif - HostInterface::HostInterface() = default; HostInterface::~HostInterface() @@ -388,47 +364,48 @@ std::optional> HostInterface::GetBIOSImage(ConsoleRegion region) #define TRY_FILENAME(filename) \ do \ { \ - std::string try_filename = filename; \ - std::optional found_image = BIOS::LoadImageFromFile(try_filename); \ + String try_filename = filename; \ + std::optional found_image = BIOS::LoadImageFromFile(try_filename.GetCharArray()); \ if (found_image) \ { \ BIOS::Hash found_hash = BIOS::GetHash(*found_image); \ - Log_DevPrintf("Hash for BIOS '%s': %s", try_filename.c_str(), found_hash.ToString().c_str()); \ + Log_DevPrintf("Hash for BIOS '%s': %s", try_filename.GetCharArray(), found_hash.ToString().c_str()); \ if (BIOS::IsValidHashForRegion(region, found_hash)) \ { \ - Log_InfoPrintf("Using BIOS from '%s'", try_filename.c_str()); \ + Log_InfoPrintf("Using BIOS from '%s' for region '%s'", try_filename.GetCharArray(), \ + Settings::GetConsoleRegionName(region)); \ return found_image; \ } \ } \ } while (0) // Try the configured image. - TRY_FILENAME(m_settings.bios_path); + TRY_FILENAME(m_settings.bios_path.c_str()); // Try searching in the same folder for other region's images. switch (region) { case ConsoleRegion::NTSC_J: - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1000.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-10j.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph3000.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-11j.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5500.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-30j.bin")); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1000.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-10j.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph3000.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-11j.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5500.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30j.bin", false, false)); break; case ConsoleRegion::NTSC_U: - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1001.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-22a.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5501.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-30a.bin")); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1001.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-22a.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5501.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30a.bin", false, false)); break; case ConsoleRegion::PAL: - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1002.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-21e.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5502.bin")); - TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-30e.bin")); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1002.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-21e.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5502.bin", false, false)); + TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30e.bin", false, false)); break; default: