| 164 | }; |
| 165 | |
| 166 | bool patch_engine::load(patch_map& patches_map, const std::string& path, std::string content, bool importing, std::stringstream* log_messages) |
| 167 | { |
| 168 | if (content.empty()) |
| 169 | { |
| 170 | // Load patch file |
| 171 | fs::file file{path}; |
| 172 | |
| 173 | if (!file) |
| 174 | { |
| 175 | // Do nothing |
| 176 | return true; |
| 177 | } |
| 178 | |
| 179 | content = file.to_string(); |
| 180 | } |
| 181 | |
| 182 | // Interpret yaml nodes |
| 183 | auto [root, error] = yaml_load(content); |
| 184 | |
| 185 | if (!error.empty() || !root) |
| 186 | { |
| 187 | append_log_message(log_messages, "Fatal Error: Failed to load file!"); |
| 188 | patch_log.fatal("Failed to load patch file %s:\n%s", path, error); |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | // Load patch config to determine which patches are enabled |
| 193 | patch_map patch_config; |
| 194 | |
| 195 | if (!importing) |
| 196 | { |
| 197 | patch_config = load_config(); |
| 198 | } |
| 199 | |
| 200 | std::string version; |
| 201 | |
| 202 | if (const auto version_node = root[patch_key::version]) |
| 203 | { |
| 204 | version = version_node.Scalar(); |
| 205 | |
| 206 | if (version != patch_engine_version) |
| 207 | { |
| 208 | append_log_message(log_messages, fmt::format("Error: File version %s does not match patch engine target version %s (location: %s, file: %s)", version, patch_engine_version, get_yaml_node_location(version_node), path), &patch_log.error); |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | // We don't need the Version node in local memory anymore |
| 213 | root.remove(patch_key::version); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | append_log_message(log_messages, fmt::format("Error: No '%s' entry found. Patch engine version = %s (file: %s)", patch_key::version, patch_engine_version, path), &patch_log.error); |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | bool is_valid = true; |
| 222 | |
| 223 | // Go through each main key in the file |
nothing calls this directly
no test coverage detected