FreeRDP
sdl_resource_manager.cpp
1 
18 #include "sdl_resource_manager.hpp"
19 #include <iostream>
20 #if __has_include(<filesystem>)
21 #include <filesystem>
22 namespace fs = std::filesystem;
23 #elif __has_include(<experimental/filesystem>)
24 #include <experimental/filesystem>
25 namespace 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 
35 std::string SDLResourceManager::typeImages()
36 {
37  return "images";
38 }
39 
40 void 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 
47 bool SDLResourceManager::useCompiledResources()
48 {
49 #if defined(SDL_USE_COMPILED_RESOURCES)
50  return true;
51 #else
52  return false;
53 #endif
54 }
55 
56 const 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 
71 std::string SDLResourceManager::filename(const std::string& type, const std::string& id)
72 {
73 #if defined(SDL_RESOURCE_ROOT)
74  std::string uuid = type + "/" + id;
75  fs::path path(SDL_RESOURCE_ROOT);
76  path /= type;
77  path /= id;
78 
79  if (!fs::exists(path))
80  {
81  std::cerr << "sdl-freerdp expects resource '" << uuid << "' at location "
82  << fs::absolute(path) << std::endl;
83  std::cerr << "file not found, application will fail" << std::endl;
84  return "";
85  }
86  return path.u8string();
87 #else
88  return "";
89 #endif
90 }
91 
92 std::map<std::string, std::vector<unsigned char>>& SDLResourceManager::resources()
93 {
94 
95  static std::map<std::string, std::vector<unsigned char>> resources = {};
96 #if defined(SDL_USE_COMPILED_RESOURCES)
97  if (resources.empty())
98  init();
99 #endif
100  return resources;
101 }
static std::string typeFonts()