Add option to configure to download system files from Nintendo Update Service (#6269)
Co-authored-by: B3n30 <benediktthomas@gmail.com>
This commit is contained in:
parent
691cb43871
commit
6bef34852c
16 changed files with 1076 additions and 10 deletions
47
src/web_service/nus_download.cpp
Normal file
47
src/web_service/nus_download.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2020 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include <httplib.h>
|
||||
#include "common/logging/log.h"
|
||||
#include "web_service/nus_download.h"
|
||||
|
||||
namespace WebService::NUS {
|
||||
|
||||
std::optional<std::vector<u8>> Download(const std::string& path) {
|
||||
constexpr auto HOST = "http://nus.cdn.c.shop.nintendowifi.net";
|
||||
|
||||
std::unique_ptr<httplib::Client> client = std::make_unique<httplib::Client>(HOST);
|
||||
if (client == nullptr) {
|
||||
LOG_ERROR(WebService, "Invalid URL {}{}", HOST, path);
|
||||
return {};
|
||||
}
|
||||
|
||||
httplib::Request request{
|
||||
.method = "GET",
|
||||
.path = path,
|
||||
};
|
||||
|
||||
client->set_follow_location(true);
|
||||
const auto result = client->send(request);
|
||||
if (!result) {
|
||||
LOG_ERROR(WebService, "GET to {}{} returned null", HOST, path);
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto& response = result.value();
|
||||
if (response.status >= 400) {
|
||||
LOG_ERROR(WebService, "GET to {}{} returned error status code: {}", HOST, path,
|
||||
response.status);
|
||||
return {};
|
||||
}
|
||||
if (!response.headers.contains("content-type")) {
|
||||
LOG_ERROR(WebService, "GET to {}{} returned no content", HOST, path);
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::vector<u8>(response.body.begin(), response.body.end());
|
||||
}
|
||||
|
||||
} // namespace WebService::NUS
|
Loading…
Add table
Add a link
Reference in a new issue