mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-10 20:37:30 -04:00
feat: update HMCLauncher. Closes #1014.
This commit is contained in:
parent
271fb4ce87
commit
ae8600c882
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "java.h"
|
#include "java.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
@ -1,105 +1,105 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "java.h"
|
#include "java.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
|
||||||
Version J8(TEXT("8"));
|
Version J8(TEXT("8"));
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
||||||
_declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
|
_declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
L"\"" + javaPath +
|
L"\"" + javaPath +
|
||||||
L"\" -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=15 -jar \"" +
|
L"\" -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=15 -jar \"" +
|
||||||
jarPath + L"\"",
|
jarPath + L"\"",
|
||||||
workdir))
|
workdir))
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchJVM(const std::wstring &javaPath, const std::wstring &workdir,
|
void LaunchJVM(const std::wstring &javaPath, const std::wstring &workdir,
|
||||||
const std::wstring &jarPath) {
|
const std::wstring &jarPath) {
|
||||||
Version javaVersion(L"");
|
Version javaVersion(L"");
|
||||||
if (!MyGetFileVersionInfo(javaPath, javaVersion)) return;
|
if (!MyGetFileVersionInfo(javaPath, javaVersion)) return;
|
||||||
|
|
||||||
if (J8 <= javaVersion) {
|
if (J8 <= javaVersion) {
|
||||||
RawLaunchJVM(javaPath, workdir, jarPath);
|
RawLaunchJVM(javaPath, workdir, jarPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
LPWSTR lpCmdLine, int nCmdShow) {
|
LPWSTR lpCmdLine, int nCmdShow) {
|
||||||
std::wstring path, exeName;
|
std::wstring path, exeName;
|
||||||
|
|
||||||
// Since Jar file is appended to this executable, we should first get the
|
// Since Jar file is appended to this executable, we should first get the
|
||||||
// location of JAR file.
|
// location of JAR file.
|
||||||
if (ERROR_SUCCESS != MyGetModuleFileName(NULL, exeName)) return 1;
|
if (ERROR_SUCCESS != MyGetModuleFileName(NULL, exeName)) return 1;
|
||||||
|
|
||||||
std::wstring workdir;
|
std::wstring workdir;
|
||||||
size_t last_slash = exeName.find_last_of(L"/\\");
|
size_t last_slash = exeName.find_last_of(L"/\\");
|
||||||
if (last_slash != std::wstring::npos && last_slash + 1 < exeName.size()) {
|
if (last_slash != std::wstring::npos && last_slash + 1 < exeName.size()) {
|
||||||
workdir = exeName.substr(0, last_slash);
|
workdir = exeName.substr(0, last_slash);
|
||||||
exeName = exeName.substr(last_slash + 1);
|
exeName = exeName.substr(last_slash + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 is64Bit = false;
|
bool is64Bit = false;
|
||||||
GetArch(is64Bit); // if failed to determine architecture of operating system,
|
GetArch(is64Bit); // if failed to determine architecture of operating system,
|
||||||
// consider 32-bit.
|
// consider 32-bit.
|
||||||
|
|
||||||
if (is64Bit) {
|
if (is64Bit) {
|
||||||
RawLaunchJVM(L"jre-x64\\bin\\javaw.exe", workdir, exeName);
|
RawLaunchJVM(L"jre-x64\\bin\\javaw.exe", workdir, exeName);
|
||||||
} else {
|
} else {
|
||||||
RawLaunchJVM(L"jre-x86\\bin\\javaw.exe", workdir, exeName);
|
RawLaunchJVM(L"jre-x86\\bin\\javaw.exe", workdir, exeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
// Or we try to search Java in C:\Program Files.
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA data;
|
WIN32_FIND_DATA data;
|
||||||
HANDLE hFind = FindFirstFile(L"C:\\Program Files\\Java\\*",
|
HANDLE hFind = FindFirstFile(L"C:\\Program Files\\Java\\*",
|
||||||
&data); // Search all subdirectory
|
&data); // Search all subdirectory
|
||||||
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
do {
|
do {
|
||||||
std::wstring javaw = std::wstring(L"C:\\Program Files\\Java\\") +
|
std::wstring javaw = std::wstring(L"C:\\Program Files\\Java\\") +
|
||||||
data.cFileName + std::wstring(L"\\bin\\javaw.exe");
|
data.cFileName + std::wstring(L"\\bin\\javaw.exe");
|
||||||
if (FindFirstFileExists(javaw.c_str(), 0)) {
|
if (FindFirstFileExists(javaw.c_str(), 0)) {
|
||||||
LaunchJVM(javaw, workdir, exeName);
|
LaunchJVM(javaw, workdir, exeName);
|
||||||
}
|
}
|
||||||
} while (FindNextFile(hFind, &data));
|
} while (FindNextFile(hFind, &data));
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consider C:\Program Files (x86)\Java
|
// Consider C:\Program Files (x86)\Java
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA data;
|
WIN32_FIND_DATA data;
|
||||||
HANDLE hFind = FindFirstFile(L"C:\\Program Files (x86)\\Java\\*",
|
HANDLE hFind = FindFirstFile(L"C:\\Program Files (x86)\\Java\\*",
|
||||||
&data); // Search all subdirectory
|
&data); // Search all subdirectory
|
||||||
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
do {
|
do {
|
||||||
std::wstring javaw = std::wstring(L"C:\\Program Files (x86)\\Java\\") +
|
std::wstring javaw = std::wstring(L"C:\\Program Files (x86)\\Java\\") +
|
||||||
data.cFileName + L"\\bin\\javaw.exe";
|
data.cFileName + L"\\bin\\javaw.exe";
|
||||||
if (FindFirstFileExists(javaw.c_str(), 0)) {
|
if (FindFirstFileExists(javaw.c_str(), 0)) {
|
||||||
LaunchJVM(javaw, workdir, exeName);
|
LaunchJVM(javaw, workdir, exeName);
|
||||||
}
|
}
|
||||||
} while (FindNextFile(hFind, &data));
|
} while (FindNextFile(hFind, &data));
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try java in PATH
|
// Try java in PATH
|
||||||
RawLaunchJVM(L"javaw", workdir, exeName);
|
RawLaunchJVM(L"javaw", workdir, exeName);
|
||||||
|
|
||||||
MessageBox(NULL, ERROR_PROMPT, L"Error", MB_ICONERROR | MB_OK);
|
MessageBox(NULL, ERROR_PROMPT, L"Error", MB_ICONERROR | MB_OK);
|
||||||
ShellExecute(0, 0, L"https://java.com/", 0, 0, SW_SHOW);
|
ShellExecute(0, 0, L"https://java.com/", 0, 0, SW_SHOW);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user