| 138 | } |
| 139 | |
| 140 | std::optional<std::string> OHDFilesystemUtil::opt_read_file( |
| 141 | const std::string &filename, bool log_debug) { |
| 142 | if (!exists(filename)) { |
| 143 | if (log_debug) |
| 144 | openhd::log::get_default()->debug("File [{}] doesn't exist", filename); |
| 145 | return std::nullopt; |
| 146 | } |
| 147 | try { |
| 148 | std::ifstream f(filename); |
| 149 | std::string str((std::istreambuf_iterator<char>(f)), |
| 150 | std::istreambuf_iterator<char>()); |
| 151 | return str; |
| 152 | } catch (std::exception &e) { |
| 153 | if (log_debug) |
| 154 | openhd::log::get_default()->warn("Cannot read file [{}]", filename); |
| 155 | return std::nullopt; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | std::string OHDFilesystemUtil::read_file(const std::string &filename) { |
| 160 | const auto content = opt_read_file(filename); |