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

Function ValidateCheckExists

Source/Tools/FEXRootFSFetcher/Main.cpp:736–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

734}
735
736bool ValidateCheckExists(const WebFileFetcher::FileTargets& Target) {
737 fextl::string RootFS = FEXCore::Config::GetDataDirectory() + "RootFS/";
738 auto filename = Target.URL.substr(Target.URL.find_last_of('/') + 1);
739 auto PathName = RootFS + filename;
740 uint64_t ExpectedHash = std::stoul(Target.Hash, nullptr, 16);
741
742 std::error_code ec;
743 if (std::filesystem::exists(PathName, ec)) {
744 const std::array<const fextl::string, 2> Args {
745 "Overwrite",
746 "Validate",
747 };
748 fextl::string Text = filename + " already exists. What do you want to do?";
749 int Result = AskForConfirmationList(Text, Args);
750 if (Result == -1) {
751 return false;
752 }
753
754 auto Res = XXFileHash::HashFile(PathName);
755 if (Result == 0) {
756 if (Res == ExpectedHash) {
757 fextl::string Text = fextl::fmt::format("{} matches expected hash. Skipping download", filename);
758 ExecWithInfo(Text);
759 return false;
760 }
761 } else if (Result == 1) {
762 if (Res != ExpectedHash) {
763 return AskForConfirmation("RootFS doesn't match hash!\nDo you want to redownload?");
764 } else {
765 fextl::string Text = fextl::fmt::format("{} matches expected hash", filename);
766 ExecWithInfo(Text);
767 return false;
768 }
769 }
770 }
771
772 return true;
773}
774
775bool ValidateDownloadSelection(const WebFileFetcher::FileTargets& Target) {
776 fextl::string Text = fextl::fmt::format("Selected Rootfs: {}\n", Target.DistroName);

Callers 1

mainFunction · 0.85

Calls 7

GetDataDirectoryFunction · 0.85
AskForConfirmationListFunction · 0.85
formatFunction · 0.85
ExecWithInfoFunction · 0.85
AskForConfirmationFunction · 0.85
printFunction · 0.85
HashFileFunction · 0.70

Tested by

no test coverage detected