blob: d17295c69b2c44aac6cda29a68e457e37a584dea (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*******************************************************************************
* Copyright (c) 2016 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.internal.qt.core.provider;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
import org.eclipse.cdt.codan.core.cxx.Activator;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.internal.qt.core.QtInstall;
import org.eclipse.cdt.qt.core.IQtInstall;
import org.eclipse.cdt.qt.core.IQtInstallProvider;
import org.eclipse.cdt.utils.WindowsRegistry;
import org.eclipse.core.runtime.Platform;
/**
* Qt Install provider that attempts to find the Qt package as installed using Qt's own installer.
*/
public class QtInstallProvider implements IQtInstallProvider {
private static boolean isWin32 = Platform.getOS().equals(Platform.OS_WIN32);
@Override
public Collection<IQtInstall> getInstalls() {
Path root = getQtRoot();
Path qmake = Paths.get(isWin32 ? "bin/qmake.exe" : "bin/qmake"); //$NON-NLS-1$ //$NON-NLS-2$
if (root != null && Files.exists(root)) {
try {
return Files.walk(root, 2).filter((path) -> Files.exists(path.resolve(qmake)))
.map((path) -> {
QtInstall install = new QtInstall(path.resolve(qmake));
if (isWin32 && "win32-g++".equals(install.getSpec())) { //$NON-NLS-1$
install.setProperty(IToolChain.ATTR_PACKAGE, "qt"); //$NON-NLS-1$ //$NON-NLS-2$
}
return install;
}).collect(Collectors.toList());
} catch (IOException e) {
Activator.log(e);
}
}
return Collections.emptyList();
}
private Path getQtRoot() {
if (isWin32) {
WindowsRegistry registry = WindowsRegistry.getRegistry();
String uninstallKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; //$NON-NLS-1$
String subkey;
for (int i = 0; (subkey = registry.getCurrentUserKeyName(uninstallKey, i)) != null; i++) {
String compKey = uninstallKey + '\\' + subkey;
String displayName = registry.getCurrentUserValue(compKey, "DisplayName"); //$NON-NLS-1$
if ("Qt".equals(displayName)) { //$NON-NLS-1$
String installLocation = registry.getCurrentUserValue(compKey, "InstallLocation"); //$NON-NLS-1$
return Paths.get(installLocation);
}
}
} else {
Path qtDir = Paths.get(System.getProperty("user.home"), "Qt"); //$NON-NLS-1$ //$NON-NLS-2$
if (Files.exists(qtDir)) {
return qtDir;
}
}
return null;
}
// gcc is in C:\Qt\Tools\mingw492_32\bin
}
|