diff --git a/HMCL/src/main/resources/assets/HMCLauncher.exe b/HMCL/src/main/resources/assets/HMCLauncher.exe
index a4b610ff4..9a6ece8e2 100644
Binary files a/HMCL/src/main/resources/assets/HMCLauncher.exe and b/HMCL/src/main/resources/assets/HMCLauncher.exe differ
diff --git a/HMCLauncher/HMCL/HMCL.APS b/HMCLauncher/HMCL/HMCL.APS
index 37e75846d..8801fae64 100644
Binary files a/HMCLauncher/HMCL/HMCL.APS and b/HMCLauncher/HMCL/HMCL.APS differ
diff --git a/HMCLauncher/HMCL/HMCL.rc b/HMCLauncher/HMCL/HMCL.rc
index 80b93e6b6..47458e288 100644
Binary files a/HMCLauncher/HMCL/HMCL.rc and b/HMCLauncher/HMCL/HMCL.rc differ
diff --git a/HMCLauncher/HMCL/HMCL.vcxproj b/HMCLauncher/HMCL/HMCL.vcxproj
index 03e8ac938..4434f09ba 100644
--- a/HMCLauncher/HMCL/HMCL.vcxproj
+++ b/HMCLauncher/HMCL/HMCL.vcxproj
@@ -24,6 +24,7 @@
Win32Proj
HMCL
7.0
+ HMCLauncher
@@ -94,6 +95,7 @@
Windows
true
+ version.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
@@ -129,6 +131,7 @@
true
true
true
+ version.lib;%(AdditionalDependencies)
@@ -153,6 +156,7 @@
+
diff --git a/HMCLauncher/HMCL/HMCL.vcxproj.filters b/HMCLauncher/HMCL/HMCL.vcxproj.filters
index e4fb0ec74..06f818873 100644
--- a/HMCLauncher/HMCL/HMCL.vcxproj.filters
+++ b/HMCLauncher/HMCL/HMCL.vcxproj.filters
@@ -36,6 +36,9 @@
头文件
+
+ 头文件
+
diff --git a/HMCLauncher/HMCL/Version.cpp b/HMCLauncher/HMCL/Version.cpp
index a8b0279a6..9113dc7ef 100644
--- a/HMCLauncher/HMCL/Version.cpp
+++ b/HMCLauncher/HMCL/Version.cpp
@@ -1,7 +1,9 @@
#include "stdafx.h"
#include "Version.h"
-Version::Version(const std::wstring & rawString)
+using namespace std;
+
+Version::Version(const wstring & rawString)
{
int idx = 0;
ver[0] = ver[1] = ver[2] = ver[3] = 0;
diff --git a/HMCLauncher/HMCL/Version.h b/HMCLauncher/HMCL/Version.h
index 2e0784d16..630b67da2 100644
--- a/HMCLauncher/HMCL/Version.h
+++ b/HMCLauncher/HMCL/Version.h
@@ -9,6 +9,18 @@ public:
Version(const std::wstring &rawString);
+ template
+ Version(std::initializer_list ver_list)
+ {
+ int i = 0;
+ for (const auto &data : ver_list)
+ {
+ if (i >= 4)
+ break;
+ ver[i++] = data;
+ }
+ }
+
bool operator<(const Version &other) const
{
for (int i = 0; i < 4; ++i)
@@ -16,5 +28,13 @@ public:
return ver[i] < other.ver[i];
return false;
}
+
+ bool operator<=(const Version &other) const
+ {
+ for (int i = 0; i < 4; ++i)
+ if (ver[i] != other.ver[i])
+ return ver[i] < other.ver[i];
+ return true;
+ }
};
diff --git a/HMCLauncher/HMCL/java.cpp b/HMCLauncher/HMCL/java.cpp
index 93e806e66..f4f9579d5 100644
--- a/HMCLauncher/HMCL/java.cpp
+++ b/HMCLauncher/HMCL/java.cpp
@@ -58,7 +58,7 @@ bool FindJavaByRegistryKey(HKEY rootKey, LPCWSTR subKey, std::wstring & path)
{
if (Version(javaVer) < JAVA_8)
oldJavaFound = true;
- else if (!(Version(javaVer) < JAVA_11))
+ else if (JAVA_11 <= Version(javaVer))
newJavaFound = true;
else
flag = true;
diff --git a/HMCLauncher/HMCL/lang.h b/HMCLauncher/HMCL/lang.h
new file mode 100644
index 000000000..b17749023
--- /dev/null
+++ b/HMCLauncher/HMCL/lang.h
@@ -0,0 +1,4 @@
+#pragma once
+
+#define ERROR_PROMPT L"Java installation cannot be found in this computer, please download it from https://java.com \n" \
+L"δ̨ҵJava 8~Java 10 https://java.com ذװJava"
\ No newline at end of file
diff --git a/HMCLauncher/HMCL/main.cpp b/HMCLauncher/HMCL/main.cpp
index 905b31141..80717d8c8 100644
--- a/HMCLauncher/HMCL/main.cpp
+++ b/HMCLauncher/HMCL/main.cpp
@@ -2,16 +2,30 @@
#include "main.h"
#include "os.h"
#include "java.h"
+#include "lang.h"
using namespace std;
+Version J8(TEXT("8")), J11(TEXT("11"));
-void LaunchJVM(const wstring &javaPath, const wstring &jarPath)
+void RawLaunchJVM(const wstring &javaPath, const wstring &jarPath)
{
if (MyCreateProcess(L"\"" + javaPath + L"\" -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=15 -jar \"" + jarPath + L"\""))
exit(EXIT_SUCCESS);
}
+void LaunchJVM(const wstring &javaPath, const wstring &jarPath)
+{
+ Version javaVersion(L"");
+ if (!MyGetFileVersionInfo(javaPath, javaVersion))
+ return;
+
+ if (J8 <= javaVersion && javaVersion < J11)
+ {
+ RawLaunchJVM(javaPath, jarPath);
+ }
+}
+
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
wstring path, exeName;
@@ -37,9 +51,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
if (FindJava(path))
LaunchJVM(path + L"\\bin\\javaw.exe", exeName);
- // Try java in PATH
- LaunchJVM(L"javaw", exeName);
-
// Or we try to search Java in C:\Program Files.
{
WIN32_FIND_DATA data;
@@ -72,8 +83,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
}
}
- MessageBox(NULL, L"Java installation cannot be found in this computer, please download it from https://java.com \n"
- L"未能在这台电脑上找到Java 8~Java 10,请从 https://java.com 下载安装Java", L"Error", MB_ICONERROR | MB_OK);
+ // Try java in PATH
+ RawLaunchJVM(L"javaw", exeName);
+
+ MessageBox(NULL, ERROR_PROMPT, L"Error", MB_ICONERROR | MB_OK);
ShellExecute(0, 0, L"https://java.com/", 0, 0, SW_SHOW);
return 1;
}
diff --git a/HMCLauncher/HMCL/os.cpp b/HMCLauncher/HMCL/os.cpp
index 820e53819..b86d2108a 100644
--- a/HMCLauncher/HMCL/os.cpp
+++ b/HMCLauncher/HMCL/os.cpp
@@ -106,3 +106,36 @@ bool GetArch(bool & is64Bit)
#error _WIN64 and _WIN32 are both undefined.
#endif
}
+
+bool MyGetFileVersionInfo(const std::wstring & filePath, Version &version)
+{
+ DWORD verHandle = 0;
+ UINT size = 0;
+ LPBYTE lpBuffer = NULL;
+ VS_FIXEDFILEINFO *pFileInfo;
+ DWORD dwSize = GetFileVersionInfoSize(filePath.c_str(), NULL);
+
+ if (!dwSize)
+ return false;
+
+ LPBYTE data = new BYTE[dwSize];
+ if (!GetFileVersionInfo(filePath.c_str(), 0, dwSize, data))
+ {
+ delete[] data;
+ return false;
+ }
+
+ if (!VerQueryValue(data, TEXT("\\"), (LPVOID*)&pFileInfo, &size))
+ {
+ delete[] data;
+ return false;
+ }
+
+ version = Version{
+ (pFileInfo->dwFileVersionMS >> 16) & 0xFFFF,
+ (pFileInfo->dwFileVersionMS >> 0) & 0xFFFF,
+ (pFileInfo->dwFileVersionLS >> 16) & 0xFFFF,
+ (pFileInfo->dwFileVersionLS >> 0) & 0xFFFF
+ };
+ return true;
+}
diff --git a/HMCLauncher/HMCL/os.h b/HMCLauncher/HMCL/os.h
index 406e661b4..e3207899d 100644
--- a/HMCLauncher/HMCL/os.h
+++ b/HMCLauncher/HMCL/os.h
@@ -1,6 +1,7 @@
#pragma once
#include
#include
+#include "Version.h"
const int MAX_KEY_LENGTH = 255;
const int MAX_VALUE_NAME = 16383;
@@ -20,4 +21,6 @@ bool MyCreateProcess(const std::wstring &command);
// Check if file lpPath exists.
bool FindFirstFileExists(LPCWSTR lpPath, DWORD dwFilter);
-bool GetArch(bool &is64Bit);
\ No newline at end of file
+bool GetArch(bool &is64Bit);
+
+bool MyGetFileVersionInfo(const std::wstring &filePath, Version &version);
\ No newline at end of file