18 if (std::filesystem::exists(json_filename))
20 spdlog::critical(
"Cannot dump the default value to the configuration file {:?} as it's already existed!",
24 const auto parent_dir = std::filesystem::absolute(std::filesystem::path{ json_filename }).parent_path();
25 std::filesystem::create_directories(parent_dir);
26 auto buffer = std::string{};
27 auto error_code = glz::write_file_json<glz::opts{ .prettify =
true, .new_lines_in_arrays =
false }>(
28 app_config, json_filename, buffer);
31 spdlog::warn(
"Error occurred during writing the json file {}: {}",
33 glz::format_error(error_code, buffer));
39 if (json_filename.empty())
43 if (not std::filesystem::exists(json_filename))
45 spdlog::warn(
"configuration file {:?} doesn't exist. Creating a new file with default values",
51 auto buffer = std::string{};
52 auto error_code = glz::read_file_json(app_config, json_filename, buffer);
55 spdlog::warn(
"Error occurred during reading the json file {}: {}",
57 glz::format_error(error_code, buffer));