FreeRDP
Loading...
Searching...
No Matches
sdl_resource_manager.cpp
1
18#include "sdl_resource_manager.hpp"
19#include <iostream>
20#if __has_include(<filesystem>)
21#include <filesystem>
22namespace fs = std::filesystem;
23#elif __has_include(<experimental/filesystem>)
24#include <experimental/filesystem>
25namespace fs = std::experimental::filesystem;
26#else
27#error Could not find system header "<filesystem>" or "<experimental/filesystem>"
28#endif
29
31{
32 return "fonts";
33}
34
35std::string SDLResourceManager::typeImages()
36{
37 return "images";
38}
39
40void SDLResourceManager::insert(const std::string& type, const std::string& id,
41 const std::vector<unsigned char>& data)
42{
43 std::string uuid = type + "/" + id;
44 resources().emplace(uuid, data);
45}
46
47bool SDLResourceManager::useCompiledResources()
48{
49#if defined(SDL_USE_COMPILED_RESOURCES)
50 return true;
51#else
52 return false;
53#endif
54}
55
56const std::vector<unsigned char>* SDLResourceManager::data(const std::string& type,
57 const std::string& id)
58{
59#if defined(SDL_USE_COMPILED_RESOURCES)
60 std::string uuid = type + "/" + id;
61 auto val = resources().find(uuid);
62 if (val == resources().end())
63 return nullptr;
64
65 return &val->second;
66#else
67 return nullptr;
68#endif
69}
70
71std::string SDLResourceManager::filename([[maybe_unused]] const std::string& type,
72 [[maybe_unused]] const std::string& id)
73{
74#if defined(SDL_RESOURCE_ROOT)
75 std::string uuid = type + "/" + id;
76 fs::path path(SDL_RESOURCE_ROOT);
77 path /= type;
78 path /= id;
79
80 if (!fs::exists(path))
81 {
82 std::cerr << "sdl-freerdp expects resource '" << uuid << "' at location "
83 << fs::absolute(path) << std::endl;
84 std::cerr << "file not found, application will fail" << std::endl;
85 return "";
86 }
87 return path.u8string();
88#else
89 return "";
90#endif
91}
92
93std::map<std::string, std::vector<unsigned char>>& SDLResourceManager::resources()
94{
95
96 static std::map<std::string, std::vector<unsigned char>> resources = {};
97#if defined(SDL_USE_COMPILED_RESOURCES)
98 if (resources.empty())
99 init();
100#endif
101 return resources;
102}
static std::string typeFonts()