Settings: Add UserResources to EmuFolders
Allowing some resources, such as fonts/sounds to be overridden by the user.
This commit is contained in:
@ -1022,7 +1022,7 @@ void Achievements::DisplayAchievementSummary()
|
||||
|
||||
// Technically not going through the resource API, but since we're passing this to something else, we can't.
|
||||
if (g_settings.achievements_sound_effects)
|
||||
PlatformMisc::PlaySoundAsync(Path::Combine(EmuFolders::Resources, INFO_SOUND_NAME).c_str());
|
||||
PlatformMisc::PlaySoundAsync(EmuFolders::GetOverridableResourcePath(INFO_SOUND_NAME).c_str());
|
||||
}
|
||||
|
||||
void Achievements::DisplayHardcoreDeferredMessage()
|
||||
@ -1069,7 +1069,7 @@ void Achievements::HandleUnlockEvent(const rc_client_event_t* event)
|
||||
}
|
||||
|
||||
if (g_settings.achievements_sound_effects)
|
||||
PlatformMisc::PlaySoundAsync(Path::Combine(EmuFolders::Resources, UNLOCK_SOUND_NAME).c_str());
|
||||
PlatformMisc::PlaySoundAsync(EmuFolders::GetOverridableResourcePath(UNLOCK_SOUND_NAME).c_str());
|
||||
}
|
||||
|
||||
void Achievements::HandleGameCompleteEvent(const rc_client_event_t* event)
|
||||
@ -1144,7 +1144,7 @@ void Achievements::HandleLeaderboardSubmittedEvent(const rc_client_event_t* even
|
||||
}
|
||||
|
||||
if (g_settings.achievements_sound_effects)
|
||||
PlatformMisc::PlaySoundAsync(Path::Combine(EmuFolders::Resources, LBSUBMIT_SOUND_NAME).c_str());
|
||||
PlatformMisc::PlaySoundAsync(EmuFolders::GetOverridableResourcePath(LBSUBMIT_SOUND_NAME).c_str());
|
||||
}
|
||||
|
||||
void Achievements::HandleLeaderboardScoreboardEvent(const rc_client_event_t* event)
|
||||
|
||||
@ -689,7 +689,7 @@ bool CheatList::SaveToPCSXRFile(const char* filename)
|
||||
|
||||
bool CheatList::LoadFromPackage(const std::string& serial)
|
||||
{
|
||||
const std::optional<std::string> db_string(Host::ReadResourceFileToString("chtdb.txt"));
|
||||
const std::optional<std::string> db_string(Host::ReadResourceFileToString("chtdb.txt", false));
|
||||
if (!db_string.has_value())
|
||||
return false;
|
||||
|
||||
|
||||
@ -580,7 +580,7 @@ bool GameDatabase::LoadFromCache()
|
||||
return false;
|
||||
}
|
||||
|
||||
const u64 gamedb_ts = Host::GetResourceFileTimestamp("gamedb.json").value_or(0);
|
||||
const u64 gamedb_ts = Host::GetResourceFileTimestamp("gamedb.json", false).value_or(0);
|
||||
|
||||
u32 signature, version, num_entries, num_codes;
|
||||
u64 file_gamedb_ts;
|
||||
@ -674,7 +674,7 @@ bool GameDatabase::LoadFromCache()
|
||||
|
||||
bool GameDatabase::SaveToCache()
|
||||
{
|
||||
const u64 gamedb_ts = Host::GetResourceFileTimestamp("gamedb.json").value_or(0);
|
||||
const u64 gamedb_ts = Host::GetResourceFileTimestamp("gamedb.json", false).value_or(0);
|
||||
|
||||
std::unique_ptr<ByteStream> stream(
|
||||
ByteStream::OpenFile(GetCacheFile().c_str(), BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_WRITE |
|
||||
@ -830,7 +830,7 @@ static std::optional<float> GetOptionalFloatFromObject(const rapidjson::Value& o
|
||||
|
||||
bool GameDatabase::LoadGameDBJson()
|
||||
{
|
||||
std::optional<std::string> gamedb_data(Host::ReadResourceFileToString("gamedb.json"));
|
||||
std::optional<std::string> gamedb_data(Host::ReadResourceFileToString("gamedb.json", false));
|
||||
if (!gamedb_data.has_value())
|
||||
{
|
||||
Log_ErrorPrintf("Failed to read game database");
|
||||
@ -1082,7 +1082,7 @@ void GameDatabase::EnsureTrackHashesMapLoaded()
|
||||
|
||||
bool GameDatabase::LoadTrackHashes()
|
||||
{
|
||||
std::optional<std::string> gamedb_data(Host::ReadResourceFileToString("gamedb.json"));
|
||||
std::optional<std::string> gamedb_data(Host::ReadResourceFileToString("gamedb.json", false));
|
||||
if (!gamedb_data.has_value())
|
||||
{
|
||||
Log_ErrorPrintf("Failed to read game database");
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#include "settings.h"
|
||||
@ -1504,6 +1504,7 @@ std::string EmuFolders::SaveStates;
|
||||
std::string EmuFolders::Screenshots;
|
||||
std::string EmuFolders::Shaders;
|
||||
std::string EmuFolders::Textures;
|
||||
std::string EmuFolders::UserResources;
|
||||
|
||||
void EmuFolders::SetDefaults()
|
||||
{
|
||||
@ -1519,6 +1520,7 @@ void EmuFolders::SetDefaults()
|
||||
Screenshots = Path::Combine(DataRoot, "screenshots");
|
||||
Shaders = Path::Combine(DataRoot, "shaders");
|
||||
Textures = Path::Combine(DataRoot, "textures");
|
||||
UserResources = Path::Combine(DataRoot, "resources");
|
||||
}
|
||||
|
||||
static std::string LoadPathFromSettings(SettingsInterface& si, const std::string& root, const char* section,
|
||||
@ -1546,19 +1548,22 @@ void EmuFolders::LoadConfig(SettingsInterface& si)
|
||||
Screenshots = LoadPathFromSettings(si, DataRoot, "Folders", "Screenshots", "screenshots");
|
||||
Shaders = LoadPathFromSettings(si, DataRoot, "Folders", "Shaders", "shaders");
|
||||
Textures = LoadPathFromSettings(si, DataRoot, "Folders", "Textures", "textures");
|
||||
UserResources = LoadPathFromSettings(si, DataRoot, "Folders", "UserResources", "resources");
|
||||
|
||||
Log_DevPrintf("BIOS Directory: %s", Bios.c_str());
|
||||
Log_DevPrintf("Cache Directory: %s", Cache.c_str());
|
||||
Log_DevPrintf("Cheats Directory: %s", Cheats.c_str());
|
||||
Log_DevPrintf("Covers Directory: %s", Covers.c_str());
|
||||
Log_DevPrintf("Dumps Directory: %s", Dumps.c_str());
|
||||
Log_DevPrintf("Game Settings Directory: %s", GameSettings.c_str());
|
||||
Log_DevPrintf("Input Profile Directory: %s", InputProfiles.c_str());
|
||||
Log_DevPrintf("MemoryCards Directory: %s", MemoryCards.c_str());
|
||||
Log_DevPrintf("SaveStates Directory: %s", SaveStates.c_str());
|
||||
Log_DevPrintf("Screenshots Directory: %s", Screenshots.c_str());
|
||||
Log_DevPrintf("Shaders Directory: %s", Shaders.c_str());
|
||||
Log_DevPrintf("Textures Directory: %s", Textures.c_str());
|
||||
Log_DevFmt("BIOS Directory: {}", Bios);
|
||||
Log_DevFmt("Cache Directory: {}", Cache);
|
||||
Log_DevFmt("Cheats Directory: {}", Cheats);
|
||||
Log_DevFmt("Covers Directory: {}", Covers);
|
||||
Log_DevFmt("Dumps Directory: {}", Dumps);
|
||||
Log_DevFmt("Game Settings Directory: {}", GameSettings);
|
||||
Log_DevFmt("Input Profile Directory: {}", InputProfiles);
|
||||
Log_DevFmt("MemoryCards Directory: {}", MemoryCards);
|
||||
Log_DevFmt("Resources Directory: {}", Resources);
|
||||
Log_DevFmt("SaveStates Directory: {}", SaveStates);
|
||||
Log_DevFmt("Screenshots Directory: {}", Screenshots);
|
||||
Log_DevFmt("Shaders Directory: {}", Shaders);
|
||||
Log_DevFmt("Textures Directory: {}", Textures);
|
||||
Log_DevFmt("User Resources Directory: {}", UserResources);
|
||||
}
|
||||
|
||||
void EmuFolders::Save(SettingsInterface& si)
|
||||
@ -1576,6 +1581,7 @@ void EmuFolders::Save(SettingsInterface& si)
|
||||
si.SetStringValue("Folders", "Screenshots", Path::MakeRelative(Screenshots, DataRoot).c_str());
|
||||
si.SetStringValue("Folders", "Shaders", Path::MakeRelative(Shaders, DataRoot).c_str());
|
||||
si.SetStringValue("Folders", "Textures", Path::MakeRelative(Textures, DataRoot).c_str());
|
||||
si.SetStringValue("Folders", "UserResources", Path::MakeRelative(UserResources, DataRoot).c_str());
|
||||
}
|
||||
|
||||
void EmuFolders::Update()
|
||||
@ -1623,9 +1629,26 @@ bool EmuFolders::EnsureFoldersExist()
|
||||
Path::Combine(Shaders, "reshade" FS_OSPATH_SEPARATOR_STR "Textures").c_str(), false) &&
|
||||
result;
|
||||
result = FileSystem::EnsureDirectoryExists(Textures.c_str(), false) && result;
|
||||
result = FileSystem::EnsureDirectoryExists(UserResources.c_str(), false) && result;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string EmuFolders::GetOverridableResourcePath(std::string_view name)
|
||||
{
|
||||
std::string upath = Path::Combine(UserResources, name);
|
||||
if (FileSystem::FileExists(upath.c_str()))
|
||||
{
|
||||
if (UserResources != Resources)
|
||||
Log_WarningFmt("Using user-provided resource file {}", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
upath = Path::Combine(Resources, name);
|
||||
}
|
||||
|
||||
return upath;
|
||||
}
|
||||
|
||||
static const char* s_log_filters[] = {
|
||||
"Achievements",
|
||||
"AnalogController",
|
||||
|
||||
@ -1,15 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "util/audio_stream.h"
|
||||
|
||||
#include "common/log.h"
|
||||
#include "common/settings_interface.h"
|
||||
#include "common/small_string.h"
|
||||
#include "types.h"
|
||||
#include "util/audio_stream.h"
|
||||
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
enum class RenderAPI : u32;
|
||||
@ -525,6 +530,7 @@ extern std::string SaveStates;
|
||||
extern std::string Screenshots;
|
||||
extern std::string Shaders;
|
||||
extern std::string Textures;
|
||||
extern std::string UserResources;
|
||||
|
||||
// Assumes that AppRoot and DataRoot have been initialized.
|
||||
void SetDefaults();
|
||||
@ -534,4 +540,7 @@ void Save(SettingsInterface& si);
|
||||
|
||||
/// Updates the variables in the EmuFolders namespace, reloading subsystems if needed.
|
||||
void Update();
|
||||
|
||||
/// Returns the path to a resource file, allowing the user to override it.
|
||||
std::string GetOverridableResourcePath(std::string_view name);
|
||||
} // namespace EmuFolders
|
||||
|
||||
Reference in New Issue
Block a user