| 548 | } |
| 549 | |
| 550 | std::optional<std::vector<FileTargets>> GetRootFSLinks() { |
| 551 | // Decode the filetargets |
| 552 | std::string Data = DownloadToString(DownloadURL); |
| 553 | |
| 554 | if (Data.empty()) { |
| 555 | return std::nullopt; |
| 556 | } |
| 557 | |
| 558 | FEX::JSON::JsonAllocator Pool {}; |
| 559 | const json_t* json = FEX::JSON::CreateJSON(Data, Pool); |
| 560 | |
| 561 | if (!json) { |
| 562 | fmt::print(stderr, "Failed to parse JSON from RootFSLinks file '{}' - invalid JSON format", Data); |
| 563 | std::abort(); |
| 564 | } |
| 565 | |
| 566 | const json_t* RootList = json_getProperty(json, "v1"); |
| 567 | |
| 568 | if (!RootList) { |
| 569 | fprintf(stderr, "Couldn't get root list"); |
| 570 | return {}; |
| 571 | } |
| 572 | |
| 573 | std::vector<FileTargets> Targets; |
| 574 | |
| 575 | for (const json_t* RootItem = json_getChild(RootList); RootItem != nullptr; RootItem = json_getSibling(RootItem)) { |
| 576 | |
| 577 | FileTargets Target {}; |
| 578 | Target.DistroName = json_getName(RootItem); |
| 579 | |
| 580 | for (const json_t* DataItem = json_getChild(RootItem); DataItem != nullptr; DataItem = json_getSibling(DataItem)) { |
| 581 | auto DataName = std::string_view {json_getName(DataItem)}; |
| 582 | |
| 583 | if (DataName == "DistroMatch") { |
| 584 | Target.DistroMatch = json_getValue(DataItem); |
| 585 | } else if (DataName == "DistroVersion") { |
| 586 | Target.VersionMatch = json_getValue(DataItem); |
| 587 | } else if (DataName == "URL") { |
| 588 | Target.URL = json_getValue(DataItem); |
| 589 | } else if (DataName == "Hash") { |
| 590 | Target.Hash = json_getValue(DataItem); |
| 591 | } else if (DataName == "Type") { |
| 592 | auto DataValue = std::string_view {json_getValue(DataItem)}; |
| 593 | if (DataValue == "squashfs") { |
| 594 | Target.Type = FileTargets::FileType::TYPE_SQUASHFS; |
| 595 | } else if (DataValue == "erofs") { |
| 596 | Target.Type = FileTargets::FileType::TYPE_EROFS; |
| 597 | } else { |
| 598 | Target.Type = FileTargets::FileType::TYPE_UNKNOWN; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | bool SupportsSquashFS = WorkingAppsTester::Has_Squashfuse || WorkingAppsTester::Has_Unsquashfs; |
| 603 | bool SupportsEroFS = WorkingAppsTester::Has_EroFSFuse; |
| 604 | if ((Target.Type == FileTargets::FileType::TYPE_SQUASHFS && SupportsSquashFS) || |
| 605 | (Target.Type == FileTargets::FileType::TYPE_EROFS && SupportsEroFS)) { |
| 606 | // If we don't understand the type, then we can't use this. |
| 607 | // Additionally if the type is erofs but the user doesn't have erofsfuse, then we can't use this |
no test coverage detected