feat: added asset locator and replaced filesystem direct usage by asset locator

This commit is contained in:
Almamu 2025-09-13 19:10:09 +02:00
parent 79886ecc89
commit 5b65abe7b9
32 changed files with 197 additions and 111 deletions

View File

@ -269,6 +269,8 @@ add_executable(
src/WallpaperEngine/Assets/AssetLoadException.cpp
src/WallpaperEngine/Assets/AssetLoadException.h
src/WallpaperEngine/Assets/AssetLocator.cpp
src/WallpaperEngine/Assets/AssetLocator.h
src/WallpaperEngine/FileSystem/Container.h
src/WallpaperEngine/FileSystem/Container.cpp

View File

@ -29,6 +29,7 @@ float g_Time;
float g_TimeLast;
float g_Daytime;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Application;
using namespace WallpaperEngine::Data::Model;
using namespace WallpaperEngine::FileSystem;
@ -40,10 +41,10 @@ WallpaperApplication::WallpaperApplication (ApplicationContext& context) :
this->setupBrowser();
}
ContainerUniquePtr WallpaperApplication::setupContainer (const std::string& bg) const {
AssetLocatorUniquePtr WallpaperApplication::setupAssetLocator (const std::string& bg) const {
auto container = std::make_unique <Container> ();
std::filesystem::path path (bg);
const std::filesystem::path path = bg;
container->mount (path, "/");
try {
@ -193,7 +194,7 @@ ContainerUniquePtr WallpaperApplication::setupContainer (const std::string& bg)
"}"
);
return container;
return std::make_unique <AssetLocator> (std::move (container));
}
void WallpaperApplication::loadBackgrounds () {
@ -214,7 +215,7 @@ void WallpaperApplication::loadBackgrounds () {
}
ProjectUniquePtr WallpaperApplication::loadBackground (const std::string& bg) {
auto container = this->setupContainer (bg);
auto container = this->setupAssetLocator (bg);
auto json = WallpaperEngine::Data::JSON::JSON::parse (container->readString ("project.json"));
return WallpaperEngine::Data::Parsers::ProjectParser::parse (json, std::move(container));

View File

@ -1,6 +1,7 @@
#pragma once
#include "WallpaperEngine/Application/ApplicationContext.h"
#include "WallpaperEngine/Assets/AssetLocator.h"
#include "WallpaperEngine/Render/CWallpaper.h"
#include "WallpaperEngine/Render/Drivers/Detectors/FullScreenDetector.h"
@ -16,6 +17,7 @@
#include "WallpaperEngine/Data/Model/Types.h"
namespace WallpaperEngine::Application {
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Data::Model;
/**
* Small wrapper class over the actual wallpaper's main application skeleton
@ -53,12 +55,11 @@ class WallpaperApplication {
private:
/**
* Sets up a combined container for the given background, adding default files and directories to the list
* Sets up an asset locator for the given background
*
* @param container
* @param bg
*/
ContainerUniquePtr setupContainer (const std::string& bg) const;
AssetLocatorUniquePtr setupAssetLocator (const std::string& bg) const;
/**
* Loads projects based off the settings
*/

View File

@ -1,10 +1,6 @@
#include "AssetLoadException.h"
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Assets;
AssetLoadException::AssetLoadException (const std::string& filename, const std::string& extrainfo) :
m_message ("Cannot find file " + filename + ": " + extrainfo) {}
const char* AssetLoadException::what () const noexcept {
return this->m_message.c_str ();
}
AssetLoadException::AssetLoadException (const std::filesystem::filesystem_error& filesystem_error) noexcept
: std::filesystem::filesystem_error (filesystem_error) {}

View File

@ -1,16 +1,11 @@
#pragma once
#include <exception>
#include <string>
#include <filesystem>
// TODO: REWRITE THIS ONE TO MAKE MORE SENSE, IT REALLY MEANS "FILE-RELATED EXCEPTION"
namespace WallpaperEngine::Render {
class AssetLoadException final : public std::exception {
namespace WallpaperEngine::Assets {
class AssetLoadException final : public std::filesystem::filesystem_error {
public:
explicit AssetLoadException (const std::string& filename, const std::string& extrainfo = "");
[[nodiscard]] const char* what () const noexcept override;
private:
std::string m_message {};
using std::filesystem::filesystem_error::filesystem_error;
explicit AssetLoadException (const std::filesystem::filesystem_error& filesystem_error) noexcept;
};
} // namespace WallpaperEngine::Assets

View File

@ -0,0 +1,99 @@
#include "AssetLocator.h"
#include "AssetLoadException.h"
using namespace WallpaperEngine::Assets;
AssetLocator::AssetLocator (ContainerUniquePtr filesystem) : m_filesystem (std::move (filesystem)) {}
std::string AssetLocator::shader (const std::filesystem::path& filename) const {
try {
std::filesystem::path shader = filename;
// detect workshop shaders and check if there's a
if (auto it = shader.begin (); *it++ == "workshop") {
const std::filesystem::path workshopId = *it++;
if (++it != shader.end ()) {
const std::filesystem::path& shaderfile = *it;
try {
shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile;
// replace the old path with the new one
std::string contents = this->m_filesystem->readString (shader);
sLog.out ("Replaced ", filename, " with compat ", shader);
return contents;
} catch (std::filesystem::filesystem_error&) {
// these exceptions can be ignored because the replacement file might not exist
}
}
}
return this->m_filesystem->readString ("shaders" / filename);
} catch (std::filesystem::filesystem_error& base) {
throw AssetLoadException (base);
}
}
std::string AssetLocator::fragmentShader (const std::filesystem::path& filename) const {
auto final = filename;
final.replace_extension ("frag");
return this->shader (final);
}
std::string AssetLocator::vertexShader (const std::filesystem::path& filename) const {
auto final = filename;
final.replace_extension ("vert");
return this->shader (final);
}
std::string AssetLocator::includeShader (const std::filesystem::path& filename) const {
auto final = filename;
final.replace_extension ("h");
return this->shader (final);
}
std::string AssetLocator::readString (const std::filesystem::path& filename) const {
try {
return this->m_filesystem->readString (filename);
} catch (std::filesystem::filesystem_error& base) {
throw AssetLoadException (base);
}
}
ReadStreamSharedPtr AssetLocator::texture (const std::filesystem::path& filename) const {
auto final = filename;
final.replace_extension ("tex");
try {
return this->m_filesystem->read (final);
} catch (std::filesystem::filesystem_error& base) {
throw AssetLoadException (base);
}
}
ReadStreamSharedPtr AssetLocator::read (const std::filesystem::path& path) const {
try {
return this->m_filesystem->read (path);
} catch (std::filesystem::filesystem_error& base) {
throw AssetLoadException (base);
}
}
std::filesystem::path AssetLocator::physicalPath (const std::filesystem::path& path) const {
try {
return this->m_filesystem->physicalPath (path);
} catch (std::filesystem::filesystem_error& base) {
throw AssetLoadException (base);
}
}

View File

@ -0,0 +1,27 @@
#pragma once
#include "WallpaperEngine/FileSystem/Container.h"
namespace WallpaperEngine::Assets {
using namespace WallpaperEngine::FileSystem;
using namespace WallpaperEngine::Data::Model;
class AssetLocator {
public:
explicit AssetLocator (ContainerUniquePtr filesystem);
std::string vertexShader (const std::filesystem::path& filename) const;
std::string fragmentShader (const std::filesystem::path& filename) const;
std::string includeShader (const std::filesystem::path& filename) const;
ReadStreamSharedPtr texture (const std::filesystem::path& filename) const;
std::string readString (const std::filesystem::path& filename) const;
ReadStreamSharedPtr read (const std::filesystem::path& path) const;
std::filesystem::path physicalPath (const std::filesystem::path& path) const;
private:
std::string shader (const std::filesystem::path& filename) const;
ContainerUniquePtr m_filesystem;
};
using AssetLocatorUniquePtr = std::unique_ptr<AssetLocator>;
}

View File

@ -4,9 +4,10 @@
#include <memory>
#include "Types.h"
#include "WallpaperEngine/FileSystem/Container.h"
#include "WallpaperEngine/Assets/AssetLocator.h"
namespace WallpaperEngine::Data::Model {
using namespace WallpaperEngine::Assets;
/**
* Represents a wallpaper engine project
*/
@ -30,7 +31,7 @@ struct Project {
Properties properties;
/** The wallpaper this project defines */
WallpaperUniquePtr wallpaper;
/** VFS to access the project's files */
ContainerUniquePtr container;
/** Abstraction over asset loading to provide access to them */
AssetLocatorUniquePtr assetLocator;
};
};

View File

@ -10,7 +10,7 @@ using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model;
EffectUniquePtr EffectParser::load (const Project& project, const std::string& filename) {
const auto effectJson = JSON::parse (project.container->readString (filename));
const auto effectJson = JSON::parse (project.assetLocator->readString (filename));
return parse (effectJson, project);
}

View File

@ -8,7 +8,7 @@ using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model;
MaterialUniquePtr MaterialParser::load (const Project& project, const std::string& filename) {
const auto materialJson = JSON::parse (project.container->readString (filename));
const auto materialJson = JSON::parse (project.assetLocator->readString (filename));
return parse (materialJson, filename);
}

View File

@ -10,7 +10,7 @@ using namespace WallpaperEngine::Data::Parsers;
using namespace WallpaperEngine::Data::Model;
ModelUniquePtr ModelParser::load (const Project& project, const std::string& filename) {
const auto model = JSON::parse (project.container->readString (filename));
const auto model = JSON::parse (project.assetLocator->readString (filename));
return parse (model, project, filename);
}

View File

@ -13,7 +13,7 @@ using namespace WallpaperEngine::Data::Parsers;
static int backgroundId = 0;
ProjectUniquePtr ProjectParser::parse (const JSON& data, ContainerUniquePtr container) {
ProjectUniquePtr ProjectParser::parse (const JSON& data, AssetLocatorUniquePtr container) {
const auto general = data.optional ("general");
const auto workshopId = data.optional ("workshopid");
auto actualWorkshopId = std::to_string (--backgroundId);
@ -38,7 +38,7 @@ ProjectUniquePtr ProjectParser::parse (const JSON& data, ContainerUniquePtr cont
.workshopId = actualWorkshopId,
.supportsAudioProcessing = general.has_value () && general.value ().optional ("supportsaudioprocessing", false),
.properties = parseProperties (general),
.container = std::move(container),
.assetLocator = std::move(container),
});
result->wallpaper = WallpaperParser::parse (data.require ("file", "Project's main file missing"), *result);

View File

@ -4,10 +4,12 @@
#include "WallpaperEngine/Data/JSON.h"
#include "WallpaperEngine/Data/Model/Project.h"
#include "WallpaperEngine/Assets/AssetLocator.h"
namespace WallpaperEngine::Data::Parsers {
using JSON = WallpaperEngine::Data::JSON::JSON;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Data::Model;
/**
@ -15,7 +17,7 @@ using namespace WallpaperEngine::Data::Model;
*/
class ProjectParser {
public:
static ProjectUniquePtr parse (const JSON& data, ContainerUniquePtr container);
static ProjectUniquePtr parse (const JSON& data, AssetLocatorUniquePtr container);
private:
static Project::Type parseType (const std::string& type);

View File

@ -22,7 +22,7 @@ WallpaperUniquePtr WallpaperParser::parse (const JSON& file, Project& project) {
}
SceneUniquePtr WallpaperParser::parseScene (const JSON& file, Project& project) {
const auto scene = JSON::parse (project.container->readString (file));
const auto scene = JSON::parse (project.assetLocator->readString (file));
const auto camera = scene.require ("camera", "Scenes must have a camera section");
const auto general = scene.require ("general", "Scenes must have a general section");
const auto projection = general.require ("orthogonalprojection", "General section must have orthogonal projection info");

View File

@ -57,7 +57,7 @@ std::filesystem::path DirectoryAdapter::physicalPath (const std::filesystem::pat
auto finalpath = std::filesystem::canonical(this->basepath / path);
if (finalpath.string ().find (this->basepath.string ()) != 0) {
throw Render::AssetLoadException ("Cannot find file", path);
throw std::filesystem::filesystem_error ("Cannot find file", path, std::error_code ());
}
return finalpath;

View File

@ -45,7 +45,7 @@ bool PackageAdapter::exists (const std::filesystem::path& path) const {
}
std::filesystem::path PackageAdapter::physicalPath (const std::filesystem::path& path) const {
throw Render::AssetLoadException ("Package adapter does not support realpath", path);
throw std::filesystem::filesystem_error ("Package adapter does not support realpath", path, std::error_code ());
}
bool PackageFactory::handlesMountpoint (const std::filesystem::path& path) const {

View File

@ -22,7 +22,7 @@ bool VirtualAdapter::exists (const std::filesystem::path& path) const {
}
std::filesystem::path VirtualAdapter::physicalPath (const std::filesystem::path& path) const {
throw Render::AssetLoadException ("Virtual adapter does not support realpath", path);
throw std::filesystem::filesystem_error ("Virtual adapter does not support realpath", path, std::error_code ());
}

View File

@ -81,7 +81,6 @@ std::filesystem::path Container::physicalPath (const std::filesystem::path& path
return this->resolveAdapterForFile (path).physicalPath (normalized);
}
AdapterSharedPtr Container::mount (const std::filesystem::path& path, const std::filesystem::path& mountPoint) {
// check if any adapter can handle the path
for (const auto& factory : this->m_factories) {
@ -92,7 +91,8 @@ AdapterSharedPtr Container::mount (const std::filesystem::path& path, const std:
return this->m_mountpoints.emplace_back (mountPoint, factory->create (path)).second;
}
sLog.exception("The specified mount (", path, ") cannot be handled by any of the filesystem adapters");
throw std::filesystem::filesystem_error (
"The specified mount cannot be handled by any of the filesystem adapters", path, std::error_code ());
}
VirtualAdapter& Container::getVFS () const {
@ -120,5 +120,5 @@ Adapter& Container::resolveAdapterForFile (const std::filesystem::path& path) co
return this->resolveAdapterForFile ("/" + normalized.string());
}
throw Render::AssetLoadException ("Cannot find requested file ", path);
throw std::filesystem::filesystem_error ("Cannot find requested file in any of the mountpoints", path, std::error_code ());
}

View File

@ -15,8 +15,8 @@ Wallpapers::CScene& CObject::getScene () const {
return this->m_scene;
}
const Container& CObject::getContainer () const {
return this->getScene ().getContainer ();
const AssetLocator& CObject::getAssetLocator () const {
return this->getScene ().getAssetLocator ();
}
int CObject::getId () const {

View File

@ -36,7 +36,7 @@ class CObject : public Helpers::ContextAware {
virtual void render () = 0;
[[nodiscard]] Wallpapers::CScene& getScene () const;
[[nodiscard]] const Container& getContainer () const;
[[nodiscard]] const AssetLocator& getAssetLocator () const;
[[nodiscard]] int getId () const;
protected:

View File

@ -45,8 +45,8 @@ CWallpaper::CWallpaper (
CWallpaper::~CWallpaper () = default;
const Container& CWallpaper::getContainer () const {
return *this->m_wallpaperData.project.container;
const AssetLocator& CWallpaper::getAssetLocator () const {
return *this->m_wallpaperData.project.assetLocator;
}
const Wallpaper& CWallpaper::getWallpaperData () const {

View File

@ -65,7 +65,7 @@ class CWallpaper : public Helpers::ContextAware, public FBOProvider {
/**
* @return The container to resolve files for this wallpaper
*/
[[nodiscard]] const Container& getContainer () const;
[[nodiscard]] const AssetLocator& getAssetLocator () const;
/**
* @return The current audio context for this wallpaper

View File

@ -23,7 +23,7 @@ CSound::~CSound() {
void CSound::load () {
for (const auto& cur : this->m_sound.sounds) {
uint32_t filesize = 0;
auto filebuffer = this->getContainer ().read (cur);
auto filebuffer = this->getAssetLocator ().read (cur);
auto stream = new Audio::AudioStream (this->getScene ().getAudioContext (), filebuffer, filesize);
stream->setRepeat (this->m_sound.playbackmode.has_value() && this->m_sound.playbackmode == "loop");

View File

@ -427,7 +427,7 @@ void CPass::setupShaders () {
// TODO: USED TO BUILD THE TEXTURES LATER
// use the combos copied from the pass so it includes the texture format
this->m_shader = new Render::Shaders::Shader (
this->m_image.getContainer (), this->m_pass.shader, this->m_combos, this->m_override.combos,
this->m_image.getAssetLocator (), this->m_pass.shader, this->m_combos, this->m_override.combos,
this->m_pass.textures, this->m_override.textures, this->m_override.constants
);

View File

@ -10,62 +10,24 @@
#include "GLSLContext.h"
#include "WallpaperEngine/Assets/AssetLoadException.h"
#include "WallpaperEngine/Assets/AssetLocator.h"
#include "WallpaperEngine/FileSystem/Container.h"
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::Assets;
namespace WallpaperEngine::Render::Shaders {
// TODO: MOVE THIS INTO AN ASSET RESOLVER OR SOMETHING SIMILAR AS IT DOESN'T REALLY BELONG HERE BUT GETS THE CHANGESET OUT
std::string readShader (const std::filesystem::path& filename, const Container& container) {
std::filesystem::path shader = filename;
auto it = shader.begin ();
// detect workshop shaders and check if there's a
if (*it++ == "workshop") {
const std::filesystem::path workshopId = *it++;
if (++it != shader.end ()) {
const std::filesystem::path& shaderfile = *it;
try {
shader = std::filesystem::path ("zcompat") / "scene" / "shaders" / workshopId / shaderfile;
// replace the old path with the new one
std::string contents = container.readString (shader);
sLog.out ("Replaced ", filename, " with compat ", shader);
return contents;
} catch (AssetLoadException&) { }
}
}
return container.readString ("shaders" / filename);
}
std::string readVertex (const std::filesystem::path& filename, const Container& container) {
std::filesystem::path shader = filename;
shader.replace_extension (".vert");
return readShader (shader, container);
}
std::string readFragment (const std::filesystem::path& filename, const Container& container) {
std::filesystem::path shader = filename;
shader.replace_extension (".frag");
return readShader (shader, container);
}
Shader::Shader (
const Container& container, std::string filename,
const AssetLocator& assetLocator, std::string filename,
const ComboMap& combos, const ComboMap& overrideCombos,
const TextureMap& textures, const TextureMap& overrideTextures,
const ShaderConstantMap& constants
) :
m_vertex (
GLSLContext::UnitType_Vertex, filename, readVertex (filename, container),
container, constants, textures, overrideTextures, combos, overrideCombos),
GLSLContext::UnitType_Vertex, filename, assetLocator.vertexShader (filename),
assetLocator, constants, textures, overrideTextures, combos, overrideCombos),
m_fragment (
GLSLContext::UnitType_Fragment, filename, readFragment (filename, container),
container, constants, textures, overrideTextures, combos, overrideCombos),
GLSLContext::UnitType_Fragment, filename, assetLocator.fragmentShader (filename),
assetLocator, constants, textures, overrideTextures, combos, overrideCombos),
m_file (std::move (filename)),
m_combos (combos),
m_overrideCombos (overrideCombos),

View File

@ -31,7 +31,7 @@ class Shader {
* the pre-processing and compilation of the shader, adding
* required definitions if needed
*
* @param container The container to use for file lookup
* @param assetLocator The asset locator where to ask for assets for
* @param filename The file to load
* @param combos Settings for the shader
* @param overrideCombos List of override combos to use
@ -40,7 +40,7 @@ class Shader {
* @param constants Default values for shader variables
*/
Shader (
const Container& container, std::string filename,
const AssetLocator& assetLocator, std::string filename,
const ComboMap& combos, const ComboMap& overrideCombos,
const TextureMap& textures, const TextureMap& overrideTextures,
const ShaderConstantMap& constants);

View File

@ -53,7 +53,7 @@ using namespace WallpaperEngine::Data::Builders;
using namespace WallpaperEngine::Render::Shaders;
ShaderUnit::ShaderUnit (
GLSLContext::UnitType type, std::string file, std::string content, const Container& container,
GLSLContext::UnitType type, std::string file, std::string content, const AssetLocator& assetLocator,
const ShaderConstantMap& constants, const TextureMap& passTextures, const TextureMap& overrideTextures,
const ComboMap& combos, const ComboMap& overrideCombos
) :
@ -66,7 +66,7 @@ ShaderUnit::ShaderUnit (
m_passTextures (passTextures),
m_overrideTextures (overrideTextures),
m_link (nullptr),
m_container (container) {
m_assetLocator (assetLocator) {
// pre-process the shader so the units are clear
this->preprocess ();
}
@ -153,7 +153,7 @@ void ShaderUnit::preprocessIncludes () {
content += filename;
content += "\n";
// TODO: MOVE SHADER PATH FROM HERE TO SOMEWHERE LIKE AN ASSET RESOLVER OR SOMETHING LIKE THAT
content += this->m_container.readString (std::filesystem::path("shaders") / filename);
content += this->m_assetLocator.readString (std::filesystem::path("shaders") / filename);
content += "\n// end of included from file ";
content += filename;
content += "\n";
@ -193,7 +193,7 @@ void ShaderUnit::preprocessIncludes () {
content += filename;
content += "\n";
// TODO: MOVE SHADER PATH FROM HERE TO SOMEWHERE LIKE AN ASSET RESOLVER OR SOMETHING LIKE THAT
content += this->m_container.readString (std::filesystem::path("shaders") / filename);
content += this->m_assetLocator.readString (std::filesystem::path("shaders") / filename);
content += "\n// end of included from file ";
content += filename;
content += "\n";

View File

@ -6,6 +6,7 @@
#include "GLSLContext.h"
#include "WallpaperEngine/Data/JSON.h"
#include "WallpaperEngine/Assets/AssetLocator.h"
#include "WallpaperEngine/Render/Shaders/Variables/ShaderVariable.h"
#include "nlohmann/json.hpp"
@ -13,7 +14,7 @@
namespace WallpaperEngine::Render::Shaders {
using JSON = WallpaperEngine::Data::JSON::JSON;
using namespace WallpaperEngine::FileSystem;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Data::Model;
/**
@ -22,7 +23,7 @@ using namespace WallpaperEngine::Data::Model;
class ShaderUnit {
public:
ShaderUnit (
GLSLContext::UnitType type, std::string file, std::string content, const Container& container,
GLSLContext::UnitType type, std::string file, std::string content, const AssetLocator& assetLocator,
const ShaderConstantMap& constants, const TextureMap& passTextures,
const TextureMap& overrideTextures, const ComboMap& combos, const ComboMap& overrideCombos);
~ShaderUnit () = default;
@ -158,6 +159,6 @@ class ShaderUnit {
/**
* The container to source files from
*/
const Container& m_container;
const AssetLocator& m_assetLocator;
};
}

View File

@ -25,7 +25,7 @@ std::shared_ptr<const TextureProvider> TextureCache::resolve (const std::string&
// search for the texture in all the different containers just in case
for (const auto& [name, project] : this->getContext ().getApp ().getBackgrounds ()) {
try {
auto contents = project->container->read (finalFilename);
auto contents = project->assetLocator->read (finalFilename);
auto stream = BinaryReader (contents);
auto parsedTexture = TextureParser::parse (stream);
@ -39,7 +39,7 @@ std::shared_ptr<const TextureProvider> TextureCache::resolve (const std::string&
}
}
throw AssetLoadException (filename, "Cannot find file");
throw AssetLoadException ("Cannot find file", filename, std::error_code ());
}
void TextureCache::store (const std::string& name, std::shared_ptr<const TextureProvider> texture) {

View File

@ -57,7 +57,7 @@ CVideo::CVideo (
sLog.exception ("Failed to initialize MPV's GL context");
const std::filesystem::path videopath =
this->getVideo ().project.container->physicalPath (this->getVideo ().filename);
this->getVideo ().project.assetLocator->physicalPath (this->getVideo ().filename);
// build the path to the video file
const char* command [] = {"loadfile", videopath.c_str (), nullptr};

View File

@ -7,12 +7,11 @@
#include "WallpaperEngine/Data/Model/Project.h"
using namespace WallpaperEngine::Render;
using namespace WallpaperEngine::WebBrowser::CEF;
WPSchemeHandler::WPSchemeHandler(const Project& project) :
m_project (project),
m_container (*this->m_project.container) {
m_assetLoader (*this->m_project.assetLocator) {
}
bool WPSchemeHandler::Open(CefRefPtr<CefRequest> request,
@ -48,7 +47,7 @@ bool WPSchemeHandler::Open(CefRefPtr<CefRequest> request,
this->m_mimeType = mime;
}
this->m_contents = this->m_container.read (file);
this->m_contents = this->m_assetLoader.read (file);
callback->Continue ();
} catch (AssetLoadException&) {
#if !NDEBUG

View File

@ -2,7 +2,7 @@
#include <string>
#include "WallpaperEngine/FileSystem/Container.h"
#include "WallpaperEngine/Assets/AssetLocator.h"
#include "include/cef_resource_handler.h"
#include "include/wrapper/cef_helpers.h"
@ -13,7 +13,7 @@ struct Project;
namespace WallpaperEngine::WebBrowser::CEF {
using namespace WallpaperEngine::FileSystem;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Data::Model;
/**
@ -39,7 +39,7 @@ class WPSchemeHandler : public CefResourceHandler {
private:
const Project& m_project;
const Container& m_container;
const AssetLocator& m_assetLoader;
ReadStreamSharedPtr m_contents = nullptr;
std::string m_mimeType;