| 221 | } |
| 222 | |
| 223 | auto V1::getIndexForMod(QDir& index_dir, QString slug) -> Mod |
| 224 | { |
| 225 | Mod mod; |
| 226 | |
| 227 | auto normalized_fname = indexFileName(slug); |
| 228 | auto real_fname = getRealIndexName(index_dir, normalized_fname, true); |
| 229 | if (real_fname.isEmpty()) |
| 230 | return {}; |
| 231 | |
| 232 | toml::table table; |
| 233 | #if TOML_EXCEPTIONS |
| 234 | try { |
| 235 | table = toml::parse_file(index_dir.absoluteFilePath(real_fname).toStdString()); |
| 236 | } catch (const toml::parse_error& err) { |
| 237 | qWarning() << QString("Could not open file %1!").arg(normalized_fname); |
| 238 | qWarning() << "Reason: " << QString(err.what()); |
| 239 | return {}; |
| 240 | } |
| 241 | #else |
| 242 | table = toml::parse_file(index_dir.absoluteFilePath(real_fname).toStdString()); |
| 243 | if (!table) { |
| 244 | qWarning() << QString("Could not open file %1!").arg(normalized_fname); |
| 245 | qWarning() << "Reason: " << QString(table.error().what()); |
| 246 | return {}; |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | // index_file.close(); |
| 251 | |
| 252 | mod.slug = slug; |
| 253 | |
| 254 | { // Basic info |
| 255 | mod.name = stringEntry(table, "name"); |
| 256 | mod.filename = stringEntry(table, "filename"); |
| 257 | mod.side = stringEntry(table, "side"); |
| 258 | } |
| 259 | |
| 260 | { // [download] info |
| 261 | auto download_table = table["download"].as_table(); |
| 262 | if (!download_table) { |
| 263 | qCritical() << QString("No [download] section found on mod metadata!"); |
| 264 | return {}; |
| 265 | } |
| 266 | |
| 267 | mod.mode = stringEntry(*download_table, "mode"); |
| 268 | mod.url = stringEntry(*download_table, "url"); |
| 269 | mod.hash_format = stringEntry(*download_table, "hash-format"); |
| 270 | mod.hash = stringEntry(*download_table, "hash"); |
| 271 | } |
| 272 | |
| 273 | { // [update] info |
| 274 | using Provider = ModPlatform::Provider; |
| 275 | |
| 276 | auto update_table = table["update"]; |
| 277 | if (!update_table || !update_table.is_table()) { |
| 278 | qCritical() << QString("No [update] section found on mod metadata!"); |
| 279 | return {}; |
| 280 | } |
nothing calls this directly
no test coverage detected