Settings: Add UserResources to EmuFolders

Allowing some resources, such as fonts/sounds to be overridden by the
user.
This commit is contained in:
Stenzek
2024-01-10 13:35:06 +10:00
parent e4e7080f98
commit 73cee9f705
14 changed files with 105 additions and 59 deletions

View File

@@ -75,6 +75,7 @@ static void SetResourcesDirectory();
static void SetDataDirectory();
static bool SetCriticalFolders();
static void SetDefaultSettings(SettingsInterface& si, bool system, bool controller);
static std::string GetResourcePath(std::string_view name, bool allow_override);
static void StartCPUThread();
static void StopCPUThread();
static void ProcessCPUThreadEvents(bool block);
@@ -360,33 +361,39 @@ s32 Host::Internal::GetTranslatedStringImpl(const std::string_view& context, con
return static_cast<s32>(msg.size());
}
bool Host::ResourceFileExists(const char* filename)
ALWAYS_INLINE std::string NoGUIHost::GetResourcePath(std::string_view filename, bool allow_override)
{
const std::string path(Path::Combine(EmuFolders::Resources, filename));
return allow_override ? EmuFolders::GetOverridableResourcePath(filename) :
Path::Combine(EmuFolders::Resources, filename);
}
bool Host::ResourceFileExists(std::string_view filename, bool allow_override)
{
const std::string path = NoGUIHost::GetResourcePath(filename, allow_override);
return FileSystem::FileExists(path.c_str());
}
std::optional<std::vector<u8>> Host::ReadResourceFile(const char* filename)
std::optional<std::vector<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
{
const std::string path(Path::Combine(EmuFolders::Resources, filename));
const std::string path = NoGUIHost::GetResourcePath(filename, allow_override);
std::optional<std::vector<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
if (!ret.has_value())
Log_ErrorPrintf("Failed to read resource file '%s'", filename);
return ret;
}
std::optional<std::string> Host::ReadResourceFileToString(const char* filename)
std::optional<std::string> Host::ReadResourceFileToString(std::string_view filename, bool allow_override)
{
const std::string path(Path::Combine(EmuFolders::Resources, filename));
const std::string path = NoGUIHost::GetResourcePath(filename, allow_override);
std::optional<std::string> ret(FileSystem::ReadFileToString(path.c_str()));
if (!ret.has_value())
Log_ErrorPrintf("Failed to read resource file to string '%s'", filename);
return ret;
}
std::optional<std::time_t> Host::GetResourceFileTimestamp(const char* filename)
std::optional<std::time_t> Host::GetResourceFileTimestamp(std::string_view filename, bool allow_override)
{
const std::string path(Path::Combine(EmuFolders::Resources, filename));
const std::string path = NoGUIHost::GetResourcePath(filename, allow_override);
FILESYSTEM_STAT_DATA sd;
if (!FileSystem::StatFile(path.c_str(), &sd))
{