| 28 | namespace FTBImportAPP { |
| 29 | |
| 30 | Modpack parseDirectory(QString path) |
| 31 | { |
| 32 | Modpack modpack{ path }; |
| 33 | auto instanceFile = QFileInfo(FS::PathCombine(path, "instance.json")); |
| 34 | if (!instanceFile.exists() || !instanceFile.isFile()) |
| 35 | return {}; |
| 36 | try { |
| 37 | auto doc = Json::requireDocument(instanceFile.absoluteFilePath(), "FTB_APP instance JSON file"); |
| 38 | const auto root = doc.object(); |
| 39 | modpack.uuid = Json::requireString(root, "uuid", "uuid"); |
| 40 | modpack.id = Json::requireInteger(root, "id", "id"); |
| 41 | modpack.versionId = Json::requireInteger(root, "versionId", "versionId"); |
| 42 | modpack.name = Json::requireString(root, "name", "name"); |
| 43 | modpack.version = Json::requireString(root, "version", "version"); |
| 44 | modpack.mcVersion = Json::requireString(root, "mcVersion", "mcVersion"); |
| 45 | modpack.jvmArgs = Json::ensureVariant(root, "jvmArgs", {}, "jvmArgs"); |
| 46 | modpack.totalPlayTime = Json::requireInteger(root, "totalPlayTime", "totalPlayTime"); |
| 47 | } catch (const Exception& e) { |
| 48 | qDebug() << "Couldn't load ftb instance json: " << e.cause(); |
| 49 | return {}; |
| 50 | } |
| 51 | auto versionsFile = QFileInfo(FS::PathCombine(path, "version.json")); |
| 52 | if (!versionsFile.exists() || !versionsFile.isFile()) |
| 53 | return {}; |
| 54 | try { |
| 55 | auto doc = Json::requireDocument(versionsFile.absoluteFilePath(), "FTB_APP version JSON file"); |
| 56 | const auto root = doc.object(); |
| 57 | auto targets = Json::requireArray(root, "targets", "targets"); |
| 58 | |
| 59 | for (auto target : targets) { |
| 60 | auto obj = Json::requireObject(target, "target"); |
| 61 | auto name = Json::requireString(obj, "name", "name"); |
| 62 | auto version = Json::requireString(obj, "version", "version"); |
| 63 | if (name == "neoforge") { |
| 64 | modpack.loaderType = ModPlatform::NeoForge; |
| 65 | modpack.version = version; |
| 66 | break; |
| 67 | } else if (name == "forge") { |
| 68 | modpack.loaderType = ModPlatform::Forge; |
| 69 | modpack.version = version; |
| 70 | break; |
| 71 | } else if (name == "fabric") { |
| 72 | modpack.loaderType = ModPlatform::Fabric; |
| 73 | modpack.version = version; |
| 74 | break; |
| 75 | } else if (name == "quilt") { |
| 76 | modpack.loaderType = ModPlatform::Quilt; |
| 77 | modpack.version = version; |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | } catch (const Exception& e) { |
| 82 | qDebug() << "Couldn't load ftb version json: " << e.cause(); |
| 83 | return {}; |
| 84 | } |
| 85 | auto iconFile = QFileInfo(FS::PathCombine(path, "folder.jpg")); |
| 86 | if (iconFile.exists() && iconFile.isFile()) { |
| 87 | modpack.icon = QIcon(iconFile.absoluteFilePath()); |
no test coverage detected