diff --git a/common/FileSystem.cpp b/common/FileSystem.cpp index 9898196baf..461f098494 100644 --- a/common/FileSystem.cpp +++ b/common/FileSystem.cpp @@ -764,6 +764,15 @@ s64 FileSystem::GetPathFileSize(const char* Path) return sd.Size; } +std::optional FileSystem::GetFileTimestamp(const char* path) +{ + FILESYSTEM_STAT_DATA sd; + if (!StatFile(path, &sd)) + return std::nullopt; + + return sd.ModificationTime; +} + std::optional> FileSystem::ReadBinaryFile(const char* filename) { ManagedCFilePtr fp = OpenManagedCFile(filename, "rb"); diff --git a/common/FileSystem.h b/common/FileSystem.h index ec5b19b9da..13d0cb4b37 100644 --- a/common/FileSystem.h +++ b/common/FileSystem.h @@ -87,6 +87,9 @@ namespace FileSystem bool StatFile(std::FILE* fp, FILESYSTEM_STAT_DATA* pStatData); s64 GetPathFileSize(const char* path); + /// Returns the last modified timestamp for a file. + std::optional GetFileTimestamp(const char* path); + /// File exists? bool FileExists(const char* path); diff --git a/pcsx2-gsrunner/Main.cpp b/pcsx2-gsrunner/Main.cpp index afcfbd9c83..3249a0bcf1 100644 --- a/pcsx2-gsrunner/Main.cpp +++ b/pcsx2-gsrunner/Main.cpp @@ -168,34 +168,6 @@ void Host::SetDefaultUISettings(SettingsInterface& si) // nothing } -std::optional> Host::ReadResourceFile(const char* filename) -{ - const std::string path(Path::Combine(EmuFolders::Resources, filename)); - std::optional> ret(FileSystem::ReadBinaryFile(path.c_str())); - if (!ret.has_value()) - Console.Error("Failed to read resource file '%s'", filename); - return ret; -} - -std::optional Host::ReadResourceFileToString(const char* filename) -{ - const std::string path(Path::Combine(EmuFolders::Resources, filename)); - std::optional ret(FileSystem::ReadFileToString(path.c_str())); - if (!ret.has_value()) - Console.Error("Failed to read resource file to string '%s'", filename); - return ret; -} - -std::optional Host::GetResourceFileTimestamp(const char* filename) -{ - const std::string path(Path::Combine(EmuFolders::Resources, filename)); - FILESYSTEM_STAT_DATA sd; - if (!FileSystem::StatFile(filename, &sd)) - return std::nullopt; - - return sd.ModificationTime; -} - void Host::ReportErrorAsync(const std::string_view& title, const std::string_view& message) { if (!title.empty() && !message.empty()) diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index eab290deed..2bb9cb5bdd 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -1407,34 +1407,6 @@ QString QtHost::GetResourcesBasePath() return QString::fromStdString(EmuFolders::Resources); } -std::optional> Host::ReadResourceFile(const char* filename) -{ - const std::string path(Path::Combine(EmuFolders::Resources, filename)); - std::optional> ret(FileSystem::ReadBinaryFile(path.c_str())); - if (!ret.has_value()) - Console.Error("Failed to read resource file '%s'", filename); - return ret; -} - -std::optional Host::ReadResourceFileToString(const char* filename) -{ - const std::string path(Path::Combine(EmuFolders::Resources, filename)); - std::optional ret(FileSystem::ReadFileToString(path.c_str())); - if (!ret.has_value()) - Console.Error("Failed to read resource file to string '%s'", filename); - return ret; -} - -std::optional Host::GetResourceFileTimestamp(const char* filename) -{ - const std::string path(Path::Combine(EmuFolders::Resources, filename)); - FILESYSTEM_STAT_DATA sd; - if (!FileSystem::StatFile(filename, &sd)) - return std::nullopt; - - return sd.ModificationTime; -} - void Host::ReportErrorAsync(const std::string_view& title, const std::string_view& message) { if (!title.empty() && !message.empty()) diff --git a/pcsx2/GS/Renderers/Common/GSDevice.cpp b/pcsx2/GS/Renderers/Common/GSDevice.cpp index 586f79f2c1..49eabbaa8c 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.cpp +++ b/pcsx2/GS/Renderers/Common/GSDevice.cpp @@ -21,6 +21,8 @@ #include "Host.h" #include "common/BitUtils.h" +#include "common/FileSystem.h" +#include "common/Path.h" #include "common/StringUtil.h" #include "imgui.h" @@ -188,6 +190,11 @@ void GSDevice::GenerateExpansionIndexBuffer(void* buffer) } } +std::optional GSDevice::ReadShaderSource(const char* filename) +{ + return FileSystem::ReadFileToString(Path::Combine(EmuFolders::Resources, filename).c_str()); +} + bool GSDevice::Create() { m_vsync_mode = Host::GetEffectiveVSyncMode(); @@ -710,8 +717,8 @@ void GSDevice::SetHWDrawConfigForAlphaPass(GSHWDrawConfig::PSSelector* ps, bool GSDevice::GetCASShaderSource(std::string* source) { - std::optional ffx_a_source(Host::ReadResourceFileToString("shaders/common/ffx_a.h")); - std::optional ffx_cas_source(Host::ReadResourceFileToString("shaders/common/ffx_cas.h")); + std::optional ffx_a_source = ReadShaderSource("shaders/common/ffx_a.h"); + std::optional ffx_cas_source = ReadShaderSource("shaders/common/ffx_cas.h"); if (!ffx_a_source.has_value() || !ffx_cas_source.has_value()) return false; diff --git a/pcsx2/GS/Renderers/Common/GSDevice.h b/pcsx2/GS/Renderers/Common/GSDevice.h index 4aca1669cf..178fbf7ca6 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.h +++ b/pcsx2/GS/Renderers/Common/GSDevice.h @@ -824,6 +824,9 @@ public: /// Generates a fixed index buffer for expanding points and sprites. Buffer is assumed to be at least EXPAND_BUFFER_SIZE in size. static void GenerateExpansionIndexBuffer(void* buffer); + /// Reads the specified shader source file. + static std::optional ReadShaderSource(const char* filename); + __fi u64 GetPoolMemoryUsage() const { return m_pool_memory_usage; } __fi FeatureSupport Features() const { return m_features; } diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp index 095e638aec..2c34305ed5 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp @@ -179,7 +179,7 @@ bool GSDevice11::Create() SetFeatures(dxgi_adapter.get()); - std::optional shader = Host::ReadResourceFileToString("shaders/dx11/tfx.fx"); + std::optional shader = ReadShaderSource("shaders/dx11/tfx.fx"); if (!shader.has_value()) return false; m_tfx_source = std::move(*shader); @@ -193,7 +193,7 @@ bool GSDevice11::Create() {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0}, }; - std::optional convert_hlsl = Host::ReadResourceFileToString("shaders/dx11/convert.fx"); + const std::optional convert_hlsl = ReadShaderSource("shaders/dx11/convert.fx"); if (!convert_hlsl.has_value()) return false; if (!m_shader_cache.GetVertexShaderAndInputLayout(m_dev.get(), m_convert.vs.put(), m_convert.il.put(), @@ -209,7 +209,7 @@ bool GSDevice11::Create() return false; } - shader = Host::ReadResourceFileToString("shaders/dx11/present.fx"); + shader = ReadShaderSource("shaders/dx11/present.fx"); if (!shader.has_value()) return false; if (!m_shader_cache.GetVertexShaderAndInputLayout(m_dev.get(), m_present.vs.put(), m_present.il.put(), @@ -261,7 +261,7 @@ bool GSDevice11::Create() m_dev->CreateBuffer(&bd, nullptr, m_merge.cb.put()); - shader = Host::ReadResourceFileToString("shaders/dx11/merge.fx"); + shader = ReadShaderSource("shaders/dx11/merge.fx"); if (!shader.has_value()) return false; @@ -296,7 +296,7 @@ bool GSDevice11::Create() m_dev->CreateBuffer(&bd, nullptr, m_interlace.cb.put()); - shader = Host::ReadResourceFileToString("shaders/dx11/interlace.fx"); + shader = ReadShaderSource("shaders/dx11/interlace.fx"); if (!shader.has_value()) return false; for (size_t i = 0; i < std::size(m_interlace.ps); i++) @@ -316,7 +316,7 @@ bool GSDevice11::Create() m_dev->CreateBuffer(&bd, nullptr, m_shadeboost.cb.put()); - shader = Host::ReadResourceFileToString("shaders/dx11/shadeboost.fx"); + shader = ReadShaderSource("shaders/dx11/shadeboost.fx"); if (!shader.has_value()) return false; m_shadeboost.ps = m_shader_cache.GetPixelShader(m_dev.get(), *shader, nullptr, "ps_main"); @@ -1565,7 +1565,7 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex) if (!m_fxaa_ps) { - std::optional shader = Host::ReadResourceFileToString("shaders/common/fxaa.fx"); + const std::optional shader = ReadShaderSource("shaders/common/fxaa.fx"); if (!shader.has_value()) { Console.Error("FXAA shader is missing"); @@ -1879,7 +1879,7 @@ bool GSDevice11::CreateCASShaders() if (FAILED(hr)) return false; - std::optional cas_source(Host::ReadResourceFileToString("shaders/dx11/cas.hlsl")); + std::optional cas_source = ReadShaderSource("shaders/dx11/cas.hlsl"); if (!cas_source.has_value() || !GetCASShaderSource(&cas_source.value())) return false; @@ -1927,7 +1927,7 @@ bool GSDevice11::CreateImGuiResources() { HRESULT hr; - const std::optional hlsl = Host::ReadResourceFileToString("shaders/dx11/imgui.fx"); + const std::optional hlsl = ReadShaderSource("shaders/dx11/imgui.fx"); if (!hlsl.has_value()) { Console.Error("Failed to read imgui.fx"); diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index 4994e369e0..faf44c008a 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -707,7 +707,7 @@ bool GSDevice12::Create() return false; { - std::optional shader = Host::ReadResourceFileToString("shaders/dx11/tfx.fx"); + std::optional shader = ReadShaderSource("shaders/dx11/tfx.fx"); if (!shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/dx11/tfx.fxf."); @@ -1871,7 +1871,7 @@ bool GSDevice12::CompileCASPipelines() if (!m_cas_root_signature) return false; - std::optional cas_source(Host::ReadResourceFileToString("shaders/dx11/cas.hlsl")); + std::optional cas_source = ReadShaderSource("shaders/dx11/cas.hlsl"); if (!cas_source.has_value() || !GetCASShaderSource(&cas_source.value())) return false; @@ -1899,7 +1899,7 @@ bool GSDevice12::CompileCASPipelines() bool GSDevice12::CompileImGuiPipeline() { - const std::optional hlsl = Host::ReadResourceFileToString("shaders/dx11/imgui.fx"); + const std::optional hlsl = ReadShaderSource("shaders/dx11/imgui.fx"); if (!hlsl.has_value()) { Console.Error("Failed to read imgui.fx"); @@ -2368,7 +2368,7 @@ bool GSDevice12::CreateRootSignatures() bool GSDevice12::CompileConvertPipelines() { - std::optional shader = Host::ReadResourceFileToString("shaders/dx11/convert.fx"); + std::optional shader = ReadShaderSource("shaders/dx11/convert.fx"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/dx11/convert.fx."); @@ -2519,7 +2519,7 @@ bool GSDevice12::CompileConvertPipelines() bool GSDevice12::CompilePresentPipelines() { - std::optional shader = Host::ReadResourceFileToString("shaders/dx11/present.fx"); + const std::optional shader = ReadShaderSource("shaders/dx11/present.fx"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/dx11/present.fx."); @@ -2563,7 +2563,7 @@ bool GSDevice12::CompilePresentPipelines() bool GSDevice12::CompileInterlacePipelines() { - std::optional source = Host::ReadResourceFileToString("shaders/dx11/interlace.fx"); + const std::optional source = ReadShaderSource("shaders/dx11/interlace.fx"); if (!source) { Host::ReportErrorAsync("GS", "Failed to read shaders/dx11/interlace.fx."); @@ -2599,7 +2599,7 @@ bool GSDevice12::CompileInterlacePipelines() bool GSDevice12::CompileMergePipelines() { - std::optional shader = Host::ReadResourceFileToString("shaders/dx11/merge.fx"); + const std::optional shader = ReadShaderSource("shaders/dx11/merge.fx"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/dx11/merge.fx."); @@ -2646,7 +2646,7 @@ bool GSDevice12::CompilePostProcessingPipelines() gpb.SetVertexShader(m_convert_vs.get()); { - std::optional shader = Host::ReadResourceFileToString("shaders/common/fxaa.fx"); + const std::optional shader = ReadShaderSource("shaders/common/fxaa.fx"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/common/fxaa.fx."); @@ -2669,7 +2669,7 @@ bool GSDevice12::CompilePostProcessingPipelines() } { - std::optional shader = Host::ReadResourceFileToString("shaders/dx11/shadeboost.fx"); + const std::optional shader = ReadShaderSource("shaders/dx11/shadeboost.fx"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/dx11/shadeboost.fx."); diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp index ae18591cd9..e502f0814c 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp @@ -339,7 +339,7 @@ bool GSDeviceOGL::Create() } // these all share the same vertex shader - const auto convert_glsl = Host::ReadResourceFileToString("shaders/opengl/convert.glsl"); + const std::optional convert_glsl = ReadShaderSource("shaders/opengl/convert.glsl"); if (!convert_glsl.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/opengl/convert.glsl."); @@ -401,7 +401,7 @@ bool GSDeviceOGL::Create() GL_PUSH("GSDeviceOGL::Present"); // these all share the same vertex shader - const auto shader = Host::ReadResourceFileToString("shaders/opengl/present.glsl"); + const std::optional shader = ReadShaderSource("shaders/opengl/present.glsl"); if (!shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/opengl/present.glsl."); @@ -437,7 +437,7 @@ bool GSDeviceOGL::Create() { GL_PUSH("GSDeviceOGL::Merge"); - const auto shader = Host::ReadResourceFileToString("shaders/opengl/merge.glsl"); + const std::optional shader = ReadShaderSource("shaders/opengl/merge.glsl"); if (!shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/opengl/merge.glsl."); @@ -460,7 +460,7 @@ bool GSDeviceOGL::Create() { GL_PUSH("GSDeviceOGL::Interlace"); - const auto shader = Host::ReadResourceFileToString("shaders/opengl/interlace.glsl"); + const std::optional shader = ReadShaderSource("shaders/opengl/interlace.glsl"); if (!shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/opengl/interlace.glsl."); @@ -588,8 +588,8 @@ bool GSDeviceOGL::CreateTextureFX() { GL_PUSH("GSDeviceOGL::CreateTextureFX"); - auto vertex_shader = Host::ReadResourceFileToString("shaders/opengl/tfx_vgs.glsl"); - auto fragment_shader = Host::ReadResourceFileToString("shaders/opengl/tfx_fs.glsl"); + std::optional vertex_shader = ReadShaderSource("shaders/opengl/tfx_vgs.glsl"); + std::optional fragment_shader = ReadShaderSource("shaders/opengl/tfx_fs.glsl"); if (!vertex_shader.has_value() || !fragment_shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/opengl/tfx_{vgs,fs}.glsl."); @@ -1796,7 +1796,7 @@ void GSDeviceOGL::DoInterlace(GSTexture* sTex, const GSVector4& sRect, GSTexture bool GSDeviceOGL::CompileFXAAProgram() { const std::string_view fxaa_macro = "#define FXAA_GLSL_130 1\n"; - std::optional shader = Host::ReadResourceFileToString("shaders/common/fxaa.fx"); + const std::optional shader = ReadShaderSource("shaders/common/fxaa.fx"); if (!shader.has_value()) { Console.Error("Failed to read fxaa.fs"); @@ -1834,7 +1834,7 @@ void GSDeviceOGL::DoFXAA(GSTexture* sTex, GSTexture* dTex) bool GSDeviceOGL::CompileShadeBoostProgram() { - const auto shader = Host::ReadResourceFileToString("shaders/opengl/shadeboost.glsl"); + const std::optional shader = ReadShaderSource("shaders/opengl/shadeboost.glsl"); if (!shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/opengl/shadeboost.glsl."); @@ -1974,7 +1974,7 @@ void GSDeviceOGL::ClearSamplerCache() bool GSDeviceOGL::CreateCASPrograms() { - std::optional cas_source(Host::ReadResourceFileToString("shaders/opengl/cas.glsl")); + std::optional cas_source = ReadShaderSource("shaders/opengl/cas.glsl"); if (!cas_source.has_value() || !GetCASShaderSource(&cas_source.value())) { m_features.cas_sharpening = false; @@ -2027,7 +2027,7 @@ bool GSDeviceOGL::DoCAS(GSTexture* sTex, GSTexture* dTex, bool sharpen_only, con bool GSDeviceOGL::CreateImGuiProgram() { - std::optional glsl = Host::ReadResourceFileToString("shaders/opengl/imgui.glsl"); + const std::optional glsl = ReadShaderSource("shaders/opengl/imgui.glsl"); if (!glsl.has_value()) { Console.Error("Failed to read imgui.glsl"); diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index f1e049a0d7..ee2a6dd285 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -2079,7 +2079,7 @@ bool GSDeviceVK::Create() } { - std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/tfx.glsl"); + std::optional shader = ReadShaderSource("shaders/vulkan/tfx.glsl"); if (!shader.has_value()) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/tfx.glsl."); @@ -3827,7 +3827,7 @@ bool GSDeviceVK::CreateRenderPasses() bool GSDeviceVK::CompileConvertPipelines() { - std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/convert.glsl"); + const std::optional shader = ReadShaderSource("shaders/vulkan/convert.glsl"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/convert.glsl."); @@ -4015,7 +4015,7 @@ bool GSDeviceVK::CompilePresentPipelines() if (m_swap_chain_render_pass == VK_NULL_HANDLE) return false; - std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/present.glsl"); + const std::optional shader = ReadShaderSource("shaders/vulkan/present.glsl"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/present.glsl."); @@ -4066,7 +4066,7 @@ bool GSDeviceVK::CompilePresentPipelines() bool GSDeviceVK::CompileInterlacePipelines() { - std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/interlace.glsl"); + const std::optional shader = ReadShaderSource("shaders/vulkan/interlace.glsl"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/interlace.glsl."); @@ -4117,7 +4117,7 @@ bool GSDeviceVK::CompileInterlacePipelines() bool GSDeviceVK::CompileMergePipelines() { - std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/merge.glsl"); + const std::optional shader = ReadShaderSource("shaders/vulkan/merge.glsl"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/merge.glsl."); @@ -4187,14 +4187,14 @@ bool GSDeviceVK::CompilePostProcessingPipelines() gpb.SetRenderPass(rp, 0); { - std::optional vshader = Host::ReadResourceFileToString("shaders/vulkan/convert.glsl"); + const std::optional vshader = ReadShaderSource("shaders/vulkan/convert.glsl"); if (!vshader) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/convert.glsl."); return false; } - std::optional pshader = Host::ReadResourceFileToString("shaders/common/fxaa.fx"); + const std::optional pshader = ReadShaderSource("shaders/common/fxaa.fx"); if (!pshader) { Host::ReportErrorAsync("GS", "Failed to read shaders/common/fxaa.fx."); @@ -4222,7 +4222,7 @@ bool GSDeviceVK::CompilePostProcessingPipelines() } { - std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/shadeboost.glsl"); + const std::optional shader = ReadShaderSource("shaders/vulkan/shadeboost.glsl"); if (!shader) { Host::ReportErrorAsync("GS", "Failed to read shaders/vulkan/shadeboost.glsl."); @@ -4272,7 +4272,7 @@ bool GSDeviceVK::CompileCASPipelines() Vulkan::SetObjectName(dev, m_cas_pipeline_layout, "CAS pipeline layout"); // we use specialization constants to avoid compiling it twice - std::optional cas_source(Host::ReadResourceFileToString("shaders/vulkan/cas.glsl")); + std::optional cas_source = ReadShaderSource("shaders/vulkan/cas.glsl"); if (!cas_source.has_value() || !GetCASShaderSource(&cas_source.value())) return false; @@ -4298,7 +4298,7 @@ bool GSDeviceVK::CompileCASPipelines() bool GSDeviceVK::CompileImGuiPipeline() { - const std::optional glsl = Host::ReadResourceFileToString("shaders/vulkan/imgui.glsl"); + const std::optional glsl = ReadShaderSource("shaders/vulkan/imgui.glsl"); if (!glsl.has_value()) { Console.Error("Failed to read imgui.glsl"); diff --git a/pcsx2/GameDatabase.cpp b/pcsx2/GameDatabase.cpp index 760740a46c..c7f02efccc 100644 --- a/pcsx2/GameDatabase.cpp +++ b/pcsx2/GameDatabase.cpp @@ -912,7 +912,7 @@ void GameDatabase::initDatabase() Console.Error(fmt::format("[GameDB YAML] Internal Parsing error: {}", std::string_view(msg, msg_size))); }); - auto buf = Host::ReadResourceFileToString(GAMEDB_YAML_FILE_NAME); + auto buf = FileSystem::ReadFileToString(Path::Combine(EmuFolders::Resources, GAMEDB_YAML_FILE_NAME).c_str()); if (!buf.has_value()) { Console.Error("[GameDB] Unable to open GameDB file, file does not exist."); @@ -1073,7 +1073,7 @@ bool GameDatabase::loadHashDatabase() Common::Timer load_timer; - auto buf = Host::ReadResourceFileToString(HASHDB_YAML_FILE_NAME); + auto buf = FileSystem::ReadFileToString(Path::Combine(EmuFolders::Resources, HASHDB_YAML_FILE_NAME).c_str()); if (!buf.has_value()) { Console.Error("[GameDB] Unable to open hash database file, file does not exist."); diff --git a/pcsx2/Host.h b/pcsx2/Host.h index 1aedaf21cf..b8e5b5d94a 100644 --- a/pcsx2/Host.h +++ b/pcsx2/Host.h @@ -40,16 +40,6 @@ namespace Host static constexpr float OSD_INFO_DURATION = 5.0f; static constexpr float OSD_QUICK_DURATION = 2.5f; - /// Reads a file from the resources directory of the application. - /// This may be outside of the "normal" filesystem on platforms such as Mac. - std::optional> ReadResourceFile(const char* filename); - - /// Reads a resource file file from the resources directory as a string. - std::optional ReadResourceFileToString(const char* filename); - - /// Returns the modified time of a resource. - std::optional GetResourceFileTimestamp(const char* filename); - /// Returns a localized version of the specified string within the specified context. /// The pointer is guaranteed to be valid until the next language change. const char* TranslateToCString(const std::string_view& context, const std::string_view& msg); diff --git a/pcsx2/ImGui/ImGuiFullscreen.cpp b/pcsx2/ImGui/ImGuiFullscreen.cpp index dc3a55fa14..de5efb4c7e 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.cpp +++ b/pcsx2/ImGui/ImGuiFullscreen.cpp @@ -270,7 +270,7 @@ std::optional ImGuiFullscreen::LoadTextureImage(const char* if (Path::IsAbsolute(path)) data = FileSystem::ReadBinaryFile(path); else - data = Host::ReadResourceFile(path); + data = FileSystem::ReadBinaryFile(Path::Combine(EmuFolders::Resources, path).c_str()); if (data.has_value()) { image = Common::RGBA8Image(); diff --git a/pcsx2/ImGui/ImGuiManager.cpp b/pcsx2/ImGui/ImGuiManager.cpp index 5ad59664c9..d8ba9e6f75 100644 --- a/pcsx2/ImGui/ImGuiManager.cpp +++ b/pcsx2/ImGui/ImGuiManager.cpp @@ -34,6 +34,7 @@ #include "common/FileSystem.h" #include "common/Easing.h" #include "common/StringUtil.h" +#include "common/Path.h" #include "common/Timer.h" #include "fmt/core.h" @@ -390,9 +391,10 @@ bool ImGuiManager::LoadFontData() { if (s_standard_font_data.empty()) { - std::optional> font_data = s_font_path.empty() ? - Host::ReadResourceFile("fonts/Roboto-Regular.ttf") : - FileSystem::ReadBinaryFile(s_font_path.c_str()); + std::optional> font_data = + s_font_path.empty() ? FileSystem::ReadBinaryFile( + Path::Combine(EmuFolders::Resources, "fonts" FS_OSPATH_SEPARATOR_STR "Roboto-Regular.ttf").c_str()) : + FileSystem::ReadBinaryFile(s_font_path.c_str()); if (!font_data.has_value()) return false; @@ -401,7 +403,8 @@ bool ImGuiManager::LoadFontData() if (s_fixed_font_data.empty()) { - std::optional> font_data = Host::ReadResourceFile("fonts/RobotoMono-Medium.ttf"); + std::optional> font_data = FileSystem::ReadBinaryFile( + Path::Combine(EmuFolders::Resources, "fonts" FS_OSPATH_SEPARATOR_STR "RobotoMono-Medium.ttf").c_str()); if (!font_data.has_value()) return false; @@ -410,7 +413,8 @@ bool ImGuiManager::LoadFontData() if (s_icon_font_data.empty()) { - std::optional> font_data = Host::ReadResourceFile("fonts/fa-solid-900.ttf"); + std::optional> font_data = + FileSystem::ReadBinaryFile(Path::Combine(EmuFolders::Resources, "fonts" FS_OSPATH_SEPARATOR_STR "fa-solid-900.ttf").c_str()); if (!font_data.has_value()) return false; diff --git a/tests/ctest/core/StubHost.cpp b/tests/ctest/core/StubHost.cpp index f3b58b7e19..3710a53933 100644 --- a/tests/ctest/core/StubHost.cpp +++ b/tests/ctest/core/StubHost.cpp @@ -41,21 +41,6 @@ void Host::SetDefaultUISettings(SettingsInterface& si) { } -std::optional> Host::ReadResourceFile(const char* filename) -{ - return std::nullopt; -} - -std::optional Host::ReadResourceFileToString(const char* filename) -{ - return std::nullopt; -} - -std::optional Host::GetResourceFileTimestamp(const char* filename) -{ - return std::nullopt; -} - void Host::ReportErrorAsync(const std::string_view& title, const std::string_view& message) { }