MCPcopy Create free account
hub / github.com/avast/retdec / doConfigFile

Function doConfigFile

src/fileinfo/fileinfo.cpp:455–497  ·  view source on GitHub ↗

* Config file processing. * @param params Structure for storing information * @param configPath Path to fileinfo config file to read. * Default path relative to fileinfo binary is used of not * specified. * @return @c true if processing was completed successfully, @c false otherwise */

Source from the content-addressed store, hash-verified

453 * @return @c true if processing was completed successfully, @c false otherwise
454 */
455bool doConfigFile(ProgParams& params, const std::string& configPath = "")
456{
457 fs::path cp;
458
459 if (configPath.empty())
460 {
461 auto binpath = retdec::utils::getThisBinaryDirectoryPath();
462 cp = fs::path(fs::canonical(binpath).parent_path());
463 cp.append("share");
464 cp.append("retdec");
465 cp.append("fileinfo-config.json");
466
467 if (!fs::exists(cp))
468 {
469 // If the default config is not found, we ignore it.
470 return true;
471 }
472 }
473 else
474 {
475 cp = fs::path(configPath);
476
477 // If the specified config file is not found, we consider it an error.
478 if (!fs::exists(cp))
479 {
480 return false;
481 }
482 }
483
484 std::ifstream jsonFile(cp.string(), std::ios::in | std::ios::binary);
485 if (!jsonFile)
486 {
487 return false;
488 }
489 std::string jsonContent;
490 jsonFile.seekg(0, std::ios::end);
491 jsonContent.resize(jsonFile.tellg());
492 jsonFile.seekg(0, std::ios::beg);
493 jsonFile.read(&jsonContent[0], jsonContent.size());
494 jsonFile.close();
495
496 return doConfigString(params, jsonContent, cp.string());
497}
498
499/**
500 * Parameters processing

Callers 2

doParamsFunction · 0.85
mainFunction · 0.85

Calls 7

doConfigStringFunction · 0.85
tellgMethod · 0.80
emptyMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected