HostInterface: Drop std::filesystem requirement

This commit is contained in:
Connor McLaughlin 2020-04-12 21:06:33 +10:00
parent e843fcd9f0
commit 6a03bb2d15
3 changed files with 30 additions and 43 deletions

View File

@ -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<ByteStream> OpenFile(const char* FileName, u32 Flags)
{
// has a path

View File

@ -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);

View File

@ -25,30 +25,6 @@ Log_SetChannel(HostInterface);
#include <mmsystem.h>
#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 <filesystem>
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<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
#define TRY_FILENAME(filename) \
do \
{ \
std::string try_filename = filename; \
std::optional<BIOS::Image> found_image = BIOS::LoadImageFromFile(try_filename); \
String try_filename = filename; \
std::optional<BIOS::Image> 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: