HostInterface: Drop std::filesystem requirement
This commit is contained in:
parent
e843fcd9f0
commit
6a03bb2d15
|
@ -365,6 +365,14 @@ void BuildPathRelativeToFile(String& Destination, const char* CurrentFileName, c
|
||||||
BuildOSPath(Destination, Destination.GetCharArray());
|
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)
|
std::unique_ptr<ByteStream> OpenFile(const char* FileName, u32 Flags)
|
||||||
{
|
{
|
||||||
// has a path
|
// has a path
|
||||||
|
|
|
@ -128,6 +128,8 @@ void BuildPathRelativeToFile(char* Destination, u32 cbDestination, const char* C
|
||||||
bool OSPath = true, bool Canonicalize = true);
|
bool OSPath = true, bool Canonicalize = true);
|
||||||
void BuildPathRelativeToFile(String& Destination, const char* CurrentFileName, const char* NewFileName,
|
void BuildPathRelativeToFile(String& Destination, const char* CurrentFileName, const char* NewFileName,
|
||||||
bool OSPath = true, bool Canonicalize = true);
|
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.
|
// sanitizes a filename for use in a filesystem.
|
||||||
void SanitizeFileName(char* Destination, u32 cbDestination, const char* FileName, bool StripSlashes = true);
|
void SanitizeFileName(char* Destination, u32 cbDestination, const char* FileName, bool StripSlashes = true);
|
||||||
|
|
|
@ -25,30 +25,6 @@ Log_SetChannel(HostInterface);
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
#endif
|
#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() = default;
|
||||||
|
|
||||||
HostInterface::~HostInterface()
|
HostInterface::~HostInterface()
|
||||||
|
@ -388,47 +364,48 @@ std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
|
||||||
#define TRY_FILENAME(filename) \
|
#define TRY_FILENAME(filename) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
std::string try_filename = filename; \
|
String try_filename = filename; \
|
||||||
std::optional<BIOS::Image> found_image = BIOS::LoadImageFromFile(try_filename); \
|
std::optional<BIOS::Image> found_image = BIOS::LoadImageFromFile(try_filename.GetCharArray()); \
|
||||||
if (found_image) \
|
if (found_image) \
|
||||||
{ \
|
{ \
|
||||||
BIOS::Hash found_hash = BIOS::GetHash(*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)) \
|
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; \
|
return found_image; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Try the configured image.
|
// 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.
|
// Try searching in the same folder for other region's images.
|
||||||
switch (region)
|
switch (region)
|
||||||
{
|
{
|
||||||
case ConsoleRegion::NTSC_J:
|
case ConsoleRegion::NTSC_J:
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1000.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1000.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-10j.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-10j.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph3000.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph3000.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-11j.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-11j.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5500.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5500.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-30j.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30j.bin", false, false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleRegion::NTSC_U:
|
case ConsoleRegion::NTSC_U:
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1001.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1001.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-22a.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-22a.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5501.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5501.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-30a.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30a.bin", false, false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleRegion::PAL:
|
case ConsoleRegion::PAL:
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1002.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1002.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-21e.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-21e.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5502.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5502.bin", false, false));
|
||||||
TRY_FILENAME(GetRelativePath(m_settings.bios_path, "ps-30e.bin"));
|
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30e.bin", false, false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue