boxcat: Use Etag header names for file digest
This commit is contained in:
parent
e8183f9ef0
commit
92b70a3bf9
|
@ -15,25 +15,25 @@ VirtualDir ExtractZIP(VirtualFile file) {
|
|||
zip_error_t error{};
|
||||
|
||||
const auto data = file->ReadAllBytes();
|
||||
const auto src = zip_source_buffer_create(data.data(), data.size(), 0, &error);
|
||||
std::unique_ptr<zip_source_t, decltype(&zip_source_free)> src{
|
||||
zip_source_buffer_create(data.data(), data.size(), 0, &error), zip_source_free};
|
||||
if (src == nullptr)
|
||||
return nullptr;
|
||||
|
||||
const auto zip = zip_open_from_source(src, 0, &error);
|
||||
std::unique_ptr<zip_t, decltype(&zip_discard)> zip{zip_open_from_source(src.get(), 0, &error),
|
||||
zip_discard};
|
||||
if (zip == nullptr)
|
||||
return nullptr;
|
||||
|
||||
std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>();
|
||||
|
||||
const auto num_entries = zip_get_num_entries(zip, 0);
|
||||
if (num_entries == -1)
|
||||
return nullptr;
|
||||
const auto num_entries = zip_get_num_entries(zip.get(), 0);
|
||||
|
||||
zip_stat_t stat{};
|
||||
zip_stat_init(&stat);
|
||||
|
||||
for (std::size_t i = 0; i < num_entries; ++i) {
|
||||
const auto stat_res = zip_stat_index(zip, i, 0, &stat);
|
||||
const auto stat_res = zip_stat_index(zip.get(), i, 0, &stat);
|
||||
if (stat_res == -1)
|
||||
return nullptr;
|
||||
|
||||
|
@ -41,15 +41,14 @@ VirtualDir ExtractZIP(VirtualFile file) {
|
|||
if (name.empty())
|
||||
continue;
|
||||
|
||||
if (name[name.size() - 1] != '/') {
|
||||
const auto file = zip_fopen_index(zip, i, 0);
|
||||
if (name.back() != '/') {
|
||||
std::unique_ptr<zip_file_t, decltype(&zip_fclose)> file{
|
||||
zip_fopen_index(zip.get(), i, 0), zip_fclose};
|
||||
|
||||
std::vector<u8> buf(stat.size);
|
||||
if (zip_fread(file, buf.data(), buf.size()) != buf.size())
|
||||
if (zip_fread(file.get(), buf.data(), buf.size()) != buf.size())
|
||||
return nullptr;
|
||||
|
||||
zip_fclose(file);
|
||||
|
||||
const auto parts = FileUtil::SplitPathComponents(stat.name);
|
||||
const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back());
|
||||
|
||||
|
@ -74,9 +73,6 @@ VirtualDir ExtractZIP(VirtualFile file) {
|
|||
}
|
||||
}
|
||||
|
||||
zip_source_close(src);
|
||||
zip_close(zip);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,18 +111,16 @@ public:
|
|||
|
||||
DownloadResult DownloadDataZip() {
|
||||
return DownloadInternal(fmt::format(BOXCAT_PATHNAME_DATA, title_id), TIMEOUT_SECONDS,
|
||||
"Boxcat-Data-Digest", "application/zip");
|
||||
"application/zip");
|
||||
}
|
||||
|
||||
DownloadResult DownloadLaunchParam() {
|
||||
return DownloadInternal(fmt::format(BOXCAT_PATHNAME_LAUNCHPARAM, title_id),
|
||||
TIMEOUT_SECONDS / 3, "Boxcat-LaunchParam-Digest",
|
||||
"application/octet-stream");
|
||||
TIMEOUT_SECONDS / 3, "application/octet-stream");
|
||||
}
|
||||
|
||||
private:
|
||||
DownloadResult DownloadInternal(const std::string& resolved_path, u32 timeout_seconds,
|
||||
const std::string& digest_header_name,
|
||||
const std::string& content_type_name) {
|
||||
if (client == nullptr) {
|
||||
client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT, timeout_seconds);
|
||||
|
@ -136,10 +134,13 @@ private:
|
|||
|
||||
if (FileUtil::Exists(path)) {
|
||||
FileUtil::IOFile file{path, "rb"};
|
||||
std::vector<u8> bytes(file.GetSize());
|
||||
file.ReadBytes(bytes.data(), bytes.size());
|
||||
const auto digest = DigestFile(bytes);
|
||||
headers.insert({digest_header_name, Common::HexArrayToString(digest, false)});
|
||||
if (file.IsOpen()) {
|
||||
std::vector<u8> bytes(file.GetSize());
|
||||
file.ReadBytes(bytes.data(), bytes.size());
|
||||
const auto digest = DigestFile(bytes);
|
||||
headers.insert(
|
||||
{std::string("If-None-Match"), Common::HexArrayToString(digest, false)});
|
||||
}
|
||||
}
|
||||
|
||||
const auto response = client->Get(resolved_path.c_str(), headers);
|
||||
|
@ -227,7 +228,7 @@ void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title,
|
|||
FileUtil::IOFile zip{zip_path, "rb"};
|
||||
const auto size = zip.GetSize();
|
||||
std::vector<u8> bytes(size);
|
||||
if (size == 0 || zip.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
||||
if (!zip.IsOpen() || size == 0 || zip.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
||||
LOG_ERROR(Service_BCAT, "Boxcat failed to read ZIP file at path '{}'!", zip_path);
|
||||
failure();
|
||||
return;
|
||||
|
@ -335,7 +336,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title)
|
|||
FileUtil::IOFile bin{path, "rb"};
|
||||
const auto size = bin.GetSize();
|
||||
std::vector<u8> bytes(size);
|
||||
if (size == 0 || bin.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
||||
if (!bin.IsOpen() || size == 0 || bin.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
||||
LOG_ERROR(Service_BCAT, "Boxcat failed to read launch parameter binary at path '{}'!",
|
||||
path);
|
||||
return std::nullopt;
|
||||
|
|
Loading…
Reference in New Issue