MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / GetRootFSLinks

Function GetRootFSLinks

Source/Tools/FEXRootFSFetcher/Main.cpp:550–613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

548}
549
550std::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

Callers 1

mainFunction · 0.85

Calls 10

DownloadToStringFunction · 0.85
CreateJSONFunction · 0.85
printFunction · 0.85
abortFunction · 0.85
json_getPropertyFunction · 0.85
fprintfFunction · 0.85
json_getChildFunction · 0.85
json_getSiblingFunction · 0.85
json_getNameFunction · 0.85
json_getValueFunction · 0.85

Tested by

no test coverage detected