|
19 | 19 |
|
20 | 20 | import org.jackhuang.hmcl.util.KeyValuePairUtils; |
21 | 21 | import org.jackhuang.hmcl.util.platform.windows.Kernel32; |
22 | | -import org.jackhuang.hmcl.util.platform.windows.WinTypes; |
| 22 | +import org.jackhuang.hmcl.util.platform.windows.WinReg; |
23 | 23 |
|
24 | 24 | import java.io.BufferedReader; |
25 | 25 | import java.io.IOException; |
@@ -150,13 +150,35 @@ public String getJavaExecutable() { |
150 | 150 | OSVersion.Windows windowsVersion = null; |
151 | 151 |
|
152 | 152 | Kernel32 kernel32 = Kernel32.INSTANCE; |
| 153 | + WinReg reg = WinReg.INSTANCE; |
| 154 | + |
153 | 155 | // Get Windows version number |
154 | | - if (kernel32 != null) { |
155 | | - WinTypes.OSVERSIONINFOEXW osVersionInfo = new WinTypes.OSVERSIONINFOEXW(); |
156 | | - if (kernel32.GetVersionExW(osVersionInfo)) { |
157 | | - windowsVersion = new OSVersion.Windows(osVersionInfo.dwMajorVersion, osVersionInfo.dwMinorVersion, osVersionInfo.dwBuildNumber); |
158 | | - } else |
159 | | - System.err.println("Failed to obtain OS version number (" + kernel32.GetLastError() + ")"); |
| 156 | + if (reg != null) { |
| 157 | + var baseVersion = OSVersion.Windows.parse(System.getProperty("os.version")); |
| 158 | + int majorVersion = baseVersion.major(); |
| 159 | + int minorVersion = baseVersion.minor(); |
| 160 | + int buildNumber = baseVersion.build(); |
| 161 | + int revision = baseVersion.revision(); |
| 162 | + |
| 163 | + Object currentBuild = reg.queryValue(WinReg.HKEY.HKEY_LOCAL_MACHINE, |
| 164 | + "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuild"); |
| 165 | + if (currentBuild instanceof String currentBuildStr) { |
| 166 | + try { |
| 167 | + buildNumber = Integer.parseInt(currentBuildStr); |
| 168 | + } catch (NumberFormatException e) { |
| 169 | + System.err.println("Invalid Windows build number: " + currentBuildStr); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + if (majorVersion >= 10) { |
| 174 | + Object ubr = reg.queryValue(WinReg.HKEY.HKEY_LOCAL_MACHINE, |
| 175 | + "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "UBR"); |
| 176 | + |
| 177 | + if (ubr instanceof Integer ubrValue) |
| 178 | + revision = ubrValue; |
| 179 | + } |
| 180 | + |
| 181 | + windowsVersion = new OSVersion.Windows(majorVersion, minorVersion, buildNumber, revision); |
160 | 182 | } |
161 | 183 |
|
162 | 184 | if (windowsVersion == null) { |
@@ -201,6 +223,16 @@ public String getJavaExecutable() { |
201 | 223 | if (osName.equals("Windows 10") && windowsVersion.isAtLeast(OSVersion.WINDOWS_11)) |
202 | 224 | osName = "Windows 11"; |
203 | 225 |
|
| 226 | + if (windowsVersion.isAtLeast(OSVersion.WINDOWS_10) && reg != null) { |
| 227 | + Object displayVersion = reg.queryValue(WinReg.HKEY.HKEY_LOCAL_MACHINE, |
| 228 | + "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "DisplayVersion"); |
| 229 | + |
| 230 | + if (displayVersion instanceof String displayVersionStr |
| 231 | + && displayVersionStr.matches("\\d{2}H\\d")) { |
| 232 | + osName = osName + " " + displayVersionStr; |
| 233 | + } |
| 234 | + } |
| 235 | + |
204 | 236 | SYSTEM_NAME = osName; |
205 | 237 | SYSTEM_VERSION = windowsVersion; |
206 | 238 | SYSTEM_BUILD_NUMBER = windowsVersion.build(); |
|
0 commit comments