mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-03-03 11:37:20 +00:00
http: Specify expected mime types in downloads.
This commit is contained in:
parent
4c51f4761d
commit
afcf6d8e65
@ -509,7 +509,7 @@ int Download::PerformGET(const std::string &url) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
RequestParams req(fileUrl.Resource(), "*/*");
|
||||
RequestParams req(fileUrl.Resource(), acceptMime_);
|
||||
return client.GET(req, &buffer_, responseHeaders_, &progress_);
|
||||
}
|
||||
|
||||
@ -571,8 +571,10 @@ void Download::Do() {
|
||||
completed_ = true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, const Path &outfile) {
|
||||
std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, const Path &outfile, const char *acceptMime) {
|
||||
std::shared_ptr<Download> dl(new Download(url, outfile));
|
||||
if (acceptMime)
|
||||
dl->SetAccept(acceptMime);
|
||||
downloads_.push_back(dl);
|
||||
dl->Start();
|
||||
return dl;
|
||||
@ -581,8 +583,11 @@ std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, cons
|
||||
std::shared_ptr<Download> Downloader::StartDownloadWithCallback(
|
||||
const std::string &url,
|
||||
const Path &outfile,
|
||||
std::function<void(Download &)> callback) {
|
||||
std::function<void(Download &)> callback,
|
||||
const char *acceptMime) {
|
||||
std::shared_ptr<Download> dl(new Download(url, outfile));
|
||||
if (acceptMime)
|
||||
dl->SetAccept(acceptMime);
|
||||
dl->SetCallback(callback);
|
||||
downloads_.push_back(dl);
|
||||
dl->Start();
|
||||
|
@ -120,6 +120,10 @@ public:
|
||||
std::string url() const { return url_; }
|
||||
const Path &outfile() const { return outfile_; }
|
||||
|
||||
void SetAccept(const char *mime) {
|
||||
acceptMime_ = mime;
|
||||
}
|
||||
|
||||
// If not downloading to a file, access this to get the result.
|
||||
Buffer &buffer() { return buffer_; }
|
||||
const Buffer &buffer() const { return buffer_; }
|
||||
@ -160,6 +164,7 @@ private:
|
||||
std::string url_;
|
||||
Path outfile_;
|
||||
std::thread thread_;
|
||||
const char *acceptMime_ = "*/*";
|
||||
int resultCode_ = 0;
|
||||
bool completed_ = false;
|
||||
bool failed_ = false;
|
||||
@ -177,12 +182,13 @@ public:
|
||||
CancelAll();
|
||||
}
|
||||
|
||||
std::shared_ptr<Download> StartDownload(const std::string &url, const Path &outfile);
|
||||
std::shared_ptr<Download> StartDownload(const std::string &url, const Path &outfile, const char *acceptMime = nullptr);
|
||||
|
||||
std::shared_ptr<Download> StartDownloadWithCallback(
|
||||
const std::string &url,
|
||||
const Path &outfile,
|
||||
std::function<void(Download &)> callback);
|
||||
std::function<void(Download &)> callback,
|
||||
const char *acceptMime = nullptr);
|
||||
|
||||
// Drops finished downloads from the list.
|
||||
void Update();
|
||||
|
@ -1393,8 +1393,9 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
||||
// splash screen quickly), but then we'll just show the notification next time instead, we store the
|
||||
// upgrade number in the ini.
|
||||
if (iRunCount % 10 == 0 && bCheckForNewVersion) {
|
||||
std::shared_ptr<http::Download> dl = g_DownloadManager.StartDownloadWithCallback(
|
||||
"http://www.ppsspp.org/version.json", Path(), &DownloadCompletedCallback);
|
||||
const char *versionUrl = "http://www.ppsspp.org/version.json";
|
||||
const char *acceptMime = "application/json, text/*; q=0.9, */*; q=0.8";
|
||||
auto dl = g_DownloadManager.StartDownloadWithCallback(versionUrl, Path(), &DownloadCompletedCallback, acceptMime);
|
||||
dl->SetHidden(true);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,8 @@ bool GameManager::DownloadAndInstall(std::string storeFileUrl) {
|
||||
}
|
||||
|
||||
Path filename = GetTempFilename();
|
||||
curDownload_ = g_DownloadManager.StartDownload(storeFileUrl, filename);
|
||||
const char *acceptMime = "application/zip, application/x-cso, application/x-iso9660-image, application/octet-stream; q=0.9, */*; q=0.8";
|
||||
curDownload_ = g_DownloadManager.StartDownload(storeFileUrl, filename, acceptMime);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1206,7 +1206,8 @@ void FrameDumpTestScreen::update() {
|
||||
UIScreen::update();
|
||||
|
||||
if (!listing_) {
|
||||
listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, Path());
|
||||
const char *acceptMime = "text/html, */*; q=0.8";
|
||||
listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, Path(), acceptMime);
|
||||
}
|
||||
|
||||
if (listing_ && listing_->Done() && files_.empty()) {
|
||||
|
@ -134,7 +134,9 @@ void HttpImageFileView::DownloadCompletedCallback(http::Download &download) {
|
||||
void HttpImageFileView::Draw(UIContext &dc) {
|
||||
using namespace Draw;
|
||||
if (!texture_ && !textureFailed_ && !path_.empty() && !download_) {
|
||||
download_ = downloader_->StartDownloadWithCallback(path_, Path(), std::bind(&HttpImageFileView::DownloadCompletedCallback, this, std::placeholders::_1));
|
||||
auto cb = std::bind(&HttpImageFileView::DownloadCompletedCallback, this, std::placeholders::_1);
|
||||
const char *acceptMime = "image/png, image/jpeg, image/*; q=0.9, */*; q=0.8";
|
||||
download_ = downloader_->StartDownloadWithCallback(path_, Path(), cb, acceptMime);
|
||||
download_->SetHidden(true);
|
||||
}
|
||||
|
||||
@ -366,8 +368,8 @@ StoreScreen::StoreScreen() {
|
||||
loading_ = true;
|
||||
|
||||
std::string indexPath = storeBaseUrl + "index.json";
|
||||
|
||||
listing_ = g_DownloadManager.StartDownload(indexPath, Path());
|
||||
const char *acceptMime = "application/json, */*; q=0.8";
|
||||
listing_ = g_DownloadManager.StartDownload(indexPath, Path(), acceptMime);
|
||||
}
|
||||
|
||||
StoreScreen::~StoreScreen() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user