!54 download: 在有cdn工作前提下,不使用主域名

* download: 在有cdn工作前提下,不使用主域名
* merge: upstream
* README: 英文修正 ubuntu22 的依赖问题
* Merge remote-tracking branch 'upstream/master'
* widget: 检查cdn状况在下载开始前检测,不堵塞ui线程
* Merge remote-tracking branch 'upstream/master'
* readme: 修正 ubuntu 的编译说明
* download: 检查软件源的有效性
This commit is contained in:
Pluto 2022-07-02 13:11:27 +00:00 committed by shenmo
parent 5f9599c47d
commit 958988d93c

View File

@ -19,8 +19,6 @@ DownloadController::DownloadController(QObject *parent)
domains.clear();
domains.append("d.store.deepinos.org.cn");
/*
domains = {
"d1.store.deepinos.org.cn",
@ -33,14 +31,11 @@ DownloadController::DownloadController(QObject *parent)
this->threadNum = domains.size();
}
void DownloadController::setFilename(QString filename)
{
this->filename = filename;
}
void timeSleeper(int time)
{
QElapsedTimer t1;
@ -49,18 +44,6 @@ void timeSleeper(int time)
return;
}
//int checkPID(QString pidCommand){
// system(pidCommand.toUtf8());
// timeSleeper(10);
// QFile downloadStatus("/tmp/spark-store/downloadStatus.txt");
// downloadStatus.open(QFile::ReadOnly);
// auto temp = QString(downloadStatus.readAll()).toUtf8();
// downloadStatus.close();
// if (temp!=""){
// return 1;
// }
// return 0;
//}
/**
* @brief
@ -75,21 +58,25 @@ void DownloadController::startDownload(const QString &url)
return;
}
QtConcurrent::run([=](){
QtConcurrent::run([=]()
{
QFile serverList(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
if (serverList.open(QFile::ReadOnly))
{
QStringList list = QString(serverList.readAll()).trimmed().split("\n");
qDebug() << list << list.size();
domains.clear();
for (int i = 0; i < list.size(); i++) {
if (list.at(i).contains("镜像源 Download only") && i + 1 < list.size()) {
for (int j = i + 1; j < list.size(); j++) {
system("curl -I -s --connect-timeout 5 https://" + list.at(j).toUtf8()
+ "/dcs-repo.gpg-key.asc -w %{http_code} |tail -n1 > /tmp/spark-store/cdnStatus.txt");
for (int i = 0; i < list.size(); i++)
{
if (list.at(i).contains("镜像源 Download only") && i + 1 < list.size())
{
for (int j = i + 1; j < list.size(); j++)
{
system("curl -I -s --connect-timeout 5 https://" + list.at(j).toUtf8() + "/dcs-repo.gpg-key.asc -w %{http_code} |tail -n1 > /tmp/spark-store/cdnStatus.txt");
QFile cdnStatus("/tmp/spark-store/cdnStatus.txt");
if(cdnStatus.open(QFile::ReadOnly) && QString(cdnStatus.readAll()).toUtf8()=="200"){
if (cdnStatus.open(QFile::ReadOnly) && QString(cdnStatus.readAll()).toUtf8() == "200")
{
qDebug() << list.at(j);
domains.append(list.at(j));
}
@ -97,8 +84,13 @@ void DownloadController::startDownload(const QString &url)
break;
}
}
if (domains.size() == 0)
{
domains.append("d.store.deepinos.org.cn");
}
qDebug() << domains << domains.size();
}
QDir tmpdir("/tmp/spark-store/");
QString aria2Command = "-d";
QString aria2Urls = "";
@ -106,6 +98,8 @@ void DownloadController::startDownload(const QString &url)
QString aria2Threads = "-s " + QString::number(domains.size());
QStringList command;
QString downloadDir = "/tmp/spark-store/";
for (int i = 0; i < domains.size(); i++)
{
command.append(replaceDomain(url, domains.at(i)).toUtf8());
@ -129,7 +123,8 @@ void DownloadController::startDownload(const QString &url)
cmd->waitForStarted(); //等待启动完成
QObject::connect(cmd, &QProcess::readyReadStandardOutput,
[&](){
[&]()
{
//通过读取输出计算下载速度
QFileInfo info(tmpdir.absoluteFilePath(filename));
QString message = cmd->readAllStandardOutput().data();
@ -141,38 +136,40 @@ void DownloadController::startDownload(const QString &url)
int downloadSizePlace2 = message.indexOf(")");
int speedPlace1 = message.indexOf("DL:");
int speedPlace2 = message.indexOf("ETA");
if (downloadSizePlace1 != -1 && downloadSizePlace2 != -1){
if (downloadSizePlace1 != -1 && downloadSizePlace2 != -1)
{
percentInfo = message.mid(downloadSizePlace1 + 1, downloadSizePlace2 - downloadSizePlace1 - 1).replace("%", "");
if (percentInfo != "s"){
if (percentInfo != "s")
{
int percentInfoNumber = percentInfo.toUInt();
downloadSize = (percentInfoNumber + 1) * fileSize / 100;
}
}
if (speedPlace1 != -1 && speedPlace2 != -1){
if (speedPlace1 != -1 && speedPlace2 != -1)
{
speedInfo = message.mid(speedPlace1 + 3, speedPlace2 - speedPlace1 - 3);
speedInfo += "/s";
}
qDebug() << percentInfo << speedInfo;
if (downloadSize >= downloadSizeRecord)
{
downloadSizeRecord = downloadSize;
}
if(percentInfo=="OK"){
if (percentInfo == "OK")
{
finished = true;
emit downloadProcess("", fileSize, fileSize);
qDebug() << "finished:" << finished;
}
else{
else
{
emit downloadProcess(speedInfo, downloadSizeRecord, fileSize);
}
});
QObject::connect(cmd, &QProcess::readyReadStandardError,
[&](){
[&]()
{
emit errorOccur(cmd->readAllStandardError().data());
return;
});
@ -186,9 +183,7 @@ void DownloadController::startDownload(const QString &url)
statusSum += status;
}
emit downloadFinished();
});
}
/**
@ -200,10 +195,8 @@ void DownloadController::stopDownload()
QString killCmd = QString("kill -9 %1").arg(pidNumber);
system(killCmd.toUtf8());
qDebug() << "kill aria2!";
}
qint64 DownloadController::getFileSize(const QString &url)
{
QEventLoop event;
@ -224,8 +217,7 @@ qint64 DownloadController::getFileSize(const QString& url)
event.exec();
qint64 fileSize = 0;
if(reply->rawHeader("Accept-Ranges") == QByteArrayLiteral("bytes")
&& reply->hasRawHeader(QString("Content-Length").toLocal8Bit()))
if (reply->rawHeader("Accept-Ranges") == QByteArrayLiteral("bytes") && reply->hasRawHeader(QString("Content-Length").toLocal8Bit()))
{
fileSize = reply->header(QNetworkRequest::ContentLengthHeader).toUInt();
}