Add new resources system in app library

This commit is contained in:
Nikita Lisitsa 2023-07-18 15:34:46 +03:00
parent bf90a8edd9
commit 93d5c55c68
3 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,17 @@
#pragma once
#include <psemek/io/stream.hpp>
#include <filesystem>
#include <memory>
namespace psemek::app
{
std::filesystem::path resource_root();
void set_resource_root(std::filesystem::path const & root);
// Implemented by a backend library
std::unique_ptr<io::istream> open_resource(std::filesystem::path const & relative_path);
}

View file

@ -0,0 +1,24 @@
#include <psemek/app/resource.hpp>
#include <psemek/util/executable_path.hpp>
namespace psemek::app
{
namespace
{
static std::filesystem::path global_resource_root = util::executable_path().parent_path();
}
std::filesystem::path resource_root()
{
return global_resource_root;
}
void set_resource_root(std::filesystem::path const & root)
{
global_resource_root = root;
}
}

View file

@ -0,0 +1,12 @@
#include <psemek/app/resource.hpp>
#include <psemek/io/file_stream.hpp>
namespace psemek::app
{
std::unique_ptr<io::istream> open_resource(std::filesystem::path const & relative_path)
{
return std::make_unique<io::file_istream>(app::resource_root() / relative_path);
}
}