MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / DownloadFile

Method DownloadFile

pcsx2-qt/QtHost.cpp:1611–1666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1609}
1610
1611std::optional<bool> QtHost::DownloadFile(QWidget* parent, const QString& title, std::string url, std::vector<u8>* data)
1612{
1613 static constexpr u32 HTTP_POLL_INTERVAL = 10;
1614
1615 std::unique_ptr<HTTPDownloader> http = HTTPDownloader::Create(Host::GetHTTPUserAgent());
1616 if (!http)
1617 {
1618 QMessageBox::critical(parent, qApp->translate("EmuThread", "Error"), qApp->translate("EmuThread", "Failed to create HTTPDownloader."));
1619 return false;
1620 }
1621
1622 std::optional<bool> download_result;
1623 const std::string::size_type url_file_part_pos = url.rfind('/');
1624 QtModalProgressCallback progress(parent);
1625 progress.GetDialog().setLabelText(
1626 qApp->translate("EmuThread", "Downloading %1...").arg(QtUtils::StringViewToQString(std::string_view(url).substr((url_file_part_pos != std::string::npos) ? (url_file_part_pos + 1) : 0))));
1627 progress.GetDialog().setWindowTitle(title);
1628 progress.GetDialog().setWindowIcon(GetAppIcon());
1629 progress.SetCancellable(true);
1630
1631 http->CreateRequest(
1632 std::move(url), [parent, data, &download_result](s32 status_code, const std::string&, std::vector<u8> hdata) {
1633 if (status_code == HTTPDownloader::HTTP_STATUS_CANCELLED)
1634 return;
1635
1636 if (status_code != HTTPDownloader::HTTP_STATUS_OK)
1637 {
1638 QMessageBox::critical(parent, qApp->translate("EmuThread", "Error"),
1639 qApp->translate("EmuThread", "Download failed with HTTP status code %1.").arg(status_code));
1640 download_result = false;
1641 return;
1642 }
1643
1644 if (hdata.empty())
1645 {
1646 QMessageBox::critical(parent, qApp->translate("EmuThread", "Error"),
1647 qApp->translate("EmuThread", "Download failed: Data is empty.").arg(status_code));
1648
1649 download_result = false;
1650 return;
1651 }
1652
1653 *data = std::move(hdata);
1654 download_result = true;
1655 },
1656 &progress);
1657
1658 // Block until completion.
1659 while (http->HasAnyRequests())
1660 {
1661 QApplication::processEvents(QEventLoop::AllEvents, HTTP_POLL_INTERVAL);
1662 http->PollRequests();
1663 }
1664
1665 return download_result;
1666}
1667
1668bool QtHost::DownloadFile(QWidget* parent, const QString& title, std::string url, const std::string& path)

Callers

nothing calls this directly

Calls 14

StringViewToQStringFunction · 0.85
rfindMethod · 0.80
argMethod · 0.80
substrMethod · 0.80
setWindowTitleMethod · 0.80
CreateRequestMethod · 0.80
HasAnyRequestsMethod · 0.80
PollRequestsMethod · 0.80
CreateFunction · 0.50
SetCancellableMethod · 0.45
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected