MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / importResource

Method importResource

Source/Core/CtrlrPanel/CtrlrPanelResourceManager.cpp:233–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233Result CtrlrPanelResourceManager::importResource (const ValueTree &resourceTree)
234{
235 if (getResource(resourceTree.getProperty(Ids::resourceName).toString()))
236 {
237 if ((bool)owner.getCtrlrManagerOwner().getProperty(Ids::ctrlrOverwriteResources) == false)
238 {
239 return (Result::fail("ImportResource resource: " + resourceTree.getProperty(Ids::resourceName).toString() + "failed, a resource with this name already exists"));
240 }
241 else
242 {
243 return (Result::ok());
244 }
245 }
246 else
247 {
248 File resourceTempFile = File::getCurrentWorkingDirectory().getChildFile(resourceTree.getProperty(Ids::resourceFile).toString());
249 File resourceDest = resourcesDirectory.getChildFile(resourceTempFile.getFileName());
250
251 if (resourcesDirectory.isDirectory())
252 {
253 MemoryBlock resourceData;
254 if (resourceData.fromBase64Encoding (resourceTree.getProperty(Ids::resourceData).toString()))
255 {
256 if (!resourceDest.exists())
257 {
258 resourceDest.create();
259 }
260
261 if (!resourceDest.replaceWithData(resourceData.getData(), (int)resourceData.getSize()))
262 {
263 return (Result::fail("ImportResource can't replace file contents with new data, resource: "+resourceDest.getFullPathName()));
264 }
265
266 addResource (resourceDest, resourceTree.getProperty(Ids::resourceName));
267 return (Result::ok());
268 }
269 else
270 {
271 resourceDest.deleteFile();
272 return (Result::fail("ImportResource resource: " + resourceTree.getProperty(Ids::resourceName).toString() + " failed to decode base64 encoded data"));
273 }
274 }
275 else
276 {
277 return (Result::fail("Import resource failed, the path specified as the resource directory is not one:"+resourcesDirectory.getFullPathName()));
278 }
279 }
280}
281
282Result CtrlrPanelResourceManager::addResource (const File &source, const String &name)
283{

Callers

nothing calls this directly

Calls 12

fromBase64EncodingMethod · 0.80
toStringMethod · 0.45
getPropertyMethod · 0.45
getChildFileMethod · 0.45
getFileNameMethod · 0.45
isDirectoryMethod · 0.45
existsMethod · 0.45
createMethod · 0.45
replaceWithDataMethod · 0.45
getDataMethod · 0.45
getSizeMethod · 0.45
deleteFileMethod · 0.45

Tested by

no test coverage detected