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> AndroidConfig::availableNdkPlatforms(const BaseQtVersion *qtVersion) const
|
||||||
{
|
{
|
||||||
QVector<int> availableNdkPlatforms;
|
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;
|
return availableNdkPlatforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,6 @@
|
|||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
|
||||||
#include <QDirIterator>
|
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
@@ -24,7 +24,8 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "androidsdkdownloader.h"
|
#include "androidsdkdownloader.h"
|
||||||
|
#include "utils/filepath.h"
|
||||||
|
#include "utils/qtcprocess.h"
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -34,6 +35,8 @@
|
|||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Q_LOGGING_CATEGORY(sdkDownloaderLog, "qtc.android.sdkDownloader", QtWarningMsg)
|
Q_LOGGING_CATEGORY(sdkDownloaderLog, "qtc.android.sdkDownloader", QtWarningMsg)
|
||||||
}
|
}
|
||||||
@@ -59,21 +62,24 @@ void AndroidSdkDownloader::sslErrors(const QList<QSslError> &sslErrors)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void setSdkFilesExecPermission( const QString &sdkExtractPath)
|
static void setSdkFilesExecPermission( const FilePath &sdkExtractPath)
|
||||||
{
|
{
|
||||||
QDirIterator it(sdkExtractPath + "/tools", QStringList() << "*",
|
const FilePath filePath = sdkExtractPath / "tools";
|
||||||
QDir::Files, QDirIterator::Subdirectories);
|
|
||||||
while (it.hasNext()) {
|
filePath.iterateDirectory(
|
||||||
QFile file(it.next());
|
[](const FilePath &filePath) {
|
||||||
if (!file.fileName().contains('.')) {
|
if (!filePath.fileName().contains('.')) {
|
||||||
QFlags<QFileDevice::Permission> currentPermissions
|
QFlags<QFileDevice::Permission> currentPermissions = filePath.permissions();
|
||||||
= file.permissions();
|
filePath.setPermissions(currentPermissions | QFileDevice::ExeOwner);
|
||||||
file.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()) {
|
if (m_androidConfig.sdkToolsUrl().isEmpty()) {
|
||||||
logError(tr("The SDK Tools download URL is empty."));
|
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.exists()) {
|
||||||
if (!sdkDir.mkpath(".")) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QProcess jarExtractProc;
|
QtcProcess jarExtractProc;
|
||||||
jarExtractProc.setWorkingDirectory(sdkExtractPath);
|
jarExtractProc.setWorkingDirectory(sdkExtractPath);
|
||||||
QString jarCmdPath(jdkPath + "/bin/jar");
|
FilePath jarCmdPath(jdkPath / "/bin/jar");
|
||||||
jarExtractProc.start(jarCmdPath, {"xf", m_sdkFilename});
|
jarExtractProc.setCommand({jarCmdPath, {"xf", m_sdkFilename.path()}});
|
||||||
jarExtractProc.waitForFinished();
|
jarExtractProc.runBlocking();
|
||||||
|
|
||||||
return jarExtractProc.exitCode() ? false : true;
|
return jarExtractProc.exitCode() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AndroidSdkDownloader::verifyFileIntegrity()
|
bool AndroidSdkDownloader::verifyFileIntegrity()
|
||||||
{
|
{
|
||||||
QFile f(m_sdkFilename);
|
QFile f(m_sdkFilename.toString());
|
||||||
if (f.open(QFile::ReadOnly)) {
|
if (f.open(QFile::ReadOnly)) {
|
||||||
QCryptographicHash hash(QCryptographicHash::Sha256);
|
QCryptographicHash hash(QCryptographicHash::Sha256);
|
||||||
if (hash.addData(&f)) {
|
if (hash.addData(&f)) {
|
||||||
@@ -187,11 +194,12 @@ QString AndroidSdkDownloader::getSaveFilename(const QUrl &url)
|
|||||||
return fullPath;
|
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)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +226,7 @@ void AndroidSdkDownloader::downloadFinished(QNetworkReply *reply)
|
|||||||
if (isHttpRedirect(reply)) {
|
if (isHttpRedirect(reply)) {
|
||||||
cancelWithError(QString(tr("Download from %1 was redirected.")).arg(url.toString()));
|
cancelWithError(QString(tr("Download from %1 was redirected.")).arg(url.toString()));
|
||||||
} else {
|
} else {
|
||||||
m_sdkFilename = getSaveFilename(url);
|
m_sdkFilename = FilePath::fromString(getSaveFilename(url));
|
||||||
if (saveToDisk(m_sdkFilename, reply) && verifyFileIntegrity())
|
if (saveToDisk(m_sdkFilename, reply) && verifyFileIntegrity())
|
||||||
emit sdkPackageWriteFinished();
|
emit sdkPackageWriteFinished();
|
||||||
else
|
else
|
||||||
|
@@ -32,6 +32,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
|
||||||
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@ class AndroidSdkDownloader : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
AndroidSdkDownloader();
|
AndroidSdkDownloader();
|
||||||
void downloadAndExtractSdk(const QString &jdkPath, const QString &sdkExtractPath);
|
void downloadAndExtractSdk(const Utils::FilePath &jdkPath, const Utils::FilePath &sdkExtractPath);
|
||||||
static QString dialogTitle();
|
static QString dialogTitle();
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
@@ -53,10 +55,10 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static QString getSaveFilename(const QUrl &url);
|
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);
|
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();
|
bool verifyFileIntegrity();
|
||||||
void cancelWithError(const QString &error);
|
void cancelWithError(const QString &error);
|
||||||
void logError(const QString &error);
|
void logError(const QString &error);
|
||||||
@@ -68,7 +70,7 @@ private:
|
|||||||
|
|
||||||
QNetworkAccessManager m_manager;
|
QNetworkAccessManager m_manager;
|
||||||
QNetworkReply *m_reply = nullptr;
|
QNetworkReply *m_reply = nullptr;
|
||||||
QString m_sdkFilename;
|
Utils::FilePath m_sdkFilename;
|
||||||
QProgressDialog *m_progressDialog = nullptr;
|
QProgressDialog *m_progressDialog = nullptr;
|
||||||
AndroidConfig m_androidConfig;
|
AndroidConfig m_androidConfig;
|
||||||
};
|
};
|
||||||
|
@@ -872,8 +872,8 @@ void AndroidSettingsWidget::downloadSdk()
|
|||||||
if (m_javaSummary->allRowsOk()) {
|
if (m_javaSummary->allRowsOk()) {
|
||||||
auto javaPath = m_ui.OpenJDKLocationPathChooser->filePath();
|
auto javaPath = m_ui.OpenJDKLocationPathChooser->filePath();
|
||||||
m_sdkDownloader.downloadAndExtractSdk(
|
m_sdkDownloader.downloadAndExtractSdk(
|
||||||
javaPath.toString(),
|
javaPath,
|
||||||
m_ui.SDKLocationPathChooser->filePath().cleanPath().toString());
|
m_ui.SDKLocationPathChooser->filePath().cleanPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user