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