MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / add_resource_file

Method add_resource_file

src/ResourceManager.cpp:109–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109NetworkingObjects::NetObjTemporaryPtr<ResourceData> ResourceManager::add_resource_file(const std::filesystem::path& filePath) {
110 ResourceData resource;
111 resource.data = std::make_shared<std::string>();
112#ifdef __ANDROID__
113 resource.name = AndroidJNICalls::getFileNameFromURI(filePath.string());
114 if(resource.name.empty())
115 resource.name = "New Resource";
116#else
117 resource.name = std::filesystem::path(filePath).filename().string();
118#endif
119
120 try {
121 *resource.data = read_file_to_string(filePath);
122 }
123 catch(...) {
124 Logger::get().log(Logger::LogType::INFO, "[ResourceManager::add_resource_file] Could not open file " + filePath.string());
125 return {};
126 }
127
128 Logger::get().log(Logger::LogType::INFO, "[ResourceManager::add_resource_file] Successfully read file " + filePath.string());
129
130 return add_resource(resource);
131}
132
133const NetworkingObjects::NetObjOwnerPtr<ResourceData>& ResourceManager::add_resource(const ResourceData& resource) {
134 auto it = std::find_if(resourceList.begin(), resourceList.end(), [&](const auto& p) {

Callers 1

Calls 6

getFileNameFromURIFunction · 0.85
read_file_to_stringFunction · 0.85
logMethod · 0.80
getFunction · 0.50
stringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected