mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 11:00:19 +02:00
Merge pull request #4667 from Sonicadvance1/i_dislike_tuple
XXFileHash: Remove a tuple usage
This commit is contained in:
3 files changed
+16
-14
No files matched your search
@@ -749,13 +749,13 @@ bool ValidateCheckExists(const WebFileFetcher::FileTargets& Target) {
|
||||
|
||||
auto Res = XXFileHash::HashFile(PathName);
|
||||
if (Result == 0) {
|
||||
if (Res.first == true && Res.second == ExpectedHash) {
|
||||
if (Res.value_or(0) == ExpectedHash) {
|
||||
fextl::string Text = fextl::fmt::format("{} matches expected hash. Skipping download", filename);
|
||||
ExecWithInfo(Text);
|
||||
return false;
|
||||
}
|
||||
} else if (Result == 1) {
|
||||
if (Res.first == false || Res.second != ExpectedHash) {
|
||||
if (Res.value_or(0) != ExpectedHash) {
|
||||
return AskForConfirmation("RootFS doesn't match hash!\nDo you want to redownload?");
|
||||
} else {
|
||||
fextl::string Text = fextl::fmt::format("{} matches expected hash", filename);
|
||||
@@ -907,12 +907,12 @@ bool ValidateCheckExists(const WebFileFetcher::FileTargets& Target) {
|
||||
fmt::print("Validating RootFS hash...\n");
|
||||
auto Res = XXFileHash::HashFile(PathName);
|
||||
if (Result == 0) {
|
||||
if (Res.first == true && Res.second == ExpectedHash) {
|
||||
if (Res.value_or(0) == ExpectedHash) {
|
||||
fmt::print("{} matches expected hash. Skipping downloading\n", filename);
|
||||
return false;
|
||||
}
|
||||
} else if (Result == 1) {
|
||||
if (Res.first == false || Res.second != ExpectedHash) {
|
||||
if (Res.value_or(0) != ExpectedHash) {
|
||||
fmt::print("RootFS doesn't match hash!\n");
|
||||
return AskForConfirmation("Do you want to redownload?");
|
||||
} else {
|
||||
@@ -1118,8 +1118,8 @@ int main(int argc, char** argv, char** const envp) {
|
||||
|
||||
if (ArgOptions::RemainingArgs.size()) {
|
||||
auto Res = XXFileHash::HashFile(ArgOptions::RemainingArgs[0]);
|
||||
if (Res.first) {
|
||||
fmt::print("{} has hash: {:x}\n", ArgOptions::RemainingArgs[0], Res.second);
|
||||
if (Res.has_value()) {
|
||||
fmt::print("{} has hash: {:x}\n", ArgOptions::RemainingArgs[0], Res.value());
|
||||
} else {
|
||||
fmt::print("Couldn't generate hash for {}\n", ArgOptions::RemainingArgs[0]);
|
||||
}
|
||||
@@ -1178,9 +1178,9 @@ int main(int argc, char** argv, char** const envp) {
|
||||
|
||||
if (std::filesystem::exists(PathName, ec)) {
|
||||
auto Res = XXFileHash::HashFile(PathName);
|
||||
if (Res.first == false || Res.second != ExpectedHash) {
|
||||
if (Res.value_or(0) != ExpectedHash) {
|
||||
fextl::string Text = fextl::fmt::format("Couldn't hash the rootfs or hash didn't match\n");
|
||||
Text += fmt::format("Hash {:x} != Expected Hash {:x}\n", Res.second, ExpectedHash);
|
||||
Text += fmt::format("Hash {:x} != Expected Hash {:x}\n", Res.value_or(0), ExpectedHash);
|
||||
ExecWithInfo(Text);
|
||||
return std::make_pair(-1, true);
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@
|
||||
namespace XXFileHash {
|
||||
// 32MB blocks
|
||||
constexpr static size_t BLOCK_SIZE = 32 * 1024 * 1024;
|
||||
std::pair<bool, uint64_t> HashFile(const fextl::string& Filepath) {
|
||||
std::optional<uint64_t> HashFile(const fextl::string& Filepath) {
|
||||
int fd = open(Filepath.c_str(), O_RDONLY);
|
||||
if (fd == -1) {
|
||||
return {false, 0};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
XXH3_state_t* State {};
|
||||
auto HadError = [fd, &State]() -> std::pair<bool, uint64_t> {
|
||||
auto HadError = [fd, &State]() {
|
||||
close(fd);
|
||||
if (State) {
|
||||
XXH3_freeState(State);
|
||||
}
|
||||
return {false, 0};
|
||||
return std::nullopt;
|
||||
};
|
||||
// Get file size
|
||||
off_t Size = lseek(fd, 0, SEEK_END);
|
||||
@@ -78,6 +78,6 @@ std::pair<bool, uint64_t> HashFile(const fextl::string& Filepath) {
|
||||
XXH3_freeState(State);
|
||||
|
||||
close(fd);
|
||||
return {true, Hash};
|
||||
return Hash;
|
||||
}
|
||||
} // namespace XXFileHash
|
||||
@@ -2,6 +2,8 @@
|
||||
#pragma once
|
||||
#include <FEXCore/fextl/string.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace XXFileHash {
|
||||
std::pair<bool, uint64_t> HashFile(const fextl::string& Filepath);
|
||||
std::optional<uint64_t> HashFile(const fextl::string& Filepath);
|
||||
}
|
||||
Reference in new issue
Block a user