forked from qt-creator/qt-creator
Android: Enforce portable/clean Android SDK path
When reading a path from file chooser, settings or environment variable, make sure it is portable and "clean". Avoids extra compiler registrations, invalid Kits and similar issues. Fixes: QTCREATORBUG-26092 Change-Id: I2a11563f40973d5f595bf00e37ff045a503aa9f7 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -227,7 +227,7 @@ void AndroidConfig::load(const QSettings &settings)
|
||||
// user settings
|
||||
m_emulatorArgs = settings.value(EmulatorArgsKey,
|
||||
QStringList({"-netdelay", "none", "-netspeed", "full"})).toStringList();
|
||||
m_sdkLocation = FilePath::fromString(settings.value(SDKLocationKey).toString());
|
||||
m_sdkLocation = FilePath::fromUserInput(settings.value(SDKLocationKey).toString()).cleanPath();
|
||||
m_customNdkList = settings.value(CustomNdkLocationsKey).toStringList();
|
||||
m_sdkManagerToolArgs = settings.value(SDKManagerToolArgsKey).toStringList();
|
||||
m_openJDKLocation = FilePath::fromString(settings.value(OpenJDKLocationKey).toString());
|
||||
@@ -239,7 +239,7 @@ void AndroidConfig::load(const QSettings &settings)
|
||||
if (reader.load(FilePath::fromString(sdkSettingsFileName()))
|
||||
&& settings.value(changeTimeStamp).toInt() != QFileInfo(sdkSettingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) {
|
||||
// persisten settings
|
||||
m_sdkLocation = FilePath::fromString(reader.restoreValue(SDKLocationKey, m_sdkLocation.toString()).toString());
|
||||
m_sdkLocation = FilePath::fromUserInput(reader.restoreValue(SDKLocationKey, m_sdkLocation.toString()).toString()).cleanPath();
|
||||
m_customNdkList = reader.restoreValue(CustomNdkLocationsKey).toStringList();
|
||||
m_sdkManagerToolArgs = reader.restoreValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs).toStringList();
|
||||
m_openJDKLocation = FilePath::fromString(reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toString()).toString());
|
||||
@@ -1024,7 +1024,7 @@ FilePath AndroidConfig::defaultSdkPath()
|
||||
{
|
||||
QString sdkFromEnvVar = QString::fromLocal8Bit(getenv("ANDROID_SDK_ROOT"));
|
||||
if (!sdkFromEnvVar.isEmpty())
|
||||
return Utils::FilePath::fromString(sdkFromEnvVar);
|
||||
return FilePath::fromUserInput(sdkFromEnvVar).cleanPath();
|
||||
|
||||
// Set default path of SDK as used by Android Studio
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
|
@@ -596,7 +596,7 @@ void AndroidSettingsWidget::validateOpenSsl()
|
||||
|
||||
void AndroidSettingsWidget::onSdkPathChanged()
|
||||
{
|
||||
const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath();
|
||||
const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath().cleanPath();
|
||||
m_androidConfig.setSdkLocation(sdkPath);
|
||||
FilePath currentOpenSslPath = m_androidConfig.openSslLocation();
|
||||
if (currentOpenSslPath.isEmpty() || !currentOpenSslPath.exists())
|
||||
@@ -608,7 +608,7 @@ void AndroidSettingsWidget::onSdkPathChanged()
|
||||
|
||||
void AndroidSettingsWidget::validateSdk()
|
||||
{
|
||||
const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath();
|
||||
const FilePath sdkPath = m_ui.SDKLocationPathChooser->filePath().cleanPath();
|
||||
m_androidConfig.setSdkLocation(sdkPath);
|
||||
|
||||
m_androidSummary->setPointValid(SdkPathExistsRow, m_androidConfig.sdkLocation().exists());
|
||||
@@ -865,14 +865,15 @@ void AndroidSettingsWidget::downloadSdk()
|
||||
}
|
||||
|
||||
const QString message = tr("Download and install Android SDK Tools to: %1?")
|
||||
.arg(m_ui.SDKLocationPathChooser->filePath().toUserOutput());
|
||||
.arg(m_ui.SDKLocationPathChooser->filePath().cleanPath().toUserOutput());
|
||||
auto userInput = QMessageBox::information(this, AndroidSdkDownloader::dialogTitle(),
|
||||
message, QMessageBox::Yes | QMessageBox::No);
|
||||
if (userInput == QMessageBox::Yes) {
|
||||
if (m_javaSummary->allRowsOk()) {
|
||||
auto javaPath = m_ui.OpenJDKLocationPathChooser->filePath();
|
||||
m_sdkDownloader.downloadAndExtractSdk(javaPath.toString(),
|
||||
m_ui.SDKLocationPathChooser->filePath().toString());
|
||||
m_sdkDownloader.downloadAndExtractSdk(
|
||||
javaPath.toString(),
|
||||
m_ui.SDKLocationPathChooser->filePath().cleanPath().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user