forked from qt-creator/qt-creator
Android: Use FilePath
Change-Id: Ia1cf2a615f0de70038a575f851572e944a9797df Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -364,16 +364,21 @@ void AndroidConfig::parseDependenciesJson()
|
||||
QVector<int> AndroidConfig::availableNdkPlatforms(const BaseQtVersion *qtVersion) const
|
||||
{
|
||||
QVector<int> availableNdkPlatforms;
|
||||
QDirIterator it(ndkLocation(qtVersion).pathAppended("platforms").toString(),
|
||||
QStringList("android-*"),
|
||||
QDir::Dirs);
|
||||
while (it.hasNext()) {
|
||||
const QString &fileName = it.next();
|
||||
availableNdkPlatforms.push_back(
|
||||
fileName.mid(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
|
||||
}
|
||||
Utils::sort(availableNdkPlatforms, std::greater<>());
|
||||
|
||||
ndkLocation(qtVersion)
|
||||
.pathAppended("platforms")
|
||||
.iterateDirectory(
|
||||
[&availableNdkPlatforms](const FilePath &filePath) {
|
||||
availableNdkPlatforms.push_back(
|
||||
filePath.toString()
|
||||
.mid(filePath.path().lastIndexOf('-') + 1)
|
||||
.toInt());
|
||||
return true;
|
||||
},
|
||||
{"android-*"},
|
||||
QDir::Dirs);
|
||||
|
||||
Utils::sort(availableNdkPlatforms, std::greater<>());
|
||||
return availableNdkPlatforms;
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,6 @@
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <QHostAddress>
|
||||
#include <QJsonDocument>
|
||||
#include <QLoggingCategory>
|
||||
|
@@ -24,7 +24,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "androidsdkdownloader.h"
|
||||
|
||||
#include "utils/filepath.h"
|
||||
#include "utils/qtcprocess.h"
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QDir>
|
||||
@@ -34,6 +35,8 @@
|
||||
#include <QCryptographicHash>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace {
|
||||
Q_LOGGING_CATEGORY(sdkDownloaderLog, "qtc.android.sdkDownloader", QtWarningMsg)
|
||||
}
|
||||
@@ -59,21 +62,24 @@ void AndroidSdkDownloader::sslErrors(const QList<QSslError> &sslErrors)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void setSdkFilesExecPermission( const QString &sdkExtractPath)
|
||||
static void setSdkFilesExecPermission( const FilePath &sdkExtractPath)
|
||||
{
|
||||
QDirIterator it(sdkExtractPath + "/tools", QStringList() << "*",
|
||||
QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QFile file(it.next());
|
||||
if (!file.fileName().contains('.')) {
|
||||
QFlags<QFileDevice::Permission> currentPermissions
|
||||
= file.permissions();
|
||||
file.setPermissions(currentPermissions | QFileDevice::ExeOwner);
|
||||
}
|
||||
}
|
||||
const FilePath filePath = sdkExtractPath / "tools";
|
||||
|
||||
filePath.iterateDirectory(
|
||||
[](const FilePath &filePath) {
|
||||
if (!filePath.fileName().contains('.')) {
|
||||
QFlags<QFileDevice::Permission> currentPermissions = filePath.permissions();
|
||||
filePath.setPermissions(currentPermissions | QFileDevice::ExeOwner);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{"*"},
|
||||
QDir::Files,
|
||||
QDirIterator::Subdirectories);
|
||||
}
|
||||
|
||||
void AndroidSdkDownloader::downloadAndExtractSdk(const QString &jdkPath, const QString &sdkExtractPath)
|
||||
void AndroidSdkDownloader::downloadAndExtractSdk(const FilePath &jdkPath, const FilePath &sdkExtractPath)
|
||||
{
|
||||
if (m_androidConfig.sdkToolsUrl().isEmpty()) {
|
||||
logError(tr("The SDK Tools download URL is empty."));
|
||||
@@ -108,28 +114,29 @@ void AndroidSdkDownloader::downloadAndExtractSdk(const QString &jdkPath, const Q
|
||||
});
|
||||
}
|
||||
|
||||
bool AndroidSdkDownloader::extractSdk(const QString &jdkPath, const QString &sdkExtractPath)
|
||||
bool AndroidSdkDownloader::extractSdk(const FilePath &jdkPath, const FilePath &sdkExtractPath)
|
||||
{
|
||||
QDir sdkDir = QDir(sdkExtractPath);
|
||||
QDir sdkDir = sdkExtractPath.toDir();
|
||||
if (!sdkDir.exists()) {
|
||||
if (!sdkDir.mkpath(".")) {
|
||||
logError(QString(tr("Could not create the SDK folder %1.")).arg(sdkExtractPath));
|
||||
logError(QString(tr("Could not create the SDK folder %1."))
|
||||
.arg(sdkExtractPath.toUserOutput()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QProcess jarExtractProc;
|
||||
QtcProcess jarExtractProc;
|
||||
jarExtractProc.setWorkingDirectory(sdkExtractPath);
|
||||
QString jarCmdPath(jdkPath + "/bin/jar");
|
||||
jarExtractProc.start(jarCmdPath, {"xf", m_sdkFilename});
|
||||
jarExtractProc.waitForFinished();
|
||||
FilePath jarCmdPath(jdkPath / "/bin/jar");
|
||||
jarExtractProc.setCommand({jarCmdPath, {"xf", m_sdkFilename.path()}});
|
||||
jarExtractProc.runBlocking();
|
||||
|
||||
return jarExtractProc.exitCode() ? false : true;
|
||||
}
|
||||
|
||||
bool AndroidSdkDownloader::verifyFileIntegrity()
|
||||
{
|
||||
QFile f(m_sdkFilename);
|
||||
QFile f(m_sdkFilename.toString());
|
||||
if (f.open(QFile::ReadOnly)) {
|
||||
QCryptographicHash hash(QCryptographicHash::Sha256);
|
||||
if (hash.addData(&f)) {
|
||||
@@ -187,11 +194,12 @@ QString AndroidSdkDownloader::getSaveFilename(const QUrl &url)
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
bool AndroidSdkDownloader::saveToDisk(const QString &filename, QIODevice *data)
|
||||
bool AndroidSdkDownloader::saveToDisk(const FilePath &filename, QIODevice *data)
|
||||
{
|
||||
QFile file(filename);
|
||||
QFile file(filename.toString());
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
logError(QString(tr("Could not open %1 for writing: %2.")).arg(filename, file.errorString()));
|
||||
logError(QString(tr("Could not open %1 for writing: %2."))
|
||||
.arg(filename.toUserOutput(), file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -218,7 +226,7 @@ void AndroidSdkDownloader::downloadFinished(QNetworkReply *reply)
|
||||
if (isHttpRedirect(reply)) {
|
||||
cancelWithError(QString(tr("Download from %1 was redirected.")).arg(url.toString()));
|
||||
} else {
|
||||
m_sdkFilename = getSaveFilename(url);
|
||||
m_sdkFilename = FilePath::fromString(getSaveFilename(url));
|
||||
if (saveToDisk(m_sdkFilename, reply) && verifyFileIntegrity())
|
||||
emit sdkPackageWriteFinished();
|
||||
else
|
||||
|
@@ -32,6 +32,8 @@
|
||||
#include <QObject>
|
||||
#include <QProgressDialog>
|
||||
|
||||
namespace Utils { class FilePath; }
|
||||
|
||||
namespace Android {
|
||||
namespace Internal {
|
||||
|
||||
@@ -41,7 +43,7 @@ class AndroidSdkDownloader : public QObject
|
||||
|
||||
public:
|
||||
AndroidSdkDownloader();
|
||||
void downloadAndExtractSdk(const QString &jdkPath, const QString &sdkExtractPath);
|
||||
void downloadAndExtractSdk(const Utils::FilePath &jdkPath, const Utils::FilePath &sdkExtractPath);
|
||||
static QString dialogTitle();
|
||||
|
||||
void cancel();
|
||||
@@ -53,10 +55,10 @@ signals:
|
||||
|
||||
private:
|
||||
static QString getSaveFilename(const QUrl &url);
|
||||
bool saveToDisk(const QString &filename, QIODevice *data);
|
||||
bool saveToDisk(const Utils::FilePath &filename, QIODevice *data);
|
||||
static bool isHttpRedirect(QNetworkReply *m_reply);
|
||||
|
||||
bool extractSdk(const QString &jdkPath, const QString &sdkExtractPath);
|
||||
bool extractSdk(const Utils::FilePath &jdkPath, const Utils::FilePath &sdkExtractPath);
|
||||
bool verifyFileIntegrity();
|
||||
void cancelWithError(const QString &error);
|
||||
void logError(const QString &error);
|
||||
@@ -68,7 +70,7 @@ private:
|
||||
|
||||
QNetworkAccessManager m_manager;
|
||||
QNetworkReply *m_reply = nullptr;
|
||||
QString m_sdkFilename;
|
||||
Utils::FilePath m_sdkFilename;
|
||||
QProgressDialog *m_progressDialog = nullptr;
|
||||
AndroidConfig m_androidConfig;
|
||||
};
|
||||
|
@@ -872,8 +872,8 @@ void AndroidSettingsWidget::downloadSdk()
|
||||
if (m_javaSummary->allRowsOk()) {
|
||||
auto javaPath = m_ui.OpenJDKLocationPathChooser->filePath();
|
||||
m_sdkDownloader.downloadAndExtractSdk(
|
||||
javaPath.toString(),
|
||||
m_ui.SDKLocationPathChooser->filePath().cleanPath().toString());
|
||||
javaPath,
|
||||
m_ui.SDKLocationPathChooser->filePath().cleanPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user