diff options
| author | 2019-05-06 18:47:27 -0400 | |
|---|---|---|
| committer | 2019-09-30 17:27:23 -0400 | |
| commit | 92b70a3bf9d4657dccc5a5f2cffdd7789946ca14 (patch) | |
| tree | a58a396d65cf762f504542c1836576d2844ce642 /src | |
| parent | boxcat: Add downloading and client for launch parameter data (diff) | |
| download | yuzu-92b70a3bf9d4657dccc5a5f2cffdd7789946ca14.tar.gz yuzu-92b70a3bf9d4657dccc5a5f2cffdd7789946ca14.tar.xz yuzu-92b70a3bf9d4657dccc5a5f2cffdd7789946ca14.zip | |
boxcat: Use Etag header names for file digest
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/vfs_libzip.cpp | 24 | ||||
| -rw-r--r-- | src/core/hle/service/bcat/backend/boxcat.cpp | 21 |
2 files changed, 21 insertions, 24 deletions
diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp index 64f19a0ea..e34474ae0 100644 --- a/src/core/file_sys/vfs_libzip.cpp +++ b/src/core/file_sys/vfs_libzip.cpp | |||
| @@ -15,25 +15,25 @@ VirtualDir ExtractZIP(VirtualFile file) { | |||
| 15 | zip_error_t error{}; | 15 | zip_error_t error{}; |
| 16 | 16 | ||
| 17 | const auto data = file->ReadAllBytes(); | 17 | const auto data = file->ReadAllBytes(); |
| 18 | const auto src = zip_source_buffer_create(data.data(), data.size(), 0, &error); | 18 | std::unique_ptr<zip_source_t, decltype(&zip_source_free)> src{ |
| 19 | zip_source_buffer_create(data.data(), data.size(), 0, &error), zip_source_free}; | ||
| 19 | if (src == nullptr) | 20 | if (src == nullptr) |
| 20 | return nullptr; | 21 | return nullptr; |
| 21 | 22 | ||
| 22 | const auto zip = zip_open_from_source(src, 0, &error); | 23 | std::unique_ptr<zip_t, decltype(&zip_discard)> zip{zip_open_from_source(src.get(), 0, &error), |
| 24 | zip_discard}; | ||
| 23 | if (zip == nullptr) | 25 | if (zip == nullptr) |
| 24 | return nullptr; | 26 | return nullptr; |
| 25 | 27 | ||
| 26 | std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>(); | 28 | std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>(); |
| 27 | 29 | ||
| 28 | const auto num_entries = zip_get_num_entries(zip, 0); | 30 | const auto num_entries = zip_get_num_entries(zip.get(), 0); |
| 29 | if (num_entries == -1) | ||
| 30 | return nullptr; | ||
| 31 | 31 | ||
| 32 | zip_stat_t stat{}; | 32 | zip_stat_t stat{}; |
| 33 | zip_stat_init(&stat); | 33 | zip_stat_init(&stat); |
| 34 | 34 | ||
| 35 | for (std::size_t i = 0; i < num_entries; ++i) { | 35 | for (std::size_t i = 0; i < num_entries; ++i) { |
| 36 | const auto stat_res = zip_stat_index(zip, i, 0, &stat); | 36 | const auto stat_res = zip_stat_index(zip.get(), i, 0, &stat); |
| 37 | if (stat_res == -1) | 37 | if (stat_res == -1) |
| 38 | return nullptr; | 38 | return nullptr; |
| 39 | 39 | ||
| @@ -41,15 +41,14 @@ VirtualDir ExtractZIP(VirtualFile file) { | |||
| 41 | if (name.empty()) | 41 | if (name.empty()) |
| 42 | continue; | 42 | continue; |
| 43 | 43 | ||
| 44 | if (name[name.size() - 1] != '/') { | 44 | if (name.back() != '/') { |
| 45 | const auto file = zip_fopen_index(zip, i, 0); | 45 | std::unique_ptr<zip_file_t, decltype(&zip_fclose)> file{ |
| 46 | zip_fopen_index(zip.get(), i, 0), zip_fclose}; | ||
| 46 | 47 | ||
| 47 | std::vector<u8> buf(stat.size); | 48 | std::vector<u8> buf(stat.size); |
| 48 | if (zip_fread(file, buf.data(), buf.size()) != buf.size()) | 49 | if (zip_fread(file.get(), buf.data(), buf.size()) != buf.size()) |
| 49 | return nullptr; | 50 | return nullptr; |
| 50 | 51 | ||
| 51 | zip_fclose(file); | ||
| 52 | |||
| 53 | const auto parts = FileUtil::SplitPathComponents(stat.name); | 52 | const auto parts = FileUtil::SplitPathComponents(stat.name); |
| 54 | const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back()); | 53 | const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back()); |
| 55 | 54 | ||
| @@ -74,9 +73,6 @@ VirtualDir ExtractZIP(VirtualFile file) { | |||
| 74 | } | 73 | } |
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | zip_source_close(src); | ||
| 78 | zip_close(zip); | ||
| 79 | |||
| 80 | return out; | 76 | return out; |
| 81 | } | 77 | } |
| 82 | 78 | ||
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp index f37f92bf4..31d2e045c 100644 --- a/src/core/hle/service/bcat/backend/boxcat.cpp +++ b/src/core/hle/service/bcat/backend/boxcat.cpp | |||
| @@ -111,18 +111,16 @@ public: | |||
| 111 | 111 | ||
| 112 | DownloadResult DownloadDataZip() { | 112 | DownloadResult DownloadDataZip() { |
| 113 | return DownloadInternal(fmt::format(BOXCAT_PATHNAME_DATA, title_id), TIMEOUT_SECONDS, | 113 | return DownloadInternal(fmt::format(BOXCAT_PATHNAME_DATA, title_id), TIMEOUT_SECONDS, |
| 114 | "Boxcat-Data-Digest", "application/zip"); | 114 | "application/zip"); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | DownloadResult DownloadLaunchParam() { | 117 | DownloadResult DownloadLaunchParam() { |
| 118 | return DownloadInternal(fmt::format(BOXCAT_PATHNAME_LAUNCHPARAM, title_id), | 118 | return DownloadInternal(fmt::format(BOXCAT_PATHNAME_LAUNCHPARAM, title_id), |
| 119 | TIMEOUT_SECONDS / 3, "Boxcat-LaunchParam-Digest", | 119 | TIMEOUT_SECONDS / 3, "application/octet-stream"); |
| 120 | "application/octet-stream"); | ||
| 121 | } | 120 | } |
| 122 | 121 | ||
| 123 | private: | 122 | private: |
| 124 | DownloadResult DownloadInternal(const std::string& resolved_path, u32 timeout_seconds, | 123 | DownloadResult DownloadInternal(const std::string& resolved_path, u32 timeout_seconds, |
| 125 | const std::string& digest_header_name, | ||
| 126 | const std::string& content_type_name) { | 124 | const std::string& content_type_name) { |
| 127 | if (client == nullptr) { | 125 | if (client == nullptr) { |
| 128 | client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT, timeout_seconds); | 126 | client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT, timeout_seconds); |
| @@ -136,10 +134,13 @@ private: | |||
| 136 | 134 | ||
| 137 | if (FileUtil::Exists(path)) { | 135 | if (FileUtil::Exists(path)) { |
| 138 | FileUtil::IOFile file{path, "rb"}; | 136 | FileUtil::IOFile file{path, "rb"}; |
| 139 | std::vector<u8> bytes(file.GetSize()); | 137 | if (file.IsOpen()) { |
| 140 | file.ReadBytes(bytes.data(), bytes.size()); | 138 | std::vector<u8> bytes(file.GetSize()); |
| 141 | const auto digest = DigestFile(bytes); | 139 | file.ReadBytes(bytes.data(), bytes.size()); |
| 142 | headers.insert({digest_header_name, Common::HexArrayToString(digest, false)}); | 140 | const auto digest = DigestFile(bytes); |
| 141 | headers.insert( | ||
| 142 | {std::string("If-None-Match"), Common::HexArrayToString(digest, false)}); | ||
| 143 | } | ||
| 143 | } | 144 | } |
| 144 | 145 | ||
| 145 | const auto response = client->Get(resolved_path.c_str(), headers); | 146 | const auto response = client->Get(resolved_path.c_str(), headers); |
| @@ -227,7 +228,7 @@ void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title, | |||
| 227 | FileUtil::IOFile zip{zip_path, "rb"}; | 228 | FileUtil::IOFile zip{zip_path, "rb"}; |
| 228 | const auto size = zip.GetSize(); | 229 | const auto size = zip.GetSize(); |
| 229 | std::vector<u8> bytes(size); | 230 | std::vector<u8> bytes(size); |
| 230 | if (size == 0 || zip.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) { | 231 | if (!zip.IsOpen() || size == 0 || zip.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) { |
| 231 | LOG_ERROR(Service_BCAT, "Boxcat failed to read ZIP file at path '{}'!", zip_path); | 232 | LOG_ERROR(Service_BCAT, "Boxcat failed to read ZIP file at path '{}'!", zip_path); |
| 232 | failure(); | 233 | failure(); |
| 233 | return; | 234 | return; |
| @@ -335,7 +336,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title) | |||
| 335 | FileUtil::IOFile bin{path, "rb"}; | 336 | FileUtil::IOFile bin{path, "rb"}; |
| 336 | const auto size = bin.GetSize(); | 337 | const auto size = bin.GetSize(); |
| 337 | std::vector<u8> bytes(size); | 338 | std::vector<u8> bytes(size); |
| 338 | if (size == 0 || bin.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) { | 339 | if (!bin.IsOpen() || size == 0 || bin.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) { |
| 339 | LOG_ERROR(Service_BCAT, "Boxcat failed to read launch parameter binary at path '{}'!", | 340 | LOG_ERROR(Service_BCAT, "Boxcat failed to read launch parameter binary at path '{}'!", |
| 340 | path); | 341 | path); |
| 341 | return std::nullopt; | 342 | return std::nullopt; |