| 734 | } |
| 735 | |
| 736 | bool 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 | |
| 775 | bool ValidateDownloadSelection(const WebFileFetcher::FileTargets& Target) { |
| 776 | fextl::string Text = fextl::fmt::format("Selected Rootfs: {}\n", Target.DistroName); |
no test coverage detected