mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 12:56:53 -04:00
Make HMCLLauncher find Java in more places
This commit is contained in:
parent
1b9b0226f2
commit
20ddf60c48
@ -11,6 +11,10 @@ _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
|||||||
_declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
|
_declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LPCWSTR VENDOR_DIRS[] = {
|
||||||
|
L"Java", L"Microsoft", L"BellSoft", L"Zulu", L"Eclipse Foundation", L"AdoptOpenJDK", L"Semeru"
|
||||||
|
};
|
||||||
|
|
||||||
void RawLaunchJVM(const std::wstring &javaPath, const std::wstring &workdir,
|
void RawLaunchJVM(const std::wstring &javaPath, const std::wstring &workdir,
|
||||||
const std::wstring &jarPath) {
|
const std::wstring &jarPath) {
|
||||||
if (MyCreateProcess(
|
if (MyCreateProcess(
|
||||||
@ -63,13 +67,33 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||||||
exeName = exeName.substr(last_slash + 1);
|
exeName = exeName.substr(last_slash + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSVERSIONINFOEX osvi;
|
||||||
|
DWORDLONG dwlConditionMask = 0;
|
||||||
|
int op = VER_GREATER_EQUAL;
|
||||||
|
|
||||||
|
// Initialize the OSVERSIONINFOEX structure.
|
||||||
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
|
||||||
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||||
|
osvi.dwMajorVersion = 6;
|
||||||
|
osvi.dwMinorVersion = 1;
|
||||||
|
|
||||||
|
// Initialize the condition mask.
|
||||||
|
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
|
||||||
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
|
||||||
|
|
||||||
|
// Try downloading Java on Windows 7 or later
|
||||||
|
bool isWin7OrLater = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);
|
||||||
|
|
||||||
SYSTEM_INFO systemInfo;
|
SYSTEM_INFO systemInfo;
|
||||||
GetNativeSystemInfo(&systemInfo);
|
GetNativeSystemInfo(&systemInfo);
|
||||||
|
|
||||||
// TODO: check whether the bundled JRE is valid.
|
// TODO: check whether the bundled JRE is valid.
|
||||||
// First try the Java packaged together.
|
// First try the Java packaged together.
|
||||||
bool isX64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
|
bool isX64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
|
||||||
|
bool isARM64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM64);
|
||||||
|
|
||||||
|
if (isARM64) {
|
||||||
|
RawLaunchJVM(L"jre-arm64\\bin\\javaw.exe", workdir, exeName);
|
||||||
|
}
|
||||||
if (isX64) {
|
if (isX64) {
|
||||||
RawLaunchJVM(L"jre-x64\\bin\\javaw.exe", workdir, exeName);
|
RawLaunchJVM(L"jre-x64\\bin\\javaw.exe", workdir, exeName);
|
||||||
}
|
}
|
||||||
@ -77,11 +101,27 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||||||
|
|
||||||
if (FindJava(path)) LaunchJVM(path + L"\\bin\\javaw.exe", workdir, exeName);
|
if (FindJava(path)) LaunchJVM(path + L"\\bin\\javaw.exe", workdir, exeName);
|
||||||
|
|
||||||
// Or we try to search Java in C:\Program Files\Java.
|
std::wstring programFiles;
|
||||||
FindJavaInDirAndLaunchJVM(L"C:\\Program Files\\Java\\", workdir, exeName);
|
|
||||||
|
|
||||||
// Consider C:\Program Files (x86)\Java
|
// Or we try to search Java in C:\Program Files
|
||||||
FindJavaInDirAndLaunchJVM(L"C:\\Program Files (x86)\\Java\\", workdir, exeName);
|
if (!SUCCEEDED(MySHGetFolderPath(CSIDL_PROGRAM_FILES, programFiles))) programFiles = L"C:\\Program Files\\";
|
||||||
|
for (LPCWSTR vendorDir : VENDOR_DIRS) {
|
||||||
|
std::wstring dir = programFiles;
|
||||||
|
MyPathAppend(dir, vendorDir);
|
||||||
|
MyPathAddBackslash(dir);
|
||||||
|
|
||||||
|
FindJavaInDirAndLaunchJVM(dir, workdir, exeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consider C:\Program Files (x86)
|
||||||
|
if (!SUCCEEDED(MySHGetFolderPath(CSIDL_PROGRAM_FILESX86, programFiles))) programFiles = L"C:\\Program Files (x86)\\";
|
||||||
|
for (LPCWSTR vendorDir : VENDOR_DIRS) {
|
||||||
|
std::wstring dir = programFiles;
|
||||||
|
MyPathAppend(dir, vendorDir);
|
||||||
|
MyPathAddBackslash(dir);
|
||||||
|
|
||||||
|
FindJavaInDirAndLaunchJVM(dir, workdir, exeName);
|
||||||
|
}
|
||||||
|
|
||||||
// Try java in PATH
|
// Try java in PATH
|
||||||
RawLaunchJVM(L"javaw", workdir, exeName);
|
RawLaunchJVM(L"javaw", workdir, exeName);
|
||||||
@ -90,38 +130,23 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||||||
{
|
{
|
||||||
std::wstring buffer;
|
std::wstring buffer;
|
||||||
if (SUCCEEDED(MySHGetFolderPath(CSIDL_APPDATA, buffer)) || SUCCEEDED(MySHGetFolderPath(CSIDL_PROFILE, buffer))) {
|
if (SUCCEEDED(MySHGetFolderPath(CSIDL_APPDATA, buffer)) || SUCCEEDED(MySHGetFolderPath(CSIDL_PROFILE, buffer))) {
|
||||||
MyPathAppend(buffer, L".hmcl");
|
MyPathAppend(buffer, L".hmcl");
|
||||||
MyPathAppend(buffer, L"java");
|
MyPathAppend(buffer, L"java");
|
||||||
if (isX64) {
|
if (isARM64) {
|
||||||
MyPathAppend(buffer, L"windows-x86_64");
|
MyPathAppend(buffer, L"windows-arm64");
|
||||||
} else {
|
} else if (isX64) {
|
||||||
MyPathAppend(buffer, L"windows-x86");
|
MyPathAppend(buffer, L"windows-x86_64");
|
||||||
}
|
} else {
|
||||||
MyPathAddBackslash(buffer);
|
MyPathAppend(buffer, L"windows-x86");
|
||||||
hmclJavaDir = buffer;
|
}
|
||||||
|
MyPathAddBackslash(buffer);
|
||||||
|
hmclJavaDir = buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hmclJavaDir.empty()) {
|
if (!hmclJavaDir.empty()) {
|
||||||
FindJavaInDirAndLaunchJVM(hmclJavaDir, workdir, exeName);
|
FindJavaInDirAndLaunchJVM(hmclJavaDir, workdir, exeName);
|
||||||
if (isX64) {
|
if (isX64 && isWin7OrLater) {
|
||||||
OSVERSIONINFOEX osvi;
|
|
||||||
DWORDLONG dwlConditionMask = 0;
|
|
||||||
int op = VER_GREATER_EQUAL;
|
|
||||||
|
|
||||||
// Initialize the OSVERSIONINFOEX structure.
|
|
||||||
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
|
|
||||||
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
||||||
osvi.dwMajorVersion = 6;
|
|
||||||
osvi.dwMinorVersion = 1;
|
|
||||||
|
|
||||||
// Initialize the condition mask.
|
|
||||||
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
|
|
||||||
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
|
|
||||||
|
|
||||||
// Try downloading Java on Windows 7 or later
|
|
||||||
if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask)) goto error;
|
|
||||||
|
|
||||||
HRSRC scriptFileResource = FindResource(NULL, MAKEINTRESOURCE(ID_SCRIPT_DOWNLOAD_JAVA), RT_RCDATA);
|
HRSRC scriptFileResource = FindResource(NULL, MAKEINTRESOURCE(ID_SCRIPT_DOWNLOAD_JAVA), RT_RCDATA);
|
||||||
if (!scriptFileResource) goto error;
|
if (!scriptFileResource) goto error;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ HRESULT MySHGetFolderPath(int csidl, std::wstring &out) {
|
|||||||
out = std::wstring();
|
out = std::wstring();
|
||||||
out.resize(MAX_PATH);
|
out.resize(MAX_PATH);
|
||||||
|
|
||||||
HRESULT res = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, &out[0]);
|
HRESULT res = SHGetFolderPath(NULL, csidl, NULL, 0, &out[0]);
|
||||||
if (SUCCEEDED(res)) {
|
if (SUCCEEDED(res)) {
|
||||||
out.resize(wcslen(&out[0]));
|
out.resize(wcslen(&out[0]));
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
const int MAX_KEY_LENGTH = 255;
|
const int MAX_KEY_LENGTH = 255;
|
||||||
const int MAX_VALUE_NAME = 16383;
|
const int MAX_VALUE_NAME = 16383;
|
||||||
|
|
||||||
|
#ifndef PROCESSOR_ARCHITECTURE_ARM64
|
||||||
|
#define PROCESSOR_ARCHITECTURE_ARM64 12
|
||||||
|
#endif
|
||||||
|
|
||||||
// Query registry value of class root hKey, key path subKey, stores result in
|
// Query registry value of class root hKey, key path subKey, stores result in
|
||||||
// parameter out.
|
// parameter out.
|
||||||
LSTATUS MyRegQueryValue(HKEY hKey, LPCWSTR subKey, DWORD dwType,
|
LSTATUS MyRegQueryValue(HKEY hKey, LPCWSTR subKey, DWORD dwType,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user