mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
http: Use Path for the download file.
This commit is contained in:
+4
-2
@@ -3,6 +3,8 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Buffer.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/Log.h"
|
||||
|
||||
Buffer::Buffer() { }
|
||||
@@ -115,8 +117,8 @@ void Buffer::Printf(const char *fmt, ...) {
|
||||
memcpy(ptr, buffer, retval);
|
||||
}
|
||||
|
||||
bool Buffer::FlushToFile(const char *filename) {
|
||||
FILE *f = fopen(filename, "wb");
|
||||
bool Buffer::FlushToFile(const Path &filename) {
|
||||
FILE *f = File::OpenCFile(filename, "wb");
|
||||
if (!f)
|
||||
return false;
|
||||
if (data_.size()) {
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "Common/Common.h"
|
||||
|
||||
class Path;
|
||||
|
||||
// Acts as a queue. Intended to be as fast as possible for most uses.
|
||||
// Does not do synchronization, must use external mutexes.
|
||||
class Buffer {
|
||||
@@ -66,7 +68,7 @@ public:
|
||||
// Writes the entire buffer to the file descriptor. Also resets the
|
||||
// size to zero. On failure, data remains in buffer and nothing is
|
||||
// written.
|
||||
bool FlushToFile(const char *filename);
|
||||
bool FlushToFile(const Path &filename);
|
||||
|
||||
// Utilities. Try to avoid checking for size.
|
||||
size_t size() const { return data_.size(); }
|
||||
|
||||
@@ -457,7 +457,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
|
||||
return 0;
|
||||
}
|
||||
|
||||
Download::Download(const std::string &url, const std::string &outfile)
|
||||
Download::Download(const std::string &url, const Path &outfile)
|
||||
: progress_(&cancelled_), url_(url), outfile_(outfile) {
|
||||
}
|
||||
|
||||
@@ -552,12 +552,12 @@ void Download::Do() {
|
||||
}
|
||||
|
||||
if (resultCode == 200) {
|
||||
INFO_LOG(IO, "Completed downloading %s to %s", url_.c_str(), outfile_.empty() ? "memory" : outfile_.c_str());
|
||||
if (!outfile_.empty() && !buffer_.FlushToFile(outfile_.c_str())) {
|
||||
ERROR_LOG(IO, "Failed writing download to %s", outfile_.c_str());
|
||||
INFO_LOG(IO, "Completed downloading %s to %s", url_.c_str(), outfile_.empty() ? "memory" : outfile_.ToVisualString().c_str());
|
||||
if (!outfile_.empty() && !buffer_.FlushToFile(outfile_)) {
|
||||
ERROR_LOG(IO, "Failed writing download to %s", outfile_.ToVisualString().c_str());
|
||||
}
|
||||
} else {
|
||||
ERROR_LOG(IO, "Error downloading %s to %s: %i", url_.c_str(), outfile_.c_str(), resultCode);
|
||||
ERROR_LOG(IO, "Error downloading %s to %s: %i", url_.c_str(), outfile_.ToVisualString().c_str(), resultCode);
|
||||
}
|
||||
resultCode_ = resultCode;
|
||||
}
|
||||
@@ -569,7 +569,7 @@ void Download::Do() {
|
||||
completed_ = true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, const std::string &outfile) {
|
||||
std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, const Path &outfile) {
|
||||
std::shared_ptr<Download> dl(new Download(url, outfile));
|
||||
downloads_.push_back(dl);
|
||||
dl->Start();
|
||||
@@ -578,7 +578,7 @@ std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, cons
|
||||
|
||||
std::shared_ptr<Download> Downloader::StartDownloadWithCallback(
|
||||
const std::string &url,
|
||||
const std::string &outfile,
|
||||
const Path &outfile,
|
||||
std::function<void(Download &)> callback) {
|
||||
std::shared_ptr<Download> dl(new Download(url, outfile));
|
||||
dl->SetCallback(callback);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <thread>
|
||||
#include <cstdint>
|
||||
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/Net/NetBuffer.h"
|
||||
#include "Common/Net/Resolve.h"
|
||||
|
||||
@@ -90,7 +91,7 @@ protected:
|
||||
// Not particularly efficient, but hey - it's a background download, that's pretty cool :P
|
||||
class Download {
|
||||
public:
|
||||
Download(const std::string &url, const std::string &outfile);
|
||||
Download(const std::string &url, const Path &outfile);
|
||||
~Download();
|
||||
|
||||
void Start();
|
||||
@@ -108,7 +109,7 @@ public:
|
||||
int ResultCode() const { return resultCode_; }
|
||||
|
||||
std::string url() const { return url_; }
|
||||
std::string outfile() const { return outfile_; }
|
||||
const Path &outfile() const { return outfile_; }
|
||||
|
||||
// If not downloading to a file, access this to get the result.
|
||||
Buffer &buffer() { return buffer_; }
|
||||
@@ -147,7 +148,7 @@ private:
|
||||
Buffer buffer_;
|
||||
std::vector<std::string> responseHeaders_;
|
||||
std::string url_;
|
||||
std::string outfile_;
|
||||
Path outfile_;
|
||||
std::thread thread_;
|
||||
int resultCode_ = 0;
|
||||
bool completed_ = false;
|
||||
@@ -166,11 +167,11 @@ public:
|
||||
CancelAll();
|
||||
}
|
||||
|
||||
std::shared_ptr<Download> StartDownload(const std::string &url, const std::string &outfile);
|
||||
std::shared_ptr<Download> StartDownload(const std::string &url, const Path &outfile);
|
||||
|
||||
std::shared_ptr<Download> StartDownloadWithCallback(
|
||||
const std::string &url,
|
||||
const std::string &outfile,
|
||||
const Path &outfile,
|
||||
std::function<void(Download &)> callback);
|
||||
|
||||
// Drops finished downloads from the list.
|
||||
|
||||
+1
-1
@@ -1301,7 +1301,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
||||
// 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", "", &DownloadCompletedCallback);
|
||||
"http://www.ppsspp.org/version.json", Path(), &DownloadCompletedCallback);
|
||||
dl->SetHidden(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,15 +52,15 @@ GameManager g_GameManager;
|
||||
GameManager::GameManager() {
|
||||
}
|
||||
|
||||
std::string GameManager::GetTempFilename() const {
|
||||
Path GameManager::GetTempFilename() const {
|
||||
#ifdef _WIN32
|
||||
wchar_t tempPath[MAX_PATH];
|
||||
GetTempPath(MAX_PATH, tempPath);
|
||||
wchar_t buffer[MAX_PATH];
|
||||
GetTempFileName(tempPath, L"PSP", 1, buffer);
|
||||
return ConvertWStringToUTF8(buffer);
|
||||
return Path(buffer);
|
||||
#else
|
||||
return (g_Config.memStickDirectory / "ppsspp.dl").ToString();
|
||||
return g_Config.memStickDirectory / "ppsspp.dl";
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ bool GameManager::DownloadAndInstall(std::string storeFileUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filename = GetTempFilename();
|
||||
Path filename = GetTempFilename();
|
||||
curDownload_ = g_DownloadManager.StartDownload(storeFileUrl, filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
bool DetectTexturePackDest(struct zip *z, int iniIndex, Path &dest);
|
||||
void SetInstallError(const std::string &err);
|
||||
|
||||
std::string GetTempFilename() const;
|
||||
Path GetTempFilename() const;
|
||||
std::string GetGameID(const Path &path) const;
|
||||
std::string GetPBPGameID(FileLoader *loader) const;
|
||||
std::string GetISOGameID(FileLoader *loader) const;
|
||||
|
||||
+1
-1
@@ -1192,7 +1192,7 @@ void FrameDumpTestScreen::update() {
|
||||
UIScreen::update();
|
||||
|
||||
if (!listing_) {
|
||||
listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, "");
|
||||
listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, Path());
|
||||
}
|
||||
|
||||
if (listing_ && listing_->Done() && files_.empty()) {
|
||||
|
||||
+2
-2
@@ -134,7 +134,7 @@ void HttpImageFileView::DownloadCompletedCallback(http::Download &download) {
|
||||
void HttpImageFileView::Draw(UIContext &dc) {
|
||||
using namespace Draw;
|
||||
if (!texture_ && !textureFailed_ && !path_.empty() && !download_) {
|
||||
download_ = downloader_->StartDownloadWithCallback(path_, "", std::bind(&HttpImageFileView::DownloadCompletedCallback, this, std::placeholders::_1));
|
||||
download_ = downloader_->StartDownloadWithCallback(path_, Path(), std::bind(&HttpImageFileView::DownloadCompletedCallback, this, std::placeholders::_1));
|
||||
download_->SetHidden(true);
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ StoreScreen::StoreScreen() {
|
||||
|
||||
std::string indexPath = storeBaseUrl + "index.json";
|
||||
|
||||
listing_ = g_DownloadManager.StartDownload(indexPath, "");
|
||||
listing_ = g_DownloadManager.StartDownload(indexPath, Path());
|
||||
}
|
||||
|
||||
StoreScreen::~StoreScreen() {
|
||||
|
||||
Reference in New Issue
Block a user