Skip to content

Commit

Permalink
修复 HMCLauncher 无法正常识别 Windows on Arm 平台的问题 (#3425)
Browse files Browse the repository at this point in the history
* update

* update

* update
  • Loading branch information
Glavo authored Nov 4, 2024
1 parent 406f365 commit c665877
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 241 deletions.
3 changes: 2 additions & 1 deletion HMCLauncher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.25)
project(HMCLauncher)
if(MSVC)
add_compile_options(/utf-8 /D_UNICODE /W4)
add_definitions(-DUNICODE -D_UNICODE)
add_compile_options(/utf-8 /W4)
add_link_options(/ENTRY:wWinMainCRTStartup)
else()
add_compile_options(-municode -Wall -Wextra -Wpedantic)
Expand Down
4 changes: 2 additions & 2 deletions HMCLauncher/HMCL/HMCL.rc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,4,0,0
PRODUCTVERSION 3,4,0,0
FILEVERSION 3,5,0,0
PRODUCTVERSION 3,5,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand Down
225 changes: 0 additions & 225 deletions HMCLauncher/HMCL/java-download.ps1

This file was deleted.

6 changes: 2 additions & 4 deletions HMCLauncher/HMCL/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

#define ERROR_PROMPT L"The Java runtime environment is required to run HMCL and Minecraft,\n"\
L"Click 'OK' to start downloading java.\n"\
L"Please restart HMCL after installing Java.\n"\
L"Click 'Help' go for help."
L"Please restart HMCL after installing Java."

#define ERROR_PROMPT_ZH L"运行 HMCL 以及 Minecraft 需要 Java 运行时环境,点击“确定”开始下载。\n"\
L"请在安装 Java 完成后重新启动 HMCL。\n"\
L"点击“帮助”寻求帮助。"
L"请在安装 Java 完成后重新启动 HMCL。"
11 changes: 5 additions & 6 deletions HMCLauncher/HMCL/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

bool useChinese = GetUserDefaultUILanguage() == 2052; // zh-CN

SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo);
// TODO: check whether the bundled JRE is valid.
MyArchitecture architecture = MyGetArchitecture();

// First try the Java packaged together.
bool isX64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
bool isARM64 = (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM64);
bool isX64 = architecture == MyArchitecture::X86_64;
bool isARM64 = architecture == MyArchitecture::ARM64;

if (isARM64) {
RawLaunchJVM(L"jre-arm64\\bin\\javaw.exe", workdir, exeName, jvmOptions);
Expand Down Expand Up @@ -143,7 +142,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

if (isARM64) {
downloadLink = L"https://docs.hmcl.net/downloads/windows/arm64.html";
} if (isX64) {
} else if (isX64) {
downloadLink = L"https://docs.hmcl.net/downloads/windows/x86_64.html";
} else {
downloadLink = L"https://docs.hmcl.net/downloads/windows/x86.html";
Expand Down
35 changes: 35 additions & 0 deletions HMCLauncher/HMCL/os.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
#include "stdafx.h"
#include "os.h"

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS2) (HANDLE, PUSHORT, PUSHORT);

MyArchitecture MyGetArchitecture() {
LPFN_ISWOW64PROCESS2 fnIsWow64Process2 = (LPFN_ISWOW64PROCESS2)GetProcAddress(
GetModuleHandle(L"Kernel32.dll"), "IsWow64Process2");
if (NULL != fnIsWow64Process2) {
USHORT uProcessMachine = 0;
USHORT uNativeMachine = 0;
if (fnIsWow64Process2(GetCurrentProcess(), &uProcessMachine, &uNativeMachine)) {
if (uNativeMachine == 0xAA64) {
return MyArchitecture::ARM64;
}

if (uNativeMachine == 0x8664) {
return MyArchitecture::X86_64;
}

return MyArchitecture::X86;
}
}

SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo);

if (systemInfo.wProcessorArchitecture == 12) { // PROCESSOR_ARCHITECTURE_ARM64
return MyArchitecture::ARM64;
}

if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
return MyArchitecture::X86_64;
}

return MyArchitecture::X86;
}

LSTATUS MyRegQueryValue(HKEY hKey, LPCWSTR subKey, DWORD dwType,
std::wstring &out) {
DWORD dwSize = 0;
Expand Down
10 changes: 7 additions & 3 deletions HMCLauncher/HMCL/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
const int MAX_KEY_LENGTH = 255;
const int MAX_VALUE_NAME = 16383;

#ifndef PROCESSOR_ARCHITECTURE_ARM64
#define PROCESSOR_ARCHITECTURE_ARM64 12
#endif
enum MyArchitecture {
X86,
X86_64,
ARM64
};

MyArchitecture MyGetArchitecture();

// Query registry value of class root hKey, key path subKey, stores result in
// parameter out.
Expand Down

0 comments on commit c665877

Please sign in to comment.