9
9
#include < QFileInfo>
10
10
#include < QTextStream>
11
11
#include < QDebug>
12
+ #include < QSettings>
13
+ #include < QApplication>
12
14
#include < string>
13
15
#include < algorithm>
14
16
#include < random>
@@ -45,7 +47,7 @@ void JavaIntegration::startAPIServerCmd() {
45
47
+ jarPath + " \" com.mygcc.api.Main" ;
46
48
javaProcess.start (fullStr.c_str ());
47
49
} else {
48
- qDebug (" %s " , " Invalid java version" ) ;
50
+ qDebug () << " Invalid java version" ;
49
51
50
52
// Open site to show user how to install java
51
53
QDesktopServices::openUrl (QUrl (INSTALL_JAVA_SITE));
@@ -77,9 +79,61 @@ std::string* JavaIntegration::findJava() {
77
79
return new std::string (JAVA_PATH_MAC);
78
80
} else {
79
81
qDebug () << " Known macOS java path NOT found" ;
82
+ return new std::string (" " );
80
83
}
81
84
#endif
82
85
86
+ // User registry keys for finding java on Windows
87
+ #if defined(_WIN32) || defined(_WIN64)
88
+ // 64 bit registry key
89
+ QSettings jreKey64 (" HKEY_LOCAL_MACHINE\\ SOFTWARE" \
90
+ " \\ JavaSoft\\ Java Runtime Environment" ,
91
+ QSettings::Registry64Format);
92
+
93
+ // 32 bit registry key
94
+ QSettings jreKey32 (" HKEY_LOCAL_MACHINE\\ Software\\ WOW6432Node" \
95
+ " \\ JavaSoft\\ Java Runtime Environment" ,
96
+ QSettings::Registry32Format);
97
+
98
+ // If JAVA installed
99
+ if (jreKey32.allKeys ().contains (" CurrentVersion" , Qt::CaseInsensitive) ||
100
+ jreKey64.allKeys ().contains (" CurrentVersion" , Qt::CaseInsensitive)) {
101
+ QSettings *jreKey;
102
+
103
+ if (jreKey32.allKeys ().contains (" CurrentVersion" , Qt::CaseInsensitive)) {
104
+ qDebug (" 32 bit Java FOUND" );
105
+ jreKey = &jreKey32;
106
+ }
107
+ if (jreKey64.allKeys ().contains (" CurrentVersion" , Qt::CaseInsensitive)) {
108
+ qDebug (" 64 bit JAVA FOUND" );
109
+ jreKey = &jreKey64;
110
+ }
111
+
112
+ auto version = jreKey->value (" CurrentVersion" ).toString ();
113
+ qDebug () << " Latest java version identified:" <<
114
+ version.toStdString ().c_str ();
115
+ if (version.contains (" 1.8" )) {
116
+ QSettings jreVerKey (jreKey->fileName () + " \\ " + version,
117
+ QSettings::Registry64Format);
118
+
119
+ if (jreVerKey.childKeys ().contains (" JavaHome" , Qt::CaseInsensitive)) {
120
+ auto javaHome = jreVerKey.value (" JavaHome" ).toString ();
121
+ qDebug () << " Java home identified:" << javaHome.toStdString ().c_str ();
122
+
123
+ return new std::string (javaHome.toStdString () + " \\ bin\\ java.exe" );
124
+ } else {
125
+ qWarning (" JavaHome key NOT FOUND" );
126
+ }
127
+ } else {
128
+ qWarning (" Java version '1.8' NOT FOUND" );
129
+ }
130
+ } else {
131
+ qWarning (" Java NOT FOUND in default install path" );
132
+ }
133
+ return new std::string (" " );
134
+ #endif
135
+
136
+ #if defined(__unix) || defined(__unix__) || defined(__linux__)
83
137
// Check for java in $PATH
84
138
QProcess findJavaExe;
85
139
findJavaExe.start (" java" );
@@ -96,6 +150,7 @@ std::string* JavaIntegration::findJava() {
96
150
} else {
97
151
return new std::string (" " );
98
152
}
153
+ #endif
99
154
}
100
155
101
156
bool JavaIntegration::checkJavaVersion (std::string *javaPath) {
0 commit comments