| 348 | /*******************************/ |
| 349 | |
| 350 | bool 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 | { |
no test coverage detected