MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / loadJSONConfig

Function loadJSONConfig

tests/autotester/autotester.cpp:350–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348/*******************************/
349
350bool loadJSONConfig(const std::string& jsonContents)
351{
352 std::string jsonError;
353 json11::Json configJson = json11::Json::parse(jsonContents, jsonError);
354 if (jsonError.empty())
355 {
356 if (debugMode) {
357 std::cout << "[OK] JSON parsed" << std::endl;
358 }
359 } else {
360 std::cerr << "[Error] JSON parse error: " << jsonError << std::endl;
361 return false;
362 }
363
364 config = config_t();
365
366 json11::Json tmp, tmp2;
367
368 const char* forced_rom_path = getenv("AUTOTESTER_ROM");
369 if (forced_rom_path)
370 {
371 const std::string tmp_path(forced_rom_path);
372 if (file_exists(tmp_path))
373 {
374 config.rom = forced_rom_path;
375 ignoreROMfield = true;
376 } else {
377 std::cerr << "[Error] AUTOTESTER_ROM was given but the file does not exist!" << std::endl;
378 }
379 }
380
381 if (!ignoreROMfield)
382 {
383 tmp = configJson["rom"];
384 if (tmp.is_string() && !tmp.string_value().empty())
385 {
386 config.rom = tmp.string_value();
387 if (!file_exists(config.rom))
388 {
389 std::cerr << "[Error] The ROM file '" << config.rom << "' doesn't seem to exist (or requires higher permissions?)" << std::endl;
390 return false;
391 }
392 } else {
393 std::cerr << "[Error] \"rom\" parameter not given or invalid" << std::endl;
394 return false;
395 }
396 }
397
398 tmp = configJson["transfer_files"];
399 if (tmp.is_array() && !tmp.array_items().empty())
400 {
401 for (const auto& tmpFile : tmp.array_items())
402 {
403 if (tmpFile.is_string() && !tmpFile.string_value().empty())
404 {
405 const char* tmpFileStr = myrealpath(tmpFile.string_value().c_str());
406 if (!tmpFileStr || !file_exists(tmpFileStr))
407 {

Callers 2

mainFunction · 0.85
autotesterOpenMethod · 0.85

Calls 12

config_tClass · 0.85
file_existsFunction · 0.85
myrealpathFunction · 0.85
str_replace_allFunction · 0.85
hash_params_tClass · 0.85
is_stringMethod · 0.80
is_arrayMethod · 0.80
is_objectMethod · 0.80
is_boolMethod · 0.80
is_numberMethod · 0.80
bool_valueMethod · 0.45
int_valueMethod · 0.45

Tested by

no test coverage detected