| 366 | } |
| 367 | |
| 368 | void LocalModParseTask::processAsZip() |
| 369 | { |
| 370 | QuaZip zip(m_modFile.filePath()); |
| 371 | if (!zip.open(QuaZip::mdUnzip)) |
| 372 | return; |
| 373 | |
| 374 | QuaZipFile file(&zip); |
| 375 | |
| 376 | if (zip.setCurrentFile("META-INF/mods.toml")) |
| 377 | { |
| 378 | if (!file.open(QIODevice::ReadOnly)) |
| 379 | { |
| 380 | zip.close(); |
| 381 | return; |
| 382 | } |
| 383 | |
| 384 | m_result->details = ReadMCModTOML(file.readAll()); |
| 385 | file.close(); |
| 386 | |
| 387 | // to replace ${file.jarVersion} with the actual version, as needed |
| 388 | if (m_result->details && m_result->details->version == "${file.jarVersion}") |
| 389 | { |
| 390 | if (zip.setCurrentFile("META-INF/MANIFEST.MF")) |
| 391 | { |
| 392 | if (!file.open(QIODevice::ReadOnly)) |
| 393 | { |
| 394 | zip.close(); |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | // quick and dirty line-by-line parser |
| 399 | auto manifestLines = file.readAll().split('\n'); |
| 400 | QString manifestVersion = ""; |
| 401 | for (auto &line : manifestLines) |
| 402 | { |
| 403 | if (QString(line).startsWith("Implementation-Version: ")) |
| 404 | { |
| 405 | manifestVersion = QString(line).remove("Implementation-Version: "); |
| 406 | break; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | // some mods use ${projectversion} in their build.gradle, causing this mess to show up in MANIFEST.MF |
| 411 | // also keep with forge's behavior of setting the version to "NONE" if none is found |
| 412 | if (manifestVersion.contains("task ':jar' property 'archiveVersion'") || manifestVersion == "") |
| 413 | { |
| 414 | manifestVersion = "NONE"; |
| 415 | } |
| 416 | |
| 417 | m_result->details->version = manifestVersion; |
| 418 | |
| 419 | file.close(); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | zip.close(); |
| 424 | return; |
| 425 | } |
nothing calls this directly
no test coverage detected